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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 22 03:14:59 PDT 2013


Author: huhabla
Date: 2013-08-22 03:14:59 -0700 (Thu, 22 Aug 2013)
New Revision: 57485

Modified:
   grass/trunk/lib/python/temporal/spatio_temporal_relationships.py
   grass/trunk/lib/python/temporal/temporal_extent.py
Log:
Corrected overlaps/overlapped relations and added new tests to check the temporal topology builder.


Modified: grass/trunk/lib/python/temporal/spatio_temporal_relationships.py
===================================================================
--- grass/trunk/lib/python/temporal/spatio_temporal_relationships.py	2013-08-22 08:56:47 UTC (rev 57484)
+++ grass/trunk/lib/python/temporal/spatio_temporal_relationships.py	2013-08-22 10:14:59 UTC (rev 57485)
@@ -72,10 +72,11 @@
 
         >>> # Example with two lists of maps
         >>> import grass.temporal as tgis
+        >>> import datetime
         >>> # Create two list of maps with equal time stamps
         >>> mapsA = []
         >>> mapsB = []
-        >>> for i in range(10):
+        >>> for i in range(4):
         ...     idA = "a%i at B"%(i)
         ...     mapA = tgis.RasterDataset(idA)
         ...     idB = "b%i at B"%(i)
@@ -97,12 +98,6 @@
         Map a1 has equal relation to map b1
         Map a2 has equal relation to map b2
         Map a3 has equal relation to map b3
-        Map a4 has equal relation to map b4
-        Map a5 has equal relation to map b5
-        Map a6 has equal relation to map b6
-        Map a7 has equal relation to map b7
-        Map a8 has equal relation to map b8
-        Map a9 has equal relation to map b9
         >>> # Check relations of mapsB
         >>> for map in mapsB:
         ...     if map.get_equal():
@@ -113,13 +108,175 @@
         Map b1 has equal relation to map a1
         Map b2 has equal relation to map a2
         Map b3 has equal relation to map a3
-        Map b4 has equal relation to map a4
-        Map b5 has equal relation to map a5
-        Map b6 has equal relation to map a6
-        Map b7 has equal relation to map a7
-        Map b8 has equal relation to map a8
-        Map b9 has equal relation to map a9
 
