[GRASS-SVN] r57479 - grass/trunk/lib/python/temporal

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 21 11:54:55 PDT 2013


Author: huhabla
Date: 2013-08-21 11:54:55 -0700 (Wed, 21 Aug 2013)
New Revision: 57479

Added:
   grass/trunk/lib/python/temporal/open.py
Removed:
   grass/trunk/lib/python/temporal/create.py
Modified:
   grass/trunk/lib/python/temporal/Makefile
   grass/trunk/lib/python/temporal/__init__.py
   grass/trunk/lib/python/temporal/extract.py
   grass/trunk/lib/python/temporal/list.py
   grass/trunk/lib/python/temporal/mapcalc.py
   grass/trunk/lib/python/temporal/register.py
   grass/trunk/lib/python/temporal/spatio_temporal_relationships.py
   grass/trunk/lib/python/temporal/stds_export.py
   grass/trunk/lib/python/temporal/temporal_extent.py
   grass/trunk/lib/python/temporal/univar_statistics.py
Log:
Implemented open_old and open_new space time raster dataset functions
and replaced lots of code with this functions. Renamed create.py to open.py.


Modified: grass/trunk/lib/python/temporal/Makefile
===================================================================
--- grass/trunk/lib/python/temporal/Makefile	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/Makefile	2013-08-21 18:54:55 UTC (rev 57479)
@@ -8,7 +8,7 @@
 GDIR = $(PYDIR)/grass
 DSTDIR = $(GDIR)/temporal
 
-MODULES = base core abstract_dataset abstract_map_dataset abstract_space_time_dataset space_time_datasets create factory gui_support list register sampling metadata spatial_extent temporal_extent datetime_math temporal_granularity spatio_temporal_relationships unit_tests aggregation stds_export stds_import extract mapcalc univar_statistics temporal_topology_dataset_connector spatial_topology_dataset_connector
+MODULES = base core abstract_dataset abstract_map_dataset abstract_space_time_dataset space_time_datasets open factory gui_support list register sampling metadata spatial_extent temporal_extent datetime_math temporal_granularity spatio_temporal_relationships unit_tests aggregation stds_export stds_import extract mapcalc univar_statistics temporal_topology_dataset_connector spatial_topology_dataset_connector
 
 PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
 PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)

Modified: grass/trunk/lib/python/temporal/__init__.py
===================================================================
--- grass/trunk/lib/python/temporal/__init__.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/__init__.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -12,7 +12,7 @@
 from datetime_math import *
 from temporal_granularity import *
 from spatio_temporal_relationships import *
-from create import *
+from open import *
 from factory import *
 from gui_support import *
 from list import *

Deleted: grass/trunk/lib/python/temporal/create.py
===================================================================
--- grass/trunk/lib/python/temporal/create.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/create.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -1,89 +0,0 @@
-"""!@package grass.temporal
-
- at brief GRASS Python scripting module (temporal GIS functions)
-
-Temporal GIS related functions to be used in Python scripts.
-
-Usage:
-
- at code
-import grass.temporal as tgis
-
-tgis.register_maps_in_space_time_dataset(type, name, maps)
-
-...
- at endcode
-
-(C) 2008-2011 by the GRASS Development Team
-This program is free software under the GNU General Public
-License (>=v2). Read the file COPYING that comes with GRASS
-for details.
-
- at author Soeren Gebbert
-"""
-
-from space_time_datasets import *
-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 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"]
-    id = name + "@" + mapset
-
-    sp = dataset_factory(type, id)
-
-    dbif, connected = init_dbif(dbif)
-
-    if sp.is_in_db(dbif) and overwrite == False:
-        if connected:
-            dbif.close()
-        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 %(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.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,
-                          title=title, description=descr)
-    sp.insert(dbif)
-
-    if connected:
-        dbif.close()
-        
-    return sp

