-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetyears.py
More file actions
29 lines (25 loc) · 990 Bytes
/
getyears.py
File metadata and controls
29 lines (25 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
##
# getyears.pro
# looks at each of the month directories to determine which years are present. In several cases, a year from the
# dataset download was omitted, probably due to technical issues during the download
##
from os import listdir, walk
from os.path import isfile, join
import fnmatch
indir = '/Users/hg1/data/MOD13'
for root, dirs, files in walk(indir):
for name in dirs:
sub1 = join(root, name)
# get files in the month file
# get the files in month directory, figure out the year and write to outfile
outfile = join(sub1, 'years.txt')
f = open(outfile, 'w')
for root0, dirs0, files0 in walk(sub1):
for name in files0:
mstring = '*.A20*'
if (fnmatch.fnmatch(name, mstring)):
pos = name.find('.A20')
yearstring = name[pos + 2:pos + 6]
print(yearstring)
f.write(yearstring + '\n')
f.close()