+
+        >>> mapsA = []
+        >>> mapsB = []
+        >>> for i in range(4):
+        ...     idA = "a%i at B"%(i)
+        ...     mapA = tgis.RasterDataset(idA)
+        ...     idB = "b%i at B"%(i)
+        ...     mapB = tgis.RasterDataset(idB)
+        ...     check = mapA.set_relative_time(i, i + 1, "months")
+        ...     check = mapB.set_relative_time(i + 1, i + 2, "months")
+        ...     mapsA.append(mapA)
+        ...     mapsB.append(mapB)
+        >>> # Build the topology between the two map lists
+        >>> tb = SpatioTemporalTopologyBuilder()
+        >>> tb.build(mapsA, mapsB, None)
+        >>> # Check relations of mapsA
+        >>> for map in mapsA:
+        ...     print(map.get_temporal_extent_as_tuple())
+        ...     m = map.get_temporal_relations()
+        ...     for key in m.keys():
+        ...         if key not in ["NEXT", "PREV"]:
+        ...             print(key, m[key][0].get_temporal_extent_as_tuple())
+        (0, 1)
+        ('PRECEDES', (1, 2))
+        (1, 2)
+        ('PRECEDES', (2, 3))
+        ('EQUAL', (1, 2))
+        (2, 3)
+        ('FOLLOWS', (1, 2))
+        ('PRECEDES', (3, 4))
+        ('EQUAL', (2, 3))
+        (3, 4)
+        ('FOLLOWS', (2, 3))
+        ('EQUAL', (3, 4))
+        ('PRECEDES', (4, 5))
+
+        >>> mapsA = []
+        >>> mapsB = []
+        >>> for i in range(4):
+        ...     idA = "a%i at B"%(i)
+        ...     mapA = tgis.RasterDataset(idA)
+        ...     idB = "b%i at B"%(i)
+        ...     mapB = tgis.RasterDataset(idB)
+        ...     start = datetime.datetime(2000 + i, 1, 1)
+        ...     end = datetime.datetime(2000 + i + 1, 1, 1)
+        ...     check = mapA.set_absolute_time(start, end)
+        ...     start = datetime.datetime(2000 + i + 1, 1, 1)
+        ...     end = datetime.datetime(2000 + i + 2, 1, 1)
+        ...     check = mapB.set_absolute_time(start, end)
+        ...     mapsA.append(mapA)
+        ...     mapsB.append(mapB)
+        >>> # Build the topology between the two map lists
+        >>> tb = SpatioTemporalTopologyBuilder()
+        >>> tb.build(mapsA, mapsB, None)
+        >>> # Check relations of mapsA
+        >>> for map in mapsA:
+        ...     print(map.get_temporal_extent_as_tuple())
+        ...     m = map.get_temporal_relations()
+        ...     for key in m.keys():
+        ...         if key not in ["NEXT", "PREV"]:
+        ...             print(key, m[key][0].get_temporal_extent_as_tuple())
+        (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0))
+        ('PRECEDES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0)))
+        (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0))
+        ('PRECEDES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('EQUAL', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0)))
+        (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))
+        ('FOLLOWS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0)))
+        ('PRECEDES', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('EQUAL', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))
+        ('FOLLOWS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('EQUAL', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('PRECEDES', (datetime.datetime(2004, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+
+        >>> mapsA = []
+        >>> mapsB = []
+        >>> for i in range(4):
+        ...     idA = "a%i at B"%(i)
+        ...     mapA = tgis.RasterDataset(idA)
+        ...     idB = "b%i at B"%(i)
+        ...     mapB = tgis.RasterDataset(idB)
+        ...     start = datetime.datetime(2000 + i, 1, 1)
+        ...     end = datetime.datetime(2000 + i + 1, 1, 1)
+        ...     check = mapA.set_absolute_time(start, end)
+        ...     start = datetime.datetime(2000 + i, 1, 1)
+        ...     end = datetime.datetime(2000 + i + 3, 1, 1)
+        ...     check = mapB.set_absolute_time(start, end)
+        ...     mapsA.append(mapA)
+        ...     mapsB.append(mapB)
+        >>> # Build the topology between the two map lists
+        >>> tb = SpatioTemporalTopologyBuilder()
+        >>> tb.build(mapsA, mapsB, None)
+        >>> # Check relations of mapsA
+        >>> for map in mapsA:
+        ...     print(map.get_temporal_extent_as_tuple())
+        ...     m = map.get_temporal_relations()
+        ...     for key in m.keys():
+        ...         if key not in ["NEXT", "PREV"]:
+        ...             print(key, m[key][0].get_temporal_extent_as_tuple())
+        (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 1, 1, 0, 0))
+        ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('PRECEDES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0))
+        ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('PRECEDES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))
+        ('PRECEDES', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)))
+        ('FINISHES', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))
+        ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('DURING', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('FINISHES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)))
+
+        >>> mapsA = []
+        >>> mapsB = []
+        >>> for i in range(4):
+        ...     idA = "a%i at B"%(i)
+        ...     mapA = tgis.RasterDataset(idA)
+        ...     idB = "b%i at B"%(i)
+        ...     mapB = tgis.RasterDataset(idB)
+        ...     start = datetime.datetime(2000 + i, 1, 1)
+        ...     end = datetime.datetime(2000 + i + 2, 1, 1)
+        ...     check = mapA.set_absolute_time(start, end)
+        ...     start = datetime.datetime(2000 + i, 1, 1)
+        ...     end = datetime.datetime(2000 + i + 3, 1, 1)
+        ...     check = mapB.set_absolute_time(start, end)
+        ...     mapsA.append(mapA)
+        ...     mapsB.append(mapB)
+        >>> # Build the topology between the two map lists
+        >>> tb = SpatioTemporalTopologyBuilder()
+        >>> tb.build(mapsA, mapsB, None)
+        >>> # Check relations of mapsA
+        >>> for map in mapsA:
+        ...     print(map.get_temporal_extent_as_tuple())
+        ...     m = map.get_temporal_relations()
+        ...     for key in m.keys():
+        ...         if key not in ["NEXT", "PREV"]:
+        ...             print(key, m[key][0].get_temporal_extent_as_tuple())
+        (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2002, 1, 1, 0, 0))
+        ('OVERLAPS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('PRECEDES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0))
+        ('OVERLAPS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        ('PRECEDES', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)))
+        ('FINISHES', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('DURING', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0))
+        ('OVERLAPS', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)))
+        ('OVERLAPPED', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+        ('FINISHES', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('DURING', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0))
+        ('OVERLAPPED', (datetime.datetime(2001, 1, 1, 0, 0), datetime.datetime(2004, 1, 1, 0, 0)))
+        ('DURING', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        ('FINISHES', (datetime.datetime(2002, 1, 1, 0, 0), datetime.datetime(2005, 1, 1, 0, 0)))
+        ('STARTS', (datetime.datetime(2003, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)))
+        ('FOLLOWS', (datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2003, 1, 1, 0, 0)))
+
         @endcode
 
     """
@@ -309,7 +466,7 @@
 
             list_ = gis.ilist()
             rect = self._map_to_rect(tree, mapsB[j], spatial)
-            num = vector.RTreeSearch2(tree, rect, byref(list_))
+            vector.RTreeSearch2(tree, rect, byref(list_))
             vector.RTreeFreeRect(rect)
 
             for k in xrange(list_.n_values):

Modified: grass/trunk/lib/python/temporal/temporal_extent.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_extent.py	2013-08-22 08:56:47 UTC (rev 57484)
+++ grass/trunk/lib/python/temporal/temporal_extent.py	2013-08-22 10:14:59 UTC (rev 57485)
@@ -844,7 +844,7 @@
         else:
             return False
 
-    def overlapped(self, extent):
+    def overlaps(self, extent):
         """!Return True if this temporal extent (A) overlapped the provided
            temporal extent (B)
            @verbatim
@@ -860,11 +860,18 @@
 
            >>> A = AbstractTemporalExtent(start_time=5, end_time=7 )
            >>> B = AbstractTemporalExtent(start_time=6, end_time=8 )
-           >>> A.overlapped(B)
+           >>> A.overlaps(B)
            True
-           >>> B.overlapped(A)
+           >>> B.overlaps(A)
            False
 
+           >>> A = AbstractTemporalExtent(start_time=5, end_time=6 )
+           >>> B = AbstractTemporalExtent(start_time=6, end_time=8 )
+           >>> A.overlaps(B)
+           False
+           >>> B.overlaps(A)
+           False
+
            @endcode
         """
         if  self.D["end_time"] is None or extent.D["end_time"] is None:
@@ -877,7 +884,7 @@
         else:
             return False
 
-    def overlaps(self, extent):
+    def overlapped(self, extent):
         """!Return True if this temporal extent (A) overlapps the provided
            temporal extent (B)
            @verbatim
@@ -894,11 +901,18 @@
 
            >>> A = AbstractTemporalExtent(start_time=6, end_time=8 )
            >>> B = AbstractTemporalExtent(start_time=5, end_time=7 )
-           >>> A.overlaps(B)
+           >>> A.overlapped(B)
            True
-           >>> B.overlaps(A)
+           >>> B.overlapped(A)
            False
 
+           >>> A = AbstractTemporalExtent(start_time=6, end_time=8 )
+           >>> B = AbstractTemporalExtent(start_time=5, end_time=6 )
+           >>> A.overlapped(B)
+           False
+           >>> B.overlapped(A)
+           False
+
            @endcode
         """
         if  self.D["end_time"] is None or extent.D["end_time"] is None:



More information about the grass-commit mailing list