[GRASS-SVN] r69313 - in grass/trunk/lib/python/temporal: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 30 23:55:24 PDT 2016
Author: huhabla
Date: 2016-08-30 23:55:24 -0700 (Tue, 30 Aug 2016)
New Revision: 69313
Modified:
grass/trunk/lib/python/temporal/temporal_algebra.py
grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py
Log:
temporal framework: More dry-run test for the temporal algebra (merge from relbr72)
Modified: grass/trunk/lib/python/temporal/temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_algebra.py 2016-08-31 06:53:57 UTC (rev 69312)
+++ grass/trunk/lib/python/temporal/temporal_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
@@ -742,10 +742,11 @@
self.run = run
self.dry_run = dry_run # Compute the processes and output but Do not start the processes
self.process_chain_dict = {} # This dictionary stores all processes, as well as the maps to register and remove
- self.process_chain_dict["processes"] = []
- self.process_chain_dict["insert"] = []
- self.process_chain_dict["update"] = []
- self.process_chain_dict["remove"] = []
+ self.process_chain_dict["processes"] = [] # process decsription
+ self.process_chain_dict["register"] = [] # Maps that must be registered/updated or inserted in a new STDS
+ self.process_chain_dict["remove"] = [] # Maps that must be removed
+ self.process_chain_dict["STDS"] = {} # The STDS that must be created
+
self.debug = debug
self.pid = pid
# Intermediate vector map names
@@ -2045,8 +2046,7 @@
process_queue = pymod.ParallelModuleQueue(int(self.nprocs))
for map_i in t[3]:
- # Test if temporal extents have been changed by temporal
- # relation operators (i|r).
+ # Check if the map type and stds type are compatible
if count == 0:
maps_stds_type = map_i.get_new_stds_instance(None).get_type()
map_type = map_i.get_type()
@@ -2059,7 +2059,11 @@
if map_type != map_type_2:
self.msgr.fatal(_("Maps that should be registered in the "\
"resulting space time dataset have different types."))
+ count += 1
+ # Test if temporal extents was been modified by temporal
+ # relation operators (i|r).
+ # If it was modified, then the map will be copied
map_a_extent = map_i.get_temporal_extent_as_tuple()
map_b = map_i.get_new_instance(map_i.get_id())
map_b.select(dbif)
@@ -2069,7 +2073,7 @@
newident = self.basename + "_" + str(count)
map_result = map_i.get_new_instance(newident + "@" + self.mapset)
- if map_b.map_exists() and self.overwrite == False:
+ if map_result.map_exists() and self.overwrite == False:
self.msgr.fatal("Error raster maps with basename %s exist. "
"Use --o flag to overwrite existing file"%map_i.get_id())
@@ -2098,52 +2102,65 @@
else:
register_list.append(map_i)
- count += 1
-
# Wait for running processes
if self.dry_run is False:
process_queue.wait()
# Open connection to temporal database.
# Create result space time dataset based on the map stds type
- resultstds = open_new_stds(t[1],maps_stds_type,
- 'absolute', t[1], t[1],
- 'mean', self.dbif,
- overwrite=self.overwrite)
+ if self.dry_run is False:
+ resultstds = open_new_stds(t[1],maps_stds_type,
+ 'absolute', t[1], t[1],
+ 'mean', self.dbif,
+ overwrite=self.overwrite)
+
for map_i in register_list:
# Get meta data from grass database.
map_i.load()
+
+ # Put the map into the process dictionary
+ start, end = map_i.get_temporal_extent_as_tuple()
+ self.process_chain_dict["register"].append((map_i.get_name(), str(start), str(end)))
+
# Check if temporal extents have changed and a new map was created
- if hasattr(map_i, "is_new") is True:
+ 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.removable_maps[map_i.get_name()] = map_i
- continue
- start, end = map_i.get_temporal_extent_as_tuple()
+ if map_i.get_type() is "raster" or map_i.get_type() is "raster3d":
+ if map_i.metadata.get_min() is None and \
+ map_i.metadata.get_max() is None:
+ if not self.register_null:
+ 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.
- self.process_chain_dict["update"].append((map_i.get_name(), str(start), str(end)))
if self.dry_run is False:
map_i.update_all(dbif)
- elif map_i.is_in_db(dbif) and self.overwrite == False:
+ elif map_i.is_in_db(dbif) and self.overwrite is False:
# Raise error if map exists and no overwrite flag is given.
self.msgr.fatal("Error map %s exist in temporal database. "
- "Use overwrite flag."%map_i.get_map_id())
+ "Use overwrite flag."%map_i.get_map_id())
else:
# Insert map into temporal database.
- self.process_chain_dict["insert"].append((map_i.get_name(), str(start), str(end)))
if self.dry_run is False:
map_i.insert(dbif)
+
# Register map in result space time dataset.
if self.dry_run is False:
success = resultstds.register_map(map_i, dbif)
+ if not success:
+ self.msgr.warning("Unabe to register map layers "
+ "in STDS %s"%(t[1]))
+
if self.dry_run is False:
resultstds.update_from_registered_maps(dbif)
+
+ self.process_chain_dict["STDS"]["name"] = t[1]
+ self.process_chain_dict["STDS"]["stdstype"] = self.stdstype
+ self.process_chain_dict["STDS"]["temporal_type"] = 'absolute'
+
elif num == 0:
self.msgr.warning("Empty result space time dataset. "
"No map has been registered in %s"%(t[1]))
Modified: grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py 2016-08-31 06:53:57 UTC (rev 69312)
+++ grass/trunk/lib/python/temporal/testsuite/unittests_temporal_algebra.py 2016-08-31 06:55:24 UTC (rev 69313)
@@ -55,7 +55,7 @@
start="2001-01-02", increment="2 day", interval=True)
tgis.register_maps_in_space_time_dataset(type="raster", name="D", maps="d1,d2,d3",
start="2001-01-03", increment="1 day", interval=True)
- tgis.register_maps_in_space_time_dataset(type="raster", name=None, maps="singletmap",
+ tgis.register_maps_in_space_time_dataset(type="raster", name=None, maps="singletmap",
start="2001-01-03", end="2001-01-04")
def tearDown(self):
@@ -70,14 +70,14 @@
def test_temporal_select1(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A : A", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 4)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -86,14 +86,14 @@
def test_temporal_select2(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A : D", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 3)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -102,14 +102,14 @@
def test_temporal_select3(self):
"""Testing the temporal select operator with equal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A !: D", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 2)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 2)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 3))
@@ -118,14 +118,14 @@
def test_temporal_select_operators1(self):
"""Testing the temporal select operator. Including temporal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {:,during} C", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
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)
+ 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))
@@ -134,14 +134,14 @@
def test_temporal_select_operators2(self):
"""Testing the temporal select operator. Including temporal relations. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=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()
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)
+ 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))
@@ -149,16 +149,16 @@
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_select_operators3(self):
- """Testing the temporal select operator. Including temporal relations
+ """Testing the temporal select operator. Including temporal relations
and negation operation. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {!:,during} C", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
D.select()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -166,9 +166,9 @@
self.assertEqual(D.get_granularity(), u'1 day')
def test_temporal_select_operators4(self):
- """Testing the temporal select operator. Including temporal relations and
+ """Testing the temporal select operator. Including temporal relations and
temporal operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {:,during,d} C", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -179,8 +179,8 @@
self.assertEqual(start_map, datetime.datetime(2001, 1, 2))
self.assertEqual(end_map, datetime.datetime(2001, 1, 4))
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)
+ 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))
@@ -188,9 +188,9 @@
self.assertEqual(D.get_granularity(), u'2 days')
def test_temporal_select_operators5(self):
- """Testing the temporal select operator. Including temporal relations and
+ """Testing the temporal select operator. Including temporal relations and
temporal operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = C {:,contains} A", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -201,8 +201,8 @@
self.assertEqual(start_map, datetime.datetime(2001, 1, 2))
self.assertEqual(end_map, datetime.datetime(2001, 1, 4))
self.assertEqual(D.metadata.get_number_of_maps(), 1)
- self.assertEqual(D.metadata.get_min_min(), 7)
- self.assertEqual(D.metadata.get_max_max(), 7)
+ self.assertEqual(D.metadata.get_min_min(), 7)
+ self.assertEqual(D.metadata.get_max_max(), 7)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 2))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
@@ -211,15 +211,15 @@
def test_temporal_extent1(self):
"""Testing the temporal extent operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=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()
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)
+ 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))
@@ -228,15 +228,15 @@
def test_temporal_extent2(self):
"""Testing the temporal extent operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=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()
- maplist = D.get_registered_maps_as_objects()
+ 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)
+ 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))
@@ -245,7 +245,7 @@
def test_temporal_extent3(self):
"""Testing the temporal extent operators. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression="R = A {:,during,u} C", stdstype = 'strds', basename="r", overwrite=True)
D = tgis.open_old_stds("R", type="strds")
@@ -254,10 +254,10 @@
for map_i in maplist:
start_map, end_map = map_i.get_absolute_time()
self.assertEqual(start_map, datetime.datetime(2001, 1, 2))
- self.assertEqual(end_map, datetime.datetime(2001, 1, 4))
+ self.assertEqual(end_map, datetime.datetime(2001, 1, 4))
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)
+ 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))
@@ -266,15 +266,15 @@
def test_temporal_hash1(self):
"""Testing the hash function in conditional statement. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=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()
maplist = D.get_registered_maps_as_objects()
self.assertEqual(D.metadata.get_number_of_maps(), 2)
- self.assertEqual(D.metadata.get_min_min(), 3)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
@@ -283,16 +283,16 @@
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)", stdstype = 'strds',
+ ta = tgis.TemporalAlgebraParser(run=True, debug=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()
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)
+ 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))
@@ -301,33 +301,33 @@
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)",
+ ta = tgis.TemporalAlgebraParser(run=True, debug=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()
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)
+ 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(), True)
self.assertEqual(D.get_granularity(), u'1 day')
-
+
def test_tmap_function1(self):
"""Testing the tmap function. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = tmap(singletmap)', stdstype = 'strds', 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(), 1)
- self.assertEqual(D.metadata.get_min_min(), 99)
- self.assertEqual(D.metadata.get_max_max(), 99)
+ self.assertEqual(D.metadata.get_min_min(), 99)
+ self.assertEqual(D.metadata.get_max_max(), 99)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
@@ -336,15 +336,15 @@
def test_tmap_function2(self):
"""Testing the tmap function. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = A : tmap(singletmap)', stdstype = 'strds', 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(), 1)
- self.assertEqual(D.metadata.get_min_min(), 3)
- self.assertEqual(D.metadata.get_max_max(), 3)
+ self.assertEqual(D.metadata.get_min_min(), 3)
+ self.assertEqual(D.metadata.get_max_max(), 3)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 3))
self.assertEqual(end, datetime.datetime(2001, 1, 4))
@@ -353,15 +353,15 @@
def test_merge_function1(self):
"""Testing the merge function. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = merge(A,D)', stdstype = 'strds', 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(), 7)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 10)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 10)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 6))
@@ -370,20 +370,148 @@
def test_merge_function2(self):
"""Testing the merge function. """
- ta = tgis.TemporalAlgebraParser(run = True, debug = True)
+ ta = tgis.TemporalAlgebraParser(run=True, debug=True)
ta.parse(expression='R = merge(A, B {!:,contains} A)', stdstype = 'strds', 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(), 4)
- self.assertEqual(D.metadata.get_min_min(), 1)
- self.assertEqual(D.metadata.get_max_max(), 4)
+ self.assertEqual(D.metadata.get_min_min(), 1)
+ self.assertEqual(D.metadata.get_max_max(), 4)
start, end = D.get_absolute_time()
self.assertEqual(start, datetime.datetime(2001, 1, 1))
self.assertEqual(end, datetime.datetime(2001, 1, 5))
self.assertEqual( D.check_temporal_topology(), True)
self.assertEqual(D.get_granularity(), u'1 day')
+class TestTemporalAlgebraDryRun(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Initiate the temporal GIS and set the region
+ """
+ tgis.init(True) # Raise on error instead of exit(1)
+ cls.use_temp_region()
+ cls.runModule("g.region", n=80.0, s=0.0, e=120.0,
+ w=0.0, t=1.0, b=0.0, res=10.0)
+
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a1 = 1")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a2 = 2")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a3 = 3")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="a4 = 4")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="b1 = 5")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="b2 = 6")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="c1 = 7")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="d1 = 8")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="d2 = 9")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="d3 = 10")
+ cls.runModule("r.mapcalc", overwrite=True, quiet=True, expression="singletmap = 99")
+
+ tgis.open_new_stds(name="A", type="strds", temporaltype="absolute",
+ title="A", descr="A", semantic="field", overwrite=True)
+ tgis.open_new_stds(name="B", type="strds", temporaltype="absolute",
+ title="B", descr="B", semantic="field", overwrite=True)
+ tgis.open_new_stds(name="C", type="strds", temporaltype="absolute",
+ title="C", descr="C", semantic="field", overwrite=True)
+ tgis.open_new_stds(name="D", type="strds", temporaltype="absolute",
+ title="D", descr="D", semantic="field", overwrite=True)
+
+ tgis.register_maps_in_space_time_dataset(type="raster", name="A", maps="a1,a2,a3,a4",
+ start="2001-01-01", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="raster", name="B", maps="b1,b2",
+ start="2001-01-01", increment="2 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="raster", name="C", maps="c1",
+ start="2001-01-02", increment="2 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="raster", name="D", maps="d1,d2,d3",
+ start="2001-01-03", increment="1 day", interval=True)
+ tgis.register_maps_in_space_time_dataset(type="raster", name=None, maps="singletmap",
+ start="2001-01-03", end="2001-01-04")
+
+ @classmethod
+ def tearDownClass(cls):
+ """Remove the temporary region
+ """
+ cls.runModule("t.remove", flags="rf", inputs="A,B,C,D", quiet=True)
+ cls.del_temp_region()
+
+ def test_merge_function1(self):
+ """Testing the merge function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = merge(A, B {:,contains} A)',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+
+ self.assertEqual(len(pc["register"]), 6)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_merge_function2(self):
+ """Testing the merge function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = merge(A, B {!:,contains} A)',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+
+ self.assertEqual(len(pc["register"]), 4)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_merge_function3(self):
+ """Testing the merge function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = merge(A, D {!:,equal} A)',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+
+ self.assertEqual(len(pc["register"]), 5)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_shift1(self):
+ """Testing the shift function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = tshift(A, "3 days")',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+ print(pc["register"])
+ self.assertEqual(len(pc["register"]), 4)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_shift2(self):
+ """Testing the shift function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = tshift(A, "2 days") {:,during,l} C',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+ print(pc["register"])
+ self.assertEqual(len(pc["register"]), 1)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_buffer1(self):
+ """Testing the shift function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = buff_t(A, "1 day") ',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+ print(pc["register"])
+ self.assertEqual(len(pc["register"]), 4)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+ def test_buff2(self):
+ """Testing the shift function. """
+ ta = tgis.TemporalAlgebraParser(run=True, debug=False, dry_run=True)
+ pc = ta.parse(expression='R = buff_t(A, "1 day") {:,contains,l} C',
+ stdstype = 'strds', basename="r",
+ overwrite=True)
+ print(pc["register"])
+ self.assertEqual(len(pc["register"]), 2)
+ self.assertEqual(pc["STDS"]["name"], "R")
+ self.assertEqual(pc["STDS"]["stdstype"], "strds")
+
+
if __name__ == '__main__':
test()
More information about the grass-commit
mailing list