[GRASS-SVN] r50807 - in grass/trunk: lib/python/temporal
temporal/tr.list temporal/tr.out.vtk temporal/tr.series
temporal/tr.to.rast3
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 13 19:04:11 EST 2012
Author: huhabla
Date: 2012-02-13 16:04:11 -0800 (Mon, 13 Feb 2012)
New Revision: 50807
Modified:
grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
grass/trunk/temporal/tr.list/test.tr.list.sh
grass/trunk/temporal/tr.out.vtk/test.tr.out.vtk.sh
grass/trunk/temporal/tr.series/test.tr.series.sh
grass/trunk/temporal/tr.to.rast3/test.tr.to.rast3.sh
grass/trunk/temporal/tr.to.rast3/tr.to.rast3.py
Log:
Modified tests to use t.register and t.unregister.
tr.to.rast3 now creates space time voxel cubes with time stamps and
vertical unit.
Modified: grass/trunk/lib/python/temporal/abstract_space_time_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_space_time_dataset.py 2012-02-13 23:34:14 UTC (rev 50806)
+++ grass/trunk/lib/python/temporal/abstract_space_time_dataset.py 2012-02-14 00:04:11 UTC (rev 50807)
@@ -538,7 +538,7 @@
if self.is_time_absolute():
map.set_absolute_time(start, end)
elif self.is_time_relative():
- map.set_relative_time(start, end)
+ map.set_relative_time(start, end, self.get_relative_time_unit())
maplist.append(copy.copy(map))
result["samples"] = maplist
@@ -549,7 +549,7 @@
if self.is_time_absolute():
map.set_absolute_time(start, end)
elif self.is_time_relative():
- map.set_relative_time(start, end)
+ map.set_relative_time(start, end, self.get_relative_time_unit())
maplist.append(copy.copy(map))
result["samples"] = maplist
@@ -618,7 +618,7 @@
if self.is_time_absolute():
map.set_absolute_time(start, next)
elif self.is_time_relative():
- map.set_relative_time(start, next)
+ map.set_relative_time(start, next, self.get_relative_time_unit())
maplist.append(copy.copy(map))
@@ -677,7 +677,7 @@
if self.is_time_absolute():
map.set_absolute_time(start, end)
elif self.is_time_relative():
- map.set_relative_time(start, end)
+ map.set_relative_time(start, end, self.get_relative_time_unit())
obj_list.append(copy.copy(map))
if connect == True:
Modified: grass/trunk/temporal/tr.list/test.tr.list.sh
===================================================================
--- grass/trunk/temporal/tr.list/test.tr.list.sh 2012-02-13 23:34:14 UTC (rev 50806)
+++ grass/trunk/temporal/tr.list/test.tr.list.sh 2012-02-14 00:04:11 UTC (rev 50807)
@@ -72,7 +72,7 @@
t.create --o type=strds temporaltype=absolute output=precip_abs5 title="A test with input files" descr="A test with input files"
# The @test
-tr.register -i input=precip_abs0 file="${n1}" start="2001-01-01" increment="1 months"
+t.register type=rast -i input=precip_abs0 file="${n1}" start="2001-01-01" increment="1 months"
tr.list fs=" | " method=comma input=precip_abs0
tr.list -h input=precip_abs1
tr.list -h fs=" | " method=cols input=precip_abs0
@@ -80,7 +80,7 @@
tr.list -h fs=" | " method=deltagaps input=precip_abs0
tr.list -h fs=" | " method=gran input=precip_abs0
-tr.register input=precip_abs1 file="${n1}" start="2001-01-01" increment="1 months"
+t.register type=rast input=precip_abs1 file="${n1}" start="2001-01-01" increment="1 months"
tr.list fs=" | " method=comma input=precip_abs1
tr.list -h input=precip_abs1
tr.list -h fs=" | " method=cols input=precip_abs1
@@ -88,7 +88,7 @@
tr.list -h fs=" | " method=deltagaps input=precip_abs1
tr.list -h fs=" | " method=gran input=precip_abs1
-tr.register -i input=precip_abs2 file="${n2}" start=file
+t.register type=rast -i input=precip_abs2 file="${n2}"
tr.list fs=" | " method=comma input=precip_abs2
tr.list -h input=precip_abs2
tr.list -h fs=" | " method=cols input=precip_abs2
@@ -96,19 +96,19 @@
tr.list -h fs=" | " method=deltagaps input=precip_abs2
tr.list -h fs=" | " method=gran input=precip_abs2
-tr.register -i input=precip_abs3 file="${n3}" start=file end=file
+t.register type=rast -i input=precip_abs3 file="${n3}"
tr.list fs=" | " method=comma input=precip_abs3
tr.list -h fs=" | " method=delta input=precip_abs3
tr.list -h fs=" | " method=deltagaps input=precip_abs3
tr.list -h fs=" | " method=gran input=precip_abs3
-tr.register -i input=precip_abs4 file="${n4}" start=file end=file
+t.register type=rast -i input=precip_abs4 file="${n4}"
tr.list fs=" | " method=comma input=precip_abs4
tr.list -h fs=" | " method=delta input=precip_abs4
tr.list -h fs=" | " method=deltagaps input=precip_abs4
tr.list -h fs=" | " method=gran input=precip_abs4
-tr.register -i input=precip_abs5 file="${n5}" start=file end=file
+t.register type=rast -i input=precip_abs5 file="${n5}"
tr.list fs=" | " method=comma input=precip_abs5
tr.list -h input=precip_abs5
tr.list -h fs=" | " method=cols input=precip_abs5
@@ -116,5 +116,5 @@
tr.list -h fs=" | " method=deltagaps input=precip_abs5
tr.list -h fs=" | " method=gran input=precip_abs5
-t.remove type=rast input=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
t.remove type=strds input=precip_abs0,precip_abs1,precip_abs2,precip_abs3,precip_abs4,precip_abs5
Modified: grass/trunk/temporal/tr.out.vtk/test.tr.out.vtk.sh
===================================================================
--- grass/trunk/temporal/tr.out.vtk/test.tr.out.vtk.sh 2012-02-13 23:34:14 UTC (rev 50806)
+++ grass/trunk/temporal/tr.out.vtk/test.tr.out.vtk.sh 2012-02-14 00:04:11 UTC (rev 50807)
@@ -31,17 +31,17 @@
# The first @test
mkdir /tmp/test1
-tr.register -i input=precip_abs1 file="${n1}" start=file end=file
+t.register -i type=rast input=precip_abs1 file="${n1}"
tr.out.vtk input=precip_abs1 expdir=/tmp/test1
ls -al /tmp/test1
mkdir /tmp/test2
-tr.register -i input=precip_abs2 file="${n1}"
+t.register -i type=rast input=precip_abs2 file="${n1}"
tr.out.vtk input=precip_abs2 expdir=/tmp/test2 elevation=elevation
ls -al /tmp/test2
mkdir /tmp/test3
-tr.register -i input=precip_abs3 file="${n1}"
+t.register -i type=rast input=precip_abs3 file="${n1}"
tr.out.vtk -g input=precip_abs3 expdir=/tmp/test3 elevation=elevation
ls -al /tmp/test3
@@ -49,5 +49,5 @@
rm -rf /tmp/test2
rm -rf /tmp/test3
-t.remove type=rast input=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
t.remove type=strds input=precip_abs1,precip_abs2,precip_abs3
Modified: grass/trunk/temporal/tr.series/test.tr.series.sh
===================================================================
--- grass/trunk/temporal/tr.series/test.tr.series.sh 2012-02-13 23:34:14 UTC (rev 50806)
+++ grass/trunk/temporal/tr.series/test.tr.series.sh 2012-02-14 00:04:11 UTC (rev 50807)
@@ -1,12 +1,5 @@
-# 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 relative and absolute time
+# @preprocess step of this test.
# 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
@@ -17,18 +10,16 @@
r.mapcalc --o expr="prec_5 = 500"
r.mapcalc --o expr="prec_6 = 600"
-# The first @test
-# We create the space time raster inputs and register the raster maps with absolute time interval
-
+# @test
t.create --v --o type=strds temporaltype=absolute output=precip_abs title="A test" descr="A test"
-tr.register --v input=precip_abs maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 months"
+t.register --v type=rast input=precip_abs maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 months"
tr.series --o input=precip_abs method=average output=prec_average where="start_time > '2001-03-01'"
tr.series --o -t input=precip_abs method=maximum output=prec_max order=start_time
tr.series --o -t input=precip_abs method=sum output=prec_sum
-t.remove --v type=rast input=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.unregister --v type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
t.remove --v type=strds input=precip_abs
r.info prec_average
Modified: grass/trunk/temporal/tr.to.rast3/test.tr.to.rast3.sh
===================================================================
--- grass/trunk/temporal/tr.to.rast3/test.tr.to.rast3.sh 2012-02-13 23:34:14 UTC (rev 50806)
+++ grass/trunk/temporal/tr.to.rast3/test.tr.to.rast3.sh 2012-02-14 00:04:11 UTC (rev 50807)
@@ -1,8 +1,3 @@
-# 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
@@ -17,17 +12,25 @@
r.mapcalc --o expr="prec_5 = 500"
r.mapcalc --o expr="prec_6 = 600"
-# The first @test
+# @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_abs title="A test" descr="A test"
+t.create --o type=strds temporaltype=relative output=precip_rel title="A test" descr="A test"
-tr.register -i input=precip_abs maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" increment="1 months"
+t.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="1 months"
+t.info type=strds input=precip_abs
-tr.to.rast3 --o input=precip_abs output=preciptiation
+tr.to.rast3 --o input=precip_abs output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
-t.remove type=rast input=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
-t.remove type=strds input=precip_abs
+t.register --o --v -i type=rast input=precip_rel maps=prec_4,prec_5,prec_6 start=0 increment=100 unit=years
+t.info type=strds input=precip_rel
-r3.info preciptiation
-g.region s=0 n=80 w=0 e=120 b=0 t=1 res=10 res3=1
+tr.to.rast3 --o input=precip_rel output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
+
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_abs,precip_rel
Modified: grass/trunk/temporal/tr.to.rast3/tr.to.rast3.py
===================================================================
--- grass/trunk/temporal/tr.to.rast3/tr.to.rast3.py 2012-02-13 23:34:14 UTC (rev 50806)
+++ grass/trunk/temporal/tr.to.rast3/tr.to.rast3.py 2012-02-14 00:04:11 UTC (rev 50807)
@@ -64,13 +64,14 @@
maps = sp.get_registered_maps_as_objects_by_granularity()
- # Compute relative granularity and set bottom, top and top-bottom resolution
+ # Get the granularity and set bottom, top and top-bottom resolution
granularity = sp.get_granularity()
- # We do not convert months or years into days, we simply use
- # The digit of the string as topo-bottom resolution
if sp.is_time_absolute():
+ unit = granularity.split(" ")[1]
granularity = int(granularity.split(" ")[0])
+ else:
+ unit = sp.get_relative_time_unit()
num_maps = len(maps)
bottom = 0
@@ -81,7 +82,7 @@
if ret != 0:
grass.fatal(_("Unable to set 3d region"))
- # Create a NULL map in case of granularity support
+ # Create a NULL map to fill the gaps
null_map = "temporary_null_map_%i" % os.getpid()
grass.mapcalc("%s = null()" % (null_map))
@@ -109,6 +110,37 @@
grass.run_command("g.remove", rast=null_map)
+ title = _("Space time voxel cube")
+ descr = _("This space time voxel cube was created with tr.to.rast3")
+
+ # Set the unit
+ ret = grass.run_command("r3.support", map=output, vunit=unit, title=title, description=descr, overwrite=grass.overwrite())
+
+ # Register the space time voxel cube in the temporal GIS
+ if output.find("@") >= 0:
+ id = output
+ else:
+ id = output + "@" + mapset
+
+ start, end = sp.get_valid_time()
+ r3ds = tgis.raster3d_dataset(id)
+
+ if r3ds.is_in_db():
+ r3ds.select()
+ r3ds.delete()
+ r3ds = tgis.raster3d_dataset(id)
+
+ r3ds.load()
+
+ if sp.is_time_absolute():
+ r3ds.set_absolute_time(start, end)
+ r3ds.write_absolute_time_to_file()
+ else:
+ r3ds.set_relative_time(start, end, sp.get_relative_time_unit())
+ r3ds.write_relative_time_to_file()
+
+ r3ds.insert()
+
if __name__ == "__main__":
options, flags = grass.parser()
main()
More information about the grass-commit
mailing list