Modified: grass/trunk/lib/python/temporal/extract.py
===================================================================
--- grass/trunk/lib/python/temporal/extract.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/extract.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -13,6 +13,7 @@
 """
 
 from space_time_datasets import *
+from open import *
 from multiprocessing import Process
 
 ############################################################################
@@ -53,48 +54,15 @@
 
     mapset = core.gisenv()["MAPSET"]
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    if type == "raster":
-        sp = SpaceTimeRasterDataset(id)
-    elif type == "raster3d":
-        sp = SpaceTimeRaster3DDataset(id)
-    elif type == "vector":
-        sp = SpaceTimeVectorDataset(id)
-
-    dummy = sp.get_new_map_instance(None)
-
     dbif = SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    if not sp.is_in_db(dbif):
-        dbif.close()
-        core.fatal(_("Space time %(type)s dataset <%(id)s> not found") % {
-                     'type': type, 'id': id})
-
-    if expression and not base:
-        dbif.close()
-        core.fatal(_("Please specify base="))
-
-    sp.select(dbif)
-
-    if output.find("@") >= 0:
-        out_id = output
-    else:
-        out_id = output + "@" + mapset
-
-    # The new space time dataset
-    new_sp = sp.get_new_instance(out_id)
-
-    if new_sp.is_in_db():
-        if not core.overwrite():
-            dbif.close()
-            core.fatal(_("Space time %(type)s dataset <%(id)s> is already in "
-                         "database, use overwrite flag to overwrite") % {
-                         'type': type, 'id': out_id})
+    sp = open_old_space_time_dataset(input, type, dbif)
+    dummy = sp.get_new_map_instance(None)
+    # Check the new stds
+    new_sp = open_new_space_time_dataset(output, type, sp.get_temporal_type(),
+                                         "None", "None", "mean", dbif,
+                                         core.overwrite(), dry=True)
     if type == "vector":
         rows = sp.get_registered_maps(
             "id,name,mapset,layer", where, "start_time", dbif)
@@ -198,16 +166,12 @@
 
         core.percent(0, num_rows, 1)
 
-        # Insert the new space time dataset
-        if new_sp.is_in_db(dbif):
-            if core.overwrite():
-                new_sp.delete(dbif)
-                new_sp = sp.get_new_instance(out_id)
-
         temporal_type, semantic_type, title, description = sp.get_initial_values()
-        new_sp.set_initial_values(
-            temporal_type, semantic_type, title, description)
-        new_sp.insert(dbif)
+        new_sp = open_new_space_time_dataset(output, type,
+                                             sp.get_temporal_type(),
+                                             title, description,
+                                             semantic_type, dbif,
+                                             core.overwrite(), dry=False)
 
         # collect empty maps to remove them
         empty_maps = []

Modified: grass/trunk/lib/python/temporal/list.py
===================================================================
--- grass/trunk/lib/python/temporal/list.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/list.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -24,6 +24,7 @@
 
 from space_time_datasets import *
 from factory import *
+from open import *
 
 ###############################################################################
 
@@ -50,25 +51,14 @@
             - "gran" List map using the granularity of the space time dataset,
                       columns are identical to deltagaps
         @param header Set True to print column names
-        @param gran The user defined granule to be used if method=gran is set, in case gran=None the 
+        @param gran The user defined granule to be used if method=gran is set, in case gran=None the
             granule of the space time dataset is used
     """
-    mapset = core.gisenv()["MAPSET"]
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
     dbif, connected = init_dbif(None)
-    
-    sp = dataset_factory(type, id)
 
-    if not sp.is_in_db(dbif=dbif):
-        core.fatal(_("Dataset <%s> not found in temporal database") % (id))
+    sp = open_old_space_time_dataset(input, type, dbif)
 
-    sp.select(dbif=dbif)
-
     if separator is None or separator == "":
         separator = "\t"
 
@@ -87,7 +77,7 @@
                 maps = sp.get_registered_maps_as_objects_by_granularity(gran=gran, dbif=dbif)
             else:
                 maps = sp.get_registered_maps_as_objects_by_granularity(dbif=dbif)
-            
+
         if header:
             string = ""
             string += "%s%s" % ("id", separator)

