Browse Source

fix string format and PEP 8

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56823 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 12 năm trước cách đây
mục cha
commit
ac9b3f5963

+ 176 - 142
lib/python/temporal/abstract_map_dataset.py

@@ -20,27 +20,33 @@ for details.
 from abstract_dataset import *
 from datetime_math import *
 
+
 class AbstractMapDataset(AbstractDataset):
     """!This is the base class for all maps (raster, vector, raster3d).
-    
+
         The temporal extent, the spatial extent and the metadata of maps
-        are stored in the temporal database. Maps can be registered in the temporal
-        database, updated and deleted. 
-        
+        are stored in the temporal database. Maps can be registered in the
+        temporal database, updated and deleted.
+
         This class provides all functionalities that are needed to manage maps
         in the temporal database. That are:
-        - insert() to register the map and therefore its spatio-temporal extent and metadata in the temporal database
-        - update() to update the map spatio-temporal extent and metadata in the temporal database
-        - unregister() to unregister the map from each space time dataset in which this map is registered
+        - insert() to register the map and therefore its spatio-temporal extent
+                   and metadata in the temporal database
+        - update() to update the map spatio-temporal extent and metadata in the
+                   temporal database
+        - unregister() to unregister the map from each space time dataset in
+                       which this map is registered
         - delete() to remove the map from the temporal database
         - Methods to set relative and absolute time stamps
-        - Abstract methods that must be implemented in the map specific subclasses
+        - Abstract methods that must be implemented in the map specific
+          subclasses
     """
     def __init__(self):
         AbstractDataset.__init__(self)
 
     def get_new_stds_instance(self, ident):
-        """!Return a new space time dataset instance that store maps with the type of this map object (rast, rast3d or vect)
+        """!Return a new space time dataset instance that store maps with the
+           type of this map object (rast, rast3d or vect)
 
            @param ident The identifier of the space time dataset
            @return The new space time dataset instance
@@ -50,11 +56,11 @@ class AbstractMapDataset(AbstractDataset):
 
     def get_stds_register(self):
         """!Return the space time dataset register table name
-        
+
             Maps can be registered in several different space time datasets.
-            This method returns the name of the register table in the 
+            This method returns the name of the register table in the
             temporal database.
-            
+
             @return The name of the stds register table
         """
         raise ImplementationError(
@@ -63,7 +69,7 @@ class AbstractMapDataset(AbstractDataset):
     def set_stds_register(self, name):
         """!Set the space time dataset register table name.
 
-           This table stores all space time datasets in 
+           This table stores all space time datasets in
            which this map is registered.
 
            @param name The name of the register table
@@ -72,16 +78,17 @@ class AbstractMapDataset(AbstractDataset):
             "This method must be implemented in the subclasses")
 
     def check_resolution_with_current_region(self):
-        """!Check if the raster or voxel resolution is 
+        """!Check if the raster or voxel resolution is
            finer than the current resolution
-           
-           - Return "finer" in case the raster/voxel resolution is finer 
+
+           - Return "finer" in case the raster/voxel resolution is finer
              than the current region
-           - Return "coarser" in case the raster/voxel resolution is coarser 
+           - Return "coarser" in case the raster/voxel resolution is coarser
              than the current region
 
-           Vector maps have no resolution, since they store the coordinates directly.
-           
+           Vector maps have no resolution, since they store the coordinates
+           directly.
+
            @return "finer" or "coarser"
         """
         raise ImplementationError(
@@ -89,20 +96,21 @@ class AbstractMapDataset(AbstractDataset):
 
     def has_grass_timestamp(self):
         """!Check if a grass file based time stamp exists for this map.
-            @return True is the grass file based time stamped exists for this map
+            @return True is the grass file based time stamped exists for this
+                    map
         """
         raise ImplementationError(
             "This method must be implemented in the subclasses")
 
     def write_timestamp_to_grass(self):
-        """!Write the timestamp of this map into the map metadata 
+        """!Write the timestamp of this map into the map metadata
            in the grass file system based spatial database.
         """
         raise ImplementationError(
             "This method must be implemented in the subclasses")
 
     def remove_timestamp_from_grass(self):
-        """!Remove the timestamp from the grass file 
+        """!Remove the timestamp from the grass file
            system based spatial database
         """
         raise ImplementationError(
@@ -117,20 +125,20 @@ class AbstractMapDataset(AbstractDataset):
             "This method must be implemented in the subclasses")
 
     def read_info(self):
-        """!Read the map info from the grass file system based database and 
+        """!Read the map info from the grass file system based database and
            store the content into a dictionary
         """
         raise ImplementationError(
             "This method must be implemented in the subclasses")
 
     def load(self):
-        """!Load the content of this object from the grass 
+        """!Load the content of this object from the grass
            file system based database"""
         raise ImplementationError(
             "This method must be implemented in the subclasses")
 
     def _convert_timestamp(self):
-        """!Convert the valid time into a grass datetime library 
+        """!Convert the valid time into a grass datetime library
            compatible timestamp string
 
             This methods works for relative and absolute time
@@ -155,13 +163,13 @@ class AbstractMapDataset(AbstractDataset):
         return start
 
     def get_map_id(self):
-        """!Return the map id. The map id is the unique identifier 
+        """!Return the map id. The map id is the unique identifier
            in grass and must not be equal to the
-           primary key identifier (id) of the map in the database. 
+           primary key identifier (id) of the map in the database.
            Since vector maps may have layer information,
            the unique id is a combination of name, layer and mapset.
 
-           Use get_map_id() every time your need to access the grass map 
+           Use get_map_id() every time your need to access the grass map
            in the file system but not to identify
            map information in the temporal database.
 
@@ -172,15 +180,16 @@ class AbstractMapDataset(AbstractDataset):
     def build_id(self, name, mapset, layer=None):
         """!Convenient method to build the unique identifier
 
-            Existing layer and mapset definitions in the name 
+            Existing layer and mapset definitions in the name
             string will be reused
-           
+
            @param name The name of the map
            @param mapset The mapset in which the map is located
-           @param layer The layer of the vector map, use None in case no layer exists
+           @param layer The layer of the vector map, use None in case no
+                        layer exists
 
-           @return the id of the map as "name(:layer)@mapset" 
-                  while layer is optional
+           @return the id of the map as "name(:layer)@mapset"
+                   while layer is optional
         """
 
         # Check if the name includes any mapset
@@ -262,16 +271,19 @@ class AbstractMapDataset(AbstractDataset):
             self.print_topology_shell_info()
 
     def insert(self, dbif=None, execute=True):
-        """!Insert the map content into the database from the internal structure
+        """!Insert the map content into the database from the internal
+           structure
 
-           This functions assures that the timestamp is written to the 
-           grass file system based database in addition to the temporal database entry.
+           This functions assures that the timestamp is written to the
+           grass file system based database in addition to the temporal
+           database entry.
 
            @param dbif The database interface to be used
            @param execute If True the SQL statements will be executed.
-                           If False the prepared SQL statements are 
-                           returned and must be executed by the caller.
-            @return The SQL insert statement in case execute=False, or an empty string otherwise
+                          If False the prepared SQL statements are
+                          returned and must be executed by the caller.
+           @return The SQL insert statement in case execute=False, or an
+                   empty string otherwise
         """
         self.write_timestamp_to_grass()
         return AbstractDataset.insert(self, dbif, execute)
@@ -280,14 +292,16 @@ class AbstractMapDataset(AbstractDataset):
         """!Update the map content in the database from the internal structure
            excluding None variables
 
-           This functions assures that the timestamp is written to the 
-           grass file system based database in addition to the temporal database entry.
+           This functions assures that the timestamp is written to the
+           grass file system based database in addition to the temporal
+           database entry.
 
            @param dbif The database interface to be used
            @param execute If True the SQL statements will be executed.
-                           If False the prepared SQL statements are 
-                           returned and must be executed by the caller.
-            @return The SQL insert statement in case execute=False, or an empty string otherwise
+                          If False the prepared SQL statements are
+                          returned and must be executed by the caller.
+           @return The SQL insert statement in case execute=False, or an
+                   empty string otherwise
         """
         self.write_timestamp_to_grass()
         return AbstractDataset.update(self, dbif, execute)
@@ -296,14 +310,16 @@ class AbstractMapDataset(AbstractDataset):
         """!Update the map content in the database from the internal structure
            including None variables
 
-           This functions assures that the timestamp is written to the 
-           grass file system based database in addition to the temporal database entry.
+           This functions assures that the timestamp is written to the
+           grass file system based database in addition to the temporal
+           database entry.
 
            @param dbif The database interface to be used
            @param execute If True the SQL statements will be executed.
-                           If False the prepared SQL statements are 
-                           returned and must be executed by the caller.
-            @return The SQL insert statement in case execute=False, or an empty string otherwise
+                          If False the prepared SQL statements are
+                          returned and must be executed by the caller.
+            @return The SQL insert statement in case execute=False, or an
+                    empty string otherwise
         """
         self.write_timestamp_to_grass()
         return AbstractDataset.update_all(self, dbif, execute)
@@ -311,50 +327,56 @@ class AbstractMapDataset(AbstractDataset):
     def set_absolute_time(self, start_time, end_time=None, timezone=None):
         """!Set the absolute time with start time and end time
 
-            The end time is optional and must be set to None in case of time instance.
-        
+            The end time is optional and must be set to None in case of time
+            instance.
+
             This method only modifies this object and does not commit
             the modifications to the temporal database.
-            
-           @param start_time a datetime object specifying the start time of the map
-           @param end_time a datetime object specifying the end time of the map, None in case or time instance
+
+           @param start_time a datetime object specifying the start time of the
+                             map
+           @param end_time a datetime object specifying the end time of the
+                           map, None in case or time instance
            @param timezone Thee timezone of the map (not used)
         """
         if start_time and not isinstance(start_time, datetime):
             if self.get_layer() is not None:
-                core.fatal(_("Start time must be of type datetime "
-                             "for %s map <%s> with layer: %s") % \
-                           (self.get_type(), self.get_map_id(), 
-                            self.get_layer()))
+                core.fatal(_("Start time must be of type datetime for %(type)s"
+                             " map <%(id)s> with layer: %(l)s") % {
+                             'type': self.get_type(), 'id': self.get_map_id(), 
+                             'l': self.get_layer()})
             else:
-                core.fatal(_("Start time must be of type "
-                             "datetime ""for %s map <%s>") % \
-                           (self.get_type(), self.get_map_id()))
+                core.fatal(_("Start time must be of type datetime for "
+                             "%(type)s map <%(id)s>") % {
+                             'type': self.get_type(), 'id': self.get_map_id()})
 
         if end_time and not isinstance(end_time, datetime):
             if self.get_layer():
-                core.fatal(_("End time must be of type datetime "
-                             "for %s map <%s> with layer: %s") % \
-                           (self.get_type(), self.get_map_id(), 
-                            self.get_layer()))
+                core.fatal(_("End time must be of type datetime for %(type)s "
+                             "map <%(id)s> with layer: %(l)s") % {
+                             'type': self.get_type(), 'id': self.get_map_id(),
+                             'l': self.get_layer()})
             else:
-                core.fatal(_("End time must be of type datetime "
-                             "for %s map <%s>") % (self.get_type(), 
-                                                   self.get_map_id()))
+                core.fatal(_("End time must be of type datetime for "
+                             "%(type)s map <%(id)s>") % {
+                             'type': self.get_type(), 'id': self.get_map_id()})
 
         if start_time is not None and end_time is not None:
             if start_time > end_time:
                 if self.get_layer():
-                    core.fatal(_("End time must be greater than "
-                                 "start time for %s map <%s> with layer: %s") %\
-                                (self.get_type(), self.get_map_id(), 
-                                 self.get_layer()))
+                    core.fatal(_("End time must be greater than start time for"
+                                 " %(type)s map <%(id)s> with layer: %(l)s") % {
+                                 'type': self.get_type(),
+                                 'id': self.get_map_id(),
+                                 'l': self.get_layer()})
                 else:
-                    core.fatal(_("End time must be greater than "
-                                 "start time for %s map <%s>") % \
-                               (self.get_type(), self.get_map_id()))
+                    core.fatal(_("End time must be greater than start time "
+                                 "for %(type)s map <%(id)s>") % {
+                                 'type': self.get_type(),
+                                 'id': self.get_map_id()})
             else:
-                # Do not create an interval in case start and end time are equal
+                # Do not create an interval in case start and end time are
+                # equal
                 if start_time == end_time:
                     end_time = None
 
@@ -362,20 +384,24 @@ class AbstractMapDataset(AbstractDataset):
         self.absolute_time.set_start_time(start_time)
         self.absolute_time.set_end_time(end_time)
         self.absolute_time.set_timezone(timezone)
-        
+
         return True
 
-    def update_absolute_time(self, start_time, end_time=None, 
+    def update_absolute_time(self, start_time, end_time=None,
                              timezone=None, dbif=None):
         """!Update the absolute time
 
-            The end time is optional and must be set to None in case of time instance.
+           The end time is optional and must be set to None in case of time
+           instance.
 
-           This functions assures that the timestamp is written to the 
-           grass file system based database in addition to the temporal database entry.
-           
-           @param start_time a datetime object specifying the start time of the map
-           @param end_time a datetime object specifying the end time of the map, None in case or time instance
+           This functions assures that the timestamp is written to the
+           grass file system based database in addition to the temporal
+           database entry.
+
+           @param start_time a datetime object specifying the start time of
+                  the map
+           @param end_time a datetime object specifying the end time of the
+                  map, None in case or time instance
            @param timezone Thee timezone of the map (not used)
            @param dbif The database interface to be used
         """
@@ -392,16 +418,17 @@ class AbstractMapDataset(AbstractDataset):
 
     def set_relative_time(self, start_time, end_time, unit):
         """!Set the relative time interval
-        
-            The end time is optional and must be set to None in case of time instance.
-            
+
+            The end time is optional and must be set to None in case of time
+            instance.
+
             This method only modifies this object and does not commit
             the modifications to the temporal database.
 
            @param start_time An integer value
            @param end_time An integer value, None in case or time instance
-           @param unit The unit of the relative time. Supported units: 
-                        year(s), month(s), day(s), hour(s), minute(s), second(s)
+           @param unit The unit of the relative time. Supported units:
+                       year(s), month(s), day(s), hour(s), minute(s), second(s)
 
            @return True for success and False otherwise
 
@@ -409,31 +436,32 @@ class AbstractMapDataset(AbstractDataset):
 
         if not self.check_relative_time_unit(unit):
             if self.get_layer() is not None:
-                core.error(_("Unsupported relative time unit type for %s map "
-                             "<%s> with layer %s: %s") % (self.get_type(), 
-                                                          self.get_id(), 
-                                                          self.get_layer(), 
-                                                          unit))
+                core.error(_("Unsupported relative time unit type for %(type)s"
+                             " map <%(id)s> with layer %(l)s: %(u)s") % {
+                             'type': self.get_type(), 'id': self.get_id(),
+                             'l': self.get_layer(), 'u': unit})
             else:
-                core.error(_("Unsupported relative time unit type for %s map "
-                             "<%s>: %s") % (self.get_type(), self.get_id(), 
-                                            unit))
+                core.error(_("Unsupported relative time unit type for %(type)s"
+                             " map <%(id)s>: %(u)s") % {
+                             'type': self.get_type(), 'id': self.get_id(),
+                             'u': unit})
             return False
 
         if start_time is not None and end_time is not None:
             if int(start_time) > int(end_time):
                 if self.get_layer() is not None:
                     core.error(_("End time must be greater than start time for"
-                                 " %s map <%s> with layer %s") % \
-                               (self.get_type(), self.get_id(), 
-                                self.get_layer()))
+                                 " %(type)s map <%(id)s> with layer %(l)s") % \
+                                 {'type': self.get_type(), 'id': self.get_id(),
+                                  'l': self.get_layer()})
                 else:
                     core.error(_("End time must be greater than start time for"
-                                 " %s map <%s>") % (self.get_type(), 
-                                                    self.get_id()))
+                                 " %(type)s map <%(id)s>") % {
+                                 'type': self.get_type(), 'id': self.get_id()})
                 return False
             else:
