[GRASS-SVN] r47848 - in grass-addons/grass7/raster/r.modis:
libmodis r.modis.import
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 23 10:12:08 EDT 2011
Author: lucadelu
Date: 2011-08-23 07:12:07 -0700 (Tue, 23 Aug 2011)
New Revision: 47848
Modified:
grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
Log:
fix problems with NDVI product
Modified: grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py 2011-08-23 13:42:29 UTC (rev 47847)
+++ grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py 2011-08-23 14:12:07 UTC (rev 47848)
@@ -59,20 +59,21 @@
lst6km_suff = {'.LST_Day_6km':'.QC_Day','.LST_Night_6km':'.QC_Night'}
# color for lst product
lst_color = ['celsius']
- # all the possible layers of lst and vi products, it is used when mosaic it's created
- lstvi_specall = '( 1 1 1 1 1 1 1 1 1 1 1 1)'
### values of vi product:
vi_spec = '( 1 1 0 0 0 0 0 0 0 0 0 )'
vi_specqa = '( 1 1 1 0 0 0 0 0 0 0 0 )'
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']
- vi_suff = {'.250m_16_days_NDVI' : '.250m_16_days_VI_Quality',
+ vi250m_suff = {'.250m_16_days_NDVI' : '.250m_16_days_VI_Quality',
'.250m_16_days_EVI' : '.250m_16_days_VI_Quality'}
+ vi500m_suff = {'.500m_16_days_NDVI' : '.500m_16_days_VI_Quality',
+ '.500m_16_days_EVI' : '.500m_16_days_VI_Quality'}
+ vi1km_suff = {'.1_km_16_days_NDVI' : '.1_km_16_days_VI_Quality',
+ '.1_km_16_days_EVI' : '.1_km_16_days_VI_Quality'}
### values of snow product:
snow1_spec = ('( 1 )')
snow1_specqa = ('( 1 1 )')
- snow1_specall = ('( 1 1 1 1 )')
snow1_suff = {'.Snow_Cover_Daily_Tile':'.Snow_Spatial_QA'}
snow1_patt = {3 : [2,3], 7 : [6, 7], 15 : [10, 11, 14, 15]}
@@ -84,78 +85,86 @@
self.prod = value
lst = {'lst_aqua_daily_1000' : {'url' : urlbase, 'folder' : 'MOLA/MYD11A1.005',
'res' : 1000, 'spec' : lst_spec, 'spec_qa' : lst_specqa,
- 'spec_all' : lstvi_specall, 'suff' : lst1km_suff,
- 'pattern' : lst_patt, 'color' : lst_color
+ 'suff' : lst1km_suff, 'pattern' : lst_patt,
+ 'color' : lst_color
},
'lst_terra_daily_1000' : {'url' : urlbase, 'folder' : 'MOLT/MOD11A1.005',
'res' : 1000, 'spec': lst_spec,'spec_qa': lst_specqa,
- 'spec_all' : lstvi_specall, 'suff' : lst1km_suff,
- 'pattern' : lst_patt, 'color' : lst_color
+ 'suff' : lst1km_suff, 'pattern' : lst_patt,
+ 'color' : lst_color
},
'lst_terra_eight_1000' : {'url' : urlbase, 'folder' : 'MOLT/MOD11A2.005',
'res' : 1000, 'spec': lst_spec,'spec_qa': lst_specqa,
- 'spec_all' : lstvi_specall, 'suff' : lst1km_suff,
- 'pattern' : lst_patt, 'color' : lst_color
+ 'suff' : lst1km_suff, 'pattern' : lst_patt,
+ 'color' : lst_color
},
'lst_aqua_eight_1000' : {'url' : urlbase, 'folder' : 'MOLA/MYD11A2.005',
'res' : 1000, 'spec': lst_spec,'spec_qa': lst_specqa,
- 'spec_all' : lstvi_specall, 'suff' : lst1km_suff,
- 'pattern' : lst_patt, 'color' : lst_color
+ 'suff' : lst1km_suff, 'pattern' : lst_patt,
+ 'color' : lst_color
},
'lst_terra_daily_6000' : {'url' : urlbase, 'folder' : 'MOLT/MOD11B1.005',
'res' : 6000, 'spec': lst_spec,'spec_qa': lst_specqa,
- 'spec_all' : lstvi_specall, 'suff' : lst6km_suff,
- 'pattern' : lst_patt, 'color' : lst_color
+ 'suff' : lst6km_suff, 'pattern' : lst_patt,
+ 'color' : lst_color
},
'lst_aqua_daily_6000' : {'url' : urlbase, 'folder' : 'MOLA/MYD11B1.005',
'res' : 6000, 'spec': lst_spec,'spec_qa': lst_specqa,
- 'spec_all' : lstvi_specall, 'suff' : lst6km_suff,
- 'pattern' : lst_patt, 'color' : lst_color
+ 'suff' : lst6km_suff, 'pattern' : lst_patt,
+ 'color' : lst_color
},
}
vi = {'ndvi_terra_sixteen_250':{'url':urlbase, 'folder':'MOLT/MOD13Q1.005',
'res':250,'spec': vi_spec,'spec_qa': vi_specqa,
- 'spec_all' : lstvi_specall, 'suff' : vi_suff,
- 'pattern' : vi_patt, 'color' : vi_color
+ 'suff' : vi250m_suff, 'pattern' : vi_patt,
+ 'color' : vi_color
},
'ndvi_aqua_sixteen_250':{'url':urlbase, 'folder':'MOLA/MYD13Q1.005',
'res':250,'spec': vi_spec,'spec_qa': vi_specqa,
- 'spec_all' : lstvi_specall, 'suff' : vi_suff,
- 'pattern' : vi_patt, 'color' : vi_color
+ 'suff' : vi250m_suff, 'pattern' : vi_patt,
+ 'color' : vi_color
},
- 'ndvi_terra_sixteen_500':{'url':urlbase, 'folder':'MOLT/MOD13A2.005',
+ 'ndvi_terra_sixteen_500':{'url':urlbase, 'folder':'MOLT/MOD13A1.005',
'res':500,'spec': vi_spec,'spec_qa': vi_specqa,
- 'spec_all' : lstvi_specall, 'suff' : vi_suff,
- 'pattern' : vi_patt, 'color' : vi_color
+ 'suff' : vi1km_suff, 'pattern' : vi_patt,
+ 'color' : vi_color
},
- 'ndvi_aqua_sixteen_500':{'url':urlbase, 'folder':'MOLA/MYD13A2.005',
+ 'ndvi_aqua_sixteen_500':{'url':urlbase, 'folder':'MOLA/MYD13A1.005',
'res':500,'spec': vi_spec,'spec_qa': vi_specqa,
- 'spec_all' : lstvi_specall, 'suff' : vi_suff,
- 'pattern' : vi_patt, 'color' : vi_color
+ 'suff' : vi500m_suff, 'pattern' : vi_patt,
+ 'color' : vi_color
+ },
+ 'ndvi_terra_sixteen_1000':{'url':urlbase, 'folder':'MOLT/MOD13A2.005',
+ 'res':1000,'spec': vi_spec,'spec_qa': vi_specqa,
+ 'suff' : vi500m_suff, 'pattern' : vi_patt,
+ 'color' : vi_color
+ },
+ 'ndvi_aqua_sixteen_1000':{'url':urlbase, 'folder':'MOLA/MYD13A2.005',
+ 'res':1000,'spec': vi_spec,'spec_qa': vi_specqa,
+ 'suff' : vi1km_suff, 'pattern' : vi_patt,
+ 'color' : vi_color
}
}
snow = {'snow_terra_daily_500' : {'url' : usrsnow, 'folder' :
'SAN/MOST/MOD10A1.005', 'res' : 500, 'spec' : snow1_spec
- ,'spec_qa': snow1_specqa,'spec_all' :snow1_specall ,
- 'suff' : snow1_suff, 'pattern' : snow1_patt,
- 'color' : snow_color
+ ,'spec_qa': snow1_specqa, 'color' : snow_color,
+ 'suff' : snow1_suff, 'pattern' : snow1_patt
},
'snow_aqua_daily_500' : {'url' : usrsnow, 'folder' :
'SAN/MOSA/MYD10A1.005', 'res' : 500, 'spec' : snow1_spec
- ,'spec_qa': snow1_specqa, 'spec_all' : snow1_specall,
- 'suff' : snow1_suff, 'pattern' : snow1_patt,
- 'color' : snow_color
+ ,'spec_qa': snow1_specqa, 'color' : snow_color,
+ 'suff' : snow1_suff, 'pattern' : snow1_patt
},
'snow_terra_eight_500' : {'url' : usrsnow, 'folder' :
'SAN/MOST/MOD10A2.005', 'res' : 500, 'spec' : snow8_spec
- ,'spec_qa': None, 'spec_all' : snow8_spec,
- 'pattern' : None, 'suff' : snow8_suff, 'color' : snow_color
+ ,'spec_qa': None, 'color' : snow_color,
+ 'pattern' : None, 'suff' : snow8_suff
},
'snow_aqua_eight_500' : {'url' : usrsnow, 'folder' :
'SAN/MOSA/MYD10A2.005', 'res' : 500, 'spec' : snow8_spec
- ,'spec_qa': None, 'spec_all' : snow8_spec,
- 'pattern' : None, 'suff' : snow8_suff, 'color' : snow_color
+ ,'spec_qa': None, 'color' : snow_color,
+ 'pattern' : None, 'suff' : snow8_suff
}
}
self.products = { }
Modified: grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
===================================================================
--- grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py 2011-08-23 13:42:29 UTC (rev 47847)
+++ grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py 2011-08-23 14:12:07 UTC (rev 47848)
@@ -131,23 +131,22 @@
basedir = os.path.split(filelist[0])[0]
return filelist, basedir
-def spectral(opts, code, q, m = False):
+def spectral(opts, prod, q, m = False):
"""Return spectral string"""
# return the spectral set selected by the user
if opts['spectral'] != '':
spectr = opts['spectral']
# return the spectral by default
else:
- prod = product().fromcode(code)
- if m:
- spectr = prod['spec_all']
- elif q:
+ if q:
if prod['spec_qa']:
spectr = prod['spec_qa']
else:
spectr = prod['spec']
else:
spectr = prod['spec']
+ if m:
+ spectr = spectr.replace(' 0', '')
return spectr
def confile(pm, opts, q, mosaik=False):
@@ -161,11 +160,13 @@
else:
zone = None
cod = os.path.split(pm.hdfname)[1].split('.')[0]
+ prod = product().fromcode(cod)
if mosaik:
- # if mosaic import all because the layers are choosen during mosaic
- spectr = spectral(opts, cod, q, True)
+ # if mosaic it remove all the 0 from the subset string to convert all
+ # the right layer
+ spectr = spectral(opts, prod, q, True)
else:
- spectr = spectral(opts, cod, q)
+ spectr = spectral(opts, prod, q)
# out prefix
pref = prefix(opts)
# resampling
@@ -174,7 +175,12 @@
projpar = projObj.return_params()
if projpar != "( 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )":
dat = "NoDatum"
- return pm.confResample(spectr, None, pref, dat, resampl, proj, zone, projpar)
+ # resolution
+ if proj != 'GEO':
+ res = int(prod['res']) * int(projObj.proj['meters'])
+ else:
+ res = None
+ return pm.confResample(spectr, res, pref, dat, resampl, proj, zone, projpar)
def prefix(options, name = False):
"""Return the prefix of output file if not set return None to use default
@@ -260,7 +266,6 @@
val.append(findfile(pref,v))
if q:
qa.append(findfile(pref,q))
-
for n in range(len(val)):
valname = val[n]['name']
valfull = val[n]['fullname']
@@ -268,10 +273,9 @@
grass.run_command('r.null', map = valfull, setnull = 0)
if string.find(cod,'13Q1') >= 0 or string.find(cod,'13A2') >= 0:
mapc = "%s.2 = %s / 10000." % (valname, valfull)
- grass.mapcalc(mapc)
elif string.find(cod,'11A1') >= 0 or string.find(cod,'11A2') >= 0 or string.find(cod,'11B1') >= 0:
mapc = "%s.2 = (%s * 0.0200) - 273.15" % (valname, valfull)
- grass.mapcalc(mapc)
+ grass.mapcalc(mapc)
if an == 'noqa':
#grass.run_command('g.remove', quiet = True, rast = valfull)
try:
@@ -303,7 +307,7 @@
finalmap += "&& %s == 0 " % outpat
if string.find(cod,'13Q1') >= 0 or string.find(cod,'13A2') >= 0:
- finalmap += "%s.2 <= 1.000" % valname
+ finalmap += "&& %s.2 <= 1.000" % valname
finalmap += ",%s.2, null() )" % valname
# grass.message("mapc finalmap: %s" % finalmap)
grass.mapcalc(finalmap)
@@ -323,6 +327,7 @@
"""Convert the HDF file to TIF and import it
"""
listfile, basedir = list_files(options)
+ pid = str(os.getpid())
# for each file
for i in listfile:
# the full path to hdf file
@@ -339,14 +344,14 @@
# import tif files
maps_import = import_tif(output,basedir,remove,ow)
if an:
- grass.run_command('g.region', save = 'oldregion.%s' % str(os.getpid()))
+ grass.run_command('g.region', save = 'oldregion.%s' % pid)
try:
cod = os.path.split(pm.hdfname)[1].split('.')[0]
analyze(outname, an, cod, pm, ow)
except:
- grass.run_command('g.region', region = 'oldregion.%s' % str(os.getpid()))
+ grass.run_command('g.region', region = 'oldregion.%s' % pid)
grass.run_command('g.remove',quiet = True,
- region = 'oldregion.%s' % str(os.getpid()))
+ region = 'oldregion.%s' % pid)
cod = os.path.split(pm.hdfname)[1].split('.')[0]
analyze(output, an, cod, pm, ow)
os.remove(confname)
@@ -356,10 +361,11 @@
"""Create a daily mosaic of HDF files convert to TIF and import it
"""
dictfile, targetdir = list_files(options,True)
+ pid = str(os.getpid())
# for each day
for dat, listfiles in dictfile.iteritems():
# create the file with the list of name
- tempfile = open(os.path.join(targetdir,str(os.getpid())),'w')
+ tempfile = open(os.path.join(targetdir,pid),'w')
tempfile.writelines(listfiles)
tempfile.close()
# basedir of tempfile, where hdf files are write
@@ -367,7 +373,8 @@
outname = "%s.%s.mosaic" % (listfiles[0].split('/')[-1].split('.')[0],
listfiles[0].split('/')[-1].split('.')[1])
# return the spectral subset in according mrtmosaic tool format
- spectr = spectral(options,listfiles[0].split('/')[-1].split('.')[0],an, True)
+ prod = product().fromcode(listfiles[0].split('/')[-1].split('.')[0])
+ spectr = spectral(options,prod,an)
spectr = spectr.lstrip('( ').rstrip(' )')
# create mosaic
cm = createMosaic(tempfile.name, outname, options['mrtpath'], spectr)
@@ -379,7 +386,7 @@
hdf = os.path.join(basedir,i)
# create conf file fro mrt tools
pm = parseModis(hdf)
- confname = confile(pm,options,an)
+ confname = confile(pm,options,an, True)
# create convertModis class and convert it in tif file
execmodis = convertModis(hdf, confname, options['mrtpath'])
execmodis.run()
@@ -388,14 +395,14 @@
# import tif files
import_tif(outname, basedir, remove, ow)
if an:
- grass.run_command('g.region', save = 'oldregion.%s' % str(os.getpid()))
+ grass.run_command('g.region', save = 'oldregion.%s' % pid)
try:
cod = os.path.split(pm.hdfname)[1].split('.')[0]
analyze(outname, an, cod, pm, ow)
except:
- grass.run_command('g.region', region = 'oldregion.%s' % str(os.getpid()))
+ grass.run_command('g.region', region = 'oldregion.%s' % pid)
grass.run_command('g.remove',quiet = True,
- region = 'oldregion.%s' % str(os.getpid()))
+ region = 'oldregion.%s' % pid)
os.remove(hdf)
os.remove(hdf + '.xml')
# or move the hdf and hdf.xml to the dir where are the original files
@@ -403,13 +410,13 @@
# import tif files
import_tif(outname, basedir, remove, ow, targetdir)
if an:
- grass.run_command('g.region', save = 'oldregion.%s' % str(os.getpid()))
+ grass.run_command('g.region', save = 'oldregion.%s' % pid)
try:
cod = os.path.split(pm.hdfname)[1].split('.')[0]
analyze(outname, an, cod, pm, ow)
except:
- grass.run_command('g.region', region = 'oldregion.%s' % str(os.getpid()))
- grass.run_command('g.remove', region = 'oldregion.%s' % str(os.getpid()))
+ grass.run_command('g.region', region = 'oldregion.%s' % pid)
+ grass.run_command('g.remove', region = 'oldregion.%s' % pid)
try:
shutil.move(hdf,targetdir)
shutil.move(hdf + '.xml',targetdir)
@@ -418,7 +425,7 @@
# remove the conf file
os.remove(confname)
grass.try_remove(tempfile.name)
- grass.try_remove(os.path.join(targetdir,'mosaic',str(os.getpid())))
+ grass.try_remove(os.path.join(targetdir,'mosaic',pid))
return grass.message(_('All files imported correctly'))
def main():
More information about the grass-commit
mailing list