Modified: grass/trunk/lib/python/temporal/mapcalc.py
===================================================================
--- grass/trunk/lib/python/temporal/mapcalc.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/mapcalc.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -13,6 +13,7 @@
 """
 
 from space_time_datasets import *
+from open import *
 from multiprocessing import Process
 
 ############################################################################
@@ -82,25 +83,8 @@
 
     input_name_list = inputs.split(",")
 
-    # Process the first input
-    if input_name_list[0].find("@") >= 0:
-        id = input_name_list[0]
-    else:
-        id = input_name_list[0] + "@" + mapset
+    first_input = open_old_space_time_dataset(input_name_list[0], type, dbif)
 
-    if type == "raster":
-        first_input = SpaceTimeRasterDataset(id)
-    else:
-        first_input = SpaceTimeRaster3DDataset(id)
-
-    if not first_input.is_in_db(dbif):
-        dbif.close()
-        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
     # wrong name substitution
     input_name_list = input_name_list[1:]
@@ -109,39 +93,14 @@
     input_list = []
 
     for input in input_name_list:
-
-        if input.find("@") >= 0:
-            id = input
-        else:
-            id = input + "@" + mapset
-
-        sp = first_input.get_new_instance(id)
-
-        if not sp.is_in_db(dbif):
-            dbif.close()
-            core.fatal(_("Space time %(t)s dataset <%(i)s> not "
-                         "found in temporal database") % {'t': type, 'i': id})
-
-        sp.select(dbif)
-
+        sp = open_old_space_time_dataset(input, type, dbif)
         input_list.append(copy.copy(sp))
 
-    # Create the new space time dataset
-    if output.find("@") >= 0:
-        out_id = output
-    else:
-        out_id = output + "@" + mapset
+    new_sp = open_new_space_time_dataset(output, type,
+                                         first_input.get_temporal_type(),
+                                         "New", "New dataset", "mean", dbif,
+                                         core.overwrite(), True)
 
-    new_sp = first_input.get_new_instance(out_id)
-
-    # Check if in database
-    if new_sp.is_in_db(dbif):
-        if not core.overwrite():
-            dbif.close()
-            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:
         core.message(_("Start spatio-temporal sampling"))
@@ -321,19 +280,12 @@
         # Register the new maps in the output space time dataset
         core.message(_("Start map registration in temporal database"))
 
-        # Overwrite an existing dataset if requested
-        if new_sp.is_in_db(dbif):
-            if core.overwrite():
-                new_sp.delete(dbif)
-                new_sp = first_input.get_new_instance(out_id)
-
-        # Copy the ids from the first input
         temporal_type, semantic_type, title, description = first_input.get_initial_values()
-        new_sp.set_initial_values(
-            temporal_type, semantic_type, title, description)
-        # Insert the dataset in the temporal database
-        new_sp.insert(dbif)
 
+        new_sp = open_new_space_time_dataset(output, type,
+                                         temporal_type, title, description,
+                                         semantic_type, dbif,
+                                         core.overwrite(), False)
         count = 0
 
         # collect empty maps to remove them
@@ -670,7 +622,7 @@
 
 
 def _parse_start_time_operator(expr, is_time_absolute, first, current):
-    """Parse the start_time() operator. This operator represent 
+    """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

Copied: grass/trunk/lib/python/temporal/open.py (from rev 57415, grass/trunk/lib/python/temporal/create.py)
===================================================================
--- grass/trunk/lib/python/temporal/open.py	                        (rev 0)
+++ grass/trunk/lib/python/temporal/open.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -0,0 +1,156 @@
+"""!@package grass.temporal
+
+ at brief GRASS Python scripting module (temporal GIS functions)
+
+Temporal GIS related functions to be used in Python scripts.
+
+Usage:
+
+ at code
+import grass.temporal as tgis
+
+tgis.register_maps_in_space_time_dataset(type, name, maps)
+
+...
+ at endcode
+
+(C) 2008-2011 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Soeren Gebbert
+"""
+
+from space_time_datasets import *
+from factory import *
+
+###############################################################################
+
+def open_old_space_time_dataset(name, type, dbif=None):
+    """!This function opens an existing space time dataset and return the
+       created and intialized object of the specified type.
+
+       This function will raise a ScriptError in case the type is wrong,
+       or the space time dataset was not found.
+
+       @param name The name of the space time dataset, if the name does not
+                    contain the mapset (name at mapset) then the current mapset
+                    will be used to identifiy the space time dataset
+       @param type The type of the space time dataset (strd, str3ds, stvds,
+                                                       raster, vector, raster3d)
+       @param dbif The optional database interface to be used
+
+    """
+    mapset = core.gisenv()["MAPSET"]
+
+    # Check if the dataset name contains the mapset as well
+    if name.find("@") < 0:
+        id = name + "@" + mapset
+    else:
+        id = name
+
+    if type == "strds" or type == "rast" or type == "raster":
+        sp = dataset_factory("strds", id)
+    elif type == "str3ds" or type == "rast3d" or type == "raster3d":
+        sp = dataset_factory("str3ds", id)
+    elif type == "stvds" or type == "vect" or type == "vector":
+        sp = dataset_factory("stvds", id)
+    else:
+        core.fatal(_("Unkown type: %s") % (type))
+
+    dbif, connected = init_dbif(dbif)
+
+    if not sp.is_in_db(dbif):
+        dbif.close()
+        core.fatal(_("Space time %(sp)s dataset <%(name)s> no found") %
+                     {'sp': sp.get_new_map_instance(None).get_type(),
+                      'name': name})
+
+    # Read content from temporal database
+    sp.select(dbif)
+    if connected:
+        dbif.close()
+
+    return sp
+
+###############################################################################
+
+def open_new_space_time_dataset(name, type, temporaltype, title, descr, semantic,
+                              dbif=None, overwrite=False, dry=False):
+    """!Create a new space time dataset of a specific type
+
+       This function is sensitive to the settings in grass.core.overwrite to
+       overwrite existing space time datasets.
+
+       @param name The name of the new space time dataset
+       @param type The type of the new space time dataset (strd, str3ds, stvds,
+                                                      raster, vector, raster3d)
+       @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
+       @param dry Do not create the space time dataset in the temporal database,
+                  make a dry run with including all checks
+
+       @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"]
+
+    if name.find("@") < 0:
+        id = name + "@" + mapset
+    else:
+        n, m = name.split("@")
+        if mapset != m:
+            core.fatal(_("Space time datasets can only be created in the "
+                         "current mapset"))
+        id = name
+
+    if type == "strds" or type == "rast" or type == "raster":
+        sp = dataset_factory("strds", id)
+    elif type == "str3ds" or type == "rast3d" or type == "raster3d":
+        sp = dataset_factory("str3ds", id)
+    elif type == "stvds" or type == "vect" or type == "vector":
+        sp = dataset_factory("stvds", id)
+    else:
+        core.fatal(_("Unkown type: %s") % (type))
+
+    dbif, connected = init_dbif(dbif)
+
+    if sp.is_in_db(dbif) and overwrite is False:
+        if connected:
+            dbif.close()
+        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 is True:
+        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})
+        if not dry:
+            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.set_initial_values(temporal_type=temporaltype, semantic_type=semantic,
+                          title=title, description=descr)
+    if not dry:
+        sp.insert(dbif)
+
+    if connected:
+        dbif.close()
+
+    return sp

