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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 12 16:08:53 PDT 2012


Author: huhabla
Date: 2012-08-12 16:08:53 -0700 (Sun, 12 Aug 2012)
New Revision: 52646

Modified:
   grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
   grass/trunk/lib/python/temporal/aggregation.py
   grass/trunk/lib/python/temporal/base.py
   grass/trunk/lib/python/temporal/extract.py
   grass/trunk/lib/python/temporal/mapcalc.py
   grass/trunk/lib/python/temporal/space_time_datasets.py
   grass/trunk/lib/python/temporal/space_time_datasets_tools.py
   grass/trunk/lib/python/temporal/temporal_extent.py
   grass/trunk/lib/python/temporal/unit_tests.py
Log:
PEP8 compliance. Added RTree unit tests for 1 - 4 dimensional trees.
Bug fixing after class name conversion to camel case style.


Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -796,16 +796,16 @@
                 map_view = self.get_new_map_instance(
                     None).get_type() + "_view_rel_time"
 
-            if columns is not None:
+            if columns is not None and columns != "":
                 sql = "SELECT %s FROM %s  WHERE %s.id IN (SELECT id FROM %s)" %\
                       (columns, map_view, map_view, self.get_map_register())
             else:
                 sql = "SELECT * FROM %s  WHERE %s.id IN (SELECT id FROM %s)" % \
                       (map_view, map_view, self.get_map_register())
 
-            if where is not None:
+            if where is not None and where != "":
                 sql += " AND (%s)" % (where.split(";")[0])
-            if order is not None:
+            if order is not None and order != "":
                 sql += " ORDER BY %s" % (order.split(";")[0])
 
             try:

Modified: grass/trunk/lib/python/temporal/aggregation.py
===================================================================
--- grass/trunk/lib/python/temporal/aggregation.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/aggregation.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -119,14 +119,14 @@
 
     mapset = libgis.G_mapset()
     map_id = output + "@" + mapset
-    new_map = raster_dataset(map_id)
+    new_map = RasterDataset(map_id)
 
     # Check if new map is in the temporal database
     if new_map.is_in_db(dbif):
         if core.overwrite() == True:
             # Remove the existing temporal database entry
             new_map.delete(dbif)
-            new_map = raster_dataset(map_id)
+            new_map = RasterDataset(map_id)
         else:
             core.error(_("Raster map <%s> is already in temporal database, use overwrite flag to overwrite"))
             return

Modified: grass/trunk/lib/python/temporal/base.py
===================================================================
--- grass/trunk/lib/python/temporal/base.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/base.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -663,7 +663,7 @@
         """
         if self.id.find(":") >= 0:
             # Remove the layer identifier from the id
-            return iself.d.split("@")[0].split(":")[0] + "@" + \
+            return self.id.split("@")[0].split(":")[0] + "@" + \
                    self.id.split("@")[1]
         else:
             return self.id

Modified: grass/trunk/lib/python/temporal/extract.py
===================================================================
--- grass/trunk/lib/python/temporal/extract.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/extract.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -17,7 +17,6 @@
 
 ############################################################################
 
-
 def extract_dataset(input, output, type, where, expression, base, nprocs=1,
                     register_null=False, layer=1,
                     vtype="point,line,boundary,centroid,area,face"):
@@ -55,15 +54,15 @@
         id = input + "@" + mapset
 
     if type == "raster":
-        sp = space_time_raster_dataset(id)
+        sp = SpaceTimeRasterDataset(id)
     elif type == "raster3d":
-        sp = space_time_raster3d_dataset(id)
+        sp = SpaceTimeRaster3DDataset(id)
     elif type == "vector":
-        sp = space_time_vector_dataset(id)
+        sp = SpaceTimeVectorDataset(id)
 
     dummy = sp.get_new_map_instance(None)
 
-    dbif = ()
+    dbif = SQLDatabaseInterfaceConnection()
     dbif.connect()
 
     if not sp.is_in_db(dbif):
@@ -156,20 +155,22 @@
                                  % expression)
                     if row["layer"]:
                         proc_list.append(Process(target=run_vector_extraction,
-                                                 args=(row["name"] + "@" + row["mapset"],
+                                                 args=(row["name"] + "@" + \
+                                                       row["mapset"],
                                                  map_name, row["layer"], 
                                                  vtype, expression)))
                     else:
                         proc_list.append(Process(target=run_vector_extraction,
-                                                 args=(row["name"] + "@" + row["mapset"],
+                                                 args=(row["name"] + "@" + \
+                                                       row["mapset"],
                                                  map_name, layer, vtype, 
                                                  expression)))
 
                 proc_list[proc_count].start()
                 proc_count += 1
 
-                # Join processes if the maximum number of processes are reached or the end of the
-                # loop is reached
+                # 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
                     exitcodes = 0
@@ -229,8 +230,8 @@
                                 empty_maps.append(new_map)
                                 continue
                     elif type == "vector":
-                        if new_map.metadata.get_primitives() == 0 or \
-                           new_map.metadata.get_primitives() is None:
+                        if new_map.metadata.get_number_of_primitives() == 0 or \
+                           new_map.metadata.get_number_of_primitives() is None:
                             if not register_null:
                                 empty_maps.append(new_map)
                                 continue
@@ -276,19 +277,16 @@
 
 ###############################################################################
 
-
 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,

Modified: grass/trunk/lib/python/temporal/mapcalc.py
===================================================================
--- grass/trunk/lib/python/temporal/mapcalc.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/mapcalc.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -42,7 +42,7 @@
     """
 
     # We need a database interface for fast computation
