From 0471798079e5b38123dc3cd670d69873076d5817 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Mon, 27 Feb 2023 22:05:42 +0100 Subject: [PATCH 01/21] support mapset in file --- python/grass/temporal/register.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index f223e74398a..56cdd72ff73 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -226,7 +226,9 @@ def register_maps_in_space_time_dataset( found = gscript.find_file(element=type, name=mapname) if found["mapset"] is not None and len(found["mapset"]) > 0: map_mapset = found["mapset"] - row["id"] = AbstractMapDataset.build_id(mapname, map_mapset) + row["id"] = AbstractMapDataset.build_id(mapname, map_mapset) + else: + row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2]) maplist.append(row) From a96ce33f480189cc59af2a48f9380b7bc6838951 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Mon, 27 Feb 2023 22:07:34 +0100 Subject: [PATCH 02/21] test mapset in file --- .../t.register/test.t.register.raster.file.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/temporal/t.register/test.t.register.raster.file.sh b/temporal/t.register/test.t.register.raster.file.sh index ce23b19f1fe..8b5fb3763c5 100755 --- a/temporal/t.register/test.t.register.raster.file.sh +++ b/temporal/t.register/test.t.register.raster.file.sh @@ -19,9 +19,11 @@ r.mapcalc --o expr="prec_4 = rand(0, 510)" -s r.mapcalc --o expr="prec_5 = rand(0, 300)" -s r.mapcalc --o expr="prec_6 = rand(0, 650)" -s +eval `g.gisenv` n1=`g.tempfile pid=1 -d` # Only map names n2=`g.tempfile pid=2 -d` # Map names and start time n3=`g.tempfile pid=3 -d` # Map names start time and increment +n4=`g.tempfile pid=4 -d` # Full map names, start time, end time and semantic label cat > "${n1}" << EOF prec_1 @@ -53,6 +55,16 @@ prec_6|2002-04-01|2002-07-01 EOF cat "${n3}" +cat > "${n4}" << EOF +prec_1@${MAPSET}|2001-01-01|2001-04-01|semantic_label +prec_2@${MAPSET}|2001-04-01|2001-07-01|semantic_label +prec_3@${MAPSET}|2001-07-01|2001-10-01|semantic_label +prec_4@${MAPSET}|2001-10-01|2002-01-01|semantic_label +prec_5@${MAPSET}|2002-01-01|2002-04-01|semantic_label +prec_6@${MAPSET}|2002-04-01|2002-07-01|semantic_label +EOF +cat "${n4}" + # The first @test # We create the space time raster inputs and register the raster maps with absolute time interval t.create --o type=strds temporaltype=absolute output=precip_abs8 title="A test with input files" descr="A test with input files" @@ -78,6 +90,10 @@ t.rast.list input=precip_abs8 t.register --o -i input=precip_abs8 file="${n3}" t.info type=strds input=precip_abs8 t.rast.list input=precip_abs8 +# File 4 +t.register --o input=precip_abs8 file="${n4}" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 t.remove --v type=strds input=precip_abs8 t.unregister --v type=raster file="${n1}" From 6e81fb9f8369f2b17f1f188e8ec80559d8e1d2fe Mon Sep 17 00:00:00 2001 From: ninsbl Date: Tue, 28 Feb 2023 23:17:00 +0100 Subject: [PATCH 03/21] handle find_file elements and results --- python/grass/temporal/register.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index 56cdd72ff73..55dd7337300 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -81,6 +81,14 @@ def register_maps_in_space_time_dataset( start_time_in_file = False end_time_in_file = False semantic_label_in_file = False + element = { + "rast": "cell", + "raster": "cell", + "rast3d": "grid3", + "raster3d": "grid3", + "raster_3d": "grid3", + "vector": "vector", + }[type] msgr = get_tgis_message_interface() @@ -159,12 +167,12 @@ def register_maps_in_space_time_dataset( mapname = maplist[count] map_mapset = mapset if "@" not in mapname: - found = gscript.find_file(element=type, name=mapname) - if found["mapset"] is not None and len(found["mapset"]) > 0: + found = gscript.find_file(element=element, name=mapname) + if found["mapset"]: map_mapset = found["mapset"] - mapid = AbstractMapDataset.build_id(mapname, map_mapset, None) - - row["id"] = mapid + row["id"] = AbstractMapDataset.build_id(mapname, map_mapset, None) + else: + row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2], None) maplist[count] = row # Read the map list from file @@ -223,13 +231,12 @@ def register_maps_in_space_time_dataset( map_mapset = mapset if "@" not in mapname: - found = gscript.find_file(element=type, name=mapname) - if found["mapset"] is not None and len(found["mapset"]) > 0: + found = gscript.find_file(element=element, name=mapname) + if found["mapset"]: map_mapset = found["mapset"] row["id"] = AbstractMapDataset.build_id(mapname, map_mapset) else: row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2]) - maplist.append(row) if start_time_in_file is True and increment: From c8bf7caa2b0e4e386a456ef849c2716a5b54b4b1 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Tue, 28 Feb 2023 23:41:12 +0100 Subject: [PATCH 04/21] first Python code --- .../testsuite/test_t_register_raster_file.sh | 379 ++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100755 temporal/t.register/testsuite/test_t_register_raster_file.sh diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.sh b/temporal/t.register/testsuite/test_t_register_raster_file.sh new file mode 100755 index 00000000000..ebf9df9bd86 --- /dev/null +++ b/temporal/t.register/testsuite/test_t_register_raster_file.sh @@ -0,0 +1,379 @@ +"""Test t.register + +(C) 2014-2023 by the GRASS Development Team +This program is free software under the GNU General Public +License (>=v2). Read the file COPYING that comes with GRASS +for details. + +@author Soeren Gebbert + Ported to Python by Stefan Blumentrath + +This is a test to register and unregister raster maps in +space time raster input. +The raster maps will be registered in different space time raster +inputs + +We need to set a specific region in the +@preprocess step of this test. We generate +raster with r.mapcalc and create two space time raster inputs +with absolute time +The region setting should work for UTM and LL test locations + +""" + +from grass.gunittest.case import TestCase +from grass.gunittest.gmodules import SimpleModule + +""" +eval `g.gisenv` +n1=`g.tempfile pid=1 -d` # Only map names +n2=`g.tempfile pid=2 -d` # Map names and start time +n3=`g.tempfile pid=3 -d` # Map names start time and increment +n4=`g.tempfile pid=4 -d` # Full map names, start time, end time and semantic label + +cat > "${n1}" << EOF +EOF +cat "${n1}" + +cat > "${n2}" << EOF +prec_1|2001-01-01 +prec_2|2001-02-01 +prec_3|2001-03-01 +prec_4|2001-04-01 +prec_5|2001-05-01 +prec_6|2001-06-01 +EOF +cat "${n2}" + +cat > "${n3}" << EOF +prec_1|2001-01-01|2001-04-01 +prec_2|2001-04-01|2001-07-01 +prec_3|2001-07-01|2001-10-01 +prec_4|2001-10-01|2002-01-01 +prec_5|2002-01-01|2002-04-01 +prec_6|2002-04-01|2002-07-01 +EOF +cat "${n3}" + +cat > "${n4}" << EOF +prec_1@${MAPSET}|2001-01-01|2001-04-01|semantic_label +prec_2@${MAPSET}|2001-04-01|2001-07-01|semantic_label +prec_3@${MAPSET}|2001-07-01|2001-10-01|semantic_label +prec_4@${MAPSET}|2001-10-01|2002-01-01|semantic_label +prec_5@${MAPSET}|2002-01-01|2002-04-01|semantic_label +prec_6@${MAPSET}|2002-04-01|2002-07-01|semantic_label +EOF +cat "${n4}" + +# The first @test +# We create the space time raster inputs and register the raster maps with absolute time interval + + +# Test with input files +# File 1 +# File 1 +t.register --o input=precip_abs8 file="${n1}" start="2001-01-01" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 +# File 2 +t.register --o input=precip_abs8 file="${n2}" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 +# File 2 +t.register --o input=precip_abs8 file="${n2}" increment="1 months" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 +# File 3 +t.register --o -i input=precip_abs8 file="${n3}" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 +# File 4 +t.register --o input=precip_abs8 file="${n4}" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 + +t.remove --v type=strds input=precip_abs8 +t.unregister --v type=raster file="${n1}" +""" + +class TestRasterUnivar(TestCase): + @classmethod + def setUpClass(cls): + """Initiate the temporal GIS and set the region""" + cls.use_temp_region() + cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3") + + # Generate data + cls.runModule("r.mapcalc", expression="prec_1 = rand(0, 550)", overwrite=True) + cls.runModule("r.mapcalc", expression="prec_2 = rand(0, 450)", overwrite=True) + cls.runModule("r.mapcalc", expression="prec_3 = rand(0, 320)", overwrite=True) + cls.runModule("r.mapcalc", expression="prec_4 = rand(0, 510)", overwrite=True) + cls.runModule("r.mapcalc", expression="prec_5 = rand(0, 300)", overwrite=True) + cls.runModule("r.mapcalc", expression="prec_6 = rand(0, 650)", overwrite=True) + + cls.runModule( + "t.create", + type="strds", + temporaltype="absolute", + output="precip_abs8", + title="A test with input files", + description="A test with input files", + overwrite=True, + ) + + @classmethod + def tearDownClass(cls): + """Remove the temporary region""" + cls.runModule("t.remove", flags="df", type="strds", inputs="precip_abs8") + cls.del_temp_region() + + def test_with_all_maps(self): + + tmp_file = + with open(tmp_file, "w") as register_file: + register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") + + register_module = SimpleModule( + "t.register", + input="precip_abs8", + start="2001-01-01", + where="start_time >= '2001-01-01'", + increment="1 months", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + maplist = SimpleModule("t.rast.list", + input="precip_abs8") + + #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#a_1@testing||2001-01-01 00:00:00|2001-04-01 00:00:00|100|100|100|100|0|0|0|960000|0|9600|9600 +#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 +#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 +#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 +#""" + #for ref, res in zip( + #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") + #): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + #def test_with_subset_of_maps(self): + + #t_rast_univar = SimpleModule( + #"t.rast.univar", + #input="A", + #where="start_time >= '2001-03-01'", + #overwrite=True, + #verbose=True, + #) + #self.runModule("g.region", res=1) + #self.assertModule(t_rast_univar) + + #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 +#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 +#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 +#""" + #for ref, res in zip( + #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") + #): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + #def test_coarser_resolution(self): + + #t_rast_univar = SimpleModule( + #"t.rast.univar", + #input="A", + #where="start_time >= '2001-03-01'", + #overwrite=True, + #verbose=True, + #) + #self.runModule("g.region", res=10) + #self.assertModule(t_rast_univar) + + #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|19200|0|96|96 +#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|28800|0|96|96 +#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|38400|0|96|96 +#""" + #for ref, res in zip( + #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") + #): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + #def test_subset_with_output(self): + + #self.runModule("g.region", res=10) + #self.assertModule( + #"t.rast.univar", + #input="A", + #flags="r", + #output="univar_output.txt", + #where="start_time >= '2001-03-01'", + #overwrite=True, + #verbose=True, + #) + + #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 +#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 +#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 +#""" + #univar_output = open("univar_output.txt", "r").read() + + #for ref, res in zip(univar_text.split("\n"), univar_output.split("\n")): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #print(type(ref_line)) + #print(type(res_line)) + #self.assertLooksLike(ref_line, res_line) + + #def test_subset_with_output_coarse_resolution(self): + + #self.runModule("g.region", res=10) + #self.assertModule( + #"t.rast.univar", + #input="A", + #flags="ru", + #output="univar_output.txt", + #where="start_time >= '2001-03-01'", + #overwrite=True, + #verbose=True, + #) + + #univar_text = """a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 +#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 +#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 +#""" + #univar_output = open("univar_output.txt", "r").read() + + #for ref, res in zip(univar_text.split("\n"), univar_output.split("\n")): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + #def test_error_handling_empty_strds(self): + ## Empty strds + #self.assertModuleFail( + #"t.rast.univar", + #input="A", + #output="univar_output.txt", + #where="start_time >= '2015-03-01'", + #overwrite=True, + #verbose=True, + #) + + #def test_error_handling_no_input(self): + ## No input + #self.assertModuleFail("t.rast.univar", output="out.txt") + + #def test_with_zones(self): + #"""Test use of zones""" + + #t_rast_univar = SimpleModule( + #"t.rast.univar", + #input="A", + #where="start_time >= '2001-01-01'", + #zones="zones", + #overwrite=True, + #verbose=True, + #) + #self.runModule("g.region", res=1) + #self.assertModule(t_rast_univar) + + #print(t_rast_univar.outputs.stdout.split("\n")) + + #univar_text = """id|semantic_label|start|end|zone|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#a_1@PERMANENT||2001-01-01 00:00:00|2001-04-01 00:00:00|1|100|100|100|100|0|0|0|60000|0|600|600 +#a_1@PERMANENT||2001-01-01 00:00:00|2001-04-01 00:00:00|2|100|100|100|100|0|0|0|168000|0|1680|1680 +#a_1@PERMANENT||2001-01-01 00:00:00|2001-04-01 00:00:00|3|100|100|100|100|0|0|0|732000|0|7320|7320 +#a_2@PERMANENT||2001-04-01 00:00:00|2001-07-01 00:00:00|1|200|200|200|200|0|0|0|120000|0|600|600 +#a_2@PERMANENT||2001-04-01 00:00:00|2001-07-01 00:00:00|2|200|200|200|200|0|0|0|336000|0|1680|1680 +#a_2@PERMANENT||2001-04-01 00:00:00|2001-07-01 00:00:00|3|200|200|200|200|0|0|0|1464000|0|7320|7320 +#a_3@PERMANENT||2001-07-01 00:00:00|2001-10-01 00:00:00|1|300|300|300|300|0|0|0|180000|0|600|600 +#a_3@PERMANENT||2001-07-01 00:00:00|2001-10-01 00:00:00|2|300|300|300|300|0|0|0|504000|0|1680|1680 +#a_3@PERMANENT||2001-07-01 00:00:00|2001-10-01 00:00:00|3|300|300|300|300|0|0|0|2196000|0|7320|7320 +#a_4@PERMANENT||2001-10-01 00:00:00|2002-01-01 00:00:00|1|400|400|400|400|0|0|0|240000|0|600|600 +#a_4@PERMANENT||2001-10-01 00:00:00|2002-01-01 00:00:00|2|400|400|400|400|0|0|0|672000|0|1680|1680 +#a_4@PERMANENT||2001-10-01 00:00:00|2002-01-01 00:00:00|3|400|400|400|400|0|0|0|2928000|0|7320|7320 +#""" + + #for ref, res in zip( + #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") + #): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + #def test_with_semantic_label(self): + #"""Test semantic labels""" + #t_rast_univar = SimpleModule( + #"t.rast.univar", + #input="B.S2_B1", + #where="start_time >= '2001-01-01'", + #overwrite=True, + #verbose=True, + #) + #self.runModule("g.region", res=1) + #self.assertModule(t_rast_univar) + + #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#b_1@PERMANENT|S2_B1|2001-01-01 00:00:00|2001-04-01 00:00:00|110|110|110|110|0|0|0|1056000|0|9600|9600 +#b_2@PERMANENT|S2_B1|2001-04-01 00:00:00|2001-07-01 00:00:00|220|220|220|220|0|0|0|2112000|0|9600|9600 +#b_3@PERMANENT|S2_B1|2001-07-01 00:00:00|2001-10-01 00:00:00|330|330|330|330|0|0|0|3168000|0|9600|9600 +#b_4@PERMANENT|S2_B1|2001-10-01 00:00:00|2002-01-01 00:00:00|440|440|440|440|0|0|0|4224000|0|9600|9600 +#""" + #for ref, res in zip( + #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") + #): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + #def test_with_semantic_label_parallel(self): + #"""Test semantic labels""" + #t_rast_univar = SimpleModule( + #"t.rast.univar", + #input="B.S2_B1", + #where="start_time >= '2001-01-01'", + #nprocs=2, + #overwrite=True, + #verbose=True, + #) + #self.runModule("g.region", res=1) + #self.assertModule(t_rast_univar) + + #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells +#b_1@PERMANENT|S2_B1|2001-01-01 00:00:00|2001-04-01 00:00:00|110|110|110|110|0|0|0|1056000|0|9600|9600 +#b_2@PERMANENT|S2_B1|2001-04-01 00:00:00|2001-07-01 00:00:00|220|220|220|220|0|0|0|2112000|0|9600|9600 +#b_3@PERMANENT|S2_B1|2001-07-01 00:00:00|2001-10-01 00:00:00|330|330|330|330|0|0|0|3168000|0|9600|9600 +#b_4@PERMANENT|S2_B1|2001-10-01 00:00:00|2002-01-01 00:00:00|440|440|440|440|0|0|0|4224000|0|9600|9600 +#""" + #for ref, res in zip( + #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") + #): + #if ref and res: + #ref_line = ref.split("|", 1)[1] + #res_line = res.split("|", 1)[1] + #self.assertLooksLike(ref_line, res_line) + + +if __name__ == "__main__": + from grass.gunittest.main import test + + test() From f9aa6e4616a8ce11bad1a4c62741271f41387b31 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Wed, 1 Mar 2023 00:16:44 +0100 Subject: [PATCH 05/21] port to Python --- .../testsuite/test_t_register_raster_file.py | 280 ++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100755 temporal/t.register/testsuite/test_t_register_raster_file.py diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.py b/temporal/t.register/testsuite/test_t_register_raster_file.py new file mode 100755 index 00000000000..5e22b645342 --- /dev/null +++ b/temporal/t.register/testsuite/test_t_register_raster_file.py @@ -0,0 +1,280 @@ +"""Test t.register + +(C) 2014-2023 by the GRASS Development Team +This program is free software under the GNU General Public +License (>=v2). Read the file COPYING that comes with GRASS +for details. + +@author Soeren Gebbert + Ported to Python by Stefan Blumentrath + +This is a test to register and unregister raster maps in +space time raster input. +The raster maps will be registered in different space time raster +inputs + +We need to set a specific region in the +@preprocess step of this test. We generate +raster with r.mapcalc and create two space time raster inputs +with absolute time +The region setting should work for UTM and LL test locations + +""" + +import grass.script as gs + +from grass.gunittest.case import TestCase +from grass.gunittest.gmodules import SimpleModule + +""" +eval `g.gisenv` +n1=`g.tempfile pid=1 -d` # Only map names +n2=`g.tempfile pid=2 -d` # Map names and start time +n3=`g.tempfile pid=3 -d` # Map names start time and increment +n4=`g.tempfile pid=4 -d` # Full map names, start time, end time and semantic label + +cat > "${n1}" << EOF +EOF +cat "${n1}" + +cat > "${n2}" << EOF +EOF +cat "${n2}" + +cat > "${n3}" << EOF +EOF +cat "${n3}" + +cat > "${n4}" << EOF +EOF +cat "${n4}" + +# The first @test +# We create the space time raster inputs and register the raster maps with absolute time interval + + +# Test with input files +# File 1 +# File 1 +# File 2 +# File 2 +# File 3 +# File 4 +t.register --o input=precip_abs8 file="${n4}" +t.info type=strds input=precip_abs8 +t.rast.list input=precip_abs8 + +t.remove --v type=strds input=precip_abs8 +t.unregister --v type=raster file="${n1}" +""" + + +class TestRasterUnivar(TestCase): + @classmethod + def setUpClass(cls): + """Initiate the temporal GIS and set the region""" + cls.use_temp_region() + cls.runModule( + "g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3" + ) + + # Generate data + cls.runModule( + "r.mapcalc", flags="s", expression="prec_1 = rand(0, 550)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_2 = rand(0, 450)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_3 = rand(0, 320)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_4 = rand(0, 510)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_5 = rand(0, 300)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_6 = rand(0, 650)", overwrite=True + ) + + cls.runModule( + "t.create", + type="strds", + temporaltype="absolute", + output="precip_abs8", + title="A test with input files", + description="A test with input files", + overwrite=True, + ) + + @classmethod + def tearDownClass(cls): + """Remove the temporary region""" + cls.runModule("t.remove", flags="df", type="strds", inputs="precip_abs8") + cls.del_temp_region() + + def test_with_file_and_increment(self): + + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") + + register_module = SimpleModule( + "t.register", + input="precip_abs8", + start="2001-01-01", + increment="1 months", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + # maplist = SimpleModule("t.rast.list", + # input="precip_abs8") + + def test_with_file_and_no_increment(self): + + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") + + register_module = SimpleModule( + "t.register", + input="precip_abs8", + start="2001-01-01", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + # t.info type=strds input=precip_abs8 + # t.rast.list input=precip_abs8 + + def test_with_start_in_file(self): + + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write( + "\n".join( + [ + "prec_1|2001-01-01", + "prec_2|2001-02-01", + "prec_3|2001-03-01", + "prec_4|2001-04-01", + "prec_5|2001-05-01", + "prec_6|2001-06-01", + ] + ) + ) + + register_module = SimpleModule( + "t.register", + input="precip_abs8", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + # t.info type=strds input=precip_abs8 + # t.rast.list input=precip_abs8 + + def test_with_start_in_file_and_increment(self): + + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write( + "\n".join( + [ + "prec_1|2001-01-01", + "prec_2|2001-02-01", + "prec_3|2001-03-01", + "prec_4|2001-04-01", + "prec_5|2001-05-01", + "prec_6|2001-06-01", + ] + ) + ) + + register_module = SimpleModule( + "t.register", + input="precip_abs8", + increment="1 months", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModuleFail(register_module) + + # t.info type=strds input=precip_abs8 + # t.rast.list input=precip_abs8 + + def test_with_start_and_end_in_file_and_interval(self): + + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write( + "\n".join( + [ + "prec_1|2001-01-01|2001-04-01", + "prec_2|2001-04-01|2001-07-01", + "prec_3|2001-07-01|2001-10-01", + "prec_4|2001-10-01|2002-01-01", + "prec_5|2002-01-01|2002-04-01", + "prec_6|2002-04-01|2002-07-01", + ] + ) + ) + + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs8", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModuleFail(register_module) + + # t.info type=strds input=precip_abs8 + # t.rast.list input=precip_abs8 + + def test_with_mapset_and_semantic_label(self): + + mapset = gs.gisenv()["MAPSET"] + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write( + "\n".join( + [ + f"prec_1@{mapset}|2001-01-01|2001-04-01|semantic_label", + f"prec_2@{mapset}|2001-04-01|2001-07-01|semantic_label", + f"prec_3@{mapset}|2001-07-01|2001-10-01|semantic_label", + f"prec_4@{mapset}|2001-10-01|2002-01-01|semantic_label", + f"prec_5@{mapset}|2002-01-01|2002-04-01|semantic_label", + f"prec_6@{mapset}|2002-04-01|2002-07-01|semantic_label", + ] + ) + ) + + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs8", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModuleFail(register_module) + + # t.info type=strds input=precip_abs8 + # t.rast.list input=precip_abs8 + + +if __name__ == "__main__": + from grass.gunittest.main import test + + test() From 552ac14db2ece870b7178a7f80371c483a918efb Mon Sep 17 00:00:00 2001 From: ninsbl Date: Wed, 1 Mar 2023 00:21:02 +0100 Subject: [PATCH 06/21] cleanup --- .../testsuite/test_t_register_raster_file.py | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.py b/temporal/t.register/testsuite/test_t_register_raster_file.py index 5e22b645342..4f5ef76cdcd 100755 --- a/temporal/t.register/testsuite/test_t_register_raster_file.py +++ b/temporal/t.register/testsuite/test_t_register_raster_file.py @@ -26,48 +26,6 @@ from grass.gunittest.case import TestCase from grass.gunittest.gmodules import SimpleModule -""" -eval `g.gisenv` -n1=`g.tempfile pid=1 -d` # Only map names -n2=`g.tempfile pid=2 -d` # Map names and start time -n3=`g.tempfile pid=3 -d` # Map names start time and increment -n4=`g.tempfile pid=4 -d` # Full map names, start time, end time and semantic label - -cat > "${n1}" << EOF -EOF -cat "${n1}" - -cat > "${n2}" << EOF -EOF -cat "${n2}" - -cat > "${n3}" << EOF -EOF -cat "${n3}" - -cat > "${n4}" << EOF -EOF -cat "${n4}" - -# The first @test -# We create the space time raster inputs and register the raster maps with absolute time interval - - -# Test with input files -# File 1 -# File 1 -# File 2 -# File 2 -# File 3 -# File 4 -t.register --o input=precip_abs8 file="${n4}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 - -t.remove --v type=strds input=precip_abs8 -t.unregister --v type=raster file="${n1}" -""" - class TestRasterUnivar(TestCase): @classmethod From 70e83dbc9201b16cceb6259147081b63acfebc50 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Wed, 1 Mar 2023 00:22:14 +0100 Subject: [PATCH 07/21] port to Python --- .../t.register/test.t.register.raster.file.sh | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100755 temporal/t.register/test.t.register.raster.file.sh diff --git a/temporal/t.register/test.t.register.raster.file.sh b/temporal/t.register/test.t.register.raster.file.sh deleted file mode 100755 index 8b5fb3763c5..00000000000 --- a/temporal/t.register/test.t.register.raster.file.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/sh -# This is a test to register and unregister raster maps in -# space time raster input. -# The raster maps will be registered in different space time raster -# inputs - -# We need to set a specific region in the -# @preprocess step of this test. We generate -# raster with r.mapcalc and create two space time raster inputs -# with absolute time -# The region setting should work for UTM and LL test locations -g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3 - -# Generate data -r.mapcalc --o expr="prec_1 = rand(0, 550)" -s -r.mapcalc --o expr="prec_2 = rand(0, 450)" -s -r.mapcalc --o expr="prec_3 = rand(0, 320)" -s -r.mapcalc --o expr="prec_4 = rand(0, 510)" -s -r.mapcalc --o expr="prec_5 = rand(0, 300)" -s -r.mapcalc --o expr="prec_6 = rand(0, 650)" -s - -eval `g.gisenv` -n1=`g.tempfile pid=1 -d` # Only map names -n2=`g.tempfile pid=2 -d` # Map names and start time -n3=`g.tempfile pid=3 -d` # Map names start time and increment -n4=`g.tempfile pid=4 -d` # Full map names, start time, end time and semantic label - -cat > "${n1}" << EOF -prec_1 -prec_2 -prec_3 -prec_4 -prec_5 -prec_6 -EOF -cat "${n1}" - -cat > "${n2}" << EOF -prec_1|2001-01-01 -prec_2|2001-02-01 -prec_3|2001-03-01 -prec_4|2001-04-01 -prec_5|2001-05-01 -prec_6|2001-06-01 -EOF -cat "${n2}" - -cat > "${n3}" << EOF -prec_1|2001-01-01|2001-04-01 -prec_2|2001-04-01|2001-07-01 -prec_3|2001-07-01|2001-10-01 -prec_4|2001-10-01|2002-01-01 -prec_5|2002-01-01|2002-04-01 -prec_6|2002-04-01|2002-07-01 -EOF -cat "${n3}" - -cat > "${n4}" << EOF -prec_1@${MAPSET}|2001-01-01|2001-04-01|semantic_label -prec_2@${MAPSET}|2001-04-01|2001-07-01|semantic_label -prec_3@${MAPSET}|2001-07-01|2001-10-01|semantic_label -prec_4@${MAPSET}|2001-10-01|2002-01-01|semantic_label -prec_5@${MAPSET}|2002-01-01|2002-04-01|semantic_label -prec_6@${MAPSET}|2002-04-01|2002-07-01|semantic_label -EOF -cat "${n4}" - -# The first @test -# We create the space time raster inputs and register the raster maps with absolute time interval -t.create --o type=strds temporaltype=absolute output=precip_abs8 title="A test with input files" descr="A test with input files" - -# Test with input files -# File 1 -t.register --o -i input=precip_abs8 file="${n1}" start="2001-01-01" increment="1 months" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 1 -t.register --o input=precip_abs8 file="${n1}" start="2001-01-01" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 2 -t.register --o input=precip_abs8 file="${n2}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 2 -t.register --o input=precip_abs8 file="${n2}" increment="1 months" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 3 -t.register --o -i input=precip_abs8 file="${n3}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 4 -t.register --o input=precip_abs8 file="${n4}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 - -t.remove --v type=strds input=precip_abs8 -t.unregister --v type=raster file="${n1}" From 46eb80edef23d9c4a9a40a57569690e83729d7b2 Mon Sep 17 00:00:00 2001 From: Stefan Blumentrath Date: Wed, 1 Mar 2023 00:28:48 +0100 Subject: [PATCH 08/21] Delete accidentally created file --- .../testsuite/test_t_register_raster_file.sh | 379 ------------------ 1 file changed, 379 deletions(-) delete mode 100755 temporal/t.register/testsuite/test_t_register_raster_file.sh diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.sh b/temporal/t.register/testsuite/test_t_register_raster_file.sh deleted file mode 100755 index ebf9df9bd86..00000000000 --- a/temporal/t.register/testsuite/test_t_register_raster_file.sh +++ /dev/null @@ -1,379 +0,0 @@ -"""Test t.register - -(C) 2014-2023 by the GRASS Development Team -This program is free software under the GNU General Public -License (>=v2). Read the file COPYING that comes with GRASS -for details. - -@author Soeren Gebbert - Ported to Python by Stefan Blumentrath - -This is a test to register and unregister raster maps in -space time raster input. -The raster maps will be registered in different space time raster -inputs - -We need to set a specific region in the -@preprocess step of this test. We generate -raster with r.mapcalc and create two space time raster inputs -with absolute time -The region setting should work for UTM and LL test locations - -""" - -from grass.gunittest.case import TestCase -from grass.gunittest.gmodules import SimpleModule - -""" -eval `g.gisenv` -n1=`g.tempfile pid=1 -d` # Only map names -n2=`g.tempfile pid=2 -d` # Map names and start time -n3=`g.tempfile pid=3 -d` # Map names start time and increment -n4=`g.tempfile pid=4 -d` # Full map names, start time, end time and semantic label - -cat > "${n1}" << EOF -EOF -cat "${n1}" - -cat > "${n2}" << EOF -prec_1|2001-01-01 -prec_2|2001-02-01 -prec_3|2001-03-01 -prec_4|2001-04-01 -prec_5|2001-05-01 -prec_6|2001-06-01 -EOF -cat "${n2}" - -cat > "${n3}" << EOF -prec_1|2001-01-01|2001-04-01 -prec_2|2001-04-01|2001-07-01 -prec_3|2001-07-01|2001-10-01 -prec_4|2001-10-01|2002-01-01 -prec_5|2002-01-01|2002-04-01 -prec_6|2002-04-01|2002-07-01 -EOF -cat "${n3}" - -cat > "${n4}" << EOF -prec_1@${MAPSET}|2001-01-01|2001-04-01|semantic_label -prec_2@${MAPSET}|2001-04-01|2001-07-01|semantic_label -prec_3@${MAPSET}|2001-07-01|2001-10-01|semantic_label -prec_4@${MAPSET}|2001-10-01|2002-01-01|semantic_label -prec_5@${MAPSET}|2002-01-01|2002-04-01|semantic_label -prec_6@${MAPSET}|2002-04-01|2002-07-01|semantic_label -EOF -cat "${n4}" - -# The first @test -# We create the space time raster inputs and register the raster maps with absolute time interval - - -# Test with input files -# File 1 -# File 1 -t.register --o input=precip_abs8 file="${n1}" start="2001-01-01" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 2 -t.register --o input=precip_abs8 file="${n2}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 2 -t.register --o input=precip_abs8 file="${n2}" increment="1 months" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 3 -t.register --o -i input=precip_abs8 file="${n3}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 -# File 4 -t.register --o input=precip_abs8 file="${n4}" -t.info type=strds input=precip_abs8 -t.rast.list input=precip_abs8 - -t.remove --v type=strds input=precip_abs8 -t.unregister --v type=raster file="${n1}" -""" - -class TestRasterUnivar(TestCase): - @classmethod - def setUpClass(cls): - """Initiate the temporal GIS and set the region""" - cls.use_temp_region() - cls.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3") - - # Generate data - cls.runModule("r.mapcalc", expression="prec_1 = rand(0, 550)", overwrite=True) - cls.runModule("r.mapcalc", expression="prec_2 = rand(0, 450)", overwrite=True) - cls.runModule("r.mapcalc", expression="prec_3 = rand(0, 320)", overwrite=True) - cls.runModule("r.mapcalc", expression="prec_4 = rand(0, 510)", overwrite=True) - cls.runModule("r.mapcalc", expression="prec_5 = rand(0, 300)", overwrite=True) - cls.runModule("r.mapcalc", expression="prec_6 = rand(0, 650)", overwrite=True) - - cls.runModule( - "t.create", - type="strds", - temporaltype="absolute", - output="precip_abs8", - title="A test with input files", - description="A test with input files", - overwrite=True, - ) - - @classmethod - def tearDownClass(cls): - """Remove the temporary region""" - cls.runModule("t.remove", flags="df", type="strds", inputs="precip_abs8") - cls.del_temp_region() - - def test_with_all_maps(self): - - tmp_file = - with open(tmp_file, "w") as register_file: - register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") - - register_module = SimpleModule( - "t.register", - input="precip_abs8", - start="2001-01-01", - where="start_time >= '2001-01-01'", - increment="1 months", - file=tmp_file, - overwrite=True, - verbose=True, - ) - self.assertModule(register_module) - - maplist = SimpleModule("t.rast.list", - input="precip_abs8") - - #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#a_1@testing||2001-01-01 00:00:00|2001-04-01 00:00:00|100|100|100|100|0|0|0|960000|0|9600|9600 -#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 -#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 -#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 -#""" - #for ref, res in zip( - #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") - #): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - #def test_with_subset_of_maps(self): - - #t_rast_univar = SimpleModule( - #"t.rast.univar", - #input="A", - #where="start_time >= '2001-03-01'", - #overwrite=True, - #verbose=True, - #) - #self.runModule("g.region", res=1) - #self.assertModule(t_rast_univar) - - #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 -#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 -#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 -#""" - #for ref, res in zip( - #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") - #): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - #def test_coarser_resolution(self): - - #t_rast_univar = SimpleModule( - #"t.rast.univar", - #input="A", - #where="start_time >= '2001-03-01'", - #overwrite=True, - #verbose=True, - #) - #self.runModule("g.region", res=10) - #self.assertModule(t_rast_univar) - - #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|19200|0|96|96 -#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|28800|0|96|96 -#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|38400|0|96|96 -#""" - #for ref, res in zip( - #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") - #): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - #def test_subset_with_output(self): - - #self.runModule("g.region", res=10) - #self.assertModule( - #"t.rast.univar", - #input="A", - #flags="r", - #output="univar_output.txt", - #where="start_time >= '2001-03-01'", - #overwrite=True, - #verbose=True, - #) - - #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 -#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 -#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 -#""" - #univar_output = open("univar_output.txt", "r").read() - - #for ref, res in zip(univar_text.split("\n"), univar_output.split("\n")): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #print(type(ref_line)) - #print(type(res_line)) - #self.assertLooksLike(ref_line, res_line) - - #def test_subset_with_output_coarse_resolution(self): - - #self.runModule("g.region", res=10) - #self.assertModule( - #"t.rast.univar", - #input="A", - #flags="ru", - #output="univar_output.txt", - #where="start_time >= '2001-03-01'", - #overwrite=True, - #verbose=True, - #) - - #univar_text = """a_2@testing||2001-04-01 00:00:00|2001-07-01 00:00:00|200|200|200|200|0|0|0|1920000|0|9600|9600 -#a_3@testing||2001-07-01 00:00:00|2001-10-01 00:00:00|300|300|300|300|0|0|0|2880000|0|9600|9600 -#a_4@testing||2001-10-01 00:00:00|2002-01-01 00:00:00|400|400|400|400|0|0|0|3840000|0|9600|9600 -#""" - #univar_output = open("univar_output.txt", "r").read() - - #for ref, res in zip(univar_text.split("\n"), univar_output.split("\n")): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - #def test_error_handling_empty_strds(self): - ## Empty strds - #self.assertModuleFail( - #"t.rast.univar", - #input="A", - #output="univar_output.txt", - #where="start_time >= '2015-03-01'", - #overwrite=True, - #verbose=True, - #) - - #def test_error_handling_no_input(self): - ## No input - #self.assertModuleFail("t.rast.univar", output="out.txt") - - #def test_with_zones(self): - #"""Test use of zones""" - - #t_rast_univar = SimpleModule( - #"t.rast.univar", - #input="A", - #where="start_time >= '2001-01-01'", - #zones="zones", - #overwrite=True, - #verbose=True, - #) - #self.runModule("g.region", res=1) - #self.assertModule(t_rast_univar) - - #print(t_rast_univar.outputs.stdout.split("\n")) - - #univar_text = """id|semantic_label|start|end|zone|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#a_1@PERMANENT||2001-01-01 00:00:00|2001-04-01 00:00:00|1|100|100|100|100|0|0|0|60000|0|600|600 -#a_1@PERMANENT||2001-01-01 00:00:00|2001-04-01 00:00:00|2|100|100|100|100|0|0|0|168000|0|1680|1680 -#a_1@PERMANENT||2001-01-01 00:00:00|2001-04-01 00:00:00|3|100|100|100|100|0|0|0|732000|0|7320|7320 -#a_2@PERMANENT||2001-04-01 00:00:00|2001-07-01 00:00:00|1|200|200|200|200|0|0|0|120000|0|600|600 -#a_2@PERMANENT||2001-04-01 00:00:00|2001-07-01 00:00:00|2|200|200|200|200|0|0|0|336000|0|1680|1680 -#a_2@PERMANENT||2001-04-01 00:00:00|2001-07-01 00:00:00|3|200|200|200|200|0|0|0|1464000|0|7320|7320 -#a_3@PERMANENT||2001-07-01 00:00:00|2001-10-01 00:00:00|1|300|300|300|300|0|0|0|180000|0|600|600 -#a_3@PERMANENT||2001-07-01 00:00:00|2001-10-01 00:00:00|2|300|300|300|300|0|0|0|504000|0|1680|1680 -#a_3@PERMANENT||2001-07-01 00:00:00|2001-10-01 00:00:00|3|300|300|300|300|0|0|0|2196000|0|7320|7320 -#a_4@PERMANENT||2001-10-01 00:00:00|2002-01-01 00:00:00|1|400|400|400|400|0|0|0|240000|0|600|600 -#a_4@PERMANENT||2001-10-01 00:00:00|2002-01-01 00:00:00|2|400|400|400|400|0|0|0|672000|0|1680|1680 -#a_4@PERMANENT||2001-10-01 00:00:00|2002-01-01 00:00:00|3|400|400|400|400|0|0|0|2928000|0|7320|7320 -#""" - - #for ref, res in zip( - #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") - #): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - #def test_with_semantic_label(self): - #"""Test semantic labels""" - #t_rast_univar = SimpleModule( - #"t.rast.univar", - #input="B.S2_B1", - #where="start_time >= '2001-01-01'", - #overwrite=True, - #verbose=True, - #) - #self.runModule("g.region", res=1) - #self.assertModule(t_rast_univar) - - #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#b_1@PERMANENT|S2_B1|2001-01-01 00:00:00|2001-04-01 00:00:00|110|110|110|110|0|0|0|1056000|0|9600|9600 -#b_2@PERMANENT|S2_B1|2001-04-01 00:00:00|2001-07-01 00:00:00|220|220|220|220|0|0|0|2112000|0|9600|9600 -#b_3@PERMANENT|S2_B1|2001-07-01 00:00:00|2001-10-01 00:00:00|330|330|330|330|0|0|0|3168000|0|9600|9600 -#b_4@PERMANENT|S2_B1|2001-10-01 00:00:00|2002-01-01 00:00:00|440|440|440|440|0|0|0|4224000|0|9600|9600 -#""" - #for ref, res in zip( - #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") - #): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - #def test_with_semantic_label_parallel(self): - #"""Test semantic labels""" - #t_rast_univar = SimpleModule( - #"t.rast.univar", - #input="B.S2_B1", - #where="start_time >= '2001-01-01'", - #nprocs=2, - #overwrite=True, - #verbose=True, - #) - #self.runModule("g.region", res=1) - #self.assertModule(t_rast_univar) - - #univar_text = """id|semantic_label|start|end|mean|min|max|mean_of_abs|stddev|variance|coeff_var|sum|null_cells|cells|non_null_cells -#b_1@PERMANENT|S2_B1|2001-01-01 00:00:00|2001-04-01 00:00:00|110|110|110|110|0|0|0|1056000|0|9600|9600 -#b_2@PERMANENT|S2_B1|2001-04-01 00:00:00|2001-07-01 00:00:00|220|220|220|220|0|0|0|2112000|0|9600|9600 -#b_3@PERMANENT|S2_B1|2001-07-01 00:00:00|2001-10-01 00:00:00|330|330|330|330|0|0|0|3168000|0|9600|9600 -#b_4@PERMANENT|S2_B1|2001-10-01 00:00:00|2002-01-01 00:00:00|440|440|440|440|0|0|0|4224000|0|9600|9600 -#""" - #for ref, res in zip( - #univar_text.split("\n"), t_rast_univar.outputs.stdout.split("\n") - #): - #if ref and res: - #ref_line = ref.split("|", 1)[1] - #res_line = res.split("|", 1)[1] - #self.assertLooksLike(ref_line, res_line) - - -if __name__ == "__main__": - from grass.gunittest.main import test - - test() From c521277a4c4b29affcf84f5d14c66ec67ab9cf55 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Thu, 2 Mar 2023 00:08:41 +0100 Subject: [PATCH 09/21] fail early if map is not found --- python/grass/temporal/register.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index 55dd7337300..d9601dea13b 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -165,12 +165,18 @@ def register_maps_in_space_time_dataset( for count in range(len(maplist)): row = {} mapname = maplist[count] - map_mapset = mapset if "@" not in mapname: - found = gscript.find_file(element=element, name=mapname) - if found["mapset"]: - map_mapset = found["mapset"] - row["id"] = AbstractMapDataset.build_id(mapname, map_mapset, None) + result = gscript.find_file(element=element, name=mapname) + if result["mapset"]: + row["id"] = AbstractMapDataset.build_id( + mapname, result["mapset"], None + ) + else: + gscript.fatal( + _("{type} map <{mapname}> not found on search path").format( + type=type, mapname=mapname + ) + ) else: row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2], None) maplist[count] = row @@ -229,12 +235,16 @@ def register_maps_in_space_time_dataset( # case-sensitive, the user decides on the band name row["semantic_label"] = line_list[idx].strip() - map_mapset = mapset if "@" not in mapname: - found = gscript.find_file(element=element, name=mapname) - if found["mapset"]: - map_mapset = found["mapset"] - row["id"] = AbstractMapDataset.build_id(mapname, map_mapset) + result = gscript.find_file(element=element, name=mapname) + if result["mapset"]: + row["id"] = AbstractMapDataset.build_id(mapname, result["mapset"]) + else: + gscript.fatal( + _("{type} map <{mapname}> not found on search path").format( + type=type, mapname=mapname + ) + ) else: row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2]) maplist.append(row) From 8d736bbfd8685702ac025aab9c2fa1c79b651ef3 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Thu, 2 Mar 2023 00:10:06 +0100 Subject: [PATCH 10/21] check register result --- .../testsuite/test_t_register_raster_file.py | 175 ++++++++++++++++-- 1 file changed, 161 insertions(+), 14 deletions(-) diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.py b/temporal/t.register/testsuite/test_t_register_raster_file.py index 4f5ef76cdcd..ac826a126b5 100755 --- a/temporal/t.register/testsuite/test_t_register_raster_file.py +++ b/temporal/t.register/testsuite/test_t_register_raster_file.py @@ -21,7 +21,10 @@ """ +from datetime import datetime + import grass.script as gs +import grass.temporal as tgis from grass.gunittest.case import TestCase from grass.gunittest.gmodules import SimpleModule @@ -31,6 +34,9 @@ class TestRasterUnivar(TestCase): @classmethod def setUpClass(cls): """Initiate the temporal GIS and set the region""" + + tgis.init() + # cls.mapset = gs.gisenv()["MAPSET"] cls.use_temp_region() cls.runModule( "g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3" @@ -89,8 +95,32 @@ def test_with_file_and_increment(self): ) self.assertModule(register_module) - # maplist = SimpleModule("t.rast.list", - # input="precip_abs8") + strds = tgis.open_old_stds("precip_abs8", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 6, 1)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "1 month") + + print(gs.read_command("t.info", type="strds", input="precip_abs8")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs8") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2001-02-01 00:00:00|None", + "prec_3|...|2001-03-01 00:00:00|None", + "prec_4|...|2001-04-01 00:00:00|None", + "prec_5|...|2001-05-01 00:00:00|None", + "prec_6|...|2001-06-01 00:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_file_and_no_increment(self): @@ -108,8 +138,78 @@ def test_with_file_and_no_increment(self): ) self.assertModule(register_module) - # t.info type=strds input=precip_abs8 - # t.rast.list input=precip_abs8 + strds = tgis.open_old_stds("precip_abs8", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 1, 1)) + self.assertEqual(strds.check_temporal_topology(), False) + self.assertEqual(strds.get_granularity(), None) + + print(gs.read_command("t.info", type="strds", input="precip_abs8")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs8") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2001-01-01 00:00:00|None", + "prec_3|...|2001-01-01 00:00:00|None", + "prec_4|...|2001-01-01 00:00:00|None", + "prec_5|...|2001-01-01 00:00:00|None", + "prec_6|...|2001-01-01 00:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_with_file_increment_and_intervall(self): + + tmp_file = gs.tempfile() + with open(tmp_file, "w") as register_file: + register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") + + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs8", + start="2001-01-01", + increment="1 months", + file=tmp_file, + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + print(gs.read_command("t.info", type="strds", input="precip_abs8")) + strds = tgis.open_old_stds("precip_abs8", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 7, 1)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "1 month") + + print(gs.read_command("t.info", type="strds", input="precip_abs8")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs8") + t_rast_list.run() + + # Check registered raster maps + ref_str = "\n".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2001-02-01 00:00:00", + "prec_2|...|2001-02-01 00:00:00|2001-03-01 00:00:00", + "prec_3|...|2001-03-01 00:00:00|2001-04-01 00:00:00", + "prec_4|...|2001-04-01 00:00:00|2001-05-01 00:00:00", + "prec_5|...|2001-05-01 00:00:00|2001-06-01 00:00:00", + "prec_6|...|2001-06-01 00:00:00|2001-07-01 00:00:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_start_in_file(self): @@ -137,8 +237,32 @@ def test_with_start_in_file(self): ) self.assertModule(register_module) - # t.info type=strds input=precip_abs8 - # t.rast.list input=precip_abs8 + strds = tgis.open_old_stds("precip_abs8", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 6, 1)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "1 month") + + print(gs.read_command("t.info", type="strds", input="precip_abs8")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs8") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2001-02-01 00:00:00|None", + "prec_3|...|2001-03-01 00:00:00|None", + "prec_4|...|2001-04-01 00:00:00|None", + "prec_5|...|2001-05-01 00:00:00|None", + "prec_6|...|2001-06-01 00:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_start_in_file_and_increment(self): @@ -167,8 +291,8 @@ def test_with_start_in_file_and_increment(self): ) self.assertModuleFail(register_module) - # t.info type=strds input=precip_abs8 - # t.rast.list input=precip_abs8 + # print(gs.read_command("t.info", type="strds", input="precip_abs8")) + # print(gs.read_command("t.rast.list", input="precip_abs8")) def test_with_start_and_end_in_file_and_interval(self): @@ -197,8 +321,8 @@ def test_with_start_and_end_in_file_and_interval(self): ) self.assertModuleFail(register_module) - # t.info type=strds input=precip_abs8 - # t.rast.list input=precip_abs8 + # print(gs.read_command("t.info", type="strds", input="precip_abs8")) + # print(gs.read_command("t.rast.list", input="precip_abs8")) def test_with_mapset_and_semantic_label(self): @@ -220,16 +344,39 @@ def test_with_mapset_and_semantic_label(self): register_module = SimpleModule( "t.register", - flags="i", input="precip_abs8", file=tmp_file, overwrite=True, verbose=True, ) - self.assertModuleFail(register_module) + self.assertModule(register_module) - # t.info type=strds input=precip_abs8 - # t.rast.list input=precip_abs8 + strds = tgis.open_old_stds("precip_abs8", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2002, 7, 1)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "3 months") + + print(gs.read_command("t.info", type="strds", input="precip_abs8")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs8") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2001-04-01 00:00:00", + "prec_2|...|2001-04-01 00:00:00|2001-07-01 00:00:00", + "prec_3|...|2001-07-01 00:00:00|2001-10-01 00:00:00", + "prec_4|...|2001-10-01 00:00:00|2002-01-01 00:00:00", + "prec_5|...|2002-01-01 00:00:00|2002-04-01 00:00:00", + "prec_6|...|2002-04-01 00:00:00|2002-07-01 00:00:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) if __name__ == "__main__": From 2dc70bb37a7da91e60a9d171c9cccb366bfd6ad3 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Thu, 2 Mar 2023 23:34:04 +0100 Subject: [PATCH 11/21] use function for mapid --- python/grass/temporal/register.py | 79 ++++++++++++++++++------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index d9601dea13b..a25d3c4bb8f 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -31,6 +31,44 @@ ############################################################################### +def build_abstract_map_dataset(map_item, element): + """Build AbstractMapDataset from map item and element type. + + :param map_item: The id of the map to build an abstract dataset for. + Can be of the form: mapname, mapname@mapsetname, or + mapname:layer / mapname:layer@mapsetname for vector + maps + :param element: The mapset element of the maps: cell, grid3d or vector + :return: ID String build with the AbstractMapDataset class + + .. code-block:: python + + >>> import grass.temporal as tgis + >>> tgis.register.build_abstract_map_dataset("vectormap:1@PERMANENT", "vector") + 'vectormap:1@PERMANENT' + >>> tgis.register.build_abstract_map_dataset("rastermap@PERMANENT", "cell") + 'rastermap@PERMANENT' + >>> tgis.register.build_abstract_map_dataset("raster3dmap@PERMANENT", "grid3d") + 'raster3dmap@PERMANENT' + + """ + map_name, map_mapset = ( + map_item.split("@")[0:2] if "@" in map_item else (map_item, None) + ) + map_name, map_layer = map_name.split(":") if ":" in map_name else (map_name, None) + if not map_mapset: + result = gscript.find_file(element=element, name=map_name) + if result["mapset"]: + map_mapset = result["mapset"] + else: + gscript.fatal( + _("{type} map <{map_name}> not found on search path").format( + type=type, map_name=map_name + ) + ) + return AbstractMapDataset.build_id(map_name, map_mapset, map_layer) + + def register_maps_in_space_time_dataset( type, name, @@ -162,24 +200,8 @@ def register_maps_in_space_time_dataset( maplist = maps.split(",") # Build the map list again with the ids - for count in range(len(maplist)): - row = {} - mapname = maplist[count] - if "@" not in mapname: - result = gscript.find_file(element=element, name=mapname) - if result["mapset"]: - row["id"] = AbstractMapDataset.build_id( - mapname, result["mapset"], None - ) - else: - gscript.fatal( - _("{type} map <{mapname}> not found on search path").format( - type=type, mapname=mapname - ) - ) - else: - row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2], None) - maplist[count] = row + for idx, maplist_item in enumerate(maplist): + maplist[idx] = {"id": build_abstract_map_dataset(maplist_item, element)} # Read the map list from file if file: @@ -223,30 +245,19 @@ def register_maps_in_space_time_dataset( mapname = line_list[0].strip() row = {} - if start_time_in_file and end_time_in_file: + if start_time_in_file: row["start"] = line_list[1].strip() - row["end"] = line_list[2].strip() - if start_time_in_file and not end_time_in_file: - row["start"] = line_list[1].strip() + if end_time_in_file: + row["end"] = line_list[2].strip() if semantic_label_in_file: idx = 3 if end_time_in_file else 2 # case-sensitive, the user decides on the band name row["semantic_label"] = line_list[idx].strip() - if "@" not in mapname: - result = gscript.find_file(element=element, name=mapname) - if result["mapset"]: - row["id"] = AbstractMapDataset.build_id(mapname, result["mapset"]) - else: - gscript.fatal( - _("{type} map <{mapname}> not found on search path").format( - type=type, mapname=mapname - ) - ) - else: - row["id"] = AbstractMapDataset.build_id(*mapname.split("@")[0:2]) + row["id"] = build_abstract_map_dataset(mapname, element) + maplist.append(row) if start_time_in_file is True and increment: From d7a06f8211a1e4d5ff995c84e8ba169c24436aa7 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 3 Mar 2023 00:33:26 +0100 Subject: [PATCH 12/21] move test to Python --- temporal/t.register/test.t.register.raster.sh | 128 ------------------ 1 file changed, 128 deletions(-) delete mode 100755 temporal/t.register/test.t.register.raster.sh diff --git a/temporal/t.register/test.t.register.raster.sh b/temporal/t.register/test.t.register.raster.sh deleted file mode 100755 index f27d133e9a7..00000000000 --- a/temporal/t.register/test.t.register.raster.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# This is a test to register and unregister raster maps in -# space time raster datasets. -# The raster maps will be registered in different space time raster -# datasets. - -export GRASS_OVERWRITE=1 - -# We need to set a specific region in the -# @preprocess step of this test. We generate -# raster with r.mapcalc and create several space time raster datasets -# with absolute time -# The region setting should work for UTM and LL test locations -g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3 - -# Generate data -r.mapcalc expr="prec_1 = rand(0, 550)" -s -r.mapcalc expr="prec_2 = rand(0, 450)" -s -r.mapcalc expr="prec_3 = rand(0, 320)" -s -r.mapcalc expr="prec_4 = rand(0, 510)" -s -r.mapcalc expr="prec_5 = rand(0, 300)" -s -r.mapcalc expr="prec_6 = rand(0, 650)" -s - -# The first @test -# We create the space time raster inputs and register the raster maps with absolute time interval - -t.create type=strds temporaltype=absolute output=precip_abs1 title="A test" descr="A test" -t.create type=strds temporaltype=absolute output=precip_abs2 title="A test" descr="A test" -t.create type=strds temporaltype=absolute output=precip_abs3 title="A test" descr="A test" -t.create type=strds temporaltype=absolute output=precip_abs4 title="A test" descr="A test" -t.create type=strds temporaltype=absolute output=precip_abs5 title="A test" descr="A test" -t.create type=strds temporaltype=absolute output=precip_abs6 title="A test" descr="A test" -t.create type=strds temporaltype=absolute output=precip_abs7 title="A test" descr="A test" - -t.register -i input=precip_abs1 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 seconds" -t.info type=strds input=precip_abs1 -t.info -g type=strds input=precip_abs1 -r.info map=prec_1 -t.rast.list input=precip_abs1 -t.topology input=precip_abs1 - -t.register -i input=precip_abs2 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 seconds, 5 minutes" -t.info type=strds input=precip_abs2 -t.info -g type=strds input=precip_abs2 -r.info map=prec_1 -t.rast.list input=precip_abs2 -t.topology input=precip_abs2 - -t.register -i input=precip_abs3 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="8 hours" -t.info -g type=strds input=precip_abs3 -r.info map=prec_1 -t.rast.list input=precip_abs3 -t.topology input=precip_abs3 - -t.register input=precip_abs4 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="3 days" -t.info -g type=strds input=precip_abs4 -r.info map=prec_1 -t.rast.list input=precip_abs4 -t.topology input=precip_abs4 - -t.register input=precip_abs5 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="4 weeks" -t.info -g type=strds input=precip_abs5 -r.info map=prec_1 -t.rast.list input=precip_abs5 -t.topology input=precip_abs5 - -t.register input=precip_abs6 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-08-01" increment="2 months" -t.info -g type=strds input=precip_abs6 -r.info map=prec_1 -t.rast.list input=precip_abs6 -t.topology input=precip_abs6 - -t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 years, 3 months, 1 days, 4 hours" -t.info -g type=strds input=precip_abs7 -r.info map=prec_1 -t.rast.list input=precip_abs7 -t.topology input=precip_abs7 -# Register with different valid time again -t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours" -t.info -g type=strds input=precip_abs7 -r.info map=prec_1 -t.rast.list input=precip_abs7 -t.topology input=precip_abs7 -# Register with different valid time again creating an interval -t.register -i input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours" -t.info -g type=strds input=precip_abs7 -r.info map=prec_1 -t.rast.list input=precip_abs7 -t.topology input=precip_abs7 - -t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" end="2002-01-01" -t.info -g type=strds input=precip_abs7 -r.info map=prec_1 -t.rast.list input=precip_abs7 -t.topology input=precip_abs7 - -# Check for correct errors -# Increment format error -t.register -i input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="months" - -# Check UnicodeDecodeError -LANG=fr_BE \ -LANGUAGE=fr_BE \ -LC_CTYPE=fr_BE.UTF-8 \ -LC_NUMERIC=C \ -LC_TIME=fr_BE.UTF-8 \ -LC_COLLATE=fr_BE.UTF-8 \ -LC_MONETARY=fr_BE.UTF-8 \ -LC_MESSAGES=fr_BE.UTF-8 \ -LC_PAPER=fr_BE.UTF-8 \ -LC_NAME=fr_BE.UTF-8 \ -LC_ADDRESS=fr_BE.UTF-8 \ -LC_TELEPHONE=fr_BE.UTF-8 \ -LC_MEASUREMENT=fr_BE.UTF-8 \ -LC_IDENTIFICATION=fr_BE.UTF-8 \ -LC_ALL="" \ -t.create output=pluies_nc semantictype=sum title=precipitation_mois description="Précipitation totale mensuelle NC" --o -t.register -i input=pluies_nc type=raster start=2000-01-01 increment="1 months" maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 --o -t.info pluies_nc -t.topology pluies_nc -t.remove -f pluies_nc - -t.unregister type=raster maps=prec_1,prec_2,prec_3 -# Test the warning message -t.unregister type=raster maps=prec_1,prec_2,prec_3 -t.remove type=strds input=precip_abs1,precip_abs2,precip_abs3,precip_abs4,precip_abs5,precip_abs6,precip_abs7 -t.unregister type=raster maps=prec_4,prec_5,prec_6 -r.info map=prec_1 From b5c478d714077e31a5a481bb52fac78f10ec08d9 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 3 Mar 2023 00:35:04 +0100 Subject: [PATCH 13/21] port test to Python --- temporal/t.register/testsuite/test_t_register_raster.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 temporal/t.register/testsuite/test_t_register_raster.py diff --git a/temporal/t.register/testsuite/test_t_register_raster.py b/temporal/t.register/testsuite/test_t_register_raster.py new file mode 100755 index 00000000000..e69de29bb2d From 3f0f1859261d04e0d5a9c41f8eb96f73161e3afe Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 5 Mar 2023 13:56:51 +0100 Subject: [PATCH 14/21] check semantic labels --- temporal/t.register/testsuite/test_t_register_raster_file.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.py b/temporal/t.register/testsuite/test_t_register_raster_file.py index ac826a126b5..a578b959a62 100755 --- a/temporal/t.register/testsuite/test_t_register_raster_file.py +++ b/temporal/t.register/testsuite/test_t_register_raster_file.py @@ -359,6 +359,8 @@ def test_with_mapset_and_semantic_label(self): self.assertEqual(end, datetime(2002, 7, 1)) self.assertEqual(strds.check_temporal_topology(), True) self.assertEqual(strds.get_granularity(), "3 months") + self.assertEqual(strds.metadata.get_number_of_semantic_labels(), 1) + self.assertEqual(strds.metadata.get_semantic_labels(), "semantic_label") print(gs.read_command("t.info", type="strds", input="precip_abs8")) t_rast_list = SimpleModule("t.rast.list", input="precip_abs8") From 5c89a604cce9bcb857a337c8236fe5648c7d3707 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 5 Mar 2023 13:58:56 +0100 Subject: [PATCH 15/21] split tests --- .../test_t_register_raster_different_local.py | 151 ++++++++++++++++++ .../test_t_register_raster_mapmetadata.py | 142 ++++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 temporal/t.register/testsuite/test_t_register_raster_different_local.py create mode 100644 temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py diff --git a/temporal/t.register/testsuite/test_t_register_raster_different_local.py b/temporal/t.register/testsuite/test_t_register_raster_different_local.py new file mode 100644 index 00000000000..5bd40f87b3d --- /dev/null +++ b/temporal/t.register/testsuite/test_t_register_raster_different_local.py @@ -0,0 +1,151 @@ +"""Test t.register + +(C) 2014-2023 by the GRASS Development Team +This program is free software under the GNU General Public +License (>=v2). Read the file COPYING that comes with GRASS +for details. + +@author Soeren Gebbert + Ported to Python by Stefan Blumentrath + +This is a test to register and unregister raster maps in +space time raster input. +The raster maps will be registered in different space time raster +inputs + +We need to set a specific region in the +@preprocess step of this test. We generate +raster with r.mapcalc and create two space time raster inputs +with absolute time +The region setting should work for UTM and LL test locations + +""" + +import os +from datetime import datetime + +import grass.script as gs +import grass.temporal as tgis + +from grass.gunittest.case import TestCase +from grass.gunittest.gmodules import SimpleModule + + +class TestRasterUnivar(TestCase): + @classmethod + def setUpClass(cls): + """Initiate the temporal GIS and set the region""" + + # Check UnicodeDecodeError + os.environ["LANG"] = "fr_BE" + os.environ["LANGUAGE"] = "fr_BE" + os.environ["LC_CTYPE"] = "fr_BE.UTF-8" + os.environ["LC_NUMERIC"] = "C" + os.environ["LC_TIME"] = "fr_BE.UTF-8" + os.environ["LC_COLLATE"] = "fr_BE.UTF-8" + os.environ["LC_MONETARY"] = "fr_BE.UTF-8" + os.environ["LC_MESSAGES"] = "fr_BE.UTF-8" + os.environ["LC_PAPER"] = "fr_BE.UTF-8" + os.environ["LC_NAME"] = "fr_BE.UTF-8" + os.environ["LC_ADDRESS"] = "fr_BE.UTF-8" + os.environ["LC_TELEPHONE"] = "fr_BE.UTF-8" + os.environ["LC_MEASUREMENT"] = "fr_BE.UTF-8" + os.environ["LC_IDENTIFICATION"] = "fr_BE.UTF-8" + os.environ["LC_ALL"] = "" + + tgis.init() + # cls.mapset = gs.gisenv()["MAPSET"] + cls.use_temp_region() + cls.runModule( + "g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3" + ) + + for raster_map_id, parameters in enumerate( + [ + (550, "2001-01-01 00:00:00|2001-01-01 08:00:00"), + (450, "2001-01-01 08:00:00|2001-01-01 16:00:00"), + (320, "2001-01-01 16:00:00|2001-01-02 00:00:00"), + (510, "2001-01-02 00:00:00|2001-01-02 08:00:00"), + (300, "2001-01-02 08:00:00|2001-01-02 16:00:00"), + (650, "2001-01-02 16:00:00|2001-01-03 00:00:00"), + ] + ): + # Generate data + cls.runModule( + "r.mapcalc", + flags="s", + expression=f"prec_{raster_map_id + 1} = rand(0, {parameters[0]})", + overwrite=True, + ) + cls.runModule( + "r.support", + map=f"prec_{raster_map_id + 1}", + # Note: Non-ascii characters in semantic labels lead to decode error + # semantic_label="Précipitation_totale", + semantic_label="semantic_label", + ) + + cls.runModule( + "t.create", + output="pluies_nc", + semantictype="sum", + title="precipitation_mois", + description="Précipitation totale mensuelle NC", + overwrite=True, + ) + + @classmethod + def tearDownClass(cls): + """Remove the temporary region""" + cls.runModule("t.remove", flags="df", type="strds", inputs="pluies_nc") + cls.del_temp_region() + + def test_with_different_local(self): + + register_module = SimpleModule( + "t.register", + flags="i", + input="pluies_nc", + type="raster", + start="2000-01-01", + increment="1 months", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + overwrite=True, + ) + # t.info pluies_nc + # t.topology pluies_nc + # t.remove -f pluies_nc + self.assertModule(register_module) + + strds = tgis.open_old_stds("pluies_nc", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2000, 1, 1)) + self.assertEqual(end, datetime(2000, 7, 1)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "1 month") + + print(gs.read_command("t.info", type="strds", input="pluies_nc")) + t_rast_list = SimpleModule("t.rast.list", input="pluies_nc") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2000-01-01 00:00:00|2000-02-01 00:00:00", + "prec_2|...|2000-02-01 00:00:00|2000-03-01 00:00:00", + "prec_3|...|2000-03-01 00:00:00|2000-04-01 00:00:00", + "prec_4|...|2000-04-01 00:00:00|2000-05-01 00:00:00", + "prec_5|...|2000-05-01 00:00:00|2000-06-01 00:00:00", + "prec_6|...|2000-06-01 00:00:00|2000-07-01 00:00:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + +if __name__ == "__main__": + from grass.gunittest.main import test + + test() diff --git a/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py b/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py new file mode 100644 index 00000000000..32d7dd20580 --- /dev/null +++ b/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py @@ -0,0 +1,142 @@ +"""Test t.register + +(C) 2014-2023 by the GRASS Development Team +This program is free software under the GNU General Public +License (>=v2). Read the file COPYING that comes with GRASS +for details. + +@author Soeren Gebbert + Ported to Python by Stefan Blumentrath + +This is a test to register and unregister raster maps in +space time raster input. +The raster maps will be registered in different space time raster +inputs + +We need to set a specific region in the +@preprocess step of this test. We generate +raster with r.mapcalc and create two space time raster inputs +with absolute time +The region setting should work for UTM and LL test locations + +""" + +from datetime import datetime + +import grass.script as gs +import grass.temporal as tgis + +from grass.gunittest.case import TestCase +from grass.gunittest.gmodules import SimpleModule +from grass.temporal.datetime_math import ( + datetime_to_grass_datetime_string as datetime_to_grass, +) + + +class TestRasterUnivar(TestCase): + @classmethod + def setUpClass(cls): + """Initiate the temporal GIS and set the region""" + + tgis.init() + # cls.mapset = gs.gisenv()["MAPSET"] + cls.use_temp_region() + cls.runModule( + "g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3" + ) + + for raster_map_id, parameters in enumerate( + [ + (550, "2001-01-01 00:00:00|2001-01-01 08:00:00"), + (450, "2001-01-01 08:00:00|2001-01-01 16:00:00"), + (320, "2001-01-01 16:00:00|2001-01-02 00:00:00"), + (510, "2001-01-02 00:00:00|2001-01-02 08:00:00"), + (300, "2001-01-02 08:00:00|2001-01-02 16:00:00"), + (650, "2001-01-02 16:00:00|2001-01-03 00:00:00"), + ] + ): + # Generate data + cls.runModule( + "r.mapcalc", + flags="s", + expression=f"prec_{raster_map_id + 1} = rand(0, {parameters[0]})", + overwrite=True, + ) + cls.runModule( + "r.timestamp", + map=f"prec_{raster_map_id + 1}", + date="/".join( + [ + datetime_to_grass(datetime.fromisoformat(ts)) + for ts in parameters[1].split("|") + ] + ), + ) + cls.runModule( + "r.support", + map=f"prec_{raster_map_id + 1}", + semantic_label="semantic_label", + ) + + cls.runModule( + "t.create", + type="strds", + temporaltype="absolute", + output="precip_abs1", + title="A test", + description="A test", + overwrite=True, + ) + + @classmethod + def tearDownClass(cls): + """Remove the temporary region""" + cls.runModule("t.remove", flags="df", type="strds", inputs="precip_abs1") + cls.del_temp_region() + + def test_register_metadata_from_file(self): + + register_module = SimpleModule( + "t.register", + input="precip_abs1", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + print(gs.read_command("t.info", type="strds", input="precip_abs1")) + strds = tgis.open_old_stds("precip_abs1", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 1, 3)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "8 hours") + self.assertEqual(strds.metadata.get_number_of_semantic_labels(), 1) + self.assertEqual(strds.metadata.get_semantic_labels(), "semantic_label") + + print(gs.read_command("t.info", type="strds", input="precip_abs1")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs1") + t_rast_list.run() + + # Check registered raster maps + ref_str = "\n".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2001-01-01 08:00:00", + "prec_2|...|2001-01-01 08:00:00|2001-01-01 16:00:00", + "prec_3|...|2001-01-01 16:00:00|2001-01-02 00:00:00", + "prec_4|...|2001-01-02 00:00:00|2001-01-02 08:00:00", + "prec_5|...|2001-01-02 08:00:00|2001-01-02 16:00:00", + "prec_6|...|2001-01-02 16:00:00|2001-01-03 00:00:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + +if __name__ == "__main__": + from grass.gunittest.main import test + + test() From 4195f9822cd3db7f01d0df025a44b9e2a43afa10 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 5 Mar 2023 14:01:28 +0100 Subject: [PATCH 16/21] update --- .../testsuite/test_t_register_raster.py | 470 ++++++++++++++++++ 1 file changed, 470 insertions(+) diff --git a/temporal/t.register/testsuite/test_t_register_raster.py b/temporal/t.register/testsuite/test_t_register_raster.py index e69de29bb2d..deed8c7a3af 100755 --- a/temporal/t.register/testsuite/test_t_register_raster.py +++ b/temporal/t.register/testsuite/test_t_register_raster.py @@ -0,0 +1,470 @@ +"""Test t.register + +(C) 2014-2023 by the GRASS Development Team +This program is free software under the GNU General Public +License (>=v2). Read the file COPYING that comes with GRASS +for details. + +@author Soeren Gebbert + Ported to Python by Stefan Blumentrath + +This is a test to register and unregister raster maps in +space time raster input. +The raster maps will be registered in different space time raster +inputs + +We need to set a specific region in the +@preprocess step of this test. We generate +raster with r.mapcalc and create two space time raster inputs +with absolute time +The region setting should work for UTM and LL test locations + +""" + +from datetime import datetime + +import grass.script as gs +import grass.temporal as tgis + +from grass.gunittest.case import TestCase +from grass.gunittest.gmodules import SimpleModule + + +class TestRasterUnivar(TestCase): + @classmethod + def setUpClass(cls): + """Initiate the temporal GIS and set the region""" + + tgis.init() + # cls.mapset = gs.gisenv()["MAPSET"] + cls.use_temp_region() + cls.runModule( + "g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10, flags="p3" + ) + + # Generate data + cls.runModule( + "r.mapcalc", flags="s", expression="prec_1 = rand(0, 550)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_2 = rand(0, 450)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_3 = rand(0, 320)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_4 = rand(0, 510)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_5 = rand(0, 300)", overwrite=True + ) + cls.runModule( + "r.mapcalc", flags="s", expression="prec_6 = rand(0, 650)", overwrite=True + ) + + for strds_id in range(1, 9): + cls.runModule( + "t.create", + type="strds", + temporaltype="absolute", + output=f"precip_abs{strds_id}", + title="A test", + description="A test", + overwrite=True, + ) + + @classmethod + def tearDownClass(cls): + """Remove the temporary region""" + stds = gs.read_command("t.list") + for strds_id in range(1, 9): + if f"precip_abs{strds_id}" in stds: + cls.runModule( + "t.remove", flags="df", type="strds", inputs=f"precip_abs{strds_id}" + ) + cls.del_temp_region() + + def test_with_second_increment_and_intervall(self): + + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs1", + start="2001-01-01", + increment="1 seconds", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs1", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1, 0, 0, 0)) + self.assertEqual(end, datetime(2001, 1, 1, 0, 0, 6)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "1 second") + + print(gs.read_command("t.info", type="strds", input="precip_abs1")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs1") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2001-01-01 00:00:01", + "prec_2|...|2001-01-01 00:00:01|2001-01-01 00:00:02", + "prec_3|...|2001-01-01 00:00:02|2001-01-01 00:00:03", + "prec_4|...|2001-01-01 00:00:03|2001-01-01 00:00:04", + "prec_5|...|2001-01-01 00:00:04|2001-01-01 00:00:05", + "prec_6|...|2001-01-01 00:00:05|2001-01-01 00:00:06", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_with_minutes_seconds_increment_and_intervall(self): + + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs2", + start="2001-01-01", + increment="20 seconds, 5 minutes", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs2", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 1, 1, 0, 32)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "320 seconds") + + print(gs.read_command("t.info", type="strds", input="precip_abs2")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs2") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2001-01-01 00:05:20", + "prec_2|...|2001-01-01 00:05:20|2001-01-01 00:10:40", + "prec_3|...|2001-01-01 00:10:40|2001-01-01 00:16:00", + "prec_4|...|2001-01-01 00:16:00|2001-01-01 00:21:20", + "prec_5|...|2001-01-01 00:21:20|2001-01-01 00:26:40", + "prec_6|...|2001-01-01 00:26:40|2001-01-01 00:32:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_with_hours_increment_and_intervall(self): + + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs3", + start="2001-01-01", + increment="8 hours", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + print(gs.read_command("t.info", type="strds", input="precip_abs3")) + strds = tgis.open_old_stds("precip_abs3", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 1, 3)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "8 hours") + + print(gs.read_command("t.info", type="strds", input="precip_abs3")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs3") + t_rast_list.run() + + # Check registered raster maps + ref_str = "\n".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2001-01-01 08:00:00", + "prec_2|...|2001-01-01 08:00:00|2001-01-01 16:00:00", + "prec_3|...|2001-01-01 16:00:00|2001-01-02 00:00:00", + "prec_4|...|2001-01-02 00:00:00|2001-01-02 08:00:00", + "prec_5|...|2001-01-02 08:00:00|2001-01-02 16:00:00", + "prec_6|...|2001-01-02 16:00:00|2001-01-03 00:00:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_with_days_increment_and_no_intervall(self): + + register_module = SimpleModule( + "t.register", + input="precip_abs4", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + start="2001-01-01", + increment="3 days", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs4", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 1, 16)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "3 days") + + print(gs.read_command("t.info", type="strds", input="precip_abs4")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs4") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2001-01-04 00:00:00|None", + "prec_3|...|2001-01-07 00:00:00|None", + "prec_4|...|2001-01-10 00:00:00|None", + "prec_5|...|2001-01-13 00:00:00|None", + "prec_6|...|2001-01-16 00:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_with_weeks_increment_and_no_intervall(self): + + register_module = SimpleModule( + "t.register", + input="precip_abs5", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + start="2001-01-01", + increment="4 weeks", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs5", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2001, 5, 21)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "28 days") + + print(gs.read_command("t.info", type="strds", input="precip_abs5")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs5") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2001-01-29 00:00:00|None", + "prec_3|...|2001-02-26 00:00:00|None", + "prec_4|...|2001-03-26 00:00:00|None", + "prec_5|...|2001-04-23 00:00:00|None", + "prec_6|...|2001-05-21 00:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_with_months_increment_and_no_intervall(self): + + register_module = SimpleModule( + "t.register", + input="precip_abs6", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + start="2001-08-01", + increment="2 months", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs6", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 8, 1)) + self.assertEqual(end, datetime(2002, 6, 1)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "2 months") + + print(gs.read_command("t.info", type="strds", input="precip_abs6")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs6") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-08-01 00:00:00|None", + "prec_2|...|2001-10-01 00:00:00|None", + "prec_3|...|2001-12-01 00:00:00|None", + "prec_4|...|2002-02-01 00:00:00|None", + "prec_5|...|2002-04-01 00:00:00|None", + "prec_6|...|2002-06-01 00:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + def test_re_registering(self): + + # t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 years, 3 months, 1 days, 4 hours" + # t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours" + # t.register -i input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours" + # t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" end="2002-01-01" + register_module = SimpleModule( + "t.register", + input="precip_abs7", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + start="2001-01-01", + increment="20 years, 3 months, 1 days, 4 hours", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs7", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2102, 4, 6, 20, 0)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "4 hours") + + print(gs.read_command("t.info", type="strds", input="precip_abs7")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs7") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2021-04-02 04:00:00|None", + "prec_3|...|2041-07-03 08:00:00|None", + "prec_4|...|2061-10-04 12:00:00|None", + "prec_5|...|2082-01-05 16:00:00|None", + "prec_6|...|2102-04-06 20:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + # Register with different valid time again + register_module = SimpleModule( + "t.register", + input="precip_abs7", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + start="2001-01-01", + increment="99 years, 9 months, 9 days, 9 hours", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs7", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2499, 11, 16, 21, 0)) + self.assertEqual(strds.check_temporal_topology(), True) + self.assertEqual(strds.get_granularity(), "3 hours") + + # Check raster map metadata (time stamp) + self.assertRasterFitsInfo( + raster="prec_3", + reference='timestamp="19 Jul 2200 18:00:00"', + ) + + print(gs.read_command("t.info", type="strds", input="precip_abs7")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs7") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|None", + "prec_2|...|2100-10-10 09:00:00|None", + "prec_3|...|2200-07-19 18:00:00|None", + "prec_4|...|2300-04-29 03:00:00|None", + "prec_5|...|2400-02-07 12:00:00|None", + "prec_6|...|2499-11-16 21:00:00|None", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + # Register with different valid time again creating an interval + register_module = SimpleModule( + "t.register", + flags="i", + input="precip_abs7", + maps="prec_1,prec_2,prec_3,prec_4,prec_5,prec_6", + start="2001-01-01", + increment="99 years, 9 months, 9 days, 9 hours", + overwrite=True, + verbose=True, + ) + self.assertModule(register_module) + + strds = tgis.open_old_stds("precip_abs7", type="strds") + + self.assertEqual(strds.metadata.get_number_of_maps(), 6) + start, end = strds.get_absolute_time() + self.assertEqual(start, datetime(2001, 1, 1)) + self.assertEqual(end, datetime(2599, 8, 26, 6, 0)) + self.assertEqual(strds.check_temporal_topology(), False) + self.assertEqual(strds.get_granularity(), "3 hours") + + # Check raster map metadata (time stamp) + self.assertRasterFitsInfo( + raster="prec_3", + reference='timestamp="19 Jul 2200 18:00:00 / 29 Apr 2300 03:00:00"', + ) + + print(gs.read_command("t.info", type="strds", input="precip_abs7")) + t_rast_list = SimpleModule("t.rast.list", input="precip_abs7") + t_rast_list.run() + + # Check registered raster maps + ref_str = "...".join( + [ + "name|mapset|start_time|end_time", + "prec_1|...|2001-01-01 00:00:00|2100-10-10 09:00:00", + "prec_2|...|2100-10-10 09:00:00|2200-07-19 18:00:00", + "prec_3|...|2200-07-19 18:00:00|2300-04-29 03:00:00", + "prec_4|...|2300-04-29 03:00:00|2400-02-07 12:00:00", + "prec_5|...|2400-02-07 12:00:00|2499-11-17 21:00:00", + "prec_6|...|2499-11-16 21:00:00|2599-08-26 06:00:00", + ] + ) + self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) + + +if __name__ == "__main__": + from grass.gunittest.main import test + + test() From 9f4f9c9657e4ecaffec0eaa646fa980e5f491093 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 5 Mar 2023 16:28:52 +0100 Subject: [PATCH 17/21] black 23 --- temporal/t.register/testsuite/test_t_register_raster.py | 7 ------- .../testsuite/test_t_register_raster_different_local.py | 1 - .../t.register/testsuite/test_t_register_raster_file.py | 7 ------- .../testsuite/test_t_register_raster_mapmetadata.py | 1 - 4 files changed, 16 deletions(-) diff --git a/temporal/t.register/testsuite/test_t_register_raster.py b/temporal/t.register/testsuite/test_t_register_raster.py index deed8c7a3af..e78df797df4 100755 --- a/temporal/t.register/testsuite/test_t_register_raster.py +++ b/temporal/t.register/testsuite/test_t_register_raster.py @@ -85,7 +85,6 @@ def tearDownClass(cls): cls.del_temp_region() def test_with_second_increment_and_intervall(self): - register_module = SimpleModule( "t.register", flags="i", @@ -126,7 +125,6 @@ def test_with_second_increment_and_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_minutes_seconds_increment_and_intervall(self): - register_module = SimpleModule( "t.register", flags="i", @@ -167,7 +165,6 @@ def test_with_minutes_seconds_increment_and_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_hours_increment_and_intervall(self): - register_module = SimpleModule( "t.register", flags="i", @@ -209,7 +206,6 @@ def test_with_hours_increment_and_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_days_increment_and_no_intervall(self): - register_module = SimpleModule( "t.register", input="precip_abs4", @@ -249,7 +245,6 @@ def test_with_days_increment_and_no_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_weeks_increment_and_no_intervall(self): - register_module = SimpleModule( "t.register", input="precip_abs5", @@ -289,7 +284,6 @@ def test_with_weeks_increment_and_no_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_months_increment_and_no_intervall(self): - register_module = SimpleModule( "t.register", input="precip_abs6", @@ -329,7 +323,6 @@ def test_with_months_increment_and_no_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_re_registering(self): - # t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="20 years, 3 months, 1 days, 4 hours" # t.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours" # t.register -i input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="99 years, 9 months, 9 days, 9 hours" diff --git a/temporal/t.register/testsuite/test_t_register_raster_different_local.py b/temporal/t.register/testsuite/test_t_register_raster_different_local.py index 5bd40f87b3d..cc3c8dc7d23 100644 --- a/temporal/t.register/testsuite/test_t_register_raster_different_local.py +++ b/temporal/t.register/testsuite/test_t_register_raster_different_local.py @@ -101,7 +101,6 @@ def tearDownClass(cls): cls.del_temp_region() def test_with_different_local(self): - register_module = SimpleModule( "t.register", flags="i", diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.py b/temporal/t.register/testsuite/test_t_register_raster_file.py index a578b959a62..b49bc1c3511 100755 --- a/temporal/t.register/testsuite/test_t_register_raster_file.py +++ b/temporal/t.register/testsuite/test_t_register_raster_file.py @@ -79,7 +79,6 @@ def tearDownClass(cls): cls.del_temp_region() def test_with_file_and_increment(self): - tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") @@ -123,7 +122,6 @@ def test_with_file_and_increment(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_file_and_no_increment(self): - tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") @@ -166,7 +164,6 @@ def test_with_file_and_no_increment(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_file_increment_and_intervall(self): - tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: register_file.write("prec_1\nprec_2\nprec_3\nprec_4\nprec_5\nprec_6") @@ -212,7 +209,6 @@ def test_with_file_increment_and_intervall(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_start_in_file(self): - tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: register_file.write( @@ -265,7 +261,6 @@ def test_with_start_in_file(self): self.assertLooksLike(str(t_rast_list.outputs.stdout), ref_str) def test_with_start_in_file_and_increment(self): - tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: register_file.write( @@ -295,7 +290,6 @@ def test_with_start_in_file_and_increment(self): # print(gs.read_command("t.rast.list", input="precip_abs8")) def test_with_start_and_end_in_file_and_interval(self): - tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: register_file.write( @@ -325,7 +319,6 @@ def test_with_start_and_end_in_file_and_interval(self): # print(gs.read_command("t.rast.list", input="precip_abs8")) def test_with_mapset_and_semantic_label(self): - mapset = gs.gisenv()["MAPSET"] tmp_file = gs.tempfile() with open(tmp_file, "w") as register_file: diff --git a/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py b/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py index 32d7dd20580..2c1fb510d80 100644 --- a/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py +++ b/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py @@ -95,7 +95,6 @@ def tearDownClass(cls): cls.del_temp_region() def test_register_metadata_from_file(self): - register_module = SimpleModule( "t.register", input="precip_abs1", From f5bbab7bbd96403761fd6de8e9015954c0bf927c Mon Sep 17 00:00:00 2001 From: ninsbl Date: Sun, 12 Mar 2023 00:11:14 +0100 Subject: [PATCH 18/21] rename classes --- temporal/t.register/testsuite/test_t_register_raster.py | 2 +- .../testsuite/test_t_register_raster_different_local.py | 2 +- temporal/t.register/testsuite/test_t_register_raster_file.py | 2 +- .../t.register/testsuite/test_t_register_raster_mapmetadata.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/temporal/t.register/testsuite/test_t_register_raster.py b/temporal/t.register/testsuite/test_t_register_raster.py index e78df797df4..12522ce062b 100755 --- a/temporal/t.register/testsuite/test_t_register_raster.py +++ b/temporal/t.register/testsuite/test_t_register_raster.py @@ -30,7 +30,7 @@ from grass.gunittest.gmodules import SimpleModule -class TestRasterUnivar(TestCase): +class TestRegister(TestCase): @classmethod def setUpClass(cls): """Initiate the temporal GIS and set the region""" diff --git a/temporal/t.register/testsuite/test_t_register_raster_different_local.py b/temporal/t.register/testsuite/test_t_register_raster_different_local.py index cc3c8dc7d23..f66d4297f32 100644 --- a/temporal/t.register/testsuite/test_t_register_raster_different_local.py +++ b/temporal/t.register/testsuite/test_t_register_raster_different_local.py @@ -31,7 +31,7 @@ from grass.gunittest.gmodules import SimpleModule -class TestRasterUnivar(TestCase): +class TestRegisterDifferentLocal(TestCase): @classmethod def setUpClass(cls): """Initiate the temporal GIS and set the region""" diff --git a/temporal/t.register/testsuite/test_t_register_raster_file.py b/temporal/t.register/testsuite/test_t_register_raster_file.py index b49bc1c3511..b99fa7c8e6e 100755 --- a/temporal/t.register/testsuite/test_t_register_raster_file.py +++ b/temporal/t.register/testsuite/test_t_register_raster_file.py @@ -30,7 +30,7 @@ from grass.gunittest.gmodules import SimpleModule -class TestRasterUnivar(TestCase): +class TestRegisterFile(TestCase): @classmethod def setUpClass(cls): """Initiate the temporal GIS and set the region""" diff --git a/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py b/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py index 2c1fb510d80..914e91cda6f 100644 --- a/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py +++ b/temporal/t.register/testsuite/test_t_register_raster_mapmetadata.py @@ -33,7 +33,7 @@ ) -class TestRasterUnivar(TestCase): +class TestRegisterMapMetadata(TestCase): @classmethod def setUpClass(cls): """Initiate the temporal GIS and set the region""" From a7c00300cfbbcea7bbbfa831113b008c7a80294f Mon Sep 17 00:00:00 2001 From: ninsbl Date: Fri, 17 Mar 2023 23:53:29 +0100 Subject: [PATCH 19/21] assume #2882 is merged --- python/grass/temporal/register.py | 56 +++++-------------------------- 1 file changed, 8 insertions(+), 48 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index a25d3c4bb8f..f5ac1eef577 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -31,44 +31,6 @@ ############################################################################### -def build_abstract_map_dataset(map_item, element): - """Build AbstractMapDataset from map item and element type. - - :param map_item: The id of the map to build an abstract dataset for. - Can be of the form: mapname, mapname@mapsetname, or - mapname:layer / mapname:layer@mapsetname for vector - maps - :param element: The mapset element of the maps: cell, grid3d or vector - :return: ID String build with the AbstractMapDataset class - - .. code-block:: python - - >>> import grass.temporal as tgis - >>> tgis.register.build_abstract_map_dataset("vectormap:1@PERMANENT", "vector") - 'vectormap:1@PERMANENT' - >>> tgis.register.build_abstract_map_dataset("rastermap@PERMANENT", "cell") - 'rastermap@PERMANENT' - >>> tgis.register.build_abstract_map_dataset("raster3dmap@PERMANENT", "grid3d") - 'raster3dmap@PERMANENT' - - """ - map_name, map_mapset = ( - map_item.split("@")[0:2] if "@" in map_item else (map_item, None) - ) - map_name, map_layer = map_name.split(":") if ":" in map_name else (map_name, None) - if not map_mapset: - result = gscript.find_file(element=element, name=map_name) - if result["mapset"]: - map_mapset = result["mapset"] - else: - gscript.fatal( - _("{type} map <{map_name}> not found on search path").format( - type=type, map_name=map_name - ) - ) - return AbstractMapDataset.build_id(map_name, map_mapset, map_layer) - - def register_maps_in_space_time_dataset( type, name, @@ -119,14 +81,6 @@ def register_maps_in_space_time_dataset( start_time_in_file = False end_time_in_file = False semantic_label_in_file = False - element = { - "rast": "cell", - "raster": "cell", - "rast3d": "grid3", - "raster3d": "grid3", - "raster_3d": "grid3", - "vector": "vector", - }[type] msgr = get_tgis_message_interface() @@ -201,7 +155,11 @@ def register_maps_in_space_time_dataset( # Build the map list again with the ids for idx, maplist_item in enumerate(maplist): - maplist[idx] = {"id": build_abstract_map_dataset(maplist_item, element)} + maplist[idx] = { + "id": AbstractMapDataset.build_id( + maplist_item, mapset, check_mapset_element=type + ) + } # Read the map list from file if file: @@ -256,7 +214,9 @@ def register_maps_in_space_time_dataset( # case-sensitive, the user decides on the band name row["semantic_label"] = line_list[idx].strip() - row["id"] = build_abstract_map_dataset(mapname, element) + row["id"] = AbstractMapDataset.build_id( + mapname, mapset, check_mapset_element=type + ) maplist.append(row) From 557263b71c1f54dc210c41be9dd4d6c95bda55a7 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Mon, 20 Mar 2023 22:27:03 +0100 Subject: [PATCH 20/21] use build_id_from_search_path --- python/grass/temporal/register.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index f5ac1eef577..7514cb33d03 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -156,9 +156,7 @@ def register_maps_in_space_time_dataset( # Build the map list again with the ids for idx, maplist_item in enumerate(maplist): maplist[idx] = { - "id": AbstractMapDataset.build_id( - maplist_item, mapset, check_mapset_element=type - ) + "id": AbstractMapDataset.build_id_from_search_path(maplist_item, type) } # Read the map list from file @@ -214,9 +212,7 @@ def register_maps_in_space_time_dataset( # case-sensitive, the user decides on the band name row["semantic_label"] = line_list[idx].strip() - row["id"] = AbstractMapDataset.build_id( - mapname, mapset, check_mapset_element=type - ) + row["id"] = AbstractMapDataset.build_id_from_search_path(mapname, type) maplist.append(row) From ff6ee68810a806373ce368c88cd5ffd3d7a49405 Mon Sep 17 00:00:00 2001 From: ninsbl Date: Mon, 20 Mar 2023 22:27:10 +0100 Subject: [PATCH 21/21] add documentation --- temporal/t.register/t.register.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/temporal/t.register/t.register.html b/temporal/t.register/t.register.html index eaefa45d9c4..389b330b5aa 100644 --- a/temporal/t.register/t.register.html +++ b/temporal/t.register/t.register.html @@ -22,6 +22,13 @@

DESCRIPTION

start and end time, t.register will read timestamps from the temporal database (i.e., in this case only passing map names will be enough).

+Maps can be specified both with their fully qualified map name, meaning e.g. +map@mapset and without the mapset name included. If the mapset +name is not provided in the input, t.register will look for +the given map on the current search path and assign the matching mapset. +If the map is not found on the current search path the module will fail. +Thus, registering maps with fully qualified map name is slightly faster. +

The module t.register supports absolute and relative time. The absolute temporal type refers to a fixed date while the relative temporal type refers to data without fixed timestamps (e.g., sequential maps used to calculate @@ -113,6 +120,18 @@

INPUT FILE FORMAT

prec_6|2002-04-01|2002-07-01 +

+Same as above but with fully qualified map names +(no support for increment option nor -i flag): +

+prec_1@PERMANENT|2001-01-01|2001-04-01
+prec_2@PERMANENT|2001-04-01|2001-07-01
+prec_3@PERMANENT|2001-07-01|2001-10-01
+prec_4@PERMANENT|2001-10-01|2002-01-01
+prec_5@PERMANENT|2002-01-01|2002-04-01
+prec_6@PERMANENT|2002-04-01|2002-07-01
+
+

Support for semantic labels

For more information about semantic labels and image collections