Modified: grass/trunk/lib/python/temporal/register.py
===================================================================
--- grass/trunk/lib/python/temporal/register.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/register.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -24,6 +24,7 @@
 
 from space_time_datasets import *
 from factory import *
+from open import *
 
 ###############################################################################
 
@@ -43,8 +44,8 @@
        @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 per line map with start and optional
+                   end time
        @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)
@@ -83,36 +84,12 @@
 
     # We may need the mapset
     mapset = core.gisenv()["MAPSET"]
+    dbif, connected = init_dbif(None)
 
     # The name of the space time dataset is optional
     if name:
-        # Check if the dataset name contains the mapset as well
-        if name.find("@") < 0:
-            id = name + "@" + mapset
-        else:
-            id = name
+        sp = open_old_space_time_dataset(name, type, dbif)
 
-        if type == "rast" or type == "raster":
-            sp = dataset_factory("strds", id)
-        elif type == "rast3d":
-            sp = dataset_factory("str3ds", id)
-        elif type == "vect" or type == "vector":
-            sp = dataset_factory("stvds", id)
-        else:
-            core.fatal(_("Unkown map type: %s") % (type))
-
-    dbif, connected = init_dbif(None)
-
-    if name:
-        # Read content from temporal database
-        sp.select(dbif)
-
-        if not sp.is_in_db(dbif):
-            dbif.close()
-            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 %(sp)s dataset <%(name)s> with relative"

Modified: grass/trunk/lib/python/temporal/spatio_temporal_relationships.py
===================================================================
--- grass/trunk/lib/python/temporal/spatio_temporal_relationships.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/spatio_temporal_relationships.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -29,7 +29,7 @@
 ###############################################################################
 
 class SpatioTemporalTopologyBuilder(object):