-                # Do not create an interval in case start and end time are equal
+                # Do not create an interval in case start and end time are
+                # equal
                 if start_time == end_time:
                     end_time = None
 
@@ -451,10 +479,12 @@ class AbstractMapDataset(AbstractDataset):
     def update_relative_time(self, start_time, end_time, unit, dbif=None):
         """!Update the relative time interval
 
-            The end time is optional and must be set to None in case of time instance.
+           The end time is optional and must be set to None in case of time
+           instance.
 
-           This functions assures that the timestamp is written to the 
-           grass file system based database in addition to the temporal database entry.
+           This functions assures that the timestamp is written to the
+           grass file system based database in addition to the temporal
+           database entry.
 
            @param start_time An integer value
            @param end_time An integer value, None in case or time instance
@@ -474,19 +504,20 @@ class AbstractMapDataset(AbstractDataset):
 
     def temporal_buffer(self, increment, update=False, dbif=None):
         """!Create a temporal buffer based on an increment
-        
-           For absolute time the increment must be a string of type "integer unit"
-           Unit can be year, years, month, months, day, days, hour, hours, minute,
-           minutes, day or days.
-        
-           @param increment This is the increment, a string in case of absolute 
+
+           For absolute time the increment must be a string of type "integer
+           unit"
+           Unit can be year, years, month, months, day, days, hour, hours,
+           minute, minutes, day or days.
+
+           @param increment This is the increment, a string in case of absolute
                             time or an integer in case of relative time
-           @param update Perform an immediate database update to store the 
+           @param update Perform an immediate database update to store the
                          modified temporal extent, otherwise only this object
                          will be modified
-                         
+
            Usage:
-           
+
            @code
 
            >>> import grass.temporal as tgis
@@ -547,16 +578,16 @@ class AbstractMapDataset(AbstractDataset):
 
            @endcode
         """
-        
+
         if self.is_time_absolute():
             start, end, tz = self.get_absolute_time()
-            
+
             new_start = decrement_datetime_by_string(start, increment)
             if end == None:
                 new_end = increment_datetime_by_string(start, increment)
             else:
                 new_end = increment_datetime_by_string(end, increment)
-                
+
             if update:
                 self.update_absolute_time(new_start, new_end, tz, dbif=dbif)
             else:
@@ -573,13 +604,13 @@ class AbstractMapDataset(AbstractDataset):
                 self.update_relative_time(new_start, new_end, unit, dbif=dbif)
             else:
                 self.set_relative_time(new_start, new_end, unit)
-        
+
     def set_spatial_extent(self, north, south, east, west, top=0, bottom=0):
         """!Set the spatial extent of the map
 
             This method only modifies this object and does not commit
             the modifications to the temporal database.
