[GRASS-SVN] r55828 - in grass/trunk: lib/python/temporal temporal/t.rast.neighbors temporal/t.support temporal/t.unregister

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 16 01:31:10 PDT 2013


Author: huhabla
Date: 2013-04-16 01:31:10 -0700 (Tue, 16 Apr 2013)
New Revision: 55828

Modified:
   grass/trunk/lib/python/temporal/abstract_map_dataset.py
   grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
   grass/trunk/lib/python/temporal/extract.py
   grass/trunk/lib/python/temporal/mapcalc.py
   grass/trunk/lib/python/temporal/space_time_datasets_tools.py
   grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
   grass/trunk/temporal/t.support/t.support.py
   grass/trunk/temporal/t.unregister/t.unregister.py
Log:
Massive speed gain by removing verbose and percent messages.


Modified: grass/trunk/lib/python/temporal/abstract_map_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_map_dataset.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/lib/python/temporal/abstract_map_dataset.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -506,8 +506,9 @@
             if self.get_stds_register() is not None:
                 statement += "DROP TABLE " + self.get_stds_register() + ";\n"
 
-            core.verbose(_("Delete %s dataset <%s> from temporal database")
-                         % (self.get_type(), self.get_id()))
+            # Commented because of performance issue calling g.message thousend times
+            #core.verbose(_("Delete %s dataset <%s> from temporal database")
+            #             % (self.get_type(), self.get_id()))
 
             # Delete yourself from the database, trigger functions will 
             # take care of dependencies
@@ -545,15 +546,16 @@
            @return The SQL statements if execute == False, else an empty string
         """
 
-        if self.get_layer() is not None:
-            core.verbose(_("Unregister %(type)s map <%(map)s> with "
-                           "layer %(layer)s from space time datasets" % \
-                         {'type':self.get_type(), 'map':self.get_map_id(), 
-                          'layer':self.get_layer()}))
-        else:
-            core.verbose(_("Unregister %(type)s map <%(map)s> "
-                           "from space time datasets"
-                         % {'type':self.get_type(), 'map':self.get_map_id()}))
+        # Commented because of performance issue calling g.message thousend times
+        #if self.get_layer() is not None:
+        #    core.verbose(_("Unregister %(type)s map <%(map)s> with "
+        #                   "layer %(layer)s from space time datasets" % \
+        #                 {'type':self.get_type(), 'map':self.get_map_id(), 
+        #                  'layer':self.get_layer()}))
+        #else:
+        #    core.verbose(_("Unregister %(type)s map <%(map)s> "
+        #                   "from space time datasets"
+        #                 % {'type':self.get_type(), 'map':self.get_map_id()}))
 
         statement = ""
         dbif, connect = init_dbif(dbif)
@@ -563,11 +565,7 @@
 
         # For each stds in which the map is registered
         if rows is not None:
-            count = 0
-            num_sps = len(rows)
             for row in rows:
-                core.percent(count, num_sps, 1)
-                count += 1
                 # Create a space time dataset object to remove the map
                 # from its register
                 stds = self.get_new_stds_instance(row["id"])
@@ -578,8 +576,6 @@
                 if update == True and execute == True:
                     stds.update_from_registered_maps(dbif)
 
-            core.percent(1, 1, 1)
-
         if execute:
             dbif.execute_transaction(statement)
 

Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -1115,16 +1115,11 @@
             rows = self.get_registered_maps("id", None, None, dbif)
             # Unregister each registered map in the table
             if rows is not None:
-                num_maps = len(rows)
-                count = 0
                 for row in rows:
-                    core.percent(count, num_maps, 1)
                     # Unregister map
                     map = self.get_new_map_instance(row["id"])
                     statement += self.unregister_map(
                         map=map, dbif=dbif, execute=False)
-                    count += 1
-                core.percent(1, 1, 1)
 
             # Safe the DROP table statement
             statement += "DROP TABLE " + self.get_map_register() + ";\n"
@@ -1163,17 +1158,18 @@
             dbif.close()
             core.fatal(_("Only maps with absolute or relative valid time can "
                          "be registered"))
-        if map.get_layer():
-            core.verbose(_("Register %s map <%s> with layer %s in space "
-                           "time %s dataset <%s>") % (map.get_type(), 
-                                                      map.get_map_id(), 
-                                                      map.get_layer(), 
-                                                      map.get_type(), 
-                                                      self.get_id()))
-        else:
-            core.verbose(_("Register %s map <%s> in space time %s "
-                           "dataset <%s>") % (map.get_type(), map.get_map_id(),
-                                               map.get_type(), self.get_id()))
+        # Commented because of performance issue calling g.message thousend times
+        #if map.get_layer():
+        #    core.verbose(_("Register %s map <%s> with layer %s in space "
+        #                   "time %s dataset <%s>") % (map.get_type(), 
+        #                                              map.get_map_id(), 
+        #                                              map.get_layer(), 
+        #                                              map.get_type(), 
+        #                                              self.get_id()))
+        #else:
+        #    core.verbose(_("Register %s map <%s> in space time %s "
+        #                   "dataset <%s>") % (map.get_type(), map.get_map_id(),
+        #                                       map.get_type(), self.get_id()))
 
         # First select all data from the database
         map.select(dbif)
@@ -1223,9 +1219,10 @@
             self.set_relative_time_unit(map_rel_time_unit)
             statement += self.relative_time.get_update_all_statement_mogrified(
                 dbif)
-            core.verbose(_("Set temporal unit for space time %s dataset "
-                           "<%s> to %s") % (map.get_type(), self.get_id(), 
-                                            map_rel_time_unit))
+            # Commented because of performance issue calling g.message thousend times
+            #core.verbose(_("Set temporal unit for space time %s dataset "
+            #               "<%s> to %s") % (map.get_type(), self.get_id(), 
+            #                                map_rel_time_unit))
 
         stds_rel_time_unit = self.get_relative_time_unit()
 
@@ -1303,15 +1300,16 @@
             map.set_stds_register(map_register_table)
             statement += map.metadata.get_update_statement_mogrified(dbif)
 
-            if map.get_layer():
-                core.verbose(_("Created register table <%s> for "
-                               "%s map <%s> with layer %s") %
-                                (map_register_table, map.get_type(), 
-                                 map.get_map_id(), map.get_layer()))
-            else:
-                core.verbose(_("Created register table <%s> for %s map <%s>") %
-                                (map_register_table, map.get_type(), 
-                                 map.get_map_id()))
+            # Commented because of performance issue calling g.message thousend times
+            #if map.get_layer():
+            #    core.verbose(_("Created register table <%s> for "
+            #                   "%s map <%s> with layer %s") %
+            #                    (map_register_table, map.get_type(), 
+            #                     map.get_map_id(), map.get_layer()))
+            #else:
+            #    core.verbose(_("Created register table <%s> for %s map <%s>") %
+            #                    (map_register_table, map.get_type(), 
+            #                     map.get_map_id()))
 
         # We need to create the table and register it
         if stds_register_table is None:
@@ -1332,9 +1330,10 @@
             self.set_map_register(stds_register_table)
             statement += self.metadata.get_update_statement_mogrified(dbif)
 
-            core.verbose(_("Created register table <%s> for space "
-                           "time %s  dataset <%s>") %
-                          (stds_register_table, map.get_type(), self.get_id()))
+            # Commented because of performance issue calling g.message thousend times
+            #core.verbose(_("Created register table <%s> for space "
+            #               "time %s  dataset <%s>") %
+            #              (stds_register_table, map.get_type(), self.get_id()))
 
         # We need to execute the statement at this time
         if statement != "":
@@ -1413,12 +1412,13 @@
         map_register_table = map.get_stds_register()
         stds_register_table = self.get_map_register()
 
-        if map.get_layer() is not None:
-            core.verbose(_("Unregister %s map <%s> with layer %s") % \
-                         (map.get_type(), map.get_map_id(), map.get_layer()))
-        else:
-            core.verbose(_("Unregister %s map <%s>") % (
-                map.get_type(), map.get_map_id()))
+        # Commented because of performance issue calling g.message thousend times
+        #if map.get_layer() is not None:
+        #    core.verbose(_("Unregister %s map <%s> with layer %s") % \
+        #                 (map.get_type(), map.get_map_id(), map.get_layer()))
+        #else:
+        #    core.verbose(_("Unregister %s map <%s>") % (
+        #        map.get_type(), map.get_map_id()))
 
         # Check if the map is registered in the space time raster dataset
         if map_register_table is not None:

Modified: grass/trunk/lib/python/temporal/extract.py
===================================================================
--- grass/trunk/lib/python/temporal/extract.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/lib/python/temporal/extract.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -109,7 +109,8 @@
             for row in rows:
                 count += 1
 
-                core.percent(count, num_rows, 1)
+                if count%10 == 0:
+                    core.percent(count, num_rows, 1)
 
                 map_name = "%s_%i" % (base, count)
 
@@ -141,18 +142,18 @@
 
                 # Add process to the process list
                 if type == "raster":
-                    core.verbose(_("Apply r.mapcalc expression: \"%s\"")
-                                 % expr)
+                    #core.verbose(_("Apply r.mapcalc expression: \"%s\"")
+                    #             % expr)
                     proc_list.append(Process(target=run_mapcalc2d,
                                              args=(expr,)))
                 elif type == "raster3d":
-                    core.verbose(_("Apply r3.mapcalc expression: \"%s\"")
-                                 % expr)
+                    #core.verbose(_("Apply r3.mapcalc expression: \"%s\"")
+                    #             % expr)
                     proc_list.append(Process(target=run_mapcalc3d,
                                              args=(expr,)))
                 elif type == "vector":
-                    core.verbose(_("Apply v.extract where statement: \"%s\"")
-                                 % expression)
+                    #core.verbose(_("Apply v.extract where statement: \"%s\"")
+                    #             % expression)
                     if row["layer"]:
                         proc_list.append(Process(target=run_vector_extraction,
                                                  args=(row["name"] + "@" + \
@@ -208,9 +209,10 @@
         count = 0
         for row in rows:
             count += 1
+            
+            if count%10 == 0:
+                core.percent(count, num_rows, 1)
 
-            core.percent(count, num_rows, 1)
-
             old_map = sp.get_new_map_instance(row["id"])
             old_map.select(dbif)
 

Modified: grass/trunk/lib/python/temporal/mapcalc.py
===================================================================
--- grass/trunk/lib/python/temporal/mapcalc.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/lib/python/temporal/mapcalc.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -235,7 +235,8 @@
         for i in range(num):
 
             count += 1
-            core.percent(count, num, 1)
+            if count%10 == 0:
+                core.percent(count, num, 1)
 
             # Create the r.mapcalc statement for the current time step
             map_name = "%s_%i" % (base, count)
@@ -289,9 +290,9 @@
 
             map_list.append(new_map)
 
+            #core.verbose(_("Apply mapcalc expression: \"%s\"") % expr)
+
             # Start the parallel r.mapcalc computation
-            core.verbose(_("Apply mapcalc expression: \"%s\"") % expr)
-
             if type == "raster":
                 proc_list.append(Process(target=_run_mapcalc2d, args=(expr,)))
             else:
@@ -338,7 +339,8 @@
         for new_map in map_list:
 
             count += 1
-            core.percent(count, num, 1)
+            if count%10 == 0:
+                core.percent(count, num, 1)
 
             # Read the map data
             new_map.load()

Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -182,7 +182,8 @@
     core.message(_("Gathering map informations"))
 
     for count in range(len(maplist)):
-        core.percent(count, num_maps, 1)
+        if count%50 == 0:
+            core.percent(count, num_maps, 1)
 
         # Get a new instance of the map type
         map = dataset_factory(type, maplist[count]["id"])
@@ -303,7 +304,8 @@
         num_maps = len(map_object_list)
         core.message(_("Register maps in the space time raster dataset"))
         for map in map_object_list:
-            core.percent(count, num_maps, 1)
+            if count%50 == 0:
+                core.percent(count, num_maps, 1)
             sp.register_map(map=map, dbif=dbif)
             count += 1
 
@@ -379,14 +381,15 @@
                     start_time, increment, 1)
                 if end_time is None:
                     core.fatal(_("Error in increment computation"))
-        if map.get_layer():
-            core.verbose(_("Set absolute valid time for map <%(id)s> with "
-                           "layer %(layer)s to %(start)s - %(end)s") %
-                         {'id': map.get_map_id(), 'layer': map.get_layer(),
-                          'start': str(start_time), 'end': str(end_time)})
-        else:
-            core.verbose(_("Set absolute valid time for map <%s> to %s - %s") %
-                         (map.get_map_id(), str(start_time), str(end_time)))
+        # Commented because of performance issue calling g.message thousend times
+        #if map.get_layer():
+        #    core.verbose(_("Set absolute valid time for map <%(id)s> with "
+        #                   "layer %(layer)s to %(start)s - %(end)s") %
+        #                 {'id': map.get_map_id(), 'layer': map.get_layer(),
+        #                  'start': str(start_time), 'end': str(end_time)})
+        #else:
+        #    core.verbose(_("Set absolute valid time for map <%s> to %s - %s") %
+        #                 (map.get_map_id(), str(start_time), str(end_time)))
 
         map.set_absolute_time(start_time, end_time, None)
     else:
@@ -401,15 +404,16 @@
             if interval:
                 end_time = start_time + int(increment)
 
-        if map.get_layer():
-            core.verbose(_("Set relative valid time for map <%s> with layer %s "
-                           "to %i - %s with unit %s") %
-                         (map.get_map_id(), map.get_layer(), start_time,
-                          str(end_time), unit))
-        else:
-            core.verbose(_("Set relative valid time for map <%s> to %i - %s "
-                           "with unit %s") % (map.get_map_id(), start_time,
-                                              str(end_time), unit))
+        # Commented because of performance issue calling g.message thousend times
+        #if map.get_layer():
+        #    core.verbose(_("Set relative valid time for map <%s> with layer %s "
+        #                   "to %i - %s with unit %s") %
+        #                 (map.get_map_id(), map.get_layer(), start_time,
+        #                  str(end_time), unit))
+        #else:
+        #    core.verbose(_("Set relative valid time for map <%s> to %i - %s "
+        #                   "with unit %s") % (map.get_map_id(), start_time,
+        #                                      str(end_time), unit))
 
         map.set_relative_time(start_time, end_time, unit)
 
@@ -893,13 +897,13 @@
         return None
 
     if sp.is_in_db(dbif) and overwrite == True:
-        core.info(_("Overwrite space time %s dataset <%s> "
+        core.warning(_("Overwrite space time %s dataset <%s> "
                      "and unregister all maps.") %
                    (sp.get_new_map_instance(None).get_type(), name))
         sp.delete(dbif)
         sp = sp.get_new_instance(id)
 
-    core.verbose(_("Create space time %s dataset.") %
+    core.verbose(_("Create new space time %s dataset.") %
                   sp.get_new_map_instance(None).get_type())
 
     sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,

Modified: grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py
===================================================================
--- grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/temporal/t.rast.neighbors/t.rast.neighbors.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -142,7 +142,8 @@
     for row in rows:
         count += 1
 
-        grass.percent(count, num_rows, 1)
+        if count%10 == 0:
+            grass.percent(count, num_rows, 1)
 
         map_name = "%s_%i" % (base, count)
         map_id = dummy.build_id(map_name, mapset)
@@ -206,8 +207,8 @@
     count = 0
     for row in rows:
         count += 1
-    
-        grass.percent(count, num_rows, 1)
+        if count%10 == 0:
+            grass.percent(count, num_rows, 1)
         # Register the new maps
         if row["id"] in new_maps:
             new_map = new_maps[row["id"]]

Modified: grass/trunk/temporal/t.support/t.support.py
===================================================================
--- grass/trunk/temporal/t.support/t.support.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/temporal/t.support/t.support.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -69,7 +69,6 @@
 
 ############################################################################
 
-
 def main():
 
     # Get the options
@@ -131,8 +130,9 @@
         # We collect the delete and update statements
         for map in maps:
 
-            grass.percent(count, len(maps), 1)
             count += 1
+            if count%10 == 0:
+                grass.percent(count, len(maps), 1)
 
             map.select(dbif=dbif)
 

Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py	2013-04-16 07:51:09 UTC (rev 55827)
+++ grass/trunk/temporal/t.unregister/t.unregister.py	2013-04-16 08:31:10 UTC (rev 55828)
@@ -130,7 +130,8 @@
     # Unregister already registered maps
     grass.message(_("Unregistered maps"))
     for mapid in maplist:
-        grass.percent(count, num_maps, 1)
+        if count%10 == 0:
+            grass.percent(count, num_maps, 1)
 
         map = tgis.dataset_factory(type, mapid)
 



More information about the grass-commit mailing list