-    """!This class is designed to build the spatio-temporal topology 
+    """!This class is designed to build the spatio-temporal topology
        of spatio-temporally related abstract dataset objects.
 
        The abstract dataset objects must be provided as a single list, or in two lists.
@@ -51,7 +51,7 @@
         for map in tb:
             map.select(dbif)
             map.print_info()
-            
+
         # Same can be done with the existing map list
         # But be aware that this is might not be temporally ordered
         for map in maps:
@@ -69,7 +69,7 @@
 
         # Dictionary like accessed
         map = tb["name at mapset"]
-        
+
         >>> # Example with two lists of maps
         >>> import grass.temporal as tgis
         >>> # Create two list of maps with equal time stamps
@@ -119,7 +119,7 @@
         Map b7 has equal relation to map a7
         Map b8 has equal relation to map a8
         Map b9 has equal relation to map a9
-        
+
         @endcode
 
     """
@@ -155,15 +155,15 @@
         return self._first
 
     def _build_internal_iteratable(self, maps, spatial):
-        """!Build an iteratable temporal topology structure for all maps in 
+        """!Build an iteratable temporal topology structure for all maps in
            the list and store the maps internally
 
-           Basically the "next" and "prev" relations will be set in the 
+           Basically the "next" and "prev" relations will be set in the
            temporal topology structure of each map
-           The maps will be added to the object, so they can be 
+           The maps will be added to the object, so they can be
            accessed using the iterator of this class
 
-           @param maps A sorted (by start_time)list of abstract_dataset 
+           @param maps A sorted (by start_time)list of abstract_dataset
                         objects with initiated temporal extent
         """
         self._build_iteratable(maps, spatial)
@@ -175,13 +175,13 @@
         self._detect_first()
 
     def _build_iteratable(self, maps, spatial):
-        """!Build an iteratable temporal topology structure for 
+        """!Build an iteratable temporal topology structure for
            all maps in the list
 
-           Basically the "next" and "prev" relations will be set in 
+           Basically the "next" and "prev" relations will be set in
            the temporal topology structure of each map.
 
-           @param maps A sorted (by start_time)list of abstract_dataset 
+           @param maps A sorted (by start_time)list of abstract_dataset
                         objects with initiated temporal extent
         """
 #        for i in xrange(len(maps)):
@@ -195,7 +195,7 @@
 #                    maps[i].set_next(maps[j])
 #                    break
 
-        # First we need to order the map list chronologically 
+        # First we need to order the map list chronologically
         sorted_maps = sorted(
             maps, key=AbstractDatasetComparisonKeyStartTime)
 
@@ -211,10 +211,11 @@
                 map_.set_spatial_topology_build_true()
 
     def _map_to_rect(self, tree, map_, spatial=None):
-        """Use the temporal extent of a map to create and return a RTree rectange
+        """!Use the spatio-temporal extent of a map to create and
+           return a RTree rectange
 
            @param spatial This indicates if the spatial topology is created as well:
-                          spatial can be None (no spatial topology), "2D" using west, east, 
+                          spatial can be None (no spatial topology), "2D" using west, east,
                           #south, north or "3D" using west, east, south, north, bottom, top
         """
         rect = vector.RTreeAllocRect(tree)
@@ -232,21 +233,21 @@
             vector.RTreeSetRect1D(rect, tree, float(start), float(end))
         elif spatial == "2D":
             north, south, east, west, top, bottom = map_.get_spatial_extent_as_tuple()
