From 36fef111c21f2b88fd056ccb30ff0a99e67a794d Mon Sep 17 00:00:00 2001 From: Tomas Zigo <50632337+tmszi@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:22:05 +0200 Subject: [PATCH] libpython/temporal: fix t.rast.import module import input tarball file (#3591) --- python/grass/temporal/stds_import.py | 4 +- ...ast.import.relative.with.semantic.label.sh | 81 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100755 temporal/t.rast.import/test.t.rast.import.relative.with.semantic.label.sh diff --git a/python/grass/temporal/stds_import.py b/python/grass/temporal/stds_import.py index b7f680e7936..2d4dfb1f1ac 100644 --- a/python/grass/temporal/stds_import.py +++ b/python/grass/temporal/stds_import.py @@ -410,9 +410,11 @@ def import_stds( row["id"] = mapid row["start"] = line_list[1].strip() row["end"] = line_list[2].strip() + row["semantic_label"] = line_list[3].strip() if len(line_list) == 4 else "" new_list_file.write( - "%s%s%s%s%s\n" % (mapname, fs, row["start"], fs, row["end"]) + f"{mapname}{fs}{row['start']}{fs}{row['end']}" + f"{fs}{row['semantic_label']}\n" ) maplist.append(row) diff --git a/temporal/t.rast.import/test.t.rast.import.relative.with.semantic.label.sh b/temporal/t.rast.import/test.t.rast.import.relative.with.semantic.label.sh new file mode 100755 index 00000000000..a7e855b2f72 --- /dev/null +++ b/temporal/t.rast.import/test.t.rast.import.relative.with.semantic.label.sh @@ -0,0 +1,81 @@ +#!/bin/sh + +############################################################################ +# +# MODULE: t.rast.import +# AUTHOR(S): Tomas Zigo +# +# PURPOSE: Test the import of space time raster datasets with relative time +# and with semantic label +# COPYRIGHT: (C) 2011-2024, Tomas Zigo and the GRASS Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +############################################################################# + +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 a space time raster datasets +# 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 + +mkdir test + +# 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 + +n1=`g.tempfile pid=1 -d` + +cat > "${n1}" << EOF +prec_1|1|2|S2_1 +prec_2|2|3|S2_2 +prec_3|3|4|S2_3 +prec_4|4|5|S2_4 +prec_5|5|6|S2_5 +prec_6|6|7|S2_6 +EOF + +eval `g.gisenv` + +t.create type=strds temporaltype=relative output=precip_rel \ + title="A test with input files" descr="A test with input files" + +# The first @test +t.register type=raster input=precip_rel file="${n1}" unit="years" + +t.rast.export input=precip_rel output=strds_export.tar.bz2 compression=bzip2 format=GTiff directory=test + +# Checking different flags +t.rast.import --o input=strds_export.tar.bz2 output=precip_rel directory=test\ + -oe title="A test" description="Description of a test" +r.info prec_1 + +# Check the raster maps semantic label +[[ ! "$(r.semantic.label prec_1 operation=print)" == "S2 Visible (Coastal/Aerosol)" ]] && echo "Semantic label of prec_1 raster map is not equal." && exit 1 +[[ ! "$(r.semantic.label prec_2 operation=print)" == "S2 Visible (Blue)" ]] && echo "Semantic label of prec_2 raster map is not equal." && exit 1 +[[ ! "$(r.semantic.label prec_3 operation=print)" == "S2 Visible (Green)" ]] && echo "Semantic label of prec_3 raster map is not equal." && exit 1 +[[ ! "$(r.semantic.label prec_4 operation=print)" == "S2 Visible (Red)" ]] && echo "Semantic label of prec_4 raster map is not equal." && exit 1 +[[ ! "$(r.semantic.label prec_5 operation=print)" == "S2 Vegetation Red Edge 1" ]] && echo "Semantic label of prec_5 raster map is not equal." && exit 1 +[[ ! "$(r.semantic.label prec_6 operation=print)" == "S2 Vegetation Red Edge 2" ]] && echo "Semantic label of prec_6 raster map is not equal." && exit 1 + +# Cleaning up +t.unregister type=raster maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 +t.remove type=strds input=precip_rel +g.remove -f type=raster name=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 +rm -rf test +rm strds_export.tar.bz2