[GRASS-SVN] r62775 - in grass/trunk/lib/python/temporal: . testsuite

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 17 05:30:34 PST 2014


Author: huhabla
Date: 2014-11-17 05:30:34 -0800 (Mon, 17 Nov 2014)
New Revision: 62775

Modified:
   grass/trunk/lib/python/temporal/abstract_dataset.py
   grass/trunk/lib/python/temporal/temporal_algebra.py
   grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py
   grass/trunk/lib/python/temporal/temporal_raster_algebra.py
   grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py
   grass/trunk/lib/python/temporal/temporal_vector_algebra.py
   grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py
   grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py
   grass/trunk/lib/python/temporal/testsuite/unittests_temporal_vector_algebra.py
Log:
temporal framework: Bugfixing and code cleanup in the temporal algebra


Modified: grass/trunk/lib/python/temporal/abstract_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_dataset.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/abstract_dataset.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -151,9 +151,9 @@
     def get_type(self):
         """Return the type of this class as string
 
-           The type can be "vect", "rast", "rast3d", "stvds", "strds" or "str3ds"
+           The type can be "vector", "raster", "raster3d", "stvds", "strds" or "str3ds"
 
-           :return: "vect", "rast", "rast3d", "stvds", "strds" or "str3ds"
+           :return: "vector", "raster", "raster3d", "stvds", "strds" or "str3ds"
         """
 
     @abstractmethod

Modified: grass/trunk/lib/python/temporal/temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/temporal_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -679,7 +679,7 @@
         self.dbif = SQLDatabaseInterfaceConnection()
         self.dbif.connect()
         self.register_null = register_null
-        self.empty_maps = {}
+        self.removable_maps = {}
         self.m_mremove = pymod.Module('g.remove')
         self.m_copy = pymod.Module('g.copy')
         self.nprocs = nprocs
@@ -788,10 +788,9 @@
         self.parser.parse(expression)
 
     def generate_map_name(self):
-        """Generate an unique intermediate vector map name
-            and register it in the objects map list for later removement.
+        """Generate an unique  map name and register it in the objects map list
 
-            The vector map names are unique between processes. Do not use the
+            The map names are unique between processes. Do not use the
             same object for map name generation in multiple threads.
         """
         self.count += 1
@@ -803,7 +802,8 @@
         self.names[name] = name
         return name
 
-    def generate_new_map(self, base_map, bool_op = 'and', copy = True,  rename = True):
+    def generate_new_map(self, base_map, bool_op = 'and', copy = True,  rename = True, 
+                                              remove = False):
         """Generate a new map using the spatio-temporal extent of the base map
 
            :param base_map: This map is used to create the new map
@@ -813,6 +813,7 @@
                   copied to mapA
            :param rename: Specifies if the generated map get a random name or get
                   the id from the base map.
+            :param remove: Set this True if this map is an intermediate or empty map that should be removed
            :return: Map object
         """
         # Generate an intermediate name for the result map list.
@@ -826,6 +827,8 @@
         if not rename:
             name = base_map.get_id()
             map_new.set_id(name)
+        if remove is True:
+            self.removable_maps[name] = map_new
         # Make sure to set the uid that is used in several dictionaries
         map_new.uid = name
         return map_new
@@ -966,11 +969,58 @@
     
     ######################### Temporal functions ##############################
 
-    def check_stds(self, input, clear = False):
+    def remove_maps(self):
+        """Removes empty or intermediate maps of different type.
+        """
+        
+        map_names = {}
+        map_names["raster"] = []
+        map_names["raster3d"] = []
+        map_names["vector"] = []
+                
+        if self.removable_maps:
+            for map in self.removable_maps.values():
+                    map_names[map.get_type()].append(map.get_name())
+        
+        for key in map_names.keys():
+            if map_names[key]:
+                self.msgr.message(_("Removing un-needed or empty %s maps"%(key)))
+                self._remove_maps(map_names[key],  key)
+
+    def _remove_maps(self,  namelist,  map_type):
+        """Remove maps of specific type
+        
+            :param namelist: List of map names to be removed
+            :param map_type: The type of the maps  (rast, rast3d or vect)
+        """
+        max = 100
+        chunklist = [namelist[i:i + max] for i in range(0, len(namelist), max)]
+        for chunk in chunklist:
+            stringlist = ",".join(chunk)
+            
+            # Transform the map type
+            if map_type == "raster":
+                map_type = "rast"
+            if map_type == "raster3d":
+                map_type = "rast3d"
+            if map_type == "vector":
+                map_type = "vect"
+
+            if self.run:
+                m = copy.deepcopy(self.m_mremove)
+                m.inputs["type"].value = map_type
+                m.inputs["name"].value = stringlist
+                m.flags["f"].value = True
+                print m.get_bash()
+                m.run()
+
+    def check_stds(self, input, clear = False,  stds_type = None):
         """ Check if input space time dataset exist in database and return its map list.
 
             :param input: Name of space time data set as string or list of maps.
             :param clear: Reset the stored conditional values to empty list.