-            vector.RTreeSetRect3D(rect, tree, west, east, south, north, 
+            vector.RTreeSetRect3D(rect, tree, west, east, south, north,
                                   float(start), float(end))
         elif spatial == "3D":
             north, south, east, west, top, bottom = map_.get_spatial_extent_as_tuple()
-            vector.RTreeSetRect4D(rect, tree, west, east, south, north, 
+            vector.RTreeSetRect4D(rect, tree, west, east, south, north,
                                   bottom, top, float(start), float(end))
 
         return rect
 
     def _build_rtree(self, maps, spatial=None):
-        """Build and return the 1-4 dimensional R*-Tree
+        """!Build and return the 1-4 dimensional R*-Tree
 
 
            @param spatial This indicates if the spatial topology is created as well:
-                          spatial can be None (no spatial topology), "2D" using west, east, 
+                          spatial can be None (no spatial topology), "2D" using west, east,
                           south, north or "3D" using west, east, south, north, bottom, top
         """
         dim = 1
@@ -265,25 +266,25 @@
         return tree
 
     def build(self, mapsA, mapsB=None, spatial=None):
-        """!Build the spatio-temporal topology structure between 
+        """!Build the spatio-temporal topology structure between
            one or two unordered lists of abstract dataset objects
 
-           This method builds the temporal or spatio-temporal topology from mapsA to 
+           This method builds the temporal or spatio-temporal topology from mapsA to
            mapsB and vice verse. The spatio-temporal topology structure of each map
            will be reseted and rebuild for mapsA and mapsB.
 
-           After building the temporal or spatio-temporal topology the modified 
+           After building the temporal or spatio-temporal topology the modified
            map objects of mapsA can be accessed
-           in the same way as a dictionary using there id. 
+           in the same way as a dictionary using there id.
            The implemented iterator assures
            the chronological iteration over the mapsA.
 
-           @param mapsA A list of abstract_dataset 
+           @param mapsA A list of abstract_dataset
                          objects with initiated spatio-temporal extent
-           @param mapsB An optional list of abstract_dataset 
+           @param mapsB An optional list of abstract_dataset
                          objects with initiated spatio-temporal extent
            @param spatial This indicates if the spatial topology is created as well:
-                          spatial can be None (no spatial topology), "2D" using west, east, 
+                          spatial can be None (no spatial topology), "2D" using west, east,
                           south, north or "3D" using west, east, south, north, bottom, top
         """
 
@@ -524,12 +525,12 @@
 ###############################################################################
 
 def print_temporal_topology_relationships(maps1, maps2=None, dbif=None):
-    """!Print the temporal relationships of the 
+    """!Print the temporal relationships of the
        map lists maps1 and maps2 to stdout.
 
-        @param maps1 A list of abstract_dataset 
+        @param maps1 A list of abstract_dataset
                       objects with initiated temporal extent
-        @param maps2 An optional list of abstract_dataset 
+        @param maps2 An optional list of abstract_dataset
                       objects with initiated temporal extent
         @param dbif The database interface to be used
     """
@@ -552,14 +553,14 @@
 ###############################################################################
 
 def print_spatio_temporal_topology_relationships(maps1, maps2=None, spatial="2D", dbif=None):
-    """!Print the temporal relationships of the 
+    """!Print the temporal relationships of the
        map lists maps1 and maps2 to stdout.
 
-        @param maps1 A list of abstract_dataset 
+        @param maps1 A list of abstract_dataset
                       objects with initiated temporal extent
-        @param maps2 An optional list of abstract_dataset 
+        @param maps2 An optional list of abstract_dataset
                       objects with initiated temporal extent
-        @param spatial The dimension of the spatial extent to be used: "2D" using west, east, 
+        @param spatial The dimension of the spatial extent to be used: "2D" using west, east,
                         south, north or "3D" using west, east, south, north, bottom, top
         @param dbif The database interface to be used
     """
@@ -585,9 +586,9 @@
     """!Count the temporal relations of a single list of maps or between two lists of maps
 
 
-        @param maps1 A list of abstract_dataset 
+        @param maps1 A list of abstract_dataset
                       objects with initiated temporal extent
-        @param maps2 A list of abstract_dataset 
+        @param maps2 A list of abstract_dataset
                       objects with initiated temporal extent
         @param dbif The database interface to be used
         @return A dictionary with counted temporal relationships
@@ -682,32 +683,32 @@
         >>> # Relative time
         >>> start = 1
         >>> end = 2
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False)
         >>> create_temporal_relation_sql_where_statement(start, end)
         '((start_time >= 1 and start_time < 2) )'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=True)
         '((start_time >= 1 and start_time < 2) )'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_during=True)
         '(((start_time > 1 and end_time < 2) OR (start_time >= 1 and end_time < 2) OR (start_time > 1 and end_time <= 2)))'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_overlap=True)
         '(((start_time < 1 and end_time > 1 and end_time < 2) OR (start_time < 2 and start_time > 1 and end_time > 2)))'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_contain=True)
         '(((start_time < 1 and end_time > 2) OR (start_time <= 1 and end_time > 2) OR (start_time < 1 and end_time >= 2)))'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_equal=True)
         '((start_time = 1 and end_time = 2))'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_follows=True)
         '((start_time = 2))'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_precedes=True)
         '((end_time = 1))'
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=True, use_during=True, use_overlap=True, use_contain=True,
         ... use_equal=True, use_follows=True, use_precedes=True)
         '((start_time >= 1 and start_time < 2)  OR ((start_time > 1 and end_time < 2) OR (start_time >= 1 and end_time < 2) OR (start_time > 1 and end_time <= 2)) OR ((start_time < 1 and end_time > 1 and end_time < 2) OR (start_time < 2 and start_time > 1 and end_time > 2)) OR ((start_time < 1 and end_time > 2) OR (start_time <= 1 and end_time > 2) OR (start_time < 1 and end_time >= 2)) OR (start_time = 1 and end_time = 2) OR (start_time = 2) OR (end_time = 1))'
@@ -715,32 +716,32 @@
         >>> # Absolute time
         >>> start = datetime(2001, 1, 1, 12, 30)
         >>> end = datetime(2001, 3, 31, 14, 30)
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False)
         >>> create_temporal_relation_sql_where_statement(start, end)
         "((start_time >= '2001-01-01 12:30:00' and start_time < '2001-03-31 14:30:00') )"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=True)
         "((start_time >= '2001-01-01 12:30:00' and start_time < '2001-03-31 14:30:00') )"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_during=True)
         "(((start_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time >= '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time > '2001-01-01 12:30:00' and end_time <= '2001-03-31 14:30:00')))"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_overlap=True)
         "(((start_time < '2001-01-01 12:30:00' and end_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time < '2001-03-31 14:30:00' and start_time > '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00')))"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_contain=True)
         "(((start_time < '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time <= '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time < '2001-01-01 12:30:00' and end_time >= '2001-03-31 14:30:00')))"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_equal=True)
         "((start_time = '2001-01-01 12:30:00' and end_time = '2001-03-31 14:30:00'))"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_follows=True)
         "((start_time = '2001-03-31 14:30:00'))"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=False, use_precedes=True)
         "((end_time = '2001-01-01 12:30:00'))"
-        >>> create_temporal_relation_sql_where_statement(start, end, 
+        >>> create_temporal_relation_sql_where_statement(start, end,
         ... use_start=True, use_during=True, use_overlap=True, use_contain=True,
         ... use_equal=True, use_follows=True, use_precedes=True)
         "((start_time >= '2001-01-01 12:30:00' and start_time < '2001-03-31 14:30:00')  OR ((start_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time >= '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time > '2001-01-01 12:30:00' and end_time <= '2001-03-31 14:30:00')) OR ((start_time < '2001-01-01 12:30:00' and end_time > '2001-01-01 12:30:00' and end_time < '2001-03-31 14:30:00') OR (start_time < '2001-03-31 14:30:00' and start_time > '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00')) OR ((start_time < '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time <= '2001-01-01 12:30:00' and end_time > '2001-03-31 14:30:00') OR (start_time < '2001-01-01 12:30:00' and end_time >= '2001-03-31 14:30:00')) OR (start_time = '2001-01-01 12:30:00' and end_time = '2001-03-31 14:30:00') OR (start_time = '2001-03-31 14:30:00') OR (end_time = '2001-01-01 12:30:00'))"

Modified: grass/trunk/lib/python/temporal/stds_export.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_export.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/stds_export.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -35,6 +35,7 @@
 
 from space_time_datasets import *
 from factory import *
+from open import *
 
 proj_file_name = "proj.txt"
 init_file_name = "init.txt"
@@ -215,8 +216,8 @@
     """
             !Export space time datasets as tar archive with optional compression
 
-            This method should be used to export space time datasets 
-            of type raster and vector as tar archive that can be reimported 
+            This method should be used to export space time datasets
+            of type raster and vector as tar archive that can be reimported
             with the method import_stds().
 
             @param input The name of the space time dataset to export
@@ -226,32 +227,21 @@
               - "gzip" GNU zip compression
               - "bzip2" Bzip compression
             @param workdir The working directory used for extraction and packing
-            @param where The temporal WHERE SQL statement to select a subset 
+            @param where The temporal WHERE SQL statement to select a subset
                           of maps from the space time dataset
             @param format_ The export format:
               - "GTiff" Geotiff format, only for raster maps
-              - "pack" The GRASS raster, 3D raster or vector Pack format, 
+              - "pack" The GRASS raster, 3D raster or vector Pack format,
                        this is the default setting
-              - "GML" GML file export format, only for vector maps, 
+              - "GML" GML file export format, only for vector maps,
                       v.out.ogr export option
             @param type_ The space time dataset type
               - "strds" Space time raster dataset
               - "str3ds" Space time 3D raster dataset
               - "stvds" Space time vector dataset
     """
-    mapset = core.gisenv()["MAPSET"]
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
 
-    sp = dataset_factory(type_, id)
-
-    if sp.is_in_db() == False:
-        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()
 
@@ -259,14 +249,14 @@
     new_cwd = tempfile.mkdtemp(dir=workdir)
     os.chdir(new_cwd)
 
-    sp.select()
-
     if type_ == "strds":
         columns = "name,start_time,end_time,min,max,datatype"
     elif type_ == "stvds":
         columns = "name,start_time,end_time,layer"
     else:
         columns = "name,start_time,end_time"
+
+    sp = open_old_space_time_dataset(input, type_)
     rows = sp.get_registered_maps(columns, where, "start_time", None)
 
     if compression == "gzip":
@@ -329,7 +319,7 @@
     init_file.write(string)
     init_file.close()
 
-    metadata = core.read_command("t.info", type=type_, input=id)
+    metadata = core.read_command("t.info", type=type_, input=sp.get_id())
     metadata_file = open(metadata_file_name, "w")
     metadata_file.write(metadata)
     metadata_file.close()

Modified: grass/trunk/lib/python/temporal/temporal_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_extent.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/temporal_extent.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -195,9 +195,11 @@
             end = self.D["end_time"]
 
         if issubclass(type(self), RelativeTemporalExtent):
-            return RelativeTemporalExtent(start_time=start, end_time=end, unit=self.get_unit())
+            return RelativeTemporalExtent(start_time=start, end_time=end,
+                                          unit=self.get_unit())
         elif issubclass(type(self), AbsoluteTemporalExtent):
-            return AbsoluteTemporalExtent(start_time=start, end_time=end, timezone=self.get_timezone())
+            return AbsoluteTemporalExtent(start_time=start, end_time=end,
+                                          timezone=self.get_timezone())
         elif issubclass(type(self), AbstractTemporalExtent):
             return AbstractTemporalExtent(start_time=start, end_time=end)
 
@@ -379,9 +381,11 @@
             end = self.D["end_time"]
 
         if issubclass(type(self), RelativeTemporalExtent):
-            return RelativeTemporalExtent(start_time=start, end_time=end, unit=self.get_unit())
+            return RelativeTemporalExtent(start_time=start, end_time=end,
+                                          unit=self.get_unit())
         elif issubclass(type(self), AbsoluteTemporalExtent):
-            return AbsoluteTemporalExtent(start_time=start, end_time=end, timezone=self.get_timezone())
+            return AbsoluteTemporalExtent(start_time=start, end_time=end,
+                                          timezone=self.get_timezone())
         elif issubclass(type(self), AbstractTemporalExtent):
             return AbstractTemporalExtent(start_time=start, end_time=end)
 

Modified: grass/trunk/lib/python/temporal/univar_statistics.py
===================================================================
--- grass/trunk/lib/python/temporal/univar_statistics.py	2013-08-21 17:17:36 UTC (rev 57478)
+++ grass/trunk/lib/python/temporal/univar_statistics.py	2013-08-21 18:54:55 UTC (rev 57479)
@@ -25,6 +25,7 @@
 
 from space_time_datasets import *
 from factory import *
+from open import *
 
 ###############################################################################
 
@@ -45,22 +46,8 @@
     dbif = SQLDatabaseInterfaceConnection()
     dbif.connect()
 
-    mapset = core.gisenv()["MAPSET"]
+    sp = open_old_space_time_dataset(input, "strds", dbif)
 
-    if input.find("@") >= 0:
-        id = input
-    else:
-        id = input + "@" + mapset
-
-    sp = dataset_factory(type, id)
-
-    if sp.is_in_db(dbif) == False:
-        dbif.close()
-        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)
-
     rows = sp.get_registered_maps(
         "id,start_time,end_time", where, "start_time", dbif)
 



More information about the grass-commit mailing list