-    dbif = ()
+    dbif = SQLDatabaseInterfaceConnection()
     dbif.connect()
 
     mapset = core.gisenv()["MAPSET"]
@@ -56,9 +56,9 @@
         id = input_name_list[0] + "@" + mapset
 
     if type == "raster":
-        first_input = space_time_raster_dataset(id)
+        first_input = SpaceTimeRasterDataset(id)
     else:
-        first_input = space_time_raster3d_dataset(id)
+        first_input = SpaceTimeRaster3DDataset(id)
 
     if not first_input.is_in_db(dbif):
         dbif.close()

Modified: grass/trunk/lib/python/temporal/space_time_datasets.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/space_time_datasets.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -782,18 +782,18 @@
 
         # Fill metadata
         self.metadata.set_3d_info(kvp["is_3d"])
-        self.metadata.set_points(kvp["points"])
-        self.metadata.set_lines(kvp["lines"])
-        self.metadata.set_boundaries(kvp["boundaries"])
-        self.metadata.set_centroids(kvp["centroids"])
-        self.metadata.set_faces(kvp["faces"])
-        self.metadata.set_kernels(kvp["kernels"])
-        self.metadata.set_primitives(kvp["primitives"])
-        self.metadata.set_nodes(kvp["nodes"])
-        self.metadata.set_areas(kvp["areas"])
-        self.metadata.set_islands(kvp["islands"])
-        self.metadata.set_holes(kvp["holes"])
-        self.metadata.set_volumes(kvp["volumes"])
+        self.metadata.set_number_of_points(kvp["points"])
+        self.metadata.set_number_of_lines(kvp["lines"])
+        self.metadata.set_number_of_boundaries(kvp["boundaries"])
+        self.metadata.set_number_of_centroids(kvp["centroids"])
+        self.metadata.set_number_of_faces(kvp["faces"])
+        self.metadata.set_number_of_kernels(kvp["kernels"])
+        self.metadata.set_number_of_primitives(kvp["primitives"])
+        self.metadata.set_number_of_nodes(kvp["nodes"])
+        self.metadata.set_number_of_areas(kvp["areas"])
+        self.metadata.set_number_of_islands(kvp["islands"])
+        self.metadata.set_number_of_holes(kvp["holes"])
+        self.metadata.set_number_of_volumes(kvp["volumes"])
 
 ###############################################################################
 

