[GRASS-SVN] r74123 - in grass/trunk/temporal/t.rast.series: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Feb 21 02:14:32 PST 2019
Author: sbl
Date: 2019-02-21 02:14:32 -0800 (Thu, 21 Feb 2019)
New Revision: 74123
Modified:
grass/trunk/temporal/t.rast.series/t.rast.series.py
grass/trunk/temporal/t.rast.series/test.t.rast.series.sh
grass/trunk/temporal/t.rast.series/testsuite/test_series.py
Log:
multi method support for t.rast.series; fix #3741
Modified: grass/trunk/temporal/t.rast.series/t.rast.series.py
===================================================================
--- grass/trunk/temporal/t.rast.series/t.rast.series.py 2019-02-21 09:48:50 UTC (rev 74122)
+++ grass/trunk/temporal/t.rast.series/t.rast.series.py 2019-02-21 10:14:32 UTC (rev 74123)
@@ -2,12 +2,12 @@
# -*- coding: utf-8 -*-
############################################################################
#
-# MODULE: t.rast.series
-# AUTHOR(S): Soeren Gebbert
+# MODULE: t.rast.series
+# AUTHOR(S): Soeren Gebbert
#
-# PURPOSE: Perform different aggregation algorithms from r.series on all or a
+# PURPOSE: Perform different aggregation algorithms from r.series on all or a
# selected subset of raster maps in a space time raster dataset
-# COPYRIGHT: (C) 2011-2017 by the GRASS Development Team
+# COPYRIGHT: (C) 2011-2017 by the GRASS Development Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -38,7 +38,7 @@
#% type: string
#% description: Aggregate operation to be performed on the raster maps
#% required: yes
-#% multiple: no
+#% multiple: yes
#% options: average,count,median,mode,minimum,min_raster,maximum,max_raster,stddev,range,sum,variance,diversity,slope,offset,detcoeff,quart1,quart3,perc90,quantile,skewness,kurtosis
#% answer: average
#%end
@@ -48,7 +48,7 @@
#% type: double
#% description: Quantile to calculate for method=quantile
#% required: no
-#% multiple: no
+#% multiple: yes
#% options: 0.0-1.0
#%end
@@ -65,7 +65,7 @@
#%option G_OPT_T_WHERE
#%end
-#%option G_OPT_R_OUTPUT
+#%option G_OPT_R_OUTPUTS
#%end
#%flag
@@ -99,6 +99,15 @@
add_time = flags["t"]
nulls = flags["n"]
+ # Check if number of methods and output maps matches
+ print((method.split(',')))
+ print(len(list(filter(None, quantile.split(',')))))
+ print((output.split(',')))
+
+ if (len(list(filter(None, quantile.split(',')))) +
+ len(method.split(','))) != len(output.split(',')):
+ grass.fatal(_('Number requested methods and output maps do not match.'))
+
# Make sure the temporal database exists
tgis.init()
@@ -133,16 +142,6 @@
if not add_time:
- # Create the time range for the output map
- if output.find("@") >= 0:
- id = output
- else:
- mapset = grass.gisenv()["MAPSET"]
- id = output + "@" + mapset
-
- map = sp.get_new_map_instance(id)
- map.load()
-
# 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]
@@ -159,14 +158,26 @@
extent = tgis.RelativeTemporalExtent(start_time=start_a, end_time=end_b,
unit=first_map.get_relative_time_unit())
- map.set_temporal_extent(extent=extent)
+ for out_map in output.split(','):
- # Register the map in the temporal database
- if map.is_in_db():
- map.update_all()
- else:
- map.insert()
+ # Create the time range for the output map
+ if out_map.find("@") >= 0:
+ id = out_map
+ else:
+ mapset = grass.gisenv()["MAPSET"]
+ id = out_map + "@" + mapset
+ map = sp.get_new_map_instance(id)
+ map.load()
+
+ map.set_temporal_extent(extent=extent)
+
+ # Register the map in the temporal database
+ if map.is_in_db():
+ map.update_all()
+ else:
+ map.insert()
+
if __name__ == "__main__":
options, flags = grass.parser()
main()
Modified: grass/trunk/temporal/t.rast.series/test.t.rast.series.sh
===================================================================
--- grass/trunk/temporal/t.rast.series/test.t.rast.series.sh 2019-02-21 09:48:50 UTC (rev 74122)
+++ grass/trunk/temporal/t.rast.series/test.t.rast.series.sh 2019-02-21 10:14:32 UTC (rev 74123)
@@ -18,6 +18,7 @@
t.register 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"
t.rast.list precip_abs
+t.rast.series --o -t input=precip_abs method=average,range output=prec_average,prec_range where="start_time > '2001-03-01'"
t.rast.series --o -t input=precip_abs method=average output=prec_average where="start_time > '2001-03-01'"
t.rast.series --o input=precip_abs method=maximum output=prec_max order=start_time
t.rast.series input=precip_abs method=sum output=prec_sum
@@ -32,4 +33,4 @@
t.unregister type=raster maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6,prec_sum,prec_max
t.remove type=strds input=precip_abs
-g.remove -f type=raster name=prec_sum,prec_max,prec_average
+g.remove -f type=raster name=prec_sum,prec_max,prec_average,prec_range
Modified: grass/trunk/temporal/t.rast.series/testsuite/test_series.py
===================================================================
--- grass/trunk/temporal/t.rast.series/testsuite/test_series.py 2019-02-21 09:48:50 UTC (rev 74122)
+++ grass/trunk/temporal/t.rast.series/testsuite/test_series.py 2019-02-21 10:14:32 UTC (rev 74123)
@@ -85,6 +85,22 @@
self.assertRasterMinMax(map="series_minimum", refmin=100, refmax=100,
msg="Minimum must be 100")
+ def test_multi_stats(self):
+ self.assertModule("t.rast.series", input="A",
+ method=["average", "maximum", "minimum",
+ output=["series_average", "series_maximum",
+ "series_minimum"],
+ overwrite=True)
+
+ self.assertRasterMinMax(map="series_average", refmin=250, refmax=250,
+ msg="Average must be 250")
+
+ self.assertRasterMinMax(map="series_maximum", refmin=400, refmax=400,
+ msg="Maximum must be 400")
+
+ self.assertRasterMinMax(map="series_minimum", refmin=100, refmax=100,
+ msg="Minimum must be 100")
+
def test_minimum_where(self):
self.assertModule("t.rast.series", input="A", method="minimum",
output="series_minimum_2",
More information about the grass-commit
mailing list