- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract.py
More file actions
Latest commit
84 lines (64 loc) · 2.86 KB
/
Copy pathextract.py
File metadata and controls
84 lines (64 loc) · 2.86 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
importrecord
importos
importsubprocess
datapath='/home/gis-admin/modis/data/'#path to store the .tif files
tmppath='/home/gis-admin/modis/tmp/'#path to store the .vrt files
rawpath='/home/gis-admin/modis/raw/'#path to store downloaded files
libspath='/home/gis-admin/libs/'#path where the scripts are stored
'''
-----------------------------------------------------------------------------------------------------------------------------------
def juliandate(filename) : finds the juilan date. 'filename' should be the date.txt file ie; say 2000.02.18.txt
def get_name(filename,layers=0): this function returns the name of the file type supplied. When the 'filename' is '.txt' then it searches for files of the extension '.txt' and returns their name.
When called with the layers specified, it returns the name of the layer corresponding to the subset
def getlayers(textfilename): finds all the layers the are in the .hdf files. 'textfilename' should be the date.txt file ie; say
2000.02.18.txt
-----------------------------------------------------------------------------------------------------------------------------------
'''
defjuliandate(filename):#get the julian dates of the files
try:
read=record.create_dict(filename)
forxinread:
if'h26v05'inx :
jdate=x.split('.h26v05')[0].split('.')[1]
returnjdate
except :
print"extract.juliandate() : could not extract date"
defget_name(filename,layers=0):#find the name of the vrt files and text files as stored in the directory
try:
iflayers!=0:
os.chdir(rawpath)
subset=filename
vrts=layers
#vrts=[x.split('days')[1].translate(None,'_') for x in layers ]
vrtname=[vrts[i] foriinrange(0,12) ifsubset[i]==1]
returnvrtname
else :
os.chdir(rawpath)
text_name=subprocess.check_output('ls | grep '+filename,shell=True)
text_name=text_name.translate(None,'\n')
textname=text_name.replace(' ','_')
os.rename(text_name,textname)
returntextname
except (RuntimeError, TypeError, NameError,ValueError):
print"extract.get_name(): can not find files with "+filename
defgetlayers(textfilename):#gets the layers in the hdf file
try:
os.chdir(libspath)
tiles=record.create_dict(textfilename)
forxintiles:
if'.xml'notinx:
hdffilename=x
os.chdir(rawpath)
sub=subprocess.check_output('gdalinfo '+hdffilename+'|grep SUBDATASET*',shell=True)
#split=[x for x in sub.split() if 'SUBDATASET' in x if 'NAME' in x]
tmp=[xforxinsub.split('\n') if'SUBDATASET'inxif'NAME'inx]
lay=[x[(x.rfind(':')+1):] forxintmp]
#lay=[tmp[i].split(split[i])[1] for i in range(0,len(tmp))]
#if len(split)!=len(lay):
# raise ValueError
layers=[x.replace(' ','_') forxinlay]
returnlayers
exceptValueError:
print"Check the code for extract.getlayers()"
except:
print"extract.getlayers(): could not get layer information"