[GRASS-SVN] r56164 - grass-addons/grass7/raster/r.modis/libmodis
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 8 05:15:25 PDT 2013
Author: lucadelu
Date: 2013-05-08 05:15:25 -0700 (Wed, 08 May 2013)
New Revision: 56164
Modified:
grass-addons/grass7/raster/r.modis/libmodis/convertmodis.py
grass-addons/grass7/raster/r.modis/libmodis/parsemodis.py
grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
Log:
update pymodis library
Modified: grass-addons/grass7/raster/r.modis/libmodis/convertmodis.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/convertmodis.py 2013-05-08 12:14:46 UTC (rev 56163)
+++ grass-addons/grass7/raster/r.modis/libmodis/convertmodis.py 2013-05-08 12:15:25 UTC (rev 56164)
@@ -144,10 +144,10 @@
def executable(self):
"""Return the executable of mrtmosaic MRT software
"""
- if sys.platform.count('linux') != -1:
+ if sys.platform.count('linux'):
if os.path.exists(os.path.join(self.mrtpathbin,'mrtmosaic')):
return os.path.join(self.mrtpathbin,'mrtmosaic')
- elif sys.platform.count('win32') != -1:
+ elif sys.platform.count('win32'):
if os.path.exists(os.path.join(self.mrtpathbin,'mrtmosaic.exe')):
return os.path.join(self.mrtpath,'mrtmosaic.exe')
Modified: grass-addons/grass7/raster/r.modis/libmodis/parsemodis.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/parsemodis.py 2013-05-08 12:14:46 UTC (rev 56163)
+++ grass-addons/grass7/raster/r.modis/libmodis/parsemodis.py 2013-05-08 12:15:25 UTC (rev 56164)
@@ -250,6 +250,7 @@
def confResample(self, spectral, res=None, output=None, datum='WGS84',
resample='NEAREST_NEIGHBOR', projtype='GEO', utm=None,
projpar='( 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 )',
+ bound=None
):
"""Create the parameter file to use with resample MRT software to create
tif file
@@ -303,6 +304,11 @@
Appendix C of MODIS reprojection tool user manual
https://lpdaac.usgs.gov/content/download/4831/22895/file/mrt41_usermanual_032811.pdf
+ bound = dictionary with the following keys:
+ - max_lat
+ - max_lon
+ - min_lat
+ - min_lon
"""
#check if spectral it's write with correct construct ( value )
if string.find(spectral, '(') == -1 or string.find(spectral, ')') == -1:
@@ -322,8 +328,14 @@
conFile.write("INPUT_FILENAME = %s\n" % self.hdfname)
conFile.write("SPECTRAL_SUBSET = %s\n" % spectral)
conFile.write("SPATIAL_SUBSET_TYPE = INPUT_LAT_LONG\n")
- # return the boundary from the input xml file
- bound = self.retBoundary()
+ if not bound:
+ # return the boundary from the input xml file
+ bound = self.retBoundary()
+ else:
+ if 'max_lat' not in bound or 'min_lat' not in bound or \
+ 'min_lon' not in bound or 'max_lon' not in bound:
+ raise IOError('bound variable is a dictionary with the following ' \
+ 'keys: max_lat, min_lat, min_lon, max_lon')
# Order: UL: N W - LR: S E
conFile.write("SPATIAL_SUBSET_UL_CORNER = ( %f %f )\n" % (bound['max_lat'],
bound['min_lon']))
@@ -362,6 +374,7 @@
def confResample_swath(self, sds, geoloc, res, output=None,
sphere='8', resample='NN', projtype='GEO', utm=None,
projpar='0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0',
+ bound=None
):
"""Create the parameter file to use with resample MRT software to create
tif file
@@ -425,6 +438,12 @@
projpar = a list of projection parameters, for more info check
the Appendix C of MODIS reprojection tool user manual
https://lpdaac.usgs.gov/content/download/4831/22895/file/mrt41_usermanual_032811.pdf
+
+ bound = dictionary with the following keys:
+ - max_lat
+ - max_lon
+ - min_lat
+ - min_lon
"""
# output name
if not output:
@@ -442,8 +461,14 @@
conFile.write("GEOLOCATION_FILENAME = %s\n" % geoloc)
conFile.write("INPUT_SDS_NAME = %s\n" % sds)
conFile.write("OUTPUT_SPATIAL_SUBSET_TYPE = LAT_LONG\n")
- # return the boundary from the input xml file
- bound = self.retBoundary()
+ if not bound:
+ # return the boundary from the input xml file
+ bound = self.retBoundary()
+ else:
+ if 'max_lat' not in bound or 'min_lat' not in bound or \
+ 'min_lon' not in bound or 'max_lon' not in bound:
+ raise IOError('bound variable is a dictionary with the following ' \
+ 'keys: max_lat, min_lat, min_lon, max_lon')
# Order: UL: N W - LR: S E
conFile.write("OUTPUT_SPACE_UPPER_LEFT_CORNER (LONG LAT) = %f %f\n" % (bound['max_lat'],
bound['min_lon']))
@@ -501,6 +526,12 @@
self.parModis.append(parseModis(i))
self.nfiles += 1
+
+ def _most_common(self, lst):
+ """Return the most common value of a list"""
+ return max(set(lst), key=lst.count)
+
+
def _checkval(self, vals):
"""Internal function to return values from list
@@ -528,6 +559,8 @@
valtemp.append(v[k])
if valtemp.count(valtemp[0]) == self.nfiles:
outvals[k] = valtemp[0]
+ elif len(valtemp) == self.nfiles:
+ outvals[k] = self._most_common(valtemp)
else:
raise IOError('Something wrong reading XML files')
@@ -821,4 +854,4 @@
output.write('<!DOCTYPE GranuleMetaDataFile SYSTEM "http://ecsinfo.gsfc.' \
'nasa.gov/ECSInfo/ecsmetadata/dtds/DPL/ECS/ScienceGranuleMetadata.dtd">')
output.write(self.ElementTree.tostring(granule))
- output.close()
\ No newline at end of file
+ output.close()
Modified: grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py 2013-05-08 12:14:46 UTC (rev 56163)
+++ grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py 2013-05-08 12:15:25 UTC (rev 56164)
@@ -55,9 +55,6 @@
### values of lst product:
lst_spec = '( 1 0 0 0 1 0 0 0 0 0 0 0 )'
lst_specqa = '( 1 1 0 0 1 1 0 0 0 0 0 0 )'
- # pattern for r.bitpatter (key is the pattern option, list of values
- # contain values for patval option)
- lst_patt = {3: [2, 3], 128: [81, 85], 255: [129, 133, 145, 149]}
# suffix for the lst product (key is the lst map, value the QA)
lst1km_suff = {'.LST_Day_1km': '.QC_Day', '.LST_Night_1km': '.QC_Night'}
lst6km_suff = {'.LST_Day_6km': '.QC_Day', '.LST_Night_6km': '.QC_Night'}
@@ -66,8 +63,6 @@
### values of vi product:
vi_spec = '( 1 1 0 0 0 0 0 0 0 0 0 0 )'
vi_specqa = '( 1 1 1 0 0 0 0 0 0 0 0 1 )'
- vi_patt = {3: [2, 3], 63: [13, 14, 15], 128: [3], 1024: [1],
- 8192: [0, 6, 7], 16384: [1], 32768: [1]}
vi_color = ['ndvi', 'evi']
vi250m_suff = {'.250m_16_days_NDVI': '.250m_16_days_VI_Quality',
'.250m_16_days_EVI': '.250m_16_days_VI_Quality'}
@@ -79,7 +74,6 @@
snow1_spec = ('( 1 )')
snow1_specqa = ('( 1 1 )')
snow1_suff = {'.Snow_Cover_Daily_Tile': '.Snow_Spatial_QA'}
- snow1_patt = {3: [2, 3], 7: [6, 7], 15: [10, 11, 14, 15]}
snow8_spec = ('( 1 1 )')
snow_color = ['gyr'] # TODO CREATE THE COLOR TABLE FOR MODIS_SNOW
snow8_suff = {'.Maximum_Snow_Extent': None, '.Eight_Day_Snow_Cover': None}
@@ -94,37 +88,37 @@
'.sur_refl_b07': '.sur_refl_qc_500m'}
self.prod = value
- lst = {'lst_aqua_daily_1000': {'url': urlbase, 'pattern': lst_patt,
+ lst = {'lst_aqua_daily_1000': {'url': urlbase,
'folder': 'MOLA/MYD11A1.005',
'spec': lst_spec, 'spec_qa': lst_specqa,
'suff': lst1km_suff, 'res': 1000,
'color': lst_color
},
- 'lst_terra_daily_1000': {'url': urlbase, 'pattern': lst_patt,
+ 'lst_terra_daily_1000': {'url': urlbase,
'folder': 'MOLT/MOD11A1.005',
'spec': lst_spec, 'spec_qa': lst_specqa,
'suff': lst1km_suff, 'res': 1000,
'color': lst_color
},
- 'lst_terra_eight_1000': {'url': urlbase, 'pattern': lst_patt,
+ 'lst_terra_eight_1000': {'url': urlbase,
'folder': 'MOLT/MOD11A2.005',
'spec': lst_spec, 'spec_qa': lst_specqa,
'suff': lst1km_suff, 'res': 1000,
'color': lst_color
},
- 'lst_aqua_eight_1000': {'url': urlbase, 'pattern': lst_patt,
+ 'lst_aqua_eight_1000': {'url': urlbase,
'folder': 'MOLA/MYD11A2.005',
'spec': lst_spec, 'spec_qa': lst_specqa,
'suff': lst1km_suff, 'res': 1000,
'color': lst_color
},
- 'lst_terra_daily_6000': {'url': urlbase, 'pattern': lst_patt,
+ 'lst_terra_daily_6000': {'url': urlbase,
'folder': 'MOLT/MOD11B1.005',
'spec': lst_spec, 'spec_qa': lst_specqa,
'suff': lst6km_suff, 'res': 6000,
'color': lst_color
},
- 'lst_aqua_daily_6000': {'url': urlbase, 'pattern': lst_patt,
+ 'lst_aqua_daily_6000': {'url': urlbase,
'folder': 'MOLA/MYD11B1.005',
'spec': lst_spec, 'spec_qa': lst_specqa,
'suff': lst6km_suff, 'res': 6000,
@@ -132,37 +126,37 @@
},
}
- vi = {'ndvi_terra_sixteen_250': {'url': urlbase, 'pattern': vi_patt,
+ vi = {'ndvi_terra_sixteen_250': {'url': urlbase,
'folder': 'MOLT/MOD13Q1.005',
'spec': vi_spec, 'spec_qa': vi_specqa,
'suff': vi250m_suff, 'res': 250,
'color': vi_color
},
- 'ndvi_aqua_sixteen_250': {'url': urlbase, 'pattern': vi_patt,
+ 'ndvi_aqua_sixteen_250': {'url': urlbase,
'folder': 'MOLA/MYD13Q1.005',
'spec': vi_spec, 'spec_qa': vi_specqa,
'suff': vi250m_suff, 'res': 250,
'color': vi_color
},
- 'ndvi_terra_sixteen_500': {'url': urlbase, 'pattern': vi_patt,
+ 'ndvi_terra_sixteen_500': {'url': urlbase,
'folder': 'MOLT/MOD13A1.005',
'spec': vi_spec, 'spec_qa': vi_specqa,
'suff': vi1km_suff, 'res': 500,
'color': vi_color
},
- 'ndvi_aqua_sixteen_500': {'url': urlbase, 'pattern': vi_patt,
+ 'ndvi_aqua_sixteen_500': {'url': urlbase,
'folder': 'MOLA/MYD13A1.005',
'spec': vi_spec, 'spec_qa': vi_specqa,
'suff': vi500m_suff, 'res': 500,
'color': vi_color
},
- 'ndvi_terra_sixteen_1000': {'url': urlbase, 'pattern': vi_patt,
+ 'ndvi_terra_sixteen_1000': {'url': urlbase,
'folder': 'MOLT/MOD13A2.005',
'spec': vi_spec, 'spec_qa': vi_specqa,
'suff': vi500m_suff, 'res': 1000,
'color': vi_color
},
- 'ndvi_aqua_sixteen_1000': {'url': urlbase, 'pattern': vi_patt,
+ 'ndvi_aqua_sixteen_1000': {'url': urlbase,
'folder': 'MOLA/MYD13A2.005',
'spec': vi_spec, 'spec_qa': vi_specqa,
'suff': vi1km_suff, 'res': 1000,
@@ -170,7 +164,6 @@
}
}
surf_refl = {'surfreflec_terra_eight_500': {'url': urlbase,
- 'pattern': None,
'folder': 'MOLT/MOD09A1.005',
'spec': surf_spec,
'spec_qa': surf_specqa,
@@ -179,7 +172,6 @@
'suff': surf_suff
},
'surfreflec_aqua_eight_500': {'url': urlbase,
- 'pattern': None,
'folder': 'MOLA/MYD09A1.005',
'spec': surf_spec,
'spec_qa': surf_specqa,
@@ -189,28 +181,28 @@
}
}
- snow = {'snow_terra_daily_500': {'url': usrsnow, 'pattern': snow1_patt,
+ snow = {'snow_terra_daily_500': {'url': usrsnow,
'folder': 'SAN/MOST/MOD10A1.005',
'spec': snow1_spec,
'spec_qa': snow1_specqa,
'color': snow_color,
'suff': snow1_suff, 'res': 500
},
- 'snow_aqua_daily_500': {'url': usrsnow, 'pattern': snow1_patt,
+ 'snow_aqua_daily_500': {'url': usrsnow,
'folder': 'SAN/MOSA/MYD10A1.005',
'spec' : snow1_spec,
'spec_qa': snow1_specqa,
'color' : snow_color,
'suff' : snow1_suff, 'res' : 500
},
- 'snow_terra_eight_500': {'url': usrsnow, 'pattern': None,
+ 'snow_terra_eight_500': {'url': usrsnow,
'folder': 'SAN/MOST/MOD10A2.005',
'spec': snow8_spec,
'spec_qa': None,
'color': snow_color,
'suff': snow8_suff, 'res' : 500
},
- 'snow_aqua_eight_500' : {'url': usrsnow, 'pattern' : None,
+ 'snow_aqua_eight_500' : {'url': usrsnow,
'folder': 'SAN/MOSA/MYD10A2.005',
'spec': snow8_spec,
'spec_qa': None,
@@ -257,12 +249,6 @@
else:
return self.returned()['color']
- def pattern(self, code=None):
- if code:
- return self.fromcode(code)['pattern']
- else:
- return self.returned()['pattern']
-
def suffix(self, code=None):
if code:
return self.fromcode(code)['suff']
More information about the grass-commit
mailing list