+            :param stds_type: The type of the space time dataset to be opened, if not provided 
+                                          then self.stdstype will be used
 
             :return: List of maps.
 
@@ -982,7 +1032,10 @@
             else:
                 id_input = input + "@" + self.mapset
             # Create empty spacetime dataset.
-            stds = dataset_factory(self.stdstype, id_input)
+            if stds_type:
+                stds = dataset_factory(stds_type, id_input)
+            else:
+                stds = dataset_factory(self.stdstype, id_input)
             # Check for occurence of space time dataset.
             if stds.is_in_db(dbif=self.dbif) == False:
                 raise FatalError(_("Space time %s dataset <%s> not found") %
@@ -1895,57 +1948,59 @@
 
         """
         if self.run:
+            dbif, connected = init_dbif(self.dbif) 
             if isinstance(t[3], list):
                 num = len(t[3])
                 count = 0
-                changeflag = False
-                register_list = []                
+                register_list = []      
                 if num > 0:
+                    process_queue = pymod.ParallelModuleQueue(int(self.nprocs))
                     for map_i in t[3]:
                         # Test if temporal extents have been changed by temporal 
-                        # relation oeprators (&|+). 
+                        # relation operators (i|r). 
                         map_i_extent = map_i.get_temporal_extent_as_tuple()
                         map_test = map_i.get_new_instance(map_i.get_id())
-                        map_test.select()
+                        map_test.select(dbif)
                         map_test_extent = map_test.get_temporal_extent_as_tuple()
                         if map_test_extent != map_i_extent:
-                            changeflag = True
-                    for map_i in t[3]:
-                        if changeflag:
-                            # Check if resultmap names exist in GRASS database.
-                            mapname = self.basename + "_" + str(count) + "@" + self.mapset
-                            process_queue = pymod.ParallelModuleQueue(int(self.nprocs))
-                            if self.stdstype == 'strds':
-                                map_test = RasterDataset(mapname)
-                            elif self.stdstype == 'stvds':
-                                map_test = VectorDataset(mapname)
+                            # Create new map with basename
+                            newident = self.basename + "_" + str(count)
+                            map_result = map_i.get_new_instance(newident + "@" + self.mapset)
+
                             if map_test.map_exists() and self.overwrite == False:
                                 self.msgr.fatal("Error raster maps with basename %s exist. Use --o flag to overwrite existing file" \
                                                     %(mapname))
-                            # Create new maps with basename.
-                            newident = self.basename + "_" + str(count)
-                            map_result = map_i.get_new_instance(newident + "@" + self.mapset)
+
                             map_result.set_temporal_extent(map_i.get_temporal_extent())
                             map_result.set_spatial_extent(map_i.get_spatial_extent())
+                            # Attention we attach a new attribute
+                            map_result.is_new = True
                             register_list.append(map_result)
-                            if self.stdstype == 'strds':
+
+                            # Copy the map
+                            if map_i.get_type() == 'raster':
                                 m = copy.deepcopy(self.m_copy)
                                 m.inputs["rast"].value = map_i.get_id(),  newident
                                 m.flags["overwrite"].value = self.overwrite
                                 process_queue.put(m)
-                            elif self.stdstype == 'stvds':
+                            elif map_i.get_type() == 'raster3d':
                                 m = copy.deepcopy(self.m_copy)
+                                m.inputs["rast3d"].value = map_i.get_id(),  newident
+                                m.flags["overwrite"].value = self.overwrite
+                                process_queue.put(m)
+                            elif map_i.get_type() == 'vector':
+                                m = copy.deepcopy(self.m_copy)
                                 m.inputs["vect"].value = map_i.get_id(),  newident
                                 m.flags["overwrite"].value = self.overwrite
                                 process_queue.put(m)
                         else:
                             register_list.append(map_i)
                         count  += 1
-                    if changeflag:
-                        process_queue.wait()
+
+                    # Wait for running processes
+                    process_queue.wait()
                     
                     # Open connection to temporal database.
-                    dbif, connect = init_dbif(self.dbif)
                     # Create result space time dataset.                        
                     resultstds = open_new_stds(t[1], self.stdstype, \
                                                              'absolute', t[1], t[1], \
@@ -1954,21 +2009,21 @@
                     for map_i in register_list:                
                         # Get meta data from grass database.
                         map_i.load()
-                        # Check if temporal extents have changed.
-                        if changeflag:
+                        # Check if temporal extents have changed and a new map was created
+                        if hasattr(map_i,  "is_new") is True:
                             # Do not register empty maps if not required
                             # In case of a null map continue, do not register null maps
                             if map_i.metadata.get_min() is None and \
                                map_i.metadata.get_max() is None:
                                 if not self.register_null:
-                                    self.empty_maps[map_i.get_name()] = map_i.get_name()
+                                    self.removable_maps[map_i.get_name()] = map_i
                                     continue
                             if map_i.is_in_db(dbif) and self.overwrite:
                                 # Update map in temporal database.
                                 map_i.update_all(dbif)
                             elif map_i.is_in_db(dbif) and self.overwrite == False:
                                 # Raise error if map exists and no overwrite flag is given.
-                                self.msgr.fatal("Error vector map %s exist in temporal database. Use overwrite flag.  : \n%s" \
+                                self.msgr.fatal("Error map %s exist in temporal database. Use overwrite flag.  : \n%s" \
                                                     %(map_i.get_map_id(), cmd.popen.stderr))
                             else:
                                 # Insert map into temporal database.
@@ -1976,20 +2031,18 @@
                         # Register map in result space time dataset.
                         success = resultstds.register_map(map_i, dbif)
                     resultstds.update_from_registered_maps(dbif)
-                    dbif.close()
                 elif num == 0:
                     self.msgr.warning('Empty result space time dataset. No map has \
 been registered in %s'  %(t[1] ))
                     # Open connection to temporal database.
-                    dbif, connect = init_dbif(self.dbif)
                     # Create result space time dataset.                        
                     resultstds = open_new_stds(t[1], self.stdstype, \
                                                              'absolute', t[1], t[1], \
-                                                             'mean', self.dbif, \
+                                                             'mean', dbif, \
                                                              overwrite = self.overwrite)
-                    dbif.close()
+            if connected:
+                dbif.close()
             t[0] = t[3]
-
         else:
             t[0] = t[3]
 

Modified: grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/temporal_raster3d_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -39,24 +39,6 @@
         self.expression = expression
         self.parser.parse(expression)
 
-    def remove_empty_maps(self):
-        """! Removes the intermediate vector maps.
-        """
-        if self.empty_maps:
-            self.msgr.message(_("Removing empty 3D raster maps"))
-            namelist = self.empty_maps.values()
-            max = 100
-            chunklist = [namelist[i:i + max] for i in range(0, len(namelist), max)]
-            for chunk in chunklist:
-                stringlist = ",".join(chunk)
-
-                if self.run:
-                    m = copy.deepcopy(self.m_mremove)
-                    m.inputs["type"].value = "rast3d"
-                    m.inputs["names"].value = stringlist
-                    m.flags["f"].value = True
-                    m.run()
-
     ######################### Temporal functions ##############################
 
     def p_statement_assign(self, t):

Modified: grass/trunk/lib/python/temporal/temporal_raster_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/temporal_raster_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -79,24 +79,6 @@
         self.expression = expression
         self.parser.parse(expression)
 
-    def remove_empty_maps(self):
-        """! Removes the intermediate raster maps.
-        """
-        if self.empty_maps:
-            self.msgr.message(_("Removing empty raster maps"))
-            namelist = self.empty_maps.values()
-            max = 100
-            chunklist = [namelist[i:i + max] for i in range(0, len(namelist), max)]
-            for chunk in chunklist:
-                stringlist = ",".join(chunk)
-
-                if self.run:
-                    m = copy.deepcopy(self.m_mremove)
-                    m.inputs["type"].value = "rast"
-                    m.inputs["name"].value = stringlist
-                    m.flags["f"].value = True
-                    m.run()
-
     ######################### Temporal functions ##############################
 
     def p_statement_assign(self, t):

Modified: grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/temporal_raster_base_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -142,7 +142,6 @@
                   nprocs = 1, register_null = False):
         TemporalAlgebraParser.__init__(self, pid, run, debug, spatial)
         self.nprocs = nprocs
-        self.empty_maps = {}
         self.register_null = register_null
 
     def check_null(self, t):
@@ -543,11 +542,14 @@
                 register_list = []
                 for i in range(num):
                     # Check if resultmap names exist in GRASS database.
-                    rastername = self.basename + "_" + str(i) + "@" + self.mapset
-                    rastermap = RasterDataset(rastername)
-                    if rastermap.map_exists() and self.overwrite == False:
-                        self.msgr.fatal("Error raster maps with basename %s exist. Use --o flag to overwrite existing file" \
-                                            %(rastername))
+                    map_name = self.basename + "_" + str(i) + "@" + self.mapset
+                    if self.stdstype == "strds":
+                        new_map = RasterDataset(map_name)
+                    else:
+                        new_map = Raster3DDataset(map_name)
+                    if new_map.map_exists() and self.overwrite == False:
+                        self.msgr.fatal("Error maps with basename %s exist. Use --o flag to overwrite existing file" \
+                                            %(map_name))
                 map_test_list = []
                 for map_i in t[3]:
                     newident = self.basename + "_" + str(count)
@@ -568,6 +570,7 @@
                         process_queue.put(m)
                     
                     elif map_i.map_exists():
+                        # Copy map if it exists
                         map_test = map_i.get_new_instance(newident + "@" + self.mapset)
                         map_test.set_temporal_extent(map_i.get_temporal_extent())
                         map_test.set_spatial_extent(map_i.get_spatial_extent())
@@ -577,6 +580,7 @@
                         m_expression = newident + "=" + map_i.get_map_id()
                         m.inputs["expression"].value = str(m_expression)
                         m.flags["overwrite"].value = self.overwrite
+                        print m.get_bash()
                         process_queue.put(m)
                         
                     else:
@@ -603,7 +607,7 @@
                     if map_i.metadata.get_min() is None and \
                        map_i.metadata.get_max() is None:
                         if not self.register_null:
-                            self.empty_maps[map_i.get_name()] = map_i.get_name()
+                            self.removable_maps[map_i.get_name()] = map_i
                             continue
 
                     if map_i.is_in_db(dbif) and self.overwrite:
@@ -622,7 +626,7 @@
                 dbif.close()
                 t[0] = register_list
 
-                self.remove_empty_maps()
+                self.remove_maps()
     
     def p_expr_spmap_function(self, t):
         # Add a single map.

Modified: grass/trunk/lib/python/temporal/temporal_vector_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_vector_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/temporal_vector_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -136,25 +136,6 @@
 
     ######################### Temporal functions ##############################
 
-    def remove_intermediate_vector_maps(self):
-        """ Removes the intermediate vector maps.
-        """
-        if self.names != {}:
-            namelist = self.names.values()
-            max = 100
-            chunklist = [namelist[i:i + max] for i in range(0, len(namelist), max)]
-            for chunk in chunklist:
-                stringlist = ",".join(chunk)
-                if self.debug:
-                    print "g.remove type=vect name=%s"%(stringlist)
-
-                if self.run:
-                    m = copy.deepcopy(self.m_mremove)
-                    m.inputs["type"].value = "vect"
-                    m.inputs["name"].value = stringlist
-                    m.flags["f"].value = True
-                    m.run()
-
     def get_temporal_topo_list(self, maplistA, maplistB = None, topolist = ["EQUAL"],
                                assign_val = False, count_map = False, compare_bool = False,  
                                compare_cmd = False,  compop = None, aggregate = None,  
@@ -272,6 +253,8 @@
                         resultlist = resultlist + relationmap.cmd_list
                     # Generate an intermediate name
                     name = self.generate_map_name()
+                    # Put it into the removalbe map list
+                    self.removable_maps[name] = VectorDataset(name + "@%s"%(self.mapset))
                     map_i.set_id(name + "@" + self.mapset)
                     # Set second input for overlay module.
                     mapbinput = relationmap.get_id()
@@ -320,7 +303,8 @@
             tbrelations = map_i.get_temporal_relations()
             # Generate an intermediate map for the result map list.
             map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', 
-                                                                        copy = True,  rename = False)
+                                                                        copy = True,  rename = False,  
+                                                                        remove = True)
             # Combine temporal and spatial extents of intermediate map with related maps.
             for topo in topolist:
                 if topo in tbrelations.keys():
@@ -328,7 +312,8 @@
                         if temporal == 'r':
                             # Generate an intermediate map for the result map list.
                             map_new = self.generate_new_map(base_map=map_i, bool_op = 'and', 
-                                                                                        copy = True,  rename = False)
+                                                                                        copy = True,  rename = False,  
+                                                                                        remove = True)
                         # Create overlayed map extent.
                         returncode = self.overlay_map_extent(map_new, map_j, 'and', \
                                                                 temp_op = temporal)
@@ -360,6 +345,8 @@
         """
         # Execute the command lists
         if self.run:
+            # Open connection to temporal database.
+            dbif, connected = init_dbif(dbif=self.dbif)
             if isinstance(t[3], list):
                 num = len(t[3])
                 count = 0
@@ -415,8 +402,8 @@
                                 break
                         if returncode == 0:
                             # We remove the invalid vector name from the remove list.
-                            if self.names.has_key(map_i.get_name()):
-                                self.names.pop(map_i.get_name())
+                            if self.removable_maps.has_key(map_i.get_name()):
+                                self.removable_maps.pop(map_i.get_name())
                             mapset = map_i.get_mapset()
                             # Change map name to given basename.
                             newident = self.basename + "_" + str(count)
@@ -424,17 +411,41 @@
                             m.inputs["vect"].value = (map_i.get_name(),newident)
                             m.flags["overwrite"].value = self.overwrite
                             m.run()
-                            #m(vect = (map_i.get_name(),newident), \
-                            #    overwrite = self.overwrite)
                             map_i.set_id(newident + "@" + mapset)
                             count += 1
                             register_list.append(map_i)
                     else:
-                        register_list.append(map_i)
+                        # Test if temporal extents have been changed by temporal 
+                        # relation operators (i|r). This is a code copy from temporal_algebra.py
+                        map_i_extent = map_i.get_temporal_extent_as_tuple()
+                        map_test = map_i.get_new_instance(map_i.get_id())
+                        map_test.select(dbif)
+                        map_test_extent = map_test.get_temporal_extent_as_tuple()
+                        if map_test_extent != map_i_extent:
+                            # Create new map with basename
+                            newident = self.basename + "_" + str(count)
+                            map_result = map_i.get_new_instance(newident + "@" + self.mapset)
 
+                            if map_test.map_exists() and self.overwrite == False:
+                                self.msgr.fatal("Error raster maps with basename %s exist. Use --o flag to overwrite existing file" \
+                                                    %(mapname))
+
+                            map_result.set_temporal_extent(map_i.get_temporal_extent())
+                            map_result.set_spatial_extent(map_i.get_spatial_extent())
+                            # Attention we attach a new attribute
+                            map_result.is_new = True
+                            count += 1
+                            register_list.append(map_result)
+
+                            # Copy the map
+                            m = copy.deepcopy(self.m_copy)
+                            m.inputs["vect"].value = map_i.get_id(),  newident
+                            m.flags["overwrite"].value = self.overwrite
+                            m.run()
+                        else:
+                            register_list.append(map_i)
+
                 if len(register_list) > 0:
-                    # Open connection to temporal database.
-                    dbif, connect = init_dbif(dbif=self.dbif)
                     # Create result space time dataset.
                     resultstds = open_new_stds(t[1], self.stdstype, \
                                                                 'absolute', t[1], t[1], \
@@ -442,7 +453,7 @@
                                                                 overwrite = self.overwrite)
                     for map_i in register_list:
                         # Check if modules should be executed from command list.
-                        if "cmd_list" in dir(map_i):
+                        if hasattr(map_i, "cmd_list") or hasattr(map_i, "is_new"):
                             # Get meta data from grass database.
                             map_i.load()
                             if map_i.is_in_db(dbif=dbif) and self.overwrite:
@@ -457,17 +468,17 @@
                                 # Insert map into temporal database.
                                 map_i.insert(dbif=dbif)
                         else:
-                            #Get metadata from temporal database.                          
-                            #map_i.select(dbif=dbif)
+                            # Map is original from an input STVDS
                             map_i.load()
                         # Register map in result space time dataset.
+                        print map_i.get_temporal_extent_as_tuple()
                         success = resultstds.register_map(map_i, dbif=dbif)
-                        #count += 1
-                        #if count % 10 == 0:
-                        #    grass.percent(count, num, 1)
                     resultstds.update_from_registered_maps(dbif)
-                    dbif.close()
-                self.remove_intermediate_vector_maps()
+                
+            # Remove intermediate maps    
+            self.remove_maps()
+            if connected:
+                dbif.close()
             t[0] = t[3]
 
     def p_overlay_operation(self, t):
@@ -549,7 +560,7 @@
             for map_i in bufflist:
                 # Generate an intermediate name for the result map list.
                 map_new = self.generate_new_map(base_map=map_i, bool_op=None,
-                                                copy=True)
+                                                copy=True,  remove = True)
                 # Change spatial extent based on buffer size.
                 map_new.spatial_buffer(float(t[5]))
                 # Check buff type.

Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -70,7 +70,7 @@
     def test_temporal_select1(self):
         """Testing the temporal select operator with equal relations. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A : A", basename="r", overwrite=True)
+        ta.parse(expression="R = A : A",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -86,7 +86,7 @@
     def test_temporal_select2(self):
         """Testing the temporal select operator with equal relations. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A : D", basename="r", overwrite=True)
