[GRASS-SVN] r56191 - in grass/trunk: lib/python/temporal temporal/t.rast.import

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 10 15:22:14 PDT 2013


Author: huhabla
Date: 2013-05-10 15:22:14 -0700 (Fri, 10 May 2013)
New Revision: 56191

Added:
   grass/trunk/temporal/t.rast.import/test.t.rast.import.relative.sh
Modified:
   grass/trunk/lib/python/temporal/stds_export.py
   grass/trunk/lib/python/temporal/stds_import.py
   grass/trunk/temporal/t.rast.import/test.t.rast.import.sh
Log:
Correct handling of relative time in stds import and export implemented.


Modified: grass/trunk/lib/python/temporal/stds_export.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_export.py	2013-05-10 20:46:38 UTC (rev 56190)
+++ grass/trunk/lib/python/temporal/stds_export.py	2013-05-10 22:22:14 UTC (rev 56191)
@@ -317,6 +317,8 @@
     string += "%s=%s\n" % ("format", format_) 
     string += "%s=%s\n" % ("temporal_type", sp.get_temporal_type())
     string += "%s=%s\n" % ("semantic_type", sp.get_semantic_type())
+    if sp.is_time_relative():
+	string += "%s=%s\n" % ("relative_time_unit", sp.get_relative_time_unit())
     string += "%s=%s\n" % ("number_of_maps", sp.metadata.get_number_of_maps())
     north, south, east, west, top, bottom = sp.get_spatial_extent()
     string += "%s=%s\n" % ("north", north)

Modified: grass/trunk/lib/python/temporal/stds_import.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_import.py	2013-05-10 20:46:38 UTC (rev 56190)
+++ grass/trunk/lib/python/temporal/stds_import.py	2013-05-10 22:22:14 UTC (rev 56191)
@@ -374,6 +374,14 @@
 
         temporal_type = init["temporal_type"]
         semantic_type = init["semantic_type"]
+        relative_time_unit = None
+        
+        if temporal_type == "relative":        
+            if "relative_time_unit" not in init:
+                core.fatal(_("Key word %s not found in init file.") %("relative_time_unit"))
+            relative_time_unit = init["relative_time_unit"]
+            sp.set_relative_time_unit(relative_time_unit)
+        
         core.verbose(_("Create space time %s dataset.") %
                      sp.get_new_map_instance(None).get_type())
 
@@ -387,7 +395,7 @@
         register_maps_in_space_time_dataset(
             type=sp.get_new_map_instance(None).get_type(),
             name=output, file=list_file_name, start="file", 
-            end="file", dbif=None, fs=fs)
+            end="file", unit=relative_time_unit, dbif=None, fs=fs)
 
         os.chdir(old_cwd)
     except:

