[GRASS-SVN] r47816 - in grass-addons/grass7/raster/r.modis: libmodis r.modis.import

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 22 08:15:44 EDT 2011


Author: lucadelu
Date: 2011-08-22 05:15:44 -0700 (Mon, 22 Aug 2011)
New Revision: 47816

Modified:
   grass-addons/grass7/raster/r.modis/libmodis/modis.py
   grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
   grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py
Log:
fix last problems

Modified: grass-addons/grass7/raster/r.modis/libmodis/modis.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/modis.py	2011-08-22 11:49:37 UTC (rev 47815)
+++ grass-addons/grass7/raster/r.modis/libmodis/modis.py	2011-08-22 12:15:44 UTC (rev 47816)
@@ -514,8 +514,9 @@
     self._getGranule()
     datagran = {}
     for i in self.granule.find('ECSDataGranule').getiterator():
-      if i.text.strip() != '':
-        datagran[i.tag] = i.text
+      if i.text:
+        if i.text.strip() != '':
+          datagran[i.tag] = i.text
     return datagran
 
   def retPGEVersion(self):
@@ -530,7 +531,7 @@
     self._getGranule()
     rangeTime = {}
     for i in self.granule.find('RangeDateTime').getiterator():
-      if i.text != None:
+      if i.text:
         if i.text.strip() != '':
           rangeTime[i.tag] = i.text
     return rangeTime
@@ -554,7 +555,7 @@
                 'max_lon':max(lon)}
     return extent
 
-  def retMeasure(self):
+  def retMeasure(self,flag = True):
     """Return statistics inside a dictionary"""
     value = {}
     self._getGranule()
@@ -567,12 +568,13 @@
       if i.tag != 'QAStats':
         qastat[i.tag] = i.text
     value['QAStats'] = qastat
-    meFlag = mespc.find('QAFlags')
-    flagstat = {}
-    for i in meFlag.getiterator():
-      if i.tag != 'QAFlags':
-        flagstat[i.tag] = i.text
-    value['QAFlags'] = flagstat
+    if flag:
+      meFlag = mespc.find('QAFlags')
+      flagstat = {}
+      for i in meFlag.getiterator():
+        if i.tag != 'QAFlags':
+          flagstat[i.tag] = i.text
+      value['QAFlags'] = flagstat
     return value
 
   def retPlatform(self):