+        ta.parse(expression="R = A : D",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -102,7 +102,7 @@
     def test_temporal_select3(self):
         """Testing the temporal select operator with equal relations. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A !: D", basename="r", overwrite=True)
+        ta.parse(expression="R = A !: D",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -118,7 +118,7 @@
     def test_temporal_select_operators1(self):
         """Testing the temporal select operator. Including temporal relations. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {:,during} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {:,during} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -134,7 +134,7 @@
     def test_temporal_select_operators2(self):
         """Testing the temporal select operator. Including temporal relations. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {:,equal|during} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {:,equal|during} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -151,7 +151,7 @@
         """Testing the temporal select operator. Including temporal relations 
             and negation operation. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {!:,during} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {!:,during} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -168,7 +168,7 @@
         """Testing the temporal select operator. Including temporal relations and 
             temporal operators. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {:,during,d} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {:,during,d} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -190,7 +190,7 @@
         """Testing the temporal select operator. Including temporal relations and 
             temporal operators. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = C {:,contains} A", basename="r", overwrite=True)
+        ta.parse(expression="R = C {:,contains} A",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -211,7 +211,7 @@
     def test_temporal_extent1(self):
         """Testing the temporal extent operators. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {:,during,r} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {:,during,r} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -228,7 +228,7 @@
     def test_temporal_extent2(self):
         """Testing the temporal extent operators. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {:,during,d} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {:,during,d} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -245,7 +245,7 @@
     def test_temporal_extent3(self):
         """Testing the temporal extent operators. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = A {:,during,u} C", basename="r", overwrite=True)
+        ta.parse(expression="R = A {:,during,u} C",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -266,7 +266,7 @@
     def test_temporal_hash1(self):
         """Testing the hash function in conditional statement. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = if(A # D == 1, A)", basename="r", overwrite=True)
+        ta.parse(expression="R = if(A # D == 1, A)",  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -283,7 +283,8 @@
     def test_temporal_hash_operator1(self):
         """Testing the hash operator function in conditional statement. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = if(A {#,during} C == 1, A)", basename="r", overwrite=True)
+        ta.parse(expression="R = if(A {#,during} C == 1, A)",  stdstype = 'strds', 
+                                       basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -300,7 +301,8 @@
     def test_temporal_hash_operator2(self):
         """Testing the hash operator function in conditional statement. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression="R = if({during}, C {#,contains} A == 2, A)", basename="r", overwrite=True)
+        ta.parse(expression="R = if({during}, C {#,contains} A == 2, A)",  
+                                                 stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -317,7 +319,7 @@
     def test_tmap_function1(self):
         """Testing the tmap function. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression='R = tmap(singletmap)', basename="r", overwrite=True)
+        ta.parse(expression='R = tmap(singletmap)',  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()
@@ -334,7 +336,7 @@
     def test_tmap_function2(self):
         """Testing the tmap function. """
         ta = tgis.TemporalAlgebraParser(run = True, debug = True)
-        ta.parse(expression='R = A : tmap(singletmap)', basename="r", overwrite=True)
+        ta.parse(expression='R = A : tmap(singletmap)',  stdstype = 'strds', basename="r", overwrite=True)
 
         D = tgis.open_old_stds("R", type="strds")
         D.select()

Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_raster_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -68,6 +68,23 @@
         cls.runModule("t.unregister", maps="singletmap", quiet=True)
         cls.del_temp_region()
 
+    def test_temporal_extent1(self):
+        """Testing the temporal extent operators. """
+        ta = tgis.TemporalRasterAlgebraParser(run = True, debug = True)
+        ta.parse(expression="R = A {:,during,r} C",   basename="r", overwrite=True)
+
+        D = tgis.open_old_stds("R", type="strds")
+        D.select()
+        maplist = D.get_registered_maps_as_objects()
+        self.assertEqual(D.metadata.get_number_of_maps(), 2)
+        self.assertEqual(D.metadata.get_min_min(), 2) 
+        self.assertEqual(D.metadata.get_max_max(), 3) 
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 2))
+        self.assertEqual(end, datetime.datetime(2001, 1, 4))
+        self.assertEqual( D.check_temporal_topology(),  False)
+        self.assertEqual(D.get_granularity(),  u'2 days')
+
     def test_temporal_conditional_time_dimension_bug(self):
         """Testing the conditional time dimension bug, that uses the time 
             dimension of the conditional statement instead the time dimension 

Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_vector_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_vector_algebra.py	2014-11-17 13:06:25 UTC (rev 62774)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_vector_algebra.py	2014-11-17 13:30:34 UTC (rev 62775)
@@ -84,6 +84,22 @@
         self.assertEqual( D.check_temporal_topology(),  True)
         self.assertEqual(D.get_granularity(),  u'1 day')
 
+    def test_temporal_extent1(self):
+        """Testing the temporal extent operators. """
+        ta = tgis.TemporalVectorAlgebraParser(run = True, debug = True)
+        ta.parse(expression="R = A {:,during,r} C",  basename="r", overwrite=True)
+
+        D = tgis.open_old_stds("R", type="stvds")
+        D.select()
+        D.print_info()
+        maplist = D.get_registered_maps_as_objects()
+        self.assertEqual(D.metadata.get_number_of_maps(), 2)
+        start, end = D.get_absolute_time()
+        self.assertEqual(start, datetime.datetime(2001, 1, 2))
+        self.assertEqual(end, datetime.datetime(2001, 1, 4))
+        self.assertEqual( D.check_temporal_topology(),  False)
+        self.assertEqual(D.get_granularity(),  u'2 days')
+
     def test_temporal_select_operators(self):
         """Testing the temporal select operator. Including temporal relations. """
         tva = tgis.TemporalVectorAlgebraParser(run = True, debug = True)



More information about the grass-commit mailing list