Added: grass/trunk/temporal/t.rast.import/test.t.rast.import.relative.sh
===================================================================
--- grass/trunk/temporal/t.rast.import/test.t.rast.import.relative.sh	                        (rev 0)
+++ grass/trunk/temporal/t.rast.import/test.t.rast.import.relative.sh	2013-05-10 22:22:14 UTC (rev 56191)
@@ -0,0 +1,84 @@
+#!/bin/sh
+# Test the import of space time raster datasets with relative time
+
+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
+
+r.mapcalc expr="prec_1 = rand(0, 550)"
+r.mapcalc expr="prec_2 = rand(0, 450)"
+r.mapcalc expr="prec_3 = rand(0, 320)"
+r.mapcalc expr="prec_4 = rand(0, 510)"
+r.mapcalc expr="prec_5 = rand(0, 300)"
+r.mapcalc expr="prec_6 = rand(0, 650)"
+
+n1=`g.tempfile pid=1 -d` 
+
+cat > "${n1}" << EOF
+prec_1|1|2
+prec_2|2|3
+prec_3|3|4
+prec_4|4|5
+prec_5|5|6
+prec_6|6|7
+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 -i type=rast input=precip_rel file="${n1}"  unit="years" 
+
+t.rast.export input=precip_rel output=strds_export.tar.bz2 compression=bzip2 format=GTiff workdir=test
+t.rast.export input=precip_rel output=strds_export.tar.gz compression=gzip format=GTiff workdir=test
+t.rast.export input=precip_rel output=strds_export.tar compression=no format=GTiff workdir=test
+t.rast.export input=precip_rel output=strds_export_pack.tar compression=no format=pack workdir=test
+t.rast.export input=precip_rel output=strds_export_pack.tar.gz compression=gzip format=pack workdir=test
+t.rast.export input=precip_rel output=strds_export_pack.tar.bz2 compression=bzip2 format=pack workdir=test
+
+# Checking different flags
+t.rast.import --o input=strds_export.tar.bz2 output=precip_rel extrdir=test\
+          -oe title="A test" description="Description of a test"
+t.rast.import --o input=strds_export.tar.bz2 output=precip_rel extrdir=test\
+          -loe title="A test" description="Description of a test"
+t.rast.import --o input=strds_export.tar.bz2 output=precip_rel extrdir=test\
+              title="A test" description="Description of a test"
+t.rast.import --o input=strds_export.tar.bz2 output=precip_rel extrdir=test\
+          -l  title="A test" description="Description of a test"
+
+# Import using different compression and formats
+t.rast.import --o input=strds_export.tar.gz output=precip_rel extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export.tar output=precip_rel extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export_pack.tar output=precip_rel extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export_pack.tar.gz output=precip_rel extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+t.rast.import --o input=strds_export_pack.tar.bz2 output=precip_rel extrdir=test\
+              title="A test" description="Description of a test"
+r.info prec_1
+
+# Cleaning up
+t.unregister type=rast maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_rel
+g.remove rast=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+rm -rf test
+rm strds_export.tar.bz2
+rm strds_export.tar.gz
+rm strds_export.tar
+rm strds_export_pack.tar  
+rm strds_export_pack.tar.gz
+rm strds_export_pack.tar.bz2


Property changes on: grass/trunk/temporal/t.rast.import/test.t.rast.import.relative.sh
___________________________________________________________________
Added: svn:executable
   + *

Modified: grass/trunk/temporal/t.rast.import/test.t.rast.import.sh
===================================================================
--- grass/trunk/temporal/t.rast.import/test.t.rast.import.sh	2013-05-10 20:46:38 UTC (rev 56190)
+++ grass/trunk/temporal/t.rast.import/test.t.rast.import.sh	2013-05-10 22:22:14 UTC (rev 56191)
@@ -1,6 +1,8 @@
 #!/bin/sh
 # Test the import of 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 a space time raster datasets
@@ -9,12 +11,12 @@
 
 mkdir test
 
-r.mapcalc --o expr="prec_1 = rand(0, 550)"
-r.mapcalc --o expr="prec_2 = rand(0, 450)"
-r.mapcalc --o expr="prec_3 = rand(0, 320)"
-r.mapcalc --o expr="prec_4 = rand(0, 510)"
-r.mapcalc --o expr="prec_5 = rand(0, 300)"
-r.mapcalc --o expr="prec_6 = rand(0, 650)"
+r.mapcalc expr="prec_1 = rand(0, 550)"
+r.mapcalc expr="prec_2 = rand(0, 450)"
+r.mapcalc expr="prec_3 = rand(0, 320)"
+r.mapcalc expr="prec_4 = rand(0, 510)"
+r.mapcalc expr="prec_5 = rand(0, 300)"
+r.mapcalc expr="prec_6 = rand(0, 650)"
 
 n1=`g.tempfile pid=1 -d` 
 
@@ -29,10 +31,10 @@
 
 eval `g.gisenv`
 
-t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test with input files" descr="A test with input files"
+t.create type=strds temporaltype=absolute output=precip_abs1 title="A test with input files" descr="A test with input files"
 
 # The first @test
-t.register -i type=rast input=precip_abs1 file="${n1}" start="2001-01-01" increment="1 months"
+t.register -i type=rast input=precip_abs1 file="${n1}"
 
 t.rast.export input=precip_abs1 output=strds_export.tar.bz2 compression=bzip2 format=GTiff workdir=test
 t.rast.export input=precip_abs1 output=strds_export.tar.gz compression=gzip format=GTiff workdir=test



More information about the grass-commit mailing list