[GRASS-SVN] r72479 - in grass/trunk/temporal/t.rast.series: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 21 13:18:38 PDT 2018
Author: huhabla
Date: 2018-03-21 13:18:38 -0700 (Wed, 21 Mar 2018)
New Revision: 72479
Added:
grass/trunk/temporal/t.rast.series/test_t.sereis_bug_3223.sh
Modified:
grass/trunk/temporal/t.rast.series/t.rast.series.py
grass/trunk/temporal/t.rast.series/testsuite/test_series.py
Log:
Fixed Bug #3223 wong time stamp for raster map in case where condition was used.
Modified: grass/trunk/temporal/t.rast.series/t.rast.series.py
===================================================================
--- grass/trunk/temporal/t.rast.series/t.rast.series.py 2018-03-21 19:11:23 UTC (rev 72478)
+++ grass/trunk/temporal/t.rast.series/t.rast.series.py 2018-03-21 20:18:38 UTC (rev 72479)
@@ -132,6 +132,7 @@
grass.fatal(_("%s failed. Check above error messages.") % 'r.series')
if not add_time:
+
# Create the time range for the output map
if output.find("@") >= 0:
id = output
@@ -141,8 +142,25 @@
map = sp.get_new_map_instance(id)
map.load()
- map.set_temporal_extent(sp.get_temporal_extent())
+ # We need to set the temporal extent from the subset of selected maps
+ maps = sp.get_registered_maps_as_objects(where=where, order=order, dbif=None)
+ first_map = maps[0]
+ last_map = maps[-1]
+ start_a, end_a = first_map.get_temporal_extent_as_tuple()
+ start_b, end_b = last_map.get_temporal_extent_as_tuple()
+
+ if end_b is None:
+ end_b = start_b
+
+ if first_map.is_time_absolute():
+ extent = tgis.AbsoluteTemporalExtent(start_time=start_a, end_time=end_b)
+ else:
+ extent = tgis.RelativeTemporalExtent(start_time=start_a, end_time=end_b,
+ unit=first_map.get_relative_time_unit())
+
+ map.set_temporal_extent(extent=extent)
+
# Register the map in the temporal database
if map.is_in_db():
map.update_all()
Added: grass/trunk/temporal/t.rast.series/test_t.sereis_bug_3223.sh
===================================================================
--- grass/trunk/temporal/t.rast.series/test_t.sereis_bug_3223.sh (rev 0)
+++ grass/trunk/temporal/t.rast.series/test_t.sereis_bug_3223.sh 2018-03-21 20:18:38 UTC (rev 72479)
@@ -0,0 +1,28 @@
+#/bin/bash
+# Test bug #3223
+export GRASS_OVERWRITE=1
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+
+r.mapcalc expression="prec_1 = 100" --o
+r.mapcalc expression="prec_2 = 200" --o
+r.mapcalc expression="prec_3 = 300" --o
+r.mapcalc expression="prec_4 = 400" --o
+r.mapcalc expression="prec_5 = 500" --o
+r.mapcalc expression="prec_6 = 600" --o
+
+t.create type=strds temporaltype=absolute \
+ output=precip_abs title="Example" \
+ descr="Example" --o
+
+t.register -i type=raster input=precip_abs \
+ maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 \
+ start="2001-01-01" increment="1 months" --o
+
+t.rast.series input=precip_abs output=precip_abs_average
+
+r.info precip_abs_average
+
+t.rast.series input=precip_abs output=precip_abs_average_3months where="start_time >= '2001-04-01'"
+
+r.info precip_abs_average_3months
+
Modified: grass/trunk/temporal/t.rast.series/testsuite/test_series.py
===================================================================
--- grass/trunk/temporal/t.rast.series/testsuite/test_series.py 2018-03-21 19:11:23 UTC (rev 72478)
+++ grass/trunk/temporal/t.rast.series/testsuite/test_series.py 2018-03-21 20:18:38 UTC (rev 72479)
@@ -35,10 +35,11 @@
description="A test", overwrite=True)
cls.runModule("t.register", type="raster", input="A",
- maps="a1,a2,a3,a4",
- start="2001-01-01",
- increment="1 month",
- overwrite=True)
+ maps="a1,a2,a3,a4",
+ start="2001-01-01",
+ increment="1 month",
+ flags="i",
+ overwrite=True)
@classmethod
def tearDownClass(cls):
"""Remove the temporary region
@@ -45,6 +46,8 @@
"""
cls.del_temp_region()
cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
+ cls.runModule("t.unregister", type="raster",
+ maps="series_average,series_maximum,series_minimum,series_minimum_2")
cls.runModule("g.remove", flags="f", type="raster", name="series_average")
cls.runModule("g.remove", flags="f", type="raster", name="series_maximum")
cls.runModule("g.remove", flags="f", type="raster", name="series_minimum")
@@ -51,6 +54,16 @@
cls.runModule("g.remove", flags="f", type="raster", name="series_minimum_2")
cls.runModule("g.remove", flags="f", type="raster", name="series_quantile")
+ def test_time_stamp(self):
+ self.assertModule("t.rast.series", input="A", method="average",
+ output="series_time_stamp", where="start_time > '2001-02-01'")
+
+ tinfo_string="""start_time=2001-02-01 00:00:00
+ end_time=2001-05-01 00:00:00"""
+
+ info = SimpleModule("t.info", flags="g", type="raster", input="series_time_stamp")
+ self.assertModuleKeyValue(module=info, reference=tinfo_string, precision=2, sep="=")
+
def test_average(self):
self.assertModule("t.rast.series", input="A", method="average",
output="series_average")
@@ -119,6 +132,8 @@
"""
cls.del_temp_region()
cls.runModule("t.remove", flags="rf", type="strds", inputs="A")
+ cls.runModule("t.unregister", type="raster",
+ maps="series_average,series_maximum,series_minimum,series_minimum_2")
cls.runModule("g.remove", flags="f", type="raster", name="series_average")
cls.runModule("g.remove", flags="f", type="raster", name="series_maximum")
cls.runModule("g.remove", flags="f", type="raster", name="series_minimum")
More information about the grass-commit
mailing list