@@ -617,7 +619,7 @@
        to set the metadata with r.support command
     """
     date = self.retRangeTime()
-    qa = self.retMeasure()
+    qa = self.retMeasure(False)
     pge = self.retPGEVersion()
     daynight = self.retDataGranule()
     stri = "Date:%s;BeginningTime:%s;EndingTime:%s;DayNightFlag:%s;"
@@ -820,10 +822,13 @@
       values.append(getattr(i,funct)())
     return values
 
-  def _checkval(self,vals):
+  def _checkval(self, vals, one=False, key = None):
     """Internal function to return the different values from a list"""
     if vals.count(vals[0]) == self.nfiles:
       return [vals[0]]
+    if vals.count(vals[0]) != self.nfiles and one == True:
+      raise IOError('Something strange reading XML files, %s parameters have ' \
+                    'different values' % key)
     else:
       outvals = []
       for i in vals:
@@ -842,7 +847,12 @@
       if valtemp.count(valtemp[0]) == self.nfiles:
         outvals[k] = valtemp[0]
       else:
-        raise IOError('Something wrong reading XML files')
+        if string.count(k,'Ending') != -1 or string.count(k,'End') != -1:
+          outvals[k] = self._maxval(valtemp)
+        elif string.count(k,'Beginning') != -1 or string.count(k,'Start') != -1:
+          outvals[k] = self._minval(valtemp)
+        else:
+          raise IOError('Something wrong reading XML files')
     return outvals
 
   def _minval(self, vals):
@@ -907,6 +917,26 @@
       dfc = self.ElementTree.SubElement(obj, 'DataFileContainer')
       self._cicle_values(dfc,i)
 
+  def _valECSDataGranule(self, obj):
+    values = {}
+    # add all keys
+    keys = self.parModis[0].retDataGranule().keys()
+    for i in keys:
+      values[i] = []
+    # for each key create a list of values
+    for i in self.parModis:
+      for k,v in i.retDataGranule().iteritems():
+        values[k].append(v)    
+    elem = self.ElementTree.SubElement(obj,'SizeMBECSDataGranule')
+    elem.text = str(self._meanval(values['SizeMBECSDataGranule']))
+    for i in ['ReprocessingPlanned','ReprocessingActual','DayNightFlag','LocalVersionID']:
+      elem = self.ElementTree.SubElement(obj,i)
+      elem.text = self._checkval(values[i], True, i)[0]
+    for k in ['LocalGranuleID', 'ProductionDateTime']:
+      for i in values[k]:
+        elem = self.ElementTree.SubElement(obj,k)
+        elem.text = i
+
   def _valPGEVersion(self,obj):
     """Function to add PGEVersion values"""
     values = self._retValues('retPGEVersion')
@@ -1063,9 +1093,9 @@
     # add DataFiles
     df = self.ElementTree.SubElement(gurmd,'DataFiles')
     self._valDataFiles(df)
-    
-    # TODO ADD ECSDataGranule
-    
+    # add ECSDataGranule
+    ecs = self.ElementTree.SubElement(gurmd,'ECSDataGranule')
+    self._valECSDataGranule(ecs)
     # add PGEVersionClass
     pgevc = self.ElementTree.SubElement(gurmd,'PGEVersionClass')
     self._valPGEVersion(pgevc)
@@ -1098,7 +1128,10 @@
     # add InputGranule and InputPointer
     ig = self.ElementTree.SubElement(gurmd,'InputGranule')
     self._valInputPointer(ig)
-    # TODO ADD BrowseProduct
+    # add BrowseProduct
+    bp = self.ElementTree.SubElement(gurmd,'BrowseProduct')
+    self._moreValues(bp, 'retBrowseProduct', 'BrowseGranuleId')
+    
     # write output file
     output = open(outputname, 'w')
     output.write('<?xml version="1.0" encoding="UTF-8"?>')

Modified: grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py
===================================================================
--- grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py	2011-08-22 11:49:37 UTC (rev 47815)
+++ grass-addons/grass7/raster/r.modis/libmodis/rmodislib.py	2011-08-22 12:15:44 UTC (rev 47816)
@@ -72,6 +72,7 @@
         ### 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]}
         
@@ -136,13 +137,15 @@
         }
         snow = {'snow_terra_daily_500' : {'url' : usrsnow, 'folder' : 
 				'SAN/MOST/MOD10A1.005', 'res' : 500, 'spec' : snow1_spec
-				,'spec_qa': snow1_specqa, 'suff' : snow1_suff,
-				'pattern' : snow1_patt, 'color' : snow_color
+				,'spec_qa': snow1_specqa,'spec_all' :snow1_specall ,
+				'suff' : snow1_suff, 'pattern' : snow1_patt, 
+				'color' : snow_color
 		}, 
 		'snow_aqua_daily_500' : {'url' : usrsnow, 'folder' : 
                                 'SAN/MOSA/MYD10A1.005', 'res' : 500, 'spec' : snow1_spec
-                                ,'spec_qa': snow1_specqa, 'suff' : snow1_suff,
-                                'pattern' : snow1_patt, 'color' : snow_color
+                                ,'spec_qa': snow1_specqa, 'spec_all' : snow1_specall,
+                                'suff' : snow1_suff, 'pattern' : snow1_patt, 
+                                'color' : snow_color
                 },
                 'snow_terra_eight_500' : {'url' : usrsnow, 'folder' : 
                                 'SAN/MOST/MOD10A2.005', 'res' : 500, 'spec' : snow8_spec

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-22 11:49:37 UTC (rev 47815)
+++ grass-addons/grass7/raster/r.modis/r.modis.import/r.modis.import.py	2011-08-22 12:15:44 UTC (rev 47816)
@@ -231,15 +231,16 @@
     grass.run_command('r.timestamp', map=mapp, date=dataobj.strftime("%d %b %Y"),
                       quiet = True)
     # color
-    if string.find(mapp, 'QA'):
+    if string.find(mapp, 'QC') != -1 or string.find(mapp, 'Quality') != -1 or \
+    string.find(mapp, 'QA') != -1:
         grass.run_command('r.colors', quiet = True, map=mapp, color = coll)
-    elif string.find(mapp, 'NDVI'):
+    elif string.find(mapp, 'NDVI') != -1:
         grass.run_command('r.colors', quiet = True, map=mapp, color = coll[0])
-    elif string.find(mapp, 'EVI'):
+    elif string.find(mapp, 'EVI') != -1:
         grass.run_command('r.colors', quiet = True, map=mapp, color = coll[1])
-    elif string.find(mapp, 'LST'):
+    elif string.find(mapp, 'LST') != -1:
         grass.run_command('r.colors', quiet = True, map=mapp, color = coll[0])
-    elif string.find(mapp, 'Snow'):
+    elif string.find(mapp, 'Snow') != -1:
         grass.run_command('r.colors', quiet = True, map=mapp, color = coll[0])
 
 def analize(pref, an, cod, parse, write):
@@ -277,9 +278,9 @@
             except:
                 pass
             #TODO check in modis.py to adjust the xml file of mosaic
-            #metadata(parse, valname, col)
-            #metadata(parse, valname + '.check', col)
-            #metadata(parse, qafull, 'byr')
+            metadata(parse, valname, col)
+            metadata(parse, valname + '.check', col)
+            metadata(parse, qafull, 'byr')
         if an == 'all':
             if len(qa) != len(val):
                 grass.fatal(_("The number of QA and value maps is different, something is wrong"))
@@ -305,10 +306,9 @@
             grass.run_command('g.rename', quiet = True, overwrite = write,
                               rast=(valname + '.3', valname + '.check'))
             #TODO check in modis.py to adjust the xml file of mosaic
-            #metadata(parse, valname, col)
-            #metadata(parse, valname + '.check', col)
-            #metadata(parse, qafull, 'byr')
-            
+            metadata(parse, valname, col)
+            metadata(parse, valname + '.check', col)
+            metadata(parse, qafull, 'byr')
 def single(options,remove,an,ow):
     """Convert the HDF file to TIF and import it
     """



More information about the grass-commit mailing list