Modified: grass/trunk/lib/python/temporal/space_time_datasets_tools.py
===================================================================
--- grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/space_time_datasets_tools.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -385,17 +385,17 @@
        @param id: The id of the dataset ("name at mapset")
     """
     if type == "strds":
-        sp = space_time_raster_dataset(id)
+        sp = SpaceTimeRasterDataset(id)
     elif type == "str3ds":
-        sp = space_time_raster3d_dataset(id)
+        sp = SpaceTimeRaster3DDataset(id)
     elif type == "stvds":
-        sp = space_time_vector_dataset(id)
+        sp = SpaceTimeVectorDataset(id)
     elif type == "rast" or type == "raster":
-        sp = raster_dataset(id)
+        sp = RasterDataset(id)
     elif type == "rast3d":
-        sp = raster3d_dataset(id)
+        sp = Raster3DDataset(id)
     elif type == "vect" or type == "vector":
-        sp = vector_dataset(id)
+        sp = VectorDataset(id)
     else:
         core.error(_("Unknown dataset type: %s") % type)
         return None
@@ -474,14 +474,20 @@
         if maps and len(maps) > 0:
 
             if isinstance(maps[0], list):
-                first_time, dummy = maps[0][0].get_valid_time()
+                if len(maps[0]) > 0:
+                    first_time, dummy = maps[0][0].get_valid_time()
+                else:
+                    core.fatal(_("Unable to list maps. Internal Error."))
             else:
                 first_time, dummy = maps[0].get_valid_time()
 
             for mymap in maps:
 
                 if isinstance(mymap, list):
-                    map = mymap[0]
+                    if len(mymap) > 0:
+                        map = mymap[0]
+                    else:
+                        core.fatal(_("Unable to list maps. Internal Error."))
                 else:
                     map = mymap
 
@@ -602,7 +608,7 @@
 
     sst = dataset_factory(sampletype, sid)
 
-    dbif = ()
+    dbif = SQLDatabaseInterfaceConnection()
     dbif.connect()
 
     for st in sts:

Modified: grass/trunk/lib/python/temporal/temporal_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_extent.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/temporal_extent.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -880,7 +880,7 @@
 class STVDSAbsoluteTime(STDSAbsoluteTime):
     def __init__(self, ident=None, start_time=None, end_time=None, 
                  granularity=None, timezone=None):
-        STDSAbsoluteTime.__init__(self, "RelativeTemporalExtent",
+        STDSAbsoluteTime.__init__(self, "stvds_absolute_time",
             ident, start_time, end_time, granularity, timezone)
 
 ###############################################################################

Modified: grass/trunk/lib/python/temporal/unit_tests.py
===================================================================
--- grass/trunk/lib/python/temporal/unit_tests.py	2012-08-12 23:06:44 UTC (rev 52645)
+++ grass/trunk/lib/python/temporal/unit_tests.py	2012-08-12 23:08:53 UTC (rev 52646)
@@ -1622,18 +1622,18 @@
 def test_1d_rtree():
     """Testing the rtree ctypes wrapper"""
 
-    tree = vector.RTreeNewIndex(-1, 0, 1)
+    tree = vector.RTreeCreateTree(-1, 0, 1)
 
     for i in xrange(10):
         
         rect = vector.RTree_Rect()
         # Allocate the boundary
-        vector.RTreeNewRect(byref(rect), tree)
+        vector.RTreeAllocBoundary(byref(rect), tree)
         vector.RTreeSetRect1D(byref(rect), tree, float(i - 2), float(i + 2))
         vector.RTreeInsertRect(byref(rect), i + 1, tree)
 
     rect = vector.RTree_Rect()
-    vector.RTreeNewRect(byref(rect), tree)
+    vector.RTreeAllocBoundary(byref(rect), tree)
     vector.RTreeSetRect1D(byref(rect), tree, 2.0, 7.0)
 
     list_ = gis.ilist()
@@ -1645,18 +1645,20 @@
     for i in xrange(list_.n_values):
         print "id", list_.value[i]
 
+    vector.RTreeDestroyTree(tree)
+    
 ###############################################################################
 
 def test_2d_rtree():
     """Testing the rtree ctypes wrapper"""
 
-    tree = vector.RTreeNewIndex(-1, 0, 2)
+    tree = vector.RTreeCreateTree(-1, 0, 2)
 
     for i in xrange(10):
         
         rect = vector.RTree_Rect()
         # Allocate the boundary
-        vector.RTreeNewRect(byref(rect), tree)
+        vector.RTreeAllocBoundary(byref(rect), tree)
 
         vector.RTreeSetRect2D(byref(rect), tree, 
                               float(i - 2), float(i + 2), 
@@ -1664,7 +1666,7 @@
         vector.RTreeInsertRect(byref(rect), i + 1, tree)
 
     rect = vector.RTree_Rect()
-    vector.RTreeNewRect(byref(rect), tree)
+    vector.RTreeAllocBoundary(byref(rect), tree)
     vector.RTreeSetRect2D(byref(rect), tree, 2.0, 7.0, 2.0, 7.0)
 
     list_ = gis.ilist()
@@ -1676,18 +1678,20 @@
     for i in xrange(list_.n_values):
         print "id", list_.value[i]
 
+    vector.RTreeDestroyTree(tree)
+    
 ###############################################################################
 
 def test_3d_rtree():
     """Testing the rtree ctypes wrapper"""
 
-    tree = vector.RTreeNewIndex(-1, 0, 3)
+    tree = vector.RTreeCreateTree(-1, 0, 3)
 
     for i in xrange(10):
         
         rect = vector.RTree_Rect()
         # Allocate the boundary
-        vector.RTreeNewRect(byref(rect), tree)
+        vector.RTreeAllocBoundary(byref(rect), tree)
         vector.RTreeSetRect3D(byref(rect), tree, 
                               float(i - 2), float(i + 2), 
                               float(i - 2), float(i + 2), 
@@ -1697,7 +1701,7 @@
         vector.RTreePrintRect(byref(rect), 1, tree)
 
     rect = vector.RTree_Rect()
-    vector.RTreeNewRect(byref(rect), tree)
+    vector.RTreeAllocBoundary(byref(rect), tree)
     vector.RTreeSetRect3D(byref(rect), tree, 2.0, 7.0, 2.0, 7.0, 2.0, 7.0)
     print "Select"
     vector.RTreePrintRect(byref(rect), 1, tree)
@@ -1710,18 +1714,20 @@
     print "Number of overlapping rectangles", num
     for i in xrange(list_.n_values):
         print "id", list_.value[i]
+        
+    vector.RTreeDestroyTree(tree)
 
 ###############################################################################
 
 def test_4d_rtree():
     """Testing the rtree ctypes wrapper"""
 
-    tree = vector.RTreeNewIndex(-1, 0, 4)
+    tree = vector.RTreeCreateTree(-1, 0, 4)
 
     for i in xrange(10):
         
         # Allocate the boundary
-        rect = vector.RTreeNewRect(None, tree)
+        rect = vector.RTreeAllocRect(tree)
         vector.RTreeSetRect4D(rect, tree, 
                               float(i - 2), float(i + 2), 
                               float(i - 2), float(i + 2), 
@@ -1729,18 +1735,22 @@
                               float(i - 2), float(i + 2))
         vector.RTreeInsertRect(rect, i + 1, tree)
 
-    rect = vector.RTreeNewRect(None, tree)
+    rect = vector.RTreeAllocRect(tree)
     vector.RTreeSetRect4D(rect, tree, 2.0, 7.0, 2.0, 
                           7.0, 2.0, 7.0, 2.0, 7.0)
-
+    
     list_ = gis.ilist()
 
     num = vector.RTreeSearch2(tree, rect, byref(list_))
 
+    vector.RTreeFreeRect(rect)
+
     # print rectangle ids
     print "Number of overlapping rectangles", num
     for i in xrange(list_.n_values):
         print "id", list_.value[i]
+        
+    vector.RTreeDestroyTree(tree)
 
 ###############################################################################
 



More information about the grass-commit mailing list