-            
+
            @param north The northern edge
            @param south The southern edge
            @param east The eastern edge
@@ -601,10 +632,11 @@ class AbstractMapDataset(AbstractDataset):
             if end is not None:
                 if start >= end:
                     if self.get_layer() is not None:
-                        core.error(_("Map <%s> with layer %s has incorrect "
-                                     "time interval, start time is greater "
-                                     "than end time") % (self.get_map_id(), 
-                                                         self.get_layer()))
+                        core.error(_("Map <%(id)s> with layer %(layer)s has "
+                                     "incorrect time interval, start time is "
+                                     "greater than end time") % {
+                                     'id': self.get_map_id(),
+                                     'layer': self.get_layer()})
                     else:
                         core.error(_("Map <%s> has incorrect time interval, "
                                      "start time is greater than end time") % \
@@ -621,20 +653,21 @@ class AbstractMapDataset(AbstractDataset):
         """!Delete a map entry from database if it exists
 
             Remove dependent entries:
-            * Remove the map entry in each space time dataset in which this map 
+            * Remove the map entry in each space time dataset in which this map
               is registered
             * Remove the space time dataset register table
 
            @param dbif The database interface to be used
-           @param update Call for each unregister statement the update from 
-                          registered maps of the space time dataset. 
-                          This can slow down the un-registration process significantly.
-           @param execute If True the SQL DELETE and DROP table statements will 
+           @param update Call for each unregister statement the update from
+                          registered maps of the space time dataset.
+                          This can slow down the un-registration process
+                          significantly.
+           @param execute If True the SQL DELETE and DROP table statements will
                            be executed.
-                           If False the prepared SQL statements are 
+                           If False the prepared SQL statements are
                            returned and must be executed by the caller.
 
-           @return The SQL statements if execute=False, else an empty string, 
+           @return The SQL statements if execute=False, else an empty string,
                    None in case of a failure
         """
 
@@ -679,17 +712,17 @@ class AbstractMapDataset(AbstractDataset):
         return statement
 
     def unregister(self, dbif=None, update=True, execute=True):
-        """! Remove the map entry in each space time dataset in which this map 
+        """! Remove the map entry in each space time dataset in which this map
            is registered
 
            @param dbif The database interface to be used
-           @param update Call for each unregister statement the update from 
-                          registered maps of the space time dataset. This can 
-                          slow down the un-registration process significantly.
-           @param execute If True the SQL DELETE and DROP table statements 
-                           will be executed.
-                           If False the prepared SQL statements are 
-                           returned and must be executed by the caller.
+           @param update Call for each unregister statement the update from
+                         registered maps of the space time dataset. This can
+                         slow down the un-registration process significantly.
+           @param execute If True the SQL DELETE and DROP table statements
+                          will be executed.
+                          If False the prepared SQL statements are
+                          returned and must be executed by the caller.
 
            @return The SQL statements if execute=False, else an empty string
         """
@@ -736,12 +769,13 @@ class AbstractMapDataset(AbstractDataset):
         return statement
 
     def get_registered_datasets(self, dbif=None):
-        """!Return all space time dataset ids in which this map is registered as
-           dictionary like rows with column "id" or None if this map is not 
+        """!Return all space time dataset ids in which this map is registered
+           as dictionary like rows with column "id" or None if this map is not
            registered in any space time dataset.
 
            @param dbif The database interface to be used
-           @return The SQL rows with the ids of all space time datasets in which this map is registered
+           @return The SQL rows with the ids of all space time datasets in
+                   which this map is registered
         """
         dbif, connected = init_dbif(dbif)
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 400 - 359
lib/python/temporal/abstract_space_time_dataset.py


+ 25 - 18
lib/python/temporal/aggregation.py

@@ -34,8 +34,10 @@ def collect_map_names(sp, dbif, start, end, sampling):
 
        @param sp The space time raster dataset to select aps from
        @param dbif The temporal database interface to use
-       @param start The start time of the sample interval, may be relative or absolute
-       @param end The end time of the sample interval, may be relative or absolute
+       @param start The start time of the sample interval, may be relative or
+              absolute
+       @param end The end time of the sample interval, may be relative or
+              absolute
        @param sampling The sampling methods to use
     """
 
@@ -77,13 +79,13 @@ def collect_map_names(sp, dbif, start, end, sampling):
         use_follows = False
         use_precedes = False
 
-    where = create_temporal_relation_sql_where_statement(start, end, 
-                                                         use_start, 
-                                                         use_during, 
-                                                         use_overlap, 
-                                                         use_contain, 
-                                                         use_equal, 
-                                                         use_follows, 
+    where = create_temporal_relation_sql_where_statement(start, end,
+                                                         use_start,
+                                                         use_during,
+                                                         use_overlap,
+                                                         use_contain,
+                                                         use_equal,
+                                                         use_follows,
                                                          use_precedes)
 
     rows = sp.get_registered_maps("id", where, "start_time", dbif)
@@ -100,17 +102,21 @@ def collect_map_names(sp, dbif, start, end, sampling):
 ###############################################################################
 
 
-def aggregate_raster_maps(inputs, base, start, end, count, method, 
+def aggregate_raster_maps(inputs, base, start, end, count, method,
                           register_null, dbif):
     """!Aggregate a list of raster input maps with r.series
 
        @param inputs The names of the raster maps to be aggregated
        @param base The basename of the new created raster maps
-       @param start The start time of the sample interval, may be relative or absolute
-       @param end The end time of the sample interval, may be relative or absolute
-       @param count The number to be attached to the basename of the new created raster map
+       @param start The start time of the sample interval, may be relative or
+                    absolute
+       @param end The end time of the sample interval, may be relative or
+                  absolute
+       @param count The number to be attached to the basename of the new
+                    created raster map
        @param method The aggreation method to be used by r.series
-       @param register_null If true null maps will be registered in the space time raster dataset, if false not
+       @param register_null If true null maps will be registered in the space
+                            time raster dataset, if false not
        @param dbif The temporal database interface to use
     """
 
@@ -128,11 +134,12 @@ def aggregate_raster_maps(inputs, base, start, end, count, method,
             new_map.delete(dbif)
             new_map = RasterDataset(map_id)
         else:
-            core.error(_("Raster map <%s> is already in temporal database, use overwrite flag to overwrite"))
+            core.error(_("Raster map <%s> is already in temporal database, " \
+                         "use overwrite flag to overwrite"))
             return
 
-    core.verbose(_("Compute aggregation of maps between %s - %s" % (
-        str(start), str(end))))
+    core.verbose(_("Compute aggregation of maps between %(st)s - %(end)s" % {
+                   'st': str(start), 'end': str(end)}))
 
     # Create the r.series input file
     filename = core.tempfile(True)
@@ -145,7 +152,7 @@ def aggregate_raster_maps(inputs, base, start, end, count, method,
     file.close()
     # Run r.series
     ret = core.run_command("r.series", flags="z", file=filename,
-                           output=output, overwrite=core.overwrite(), 
+                           output=output, overwrite=core.overwrite(),
                            method=method)
 
     if ret != 0:

+ 17 - 13
lib/python/temporal/create.py

@@ -27,27 +27,29 @@ from factory import *
 
 ###############################################################################
 
+
 def create_space_time_dataset(name, type, temporaltype, title, descr, semantic,
                               dbif=None, overwrite=False):
     """!Create a new space time dataset
-    
+
        This function is sensitive to the settings in grass.core.overwrite to
        overwrute existing space time datasets.
-    
+
        @param name The name of the new space time dataset
-       @param type The type (strds, stvds, str3ds) of the new space time dataset
+       @param type The type (strds, stvds, str3ds) of the new space time
+                   dataset
        @param temporaltype The temporal type (relative or absolute)
        @param title The title
        @param descr The dataset description
        @param semantic Semantical information
        @param dbif The temporal database interface to be used
        @param overwrite Flag to allow overwriting
-       
+
        @return The new created space time dataset
-       
+
        This function will raise a ScriptError in case of an error.
     """
-    
+
     #Get the current mapset to create the id of the space time dataset
 
     mapset = core.gisenv()["MAPSET"]
@@ -60,20 +62,22 @@ def create_space_time_dataset(name, type, temporaltype, title, descr, semantic,
     if sp.is_in_db(dbif) and overwrite == False:
         if connected:
             dbif.close()
-        core.fatal(_("Space time %s dataset <%s> is already in the database. "
-                      "Use the overwrite flag.") %
-                    (sp.get_new_map_instance(None).get_type(), name))
+        core.fatal(_("Space time %(sp)s dataset <%(name)s> is already in the"
+                      " database. Use the overwrite flag.") % {
+                      'sp': sp.get_new_map_instance(None).get_type(),
+                      'name': name})
         return None
 
     if sp.is_in_db(dbif) and overwrite == True:
-        core.warning(_("Overwrite space time %s dataset <%s> "
-                     "and unregister all maps.") %
-                   (sp.get_new_map_instance(None).get_type(), name))
+        core.warning(_("Overwrite space time %(sp)s dataset <%(name)s> and "
+                       "unregister all maps.") % {
+                       'sp': sp.get_new_map_instance(None).get_type(),
+                       'name': name})
         sp.delete(dbif)
         sp = sp.get_new_instance(id)
 
     core.verbose(_("Create new space time %s dataset.") %
-                  sp.get_new_map_instance(None).get_type())
+                   sp.get_new_map_instance(None).get_type())
 
     sp.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,
                           title=title, description=descr)

+ 29 - 18
lib/python/temporal/extract.py

@@ -17,24 +17,29 @@ from multiprocessing import Process
 
 ############################################################################
 
+
 def extract_dataset(input, output, type, where, expression, base, nprocs=1,
                     register_null=False, layer=1,
                     vtype="point,line,boundary,centroid,area,face"):
     """!Extract a subset of a space time raster, raster3d or vector dataset
 
-       A mapcalc expression can be provided to process the temporal extracted maps.
+       A mapcalc expression can be provided to process the temporal extracted
+       maps.
        Mapcalc expressions are supported for raster and raster3d maps.
 
        @param input The name of the input space time raster/raster3d dataset
-       @param output The name of the extracted new space time raster/raster3d dataset
+       @param output The name of the extracted new space time raster/raster3d
+                     dataset
        @param type The type of the dataset: "raster", "raster3d" or vector
        @param where The temporal SQL WHERE statement for subset extraction
-       @param expression The r(3).mapcalc expression or the v.extract where statement
+       @param expression The r(3).mapcalc expression or the v.extract where
+                         statement
        @param base The base name of the new created maps in case a mapclac
-              expression is provided
-       @param nprocs The number of parallel processes to be used for mapcalc processing
+                   expression is provided
+       @param nprocs The number of parallel processes to be used for mapcalc
+                     processing
        @param register_null Set this number True to register empty maps
-             (only raster and raster3d maps)
+                            (only raster and raster3d maps)
        @param layer The vector layer number to be used when no timestamped
               layer is present, default is 1
        @param vtype The feature type to be extracted for vector maps, default
@@ -67,7 +72,8 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
 
     if not sp.is_in_db(dbif):
         dbif.close()
-        core.fatal(_("Space time %s dataset <%s> not found") % (type, id))
+        core.fatal(_("Space time %(type)s dataset <%(id)s> not found") % {
+                     'type': type, 'id': id})
 
     if expression and not base:
         dbif.close()
@@ -86,8 +92,9 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
     if new_sp.is_in_db():
         if not core.overwrite():
             dbif.close()
-            core.fatal(_("Space time %s dataset <%s> is already in database,"
-                         " use overwrite flag to overwrite") % (type, out_id))
+            core.fatal(_("Space time %(type)s dataset <%(id)s> is already in "
+                         "database, use overwrite flag to overwrite") % {
+                         'type': type, 'id': out_id})
     if type == "vector":
         rows = sp.get_registered_maps(
             "id,name,mapset,layer", where, "start_time", dbif)
@@ -109,7 +116,7 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
             for row in rows:
                 count += 1
 
-                if count%10 == 0:
+                if count % 10 == 0:
                     core.percent(count, num_rows, 1)
 
                 map_name = "%s_%i" % (base, count)
@@ -135,8 +142,8 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
                         new_map.delete(dbif)
                         new_map = sp.get_new_map_instance(map_id)
                     else:
-                        core.error(_("Map <%s> is already in temporal database,"
-                                     " use overwrite flag to overwrite") %
+                        core.error(_("Map <%s> is already in temporal database"
+                                     ", use overwrite flag to overwrite") %
                                     (new_map.get_map_id()))
                         continue
 
@@ -158,19 +165,19 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
                         proc_list.append(Process(target=run_vector_extraction,
                                                  args=(row["name"] + "@" + \
                                                        row["mapset"],
-                                                 map_name, row["layer"], 
+                                                 map_name, row["layer"],
                                                  vtype, expression)))
                     else:
                         proc_list.append(Process(target=run_vector_extraction,
                                                  args=(row["name"] + "@" + \
                                                        row["mapset"],
-                                                 map_name, layer, vtype, 
+                                                 map_name, layer, vtype,
                                                  expression)))
 
                 proc_list[proc_count].start()
                 proc_count += 1
 
-                # Join processes if the maximum number of processes are 
+                # Join processes if the maximum number of processes are
                 # reached or the end of the loop is reached
                 if proc_count == nprocs or proc_count == num_rows:
                     proc_count = 0
@@ -209,8 +216,8 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
         count = 0
         for row in rows:
             count += 1
-            
-            if count%10 == 0:
+
+            if count % 10 == 0:
                 core.percent(count, num_rows, 1)
 
             old_map = sp.get_new_map_instance(row["id"])
@@ -224,7 +231,8 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
                     # Read the raster map data
                     new_map.load()
 
-                    # In case of a empty map continue, do not register empty maps
+                    # In case of a empty map continue, do not register empty
+                    # maps
                     if type == "raster" or type == "raster3d":
                         if new_map.metadata.get_min() is None and \
                             new_map.metadata.get_max() is None:
@@ -279,16 +287,19 @@ def extract_dataset(input, output, type, where, expression, base, nprocs=1,
 
 ###############################################################################
 
+
 def run_mapcalc2d(expr):
     """Helper function to run r.mapcalc in parallel"""
     return core.run_command("r.mapcalc", expression=expr,
                             overwrite=core.overwrite(), quiet=True)
 
+
 def run_mapcalc3d(expr):
     """Helper function to run r3.mapcalc in parallel"""
     return core.run_command("r3.mapcalc", expression=expr,
                             overwrite=core.overwrite(), quiet=True)
 
+
 def run_vector_extraction(input, output, layer, type, where):
     """Helper function to run r.mapcalc in parallel"""
     return core.run_command("v.extract", input=input, output=output,

+ 146 - 114
lib/python/temporal/mapcalc.py

@@ -18,28 +18,30 @@ from multiprocessing import Process
 ############################################################################
 
 
-def dataset_mapcalculator(inputs, output, type, expression, base, method, 
+def dataset_mapcalculator(inputs, output, type, expression, base, method,
                           nprocs=1, register_null=False, spatial=False):
-    """!Perform map-calculations of maps from different space time 
-       raster/raster3d datasets, using a specific sampling method 
+    """!Perform map-calculations of maps from different space time
+       raster/raster3d datasets, using a specific sampling method
        to select temporal related maps.
 
-       A mapcalc expression must be provided to process the temporal 
-       selected maps. Temporal operators are available in addition to 
+       A mapcalc expression must be provided to process the temporal
+       selected maps. Temporal operators are available in addition to
        the r.mapcalc operators:
-       
+
        Supported operators for relative and absolute time are:
-       - td() - the time delta of the current interval in days 
-         and fractions of days or the unit in case of relative time
-       - start_time() - The start time of the interval from the begin of the time 
-         series in days and fractions of days or the unit in case of relative time
-       - end_time() - The end time of the current interval from the begin of the time 
-         series in days and fractions of days or the unit in case of relative time
-         
+       - td() - the time delta of the current interval in days
+                and fractions of days or the unit in case of relative time
+       - start_time() - The start time of the interval from the begin of
+                        the time series in days and fractions of days or the
+                        unit in case of relative time
+       - end_time() - The end time of the current interval from the begin of
+                      the time series in days and fractions of days or the
+                      unit in case of relative time
+
        Supported operators for absolute time:
        - start_doy() - Day of year (doy) from the start time [1 - 366]
-       - start_dow() - Day of week (dow) from the start time [1 - 7], 
-         the start of the week is monday == 1
+       - start_dow() - Day of week (dow) from the start time [1 - 7],
+                       the start of the week is monday == 1
        - start_year() - The year of the start time [0 - 9999]
        - start_month() - The month of the start time [1 - 12]
        - start_week() - Week of year of the start time [1 - 54]
@@ -49,8 +51,8 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
        - start_second() - The second of the start time [0 - 59]
 
        - end_doy() - Day of year (doy) from the end time [1 - 366]
-       - end_dow() - Day of week (dow) from the end time [1 - 7], 
-         the start of the week is monday == 1
+       - end_dow() - Day of week (dow) from the end time [1 - 7],
+                     the start of the week is monday == 1
        - end_year() - The year of the end time [0 - 9999]
        - end_month() - The month of the end time [1 - 12]
        - end_week() - Week of year of the end time [1 - 54]
@@ -58,16 +60,15 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
        - end_hour() - The hour of the end time [0 - 23]
        - end_minute() - The minute of the end time [0 - 59]
        - end_second() - The minute of the end time [0 - 59]
-       
 
        @param inputs The names of the input space time raster/raster3d datasets
        @param output The name of the extracted new space time raster(3d) dataset
        @param type The type of the dataset: "raster" or "raster3d"
        @param expression The r(3).mapcalc expression
-       @param base The base name of the new created maps in case a 
+       @param base The base name of the new created maps in case a
               mapclac expression is provided
        @param method The method to be used for temporal sampling
-       @param nprocs The number of parallel processes to be used for 
+       @param nprocs The number of parallel processes to be used for
               mapcalc processing
        @param register_null Set this number True to register empty maps
        @param spatial Check spatial overlap
@@ -94,12 +95,13 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
 
     if not first_input.is_in_db(dbif):
         dbif.close()
-        core.fatal(_("Space time %s dataset <%s> not found") % (type, id))
+        core.fatal(_("Space time %(t)s dataset <%(i)s> not found") % {'t': type,
+                                                                      'i': id})
 
     # Fill the object with data from the temporal database
     first_input.select(dbif)
 
-    # All additional inputs in reverse sorted order to avoid 
+    # All additional inputs in reverse sorted order to avoid
     # wrong name substitution
     input_name_list = input_name_list[1:]
     input_name_list.sort()
@@ -117,8 +119,8 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
 
         if not sp.is_in_db(dbif):
             dbif.close()
-            core.fatal(_("Space time %s dataset <%s> not "
-                         "found in temporal database") % (type, id))
+            core.fatal(_("Space time %(t)s dataset <%(i)s> not "
+                         "found in temporal database") % {'t': type, 'i': id})
 
         sp.select(dbif)
 
@@ -136,8 +138,9 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
     if new_sp.is_in_db(dbif):
         if not core.overwrite():
             dbif.close()
-            core.fatal(_("Space time %s dataset <%s> is already in database, "
-                         "use overwrite flag to overwrite") % (type, out_id))
+            core.fatal(_("Space time %(t)s dataset <%(i)s> is already in "
+                         "database, use overwrite flag to overwrite") % {'t': type,
+                                                                         'i': out_id})
 
     # Sample all inputs by the first input and create a sample matrix
     if spatial:
@@ -154,7 +157,7 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
         has_samples = False
         for dataset in input_list:
             list = dataset.sample_by_dataset(stds=first_input,
-                                             method=method, spatial=spatial, 
+                                             method=method, spatial=spatial,
                                              dbif=dbif)
 
             # In case samples are not found
@@ -192,7 +195,7 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
                                    "computation. Use t.rast.aggregate.ds to "
                                    "create synchronous raster datasets."))
 
-                # Store all maps! This includes non existent maps, 
+                # Store all maps! This includes non existent maps,
                 # identified by id == None
                 map_name_list.append(maplist[0].get_name())
 
@@ -235,17 +238,17 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
         for i in range(num):
 
             count += 1
-            if count%10 == 0:
+            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)
             # Remove spaces and new lines
             expr = expression.replace(" ", "")
-            
+
             # Check that all maps are in the sample
             valid_maps = True
-            # Replace all dataset names with their map names of the 
+            # Replace all dataset names with their map names of the
             # current time step
             for j in range(len(map_matrix)):
                 if map_matrix[j][i] is None:
@@ -258,7 +261,7 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
             if not valid_maps:
                 continue
 
-            # Create the new map id and check if the map is already 
+            # Create the new map id and check if the map is already
             # in the database
             map_id = map_name + "@" + mapset
 
@@ -282,9 +285,10 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
             else:
                 start, end, unit = sample_map_list[i].get_relative_time()
                 new_map.set_relative_time(start, end, unit)
-            
+
             # Parse the temporal expressions
-            expr = _operator_parser(expr, sample_map_list[0], sample_map_list[i])
+            expr = _operator_parser(expr, sample_map_list[0],
+                                    sample_map_list[i])
             # Add the output map name
             expr = "%s=%s" % (map_name, expr)
 
@@ -335,11 +339,12 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
         # collect empty maps to remove them
         empty_maps = []
 
-        # Insert maps in the temporal database and in the new space time dataset
+        # Insert maps in the temporal database and in the new space time
+        # dataset
         for new_map in map_list:
 
             count += 1
-            if count%10 == 0:
+            if count % 10 == 0:
                 core.percent(count, num, 1)
 
             # Read the map data
@@ -384,34 +389,38 @@ def dataset_mapcalculator(inputs, output, type, expression, base, method,
 
 def _run_mapcalc2d(expr):
     """Helper function to run r.mapcalc in parallel"""
-    return core.run_command("r.mapcalc", expression=expr, 
+    return core.run_command("r.mapcalc", expression=expr,
                             overwrite=core.overwrite(), quiet=True)
 
 ###############################################################################
 
+
 def _run_mapcalc3d(expr):
     """Helper function to run r3.mapcalc in parallel"""
-    return core.run_command("r3.mapcalc", expression=expr, 
+    return core.run_command("r3.mapcalc", expression=expr,
                             overwrite=core.overwrite(), quiet=True)
 
 ###############################################################################
 
+
 def _operator_parser(expr, first, current):
-    """This method parses the expression string and substitutes 
+    """This method parses the expression string and substitutes
        the temporal operators with numerical values.
-       
+
        Supported operators for relative and absolute time are:
-       * td() - the time delta of the current interval in days 
+       * td() - the time delta of the current interval in days
          and fractions of days or the unit in case of relative time
-       * start_time() - The start time of the interval from the begin of the time 
-         series in days and fractions of days or the unit in case of relative time
-       * end_time() - The end time of the current interval from the begin of the time 
-         series in days and fractions of days or the unit in case of relative time
-         
+       * start_time() - The start time of the interval from the begin of the
+                        time series in days and fractions of days or the unit
+                        in case of relative time
+       * end_time() - The end time of the current interval from the begin of
+                      the time series in days and fractions of days or the
+                      unit in case of relative time
+
        Supported operators for absolute time:
        * start_doy() - Day of year (doy) from the start time [1 - 366]
-       * start_dow() - Day of week (dow) from the start time [1 - 7], 
-         the start of the week is monday == 1
+       * start_dow() - Day of week (dow) from the start time [1 - 7],
+                       the start of the week is monday == 1
        * start_year() - The year of the start time [0 - 9999]
        * start_month() - The month of the start time [1 - 12]
        * start_week() - Week of year of the start time [1 - 54]
@@ -421,8 +430,8 @@ def _operator_parser(expr, first, current):
        * start_second() - The second of the start time [0 - 59]
 
        * end_doy() - Day of year (doy) from the end time [1 - 366]
-       * end_dow() - Day of week (dow) from the end time [1 - 7], 
-         the start of the week is monday == 1
+       * end_dow() - Day of week (dow) from the end time [1 - 7],
+                     the start of the week is monday == 1
        * end_year() - The year of the end time [0 - 9999]
        * end_month() - The month of the end time [1 - 12]
        * end_week() - Week of year of the end time [1 - 54]
@@ -430,28 +439,29 @@ def _operator_parser(expr, first, current):
        * end_hour() - The hour of the end time [0 - 23]
        * end_minute() - The minute of the end time [0 - 59]
        * end_second() - The minute of the end time [0 - 59]
-       
+
        The modified expression is returned.
-       
+
     """
     is_time_absolute = first.is_time_absolute()
-    
+
     expr = _parse_td_operator(expr, is_time_absolute, first, current)
     expr = _parse_start_time_operator(expr, is_time_absolute, first, current)
     expr = _parse_end_time_operator(expr, is_time_absolute, first, current)
     expr = _parse_start_operators(expr, is_time_absolute, current)
     expr = _parse_end_operators(expr, is_time_absolute, current)
-    
+
     return expr
 
 ###############################################################################
 
+
 def _parse_start_operators(expr, is_time_absolute, current):
     """
        Supported operators for absolute time:
        * start_doy() - Day of year (doy) from the start time [1 - 366]
-       * start_dow() - Day of week (dow) from the start time [1 - 7], 
-         the start of the week is monday == 1
+       * start_dow() - Day of week (dow) from the start time [1 - 7],
+                       the start of the week is monday == 1
        * start_year() - The year of the start time [0 - 9999]
        * start_month() - The month of the start time [1 - 12]
        * start_week() - Week of year of the start time [1 - 54]
@@ -460,67 +470,77 @@ def _parse_start_operators(expr, is_time_absolute, current):
        * start_minute() - The minute of the start time [0 - 59]
        * start_second() - The second of the start time [0 - 59]
     """
-    
+
     start, end, tz = current.get_absolute_time()
-        
+
     if expr.find("start_year()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_year()", str(start.year))
-        
+
     if expr.find("start_month()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_month()", str(start.month))
-        
+
     if expr.find("start_week()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_week()", str(start.isocalendar()[1]))
-        
+
     if expr.find("start_day()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_day()", str(start.day))
-        
+
     if expr.find("start_hour()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_hour()", str(start.hour))
-        
+
     if expr.find("start_minute()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_minute()", str(start.minute))
-        
+
     if expr.find("start_second()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_second()", str(start.second))
-        
+
     if expr.find("start_dow()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         expr = expr.replace("start_dow()", str(start.isoweekday()))
-        
-    if expr.find("start_doy()") >= 0:        
+
+    if expr.find("start_doy()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("start_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("start_*")))
         year = datetime(start.year, 1, 1)
         delta = start - year
-        
+
         expr = expr.replace("start_doy()", str(delta.days + 1))
-        
+
     return expr
 
 ###############################################################################
 
+
 def _parse_end_operators(expr, is_time_absolute, current):
     """
        Supported operators for absolute time:
        - end_doy() - Day of year (doy) from the end time [1 - 366]
-       - end_dow() - Day of week (dow) from the end time [1 - 7], 
-         the start of the week is monday == 1
+       - end_dow() - Day of week (dow) from the end time [1 - 7],
+                     the start of the week is monday == 1
        - end_year() - The year of the end time [0 - 9999]
        - end_month() - The month of the end time [1 - 12]
        - end_week() - Week of year of the end time [1 - 54]
@@ -528,98 +548,109 @@ def _parse_end_operators(expr, is_time_absolute, current):
        - end_hour() - The hour of the end time [0 - 23]
        - end_minute() - The minute of the end time [0 - 59]
        - end_second() - The minute of the end time [0 - 59]
-       
-       In case of time instances the end_* expression will be replaced by null()
+
+       In case of time instances the end_* expression will be replaced by
+       null()
     """
-    
+
     start, end, tz = current.get_absolute_time()
-        
+
     if expr.find("end_year()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_year()", "null()")
         else:
             expr = expr.replace("end_year()", str(end.year))
-        
+
     if expr.find("end_month()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_month()", "null()")
         else:
             expr = expr.replace("end_month()", str(end.month))
-        
+
     if expr.find("end_week()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_week()", "null()")
         else:
             expr = expr.replace("end_week()", str(end.isocalendar()[1]))
-        
+
     if expr.find("end_day()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_day()", "null()")
         else:
             expr = expr.replace("end_day()", str(end.day))
-        
+
     if expr.find("end_hour()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_hour()", "null()")
         else:
             expr = expr.replace("end_hour()", str(end.hour))
-        
+
     if expr.find("end_minute()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_minute()", "null()")
         else:
             expr = expr.replace("end_minute()", str(end.minute))
-        
+
     if expr.find("end_second()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_second()", "null()")
         else:
             expr = expr.replace("end_second()", str(end.second))
-        
+
     if expr.find("end_dow()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_dow()", "null()")
         else:
             expr = expr.replace("end_dow()", str(end.isoweekday()))
-        
+
     if expr.find("end_doy()") >= 0:
         if not is_time_absolute:
-            core.fatal(_("The temporal operators <%s> supports only absolute time."%("end_*")))
+            core.fatal(_("The temporal operators <%s> supports only absolute"\
+                         "time." % ("end_*")))
         if not end:
             expr = expr.replace("end_doy()", "null()")
         else:
             year = datetime(end.year, 1, 1)
             delta = end - year
-            
+
             expr = expr.replace("end_doy()", str(delta.days + 1))
-        
+
     return expr
 
 ###############################################################################
 
+
 def _parse_td_operator(expr, is_time_absolute, first, current):
     """Parse the time delta operator td(). This operator
        represents the size of the current sample time interval
        in days and fraction of days for absolute time,
        and in relative units in case of relative time.
-       
-       In case of time instances, the td() operator will be of type null(). 
+
+       In case of time instances, the td() operator will be of type null().
     """
     if expr.find("td()") >= 0:
         td = "null()"
@@ -632,17 +663,18 @@ def _parse_td_operator(expr, is_time_absolute, first, current):
             if end != None:
                 td = end - start
         expr = expr.replace("td()", str(td))
-        
+
     return expr
 
 ###############################################################################
 
+
 def _parse_start_time_operator(expr, is_time_absolute, first, current):
     """Parse the start_time() operator. This operator represent 
     the time difference between the start time of the sample space time
-    raster dataset and the start time of the current sample interval or instance. The time
-    is measured  in days and fraction of days for absolute time,
-    and in relative units in case of relative time."""
+    raster dataset and the start time of the current sample interval or
+    instance. The time is measured  in days and fraction of days for absolute
+    time, and in relative units in case of relative time."""
     if expr.find("start_time()") >= 0:
         if is_time_absolute:
             start1, end, tz = first.get_absolute_time()
@@ -653,18 +685,19 @@ def _parse_start_time_operator(expr, is_time_absolute, first, current):
             start, end, unit = current.get_relative_time()
             x = start - start1
         expr = expr.replace("start_time()", str(x))
-        
+
     return expr
 
 ###############################################################################
 
+
 def _parse_end_time_operator(expr, is_time_absolute, first, current):
-    """Parse the end_time() operator. This operator represent 
+    """Parse the end_time() operator. This operator represent
     the time difference between the start time of the sample space time
     raster dataset and the end time of the current sample interval. The time
     is measured  in days and fraction of days for absolute time,
     and in relative units in case of relative time.
-    
+
     The end_time() will be represented by null() in case of a time instance.
     """
     if expr.find("end_time()") >= 0:
@@ -680,6 +713,5 @@ def _parse_end_time_operator(expr, is_time_absolute, first, current):
             if end:
                 x = end - start1
         expr = expr.replace("end_time()", str(x))
-        
-    return expr
 
+    return expr

+ 68 - 54
lib/python/temporal/register.py

@@ -32,10 +32,10 @@ def register_maps_in_space_time_dataset(
     type, name, maps=None, file=None, start=None,
     end=None, unit=None, increment=None, dbif=None,
         interval=False, fs="|"):
-    """!Use this method to register maps in space time datasets. 
+    """!Use this method to register maps in space time datasets.
 
-       Additionally a start time string and an increment string can be specified
-       to assign a time interval automatically to the maps.
+       Additionally a start time string and an increment string can be
+       specified to assign a time interval automatically to the maps.
 
        It takes care of the correct update of the space time datasets from all
        registered maps.
@@ -43,22 +43,22 @@ def register_maps_in_space_time_dataset(
        @param type The type of the maps rast, rast3d or vect
        @param name The name of the space time dataset
        @param maps A comma separated list of map names
-       @param file Input file one map with start and optional end time, 
-                    one per line
+       @param file Input file one map with start and optional end time,
+                   one per line
        @param start The start date and time of the first raster map
                     (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd",
                     format relative is integer 5)
        @param end The end date and time of the first raster map
-                   (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd",
-                   format relative is integer 5)
+                  (format absolute: "yyyy-mm-dd HH:MM:SS" or "yyyy-mm-dd",
+                  format relative is integer 5)
        @param unit The unit of the relative time: years, months, days,
-                    hours, minutes, seconds
+                   hours, minutes, seconds
        @param increment Time increment between maps for time stamp creation
-                         (format absolute: NNN seconds, minutes, hours, days,
-                         weeks, months, years; format relative: 1.0)
+                        (format absolute: NNN seconds, minutes, hours, days,
+                        weeks, months, years; format relative: 1.0)
        @param dbif The database interface to be used
        @param interval If True, time intervals are created in case the start
-                        time and an increment is provided
+                       time and an increment is provided
        @param fs Field separator used in input file
     """
 
@@ -66,18 +66,20 @@ def register_maps_in_space_time_dataset(
     end_time_in_file = False
 
     if maps and file:
-        core.fatal(_("%s= and %s= are mutually exclusive") % ("maps", "file"))
+        core.fatal(_("%(m)s= and %(f)s= are mutually exclusive") % {'m': "maps",
+                                                                    'f': "file"})
 
     if end and increment:
-        core.fatal(_("%s= and %s= are mutually exclusive") % (
-            "end", "increment"))
+        core.fatal(_("%(e)s= and %(i)s= are mutually exclusive") % {'e': "end",
+                   'i': "increment"})
 
     if end and not start:
-        core.fatal(_("Please specify %s= and %s=") % ("start_time",
-                                                      "end_time"))
+        core.fatal(_("Please specify %(st)s= and %(e)s=") % {'st': "start_time",
+                                                             'e': "end_time"})
 
     if not maps and not file:
-        core.fatal(_("Please specify %s= or %s=") % ("maps", "file"))
+        core.fatal(_("Please specify %(m)s= or %(f)s=") % {'m': "maps",
+                                                           'f': "file"})
 
     # We may need the mapset
     mapset = core.gisenv()["MAPSET"]
@@ -107,15 +109,17 @@ def register_maps_in_space_time_dataset(
 
         if not sp.is_in_db(dbif):
             dbif.close()
-            core.fatal(_("Space time %s dataset <%s> no found") %
-                       (sp.get_new_map_instance(None).get_type(), name))
+            core.fatal(_("Space time %(sp)s dataset <%(name)s> no found") %
+                         {'sp': sp.get_new_map_instance(None).get_type(),
+                          'name': name})
 
         if sp.is_time_relative() and not unit:
             dbif.close()
-            core.fatal(_("Space time %s dataset <%s> with relative time found, "
-                         "but no relative unit set for %s maps") %
-                       (sp.get_new_map_instance(None).get_type(),
-                        name, sp.get_new_map_instance(None).get_type()))
+            core.fatal(_("Space time %(sp)s dataset <%(name)s> with relative"
+                         " time found, but no relative unit set for %(sp)s "
+                         "maps") % {
+                         'sp': sp.get_new_map_instance(None).get_type(),
+                         'name': name})
 
     # We need a dummy map object to build the map ids
     dummy = dataset_factory(type, None)
@@ -183,7 +187,7 @@ def register_maps_in_space_time_dataset(
     core.message(_("Gathering map informations"))
 
     for count in range(len(maplist)):
-        if count%50 == 0:
+        if count % 50 == 0:
             core.percent(count, num_maps, 1)
 
         # Get a new instance of the map type
@@ -204,13 +208,16 @@ def register_maps_in_space_time_dataset(
             if start == "" or start is None:
                 dbif.close()
                 if map.get_layer():
-                    core.fatal(_("Unable to register %s map <%s> with layer %s. "
-                                 "The map has no valid time and the start time is not set.") %
-                               (map.get_type(), map.get_map_id(), map.get_layer()))
+                    core.fatal(_("Unable to register %(t)s map <%(id)s> with "
+                                 "layer %(l)s. The map has no valid time and "
+                                 "the start time is not set.") % {
+                                 't': map.get_type(), 'id': map.get_map_id(),
+                                 'l': map.get_layer()})
                 else:
-                    core.fatal(_("Unable to register %s map <%s>. The map has no valid"
-                                 " time and the start time is not set.") %
-                               (map.get_type(), map.get_map_id()))
+                    core.fatal(_("Unable to register %(t)s map <%(id)s>. The"
+                                 " map has no valid time and the start time "
+                                 "is not set.") % {'t': map.get_type(),
+                                                   'id': map.get_map_id()})
 
             if unit:
                 map.set_time_to_relative()
@@ -219,52 +226,57 @@ def register_maps_in_space_time_dataset(
 
         else:
             is_in_db = True
-            
             # Check the overwrite flag
-            if not core.overwrite():                        
+            if not core.overwrite():
                 if map.get_layer():
-                    core.warning(_("Map is already registered in temporal database. "
-                                   "Unable to update %s map <%s> with layer %s. "
-                                   "Overwrite flag is not set.") %
-                               (map.get_type(), map.get_map_id(), str(map.get_layer())))
+                    core.warning(_("Map is already registered in temporal "
+                                   "database. Unable to update %(t)s map "
+                                   "<%(id)s> with layer %(l)s. Overwrite flag"
+                                   " is not set.") % {'t': map.get_type(),
+                                                      'id': map.get_map_id(),
+                                                      'l': str(map.get_layer())})
                 else:
-                    core.warning(_("Map is already registered in temporal database. "
-                                   "Unable to update %s map <%s>. "
-                                   "Overwrite flag is not set.") %
-                               (map.get_type(), map.get_map_id()))
-                
+                    core.warning(_("Map is already registered in temporal "
+                                   "database. Unable to update %(t)s map "
+                                   "<%(id)s>. Overwrite flag is not set.") % {
+                                   't': map.get_type(), 'id': map.get_map_id()})
+
                 # Simple registration is allowed
                 if name:
                     map_object_list.append(map)
                 # Jump to next map
                 continue
-            
+
             # Select information from temporal database
             map.select(dbif)
-            
+
             # Save the datasets that must be updated
             datasets = map.get_registered_datasets(dbif)
             if datasets:
                 for dataset in datasets:
                     datatsets_to_modify[dataset["id"]] = dataset["id"]
-                
+
                 if name and map.get_temporal_type() != sp.get_temporal_type():
                     dbif.close()
                     if map.get_layer():
-                        core.fatal(_("Unable to update %s map <%s> with layer. "
-                                     "The temporal types are different.") %
-                                   (map.get_type(), map.get_map_id(), map.get_layer()))
+                        core.fatal(_("Unable to update %(t)s map <%(id)s> "
+                                     "with layer %(l)s. The temporal types "
+                                     "are different.") % {'t': map.get_type(),
+                                                        'id': map.get_map_id(),
+                                                        'l': map.get_layer()})
                     else:
-                        core.fatal(_("Unable to update %s map <%s>. "
+                        core.fatal(_("Unable to update %(t)s map <%(id)s>. "
                                      "The temporal types are different.") %
-                                   (map.get_type(), map.get_map_id()))
+                                     {'t': map.get_type(),
+                                      'id': map.get_map_id()})
 
         # Load the data from the grass file database
         map.load()
 
         # Set the valid time
         if start:
-            # In case the time is in the input file we ignore the increment counter
+            # In case the time is in the input file we ignore the increment
+            # counter
             if start_time_in_file:
                 count = 1
             assign_valid_time_to_map(ttype=map.get_temporal_type(),
@@ -279,7 +291,8 @@ def register_maps_in_space_time_dataset(
             #  Gather the SQL insert statement
             statement += map.insert(dbif=dbif, execute=False)
 
-        # Sqlite3 performace better for huge datasets when committing in small chunks
+        # Sqlite3 performace better for huge datasets when committing in
+        # small chunks
         if dbif.dbmi.__name__ == "sqlite3":
             if count % 100 == 0:
                 if statement is not None and statement != "":
@@ -304,7 +317,7 @@ def register_maps_in_space_time_dataset(
         num_maps = len(map_object_list)
         core.message(_("Register maps in the space time raster dataset"))
         for map in map_object_list:
-            if count%50 == 0:
+            if count % 50 == 0:
                 core.percent(count, num_maps, 1)
             sp.register_map(map=map, dbif=dbif)
             count += 1
@@ -314,7 +327,7 @@ def register_maps_in_space_time_dataset(
         core.message(_("Update space time raster dataset"))
         sp.update_from_registered_maps(dbif)
         sp.update_command_string(dbif=dbif)
-    
+
     # Update affected datasets
     if datatsets_to_modify:
         for dataset in datatsets_to_modify:
@@ -335,7 +348,8 @@ def register_maps_in_space_time_dataset(
 
 ###############################################################################
 
-def assign_valid_time_to_map(ttype, map, start, end, unit, increment=None, mult=1, interval=False):
+def assign_valid_time_to_map(ttype, map, start, end, unit, increment=None,
+                             mult=1, interval=False):
     """!Assign the valid time to a map dataset
 
        @param ttype The temporal type which should be assigned

+ 13 - 12
lib/python/temporal/stds_export.py

@@ -76,8 +76,8 @@ def _export_raster_maps_as_geotiff(rows, tar, list_file, new_cwd, fs):
                 gdal_type = "UInt32"
             else:
                 gdal_type = "Int32"
-            ret = core.run_command("r.out.gdal", flags="c", input=name, 
-                                   output=out_name, nodata=nodata, 
+            ret = core.run_command("r.out.gdal", flags="c", input=name,
+                                   output=out_name, nodata=nodata,
                                    type=gdal_type, format="GTiff")
         else:
             ret = core.run_command("r.out.gdal", flags="c",
@@ -140,8 +140,8 @@ def _export_vector_maps_as_gml(rows, tar, list_file, new_cwd, fs):
         # Write the filename, the start_time and the end_time
         list_file.write(string)
         # Export the vector map with v.out.ogr
-        ret = core.run_command("v.out.ogr", input=name, 
-                               dsn=(name + ".xml"), layer=layer, format="GML")
+        ret = core.run_command("v.out.ogr", input=name, dsn=(name + ".xml"),
+                               layer=layer, format="GML")
         if ret != 0:
             shutil.rmtree(new_cwd)
             tar.close()
@@ -210,7 +210,7 @@ def _export_raster3d_maps(rows, tar, list_file, new_cwd, fs):
 ############################################################################
 
 
-def export_stds(input, output, compression, workdir, where, format_="pack", 
+def export_stds(input, output, compression, workdir, where, format_="pack",
                 type_="strds"):
     """
             !Export space time datasets as tar archive with optional compression
@@ -249,8 +249,8 @@ def export_stds(input, output, compression, workdir, where, format_="pack",
     sp = dataset_factory(type_, id)
 
     if sp.is_in_db() == False:
-        core.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
+        core.fatal(_("Space time %(sp)s dataset <%(i)s> not found") % {
+                     'sp': sp.get_new_map_instance(None).get_type(), 'i': id})
 
     # Save current working directory path
     old_cwd = os.getcwd()
@@ -309,16 +309,17 @@ def export_stds(input, output, compression, workdir, where, format_="pack",
     init_file = open(init_file_name, "w")
     # Create the init string
     string = ""
-     # This is optional, if not present strds will be assumed for backward 
+     # This is optional, if not present strds will be assumed for backward
      # compatibility
-    string += "%s=%s\n" % ("stds_type", sp.get_type()) 
-     # This is optional, if not present gtiff will be assumed for 
+    string += "%s=%s\n" % ("stds_type", sp.get_type())
+     # This is optional, if not present gtiff will be assumed for
      # backward compatibility
-    string += "%s=%s\n" % ("format", format_) 
+    string += "%s=%s\n" % ("format", format_)
     string += "%s=%s\n" % ("temporal_type", sp.get_temporal_type())
     string += "%s=%s\n" % ("semantic_type", sp.get_semantic_type())
     if sp.is_time_relative():
-	string += "%s=%s\n" % ("relative_time_unit", sp.get_relative_time_unit())
+        string += "%s=%s\n" % ("relative_time_unit",
+                               sp.get_relative_time_unit())
     string += "%s=%s\n" % ("number_of_maps", sp.metadata.get_number_of_maps())
     north, south, east, west, top, bottom = sp.get_spatial_extent_as_tuple()
     string += "%s=%s\n" % ("north", north)

+ 35 - 32
lib/python/temporal/stds_import.py

@@ -32,13 +32,9 @@ for details.
 @author Soeren Gebbert
 """
 
-import shutil
 import os
 import os.path
 import tarfile
-import tempfile
-import time
-import filecmp
 
 import core
 from space_time_datasets import *
@@ -57,6 +53,7 @@ imported_maps = {}
 
 ############################################################################
 
+
 def _import_raster_maps_from_geotiff(maplist, overr, exp, location, link):
     impflags = ""
     if overr:
@@ -93,8 +90,9 @@ def _import_raster_maps_from_geotiff(maplist, overr, exp, location, link):
 
 ############################################################################
 
+
 def _import_raster_maps(maplist):
-    # We need to disable the projection check because of its 
+    # We need to disable the projection check because of its
     # simple implementation
     impflags = "o"
     for row in maplist:
@@ -111,6 +109,7 @@ def _import_raster_maps(maplist):
 
 ############################################################################
 
+
 def _import_vector_maps_from_gml(maplist, overr, exp, location, link):
     impflags = "o"
     if exp or location:
@@ -129,8 +128,9 @@ def _import_vector_maps_from_gml(maplist, overr, exp, location, link):
 
 ############################################################################
 
+
 def _import_vector_maps(maplist):
-    # We need to disable the projection check because of its 
+    # We need to disable the projection check because of its
     # simple implementation
     impflags = "o"
     for row in maplist:
@@ -152,8 +152,8 @@ def _import_vector_maps(maplist):
         imported_maps[name] = name
 ############################################################################
 
-def import_stds(
-    input, output, extrdir, title=None, descr=None, location=None,
+
+def import_stds(input, output, extrdir, title=None, descr=None, location=None,
         link=False, exp=False, overr=False, create=False, stds_type="strds"):
     """!Import space time datasets of type raster and vector
 
@@ -161,18 +161,18 @@ def import_stds(
         @param output The name of the output space time dataset
         @param extrdir The extraction directory
         @param title The title of the new created space time dataset
-        @param descr The description of the new created 
-                            space time dataset
+        @param descr The description of the new created
+                     space time dataset
         @param location The name of the location that should be created,
                         maps are imported into this location
         @param link Switch to link raster maps instead importing them
         @param exp Extend location extents based on new dataset
         @param overr Override projection (use location's projection)
-        @param create Create the location specified by the "location" 
+        @param create Create the location specified by the "location"
                       parameter and exit.
                       Do not import the space time datasets.
-        @param stds_type The type of the space time dataset that 
-                          should be imported
+        @param stds_type The type of the space time dataset that
+                         should be imported
     """
 
     global raise_on_error
@@ -224,7 +224,8 @@ def import_stds(
             else:
                 core.fatal(_("Projection information does not match. Aborting."))
 
-    # Create a new location based on the projection information and switch into it
+    # Create a new location based on the projection information and switch
+    # into it
     old_env = core.gisenv()
     if location:
         try:
@@ -237,8 +238,8 @@ def import_stds(
                 os.chdir(old_cwd)
                 return
         except Exception as e:
-            core.fatal(_("Unable to create location %s. Reason: %s")
-                       % (location, str(e)))
+            core.fatal(_("Unable to create location %(l)s. Reason: %(e)s")
+                         % {'l': location, 'e': str(e)})
         # Switch to the new created location
         ret = core.run_command("g.mapset", mapset="PERMANENT",
                                location=location,
@@ -300,8 +301,10 @@ def import_stds(
         if "temporal_type" not in init or \
            "semantic_type" not in init or \
            "number_of_maps" not in init:
-            core.fatal(_("Key words %s, %s or %s not found in init file.") %
-                       ("temporal_type", "semantic_type", "number_of_maps"))
+            core.fatal(_("Key words %(t)s, %(s)s or %(n)s not found in init"
+                         " file.") % {'t': "temporal_type",
+                                      's': "semantic_type",
+                                      'n': "number_of_maps"})
 
         if line_count != int(init["number_of_maps"]):
             core.fatal(_("Number of maps mismatch in init and list file."))
@@ -346,9 +349,9 @@ def import_stds(
         id = output + "@" + mapset
         sp = dataset_factory(_type, id)
         if sp.is_in_db() and core.overwrite() == False:
-            core.fatal(_("Space time %s dataset <%s> is already in the "
-                         "database. Use the overwrite flag.") % \
-                        (_type, sp.get_id()))
+            core.fatal(_("Space time %(t)s dataset <%(sp)s> is already in the "
+                         "database. Use the overwrite flag.") % {'t': _type,
+                                                                 'sp': sp.get_id()})
 
         # Import the maps
         if _type == "strds":
@@ -366,27 +369,27 @@ def import_stds(
 
         # Create the space time dataset
         if sp.is_in_db() and core.overwrite() == True:
-            core.info(_("Overwrite space time %s dataset "
-                        "<%s> and unregister all maps.") % \
-                       (sp.get_new_map_instance(None).get_type(), sp.get_id()))
+            core.info(_("Overwrite space time %(sp)s dataset "
+                        "<%(id)s> and unregister all maps.") % {
+                        'sp': sp.get_new_map_instance(None).get_type(),
+                        'id': sp.get_id()})
             sp.delete()
             sp = sp.get_new_instance(id)
 
         temporal_type = init["temporal_type"]
         semantic_type = init["semantic_type"]
         relative_time_unit = None
-        
-        if temporal_type == "relative":        
+        if temporal_type == "relative":
             if "relative_time_unit" not in init:
-                core.fatal(_("Key word %s not found in init file.") %("relative_time_unit"))
+                core.fatal(_("Key word %s not found in init file.") % ("relative_time_unit"))
             relative_time_unit = init["relative_time_unit"]
             sp.set_relative_time_unit(relative_time_unit)
-        
+
         core.verbose(_("Create space time %s dataset.") %
                      sp.get_new_map_instance(None).get_type())
 
-        sp.set_initial_values(temporal_type=temporal_type, 
-                              semantic_type=semantic_type, title=title, 
+        sp.set_initial_values(temporal_type=temporal_type,
+                              semantic_type=semantic_type, title=title,
                               description=descr)
         sp.insert()
 
@@ -394,7 +397,7 @@ def import_stds(
         fs = "|"
         register_maps_in_space_time_dataset(
             type=sp.get_new_map_instance(None).get_type(),
-            name=output, file=list_file_name, start="file", 
+            name=output, file=list_file_name, start="file",
             end="file", unit=relative_time_unit, dbif=None, fs=fs)
 
         os.chdir(old_cwd)
@@ -408,5 +411,5 @@ def import_stds(
             ret = core.run_command("g.mapset", mapset=old_env["MAPSET"],
                                    location=old_env["LOCATION_NAME"],
                                    gisdbase=old_env["GISDBASE"])
-        
+
         core.set_raise_on_error(old_state)

+ 15 - 14
lib/python/temporal/univar_statistics.py

@@ -29,7 +29,8 @@ from factory import *
 ###############################################################################
 
 
-def print_gridded_dataset_univar_statistics(type, input, where, extended, header, fs):
+def print_gridded_dataset_univar_statistics(type, input, where, extended,
+                                            header, fs):
     """!Print univariate statistics for a space time raster or raster3d dataset
 
        @param type Must be "strds" or "str3ds"
@@ -55,8 +56,8 @@ def print_gridded_dataset_univar_statistics(type, input, where, extended, header
 
     if sp.is_in_db(dbif) == False:
         dbif.close()
-        core.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
+        core.fatal(_("Space time %(sp)s dataset <%(i)s> not found") % {
+                     'sp': sp.get_new_map_instance(None).get_type(), 'i': id})
 
     sp.select(dbif)
 
@@ -65,8 +66,8 @@ def print_gridded_dataset_univar_statistics(type, input, where, extended, header
 
     if not rows:
         dbif.close()
-        core.fatal(_("Space time %s dataset <%s> is empty") % (
-            sp.get_new_map_instance(None).get_type(), id))
+        core.fatal(_("Space time %(sp)s dataset <%(i)s> is empty") % {
+                     'sp': sp.get_new_map_instance(None).get_type(), 'i': id})
 
     if header == True:
         print "id" + fs + "start" + fs + "end" + fs + "mean" + fs + \
@@ -115,13 +116,13 @@ def print_gridded_dataset_univar_statistics(type, input, where, extended, header
 ###############################################################################
 
 
-def print_vector_dataset_univar_statistics(input, twhere, layer, type, column, 
+def print_vector_dataset_univar_statistics(input, twhere, layer, type, column,
                                            where, extended, header, fs):
     """!Print univariate statistics for a space time vector dataset
 
        @param input The name of the space time dataset
        @param twhere A temporal database where statement
-       @param layer The layer number used in case no layer is present 
+       @param layer The layer number used in case no layer is present
               in the temporal dataset
        @param type options: point,line,boundary,centroid,area
        @param column The name of the attribute column
@@ -146,8 +147,8 @@ def print_vector_dataset_univar_statistics(input, twhere, layer, type, column,
 
     if sp.is_in_db(dbif) == False:
         dbif.close()
-        core.fatal(_("Space time %s dataset <%s> not found") % (
-            sp.get_new_map_instance(None).get_type(), id))
+        core.fatal(_("Space time %(sp)s dataset <%(i)s> not found") % {
+                     'sp': sp.get_new_map_instance(None).get_type(), 'i': id})
 
     sp.select(dbif)
 
@@ -156,8 +157,8 @@ def print_vector_dataset_univar_statistics(input, twhere, layer, type, column,
 
     if not rows:
         dbif.close()
-        core.fatal(_("Space time %s dataset <%s> is empty") % (
-            sp.get_new_map_instance(None).get_type(), id))
+        core.fatal(_("Space time %(sp)s dataset <%(i)s> is empty") % {
+                     'sp': sp.get_new_map_instance(None).get_type(), 'i': id})
 
     string = ""
     if header == True:
@@ -191,7 +192,7 @@ def print_vector_dataset_univar_statistics(input, twhere, layer, type, column,
             mylayer = layer
 
         stats = core.parse_command("v.univar", map=id, where=where,
-                                   column=column, layer=mylayer, 
+                                   column=column, layer=mylayer,
                                    type=type, flags=flags)
 
         string = ""
@@ -211,11 +212,11 @@ def print_vector_dataset_univar_statistics(input, twhere, layer, type, column,
                     str(stats["mean_abs"]) + fs + \
                     str(stats["population_stddev"]) + fs + \
                     str(stats["population_variance"])
-                    
+
                     string += fs + str(stats["population_coeff_variation"]) + \
                     fs + str(stats["sample_stddev"]) + fs + \
                     str(stats["sample_variance"])
-                    
+
                     string += fs + str(stats["kurtosis"]) + fs + \
                     str(stats["skewness"])
                 else: