[GRASS-SVN] r51779 - grass/trunk/temporal/t.rast.to.rast3

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 26 08:43:48 EDT 2012


Author: huhabla
Date: 2012-05-26 05:43:48 -0700 (Sat, 26 May 2012)
New Revision: 51779

Modified:
   grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py
   grass/trunk/temporal/t.rast.to.rast3/test.t.rast.to.rast3.sh
Log:
Using temporal information to scale the z-axis of space time voxel cubes.


Modified: grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py
===================================================================
--- grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2012-05-26 12:39:10 UTC (rev 51778)
+++ grass/trunk/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2012-05-26 12:43:48 UTC (rev 51779)
@@ -30,6 +30,7 @@
 import os
 import grass.script as grass
 import grass.temporal as tgis
+from datetime import datetime
 
 ############################################################################
 
@@ -55,22 +56,59 @@
         grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
 
     sp.select()
+    
+    grass.use_temp_region()
 
     maps = sp.get_registered_maps_as_objects_by_granularity()
-
+    num_maps = len(maps)
+    
     # Get the granularity and set bottom, top and top-bottom resolution
     granularity = sp.get_granularity()
+    
+    # This is the reference time to scale the z coordinate
+    reftime = datetime(1900, 1, 1)
 
+    # We set top and bottom according to the start time in relation to the date 1900-01-01 00:00:00
+    # In case of days, hours, minutes and seconds, a double number is used to represent days and fracs of a day
+    
+    # Space time voxel cubes with montly or yearly granularity can not be mixed with other temporal units
+    
+    # Compatible temporal units are : days, hours, minutes and seconds
+    # Incompatible are years and moths
+    start, end = sp.get_valid_time()
+        
     if sp.is_time_absolute():
         unit = granularity.split(" ")[1] 
         granularity = int(granularity.split(" ")[0])
+        
+        if unit == "years":
+	    bottom = start.year - 1900
+	    top = granularity * num_maps
+	elif unit == "months":
+	    bottom = (start.year - 1900) * 12 + start.month
+	    top = granularity * num_maps
+	else:
+	    bottom = tgis.time_delta_to_relative_time(start - reftime)
+	    days = 0
+	    hours = 0
+	    minutes = 0
+	    seconds = 0
+	    if unit == "days":
+		days = granularity
+	    if unit == "hours":
+		hours = granularity
+	    if unit == "minutes":
+		minutes = granularity
+	    if unit == "seconds":
+		seconds = granularity
+		
+	    granularity = days + hours/24.0 + minutes/1440.0 + seconds/86400.0 
     else:
         unit = sp.get_relative_time_unit()
+	bottom = start
 
-    num_maps = len(maps)
-    bottom = 0
-    top = granularity * num_maps
-
+    top = bottom + granularity * num_maps
+    
     ret = grass.run_command("g.region", t=top, b=bottom, tbres=granularity)
     
     if ret != 0:

Modified: grass/trunk/temporal/t.rast.to.rast3/test.t.rast.to.rast3.sh
===================================================================
--- grass/trunk/temporal/t.rast.to.rast3/test.t.rast.to.rast3.sh	2012-05-26 12:39:10 UTC (rev 51778)
+++ grass/trunk/temporal/t.rast.to.rast3/test.t.rast.to.rast3.sh	2012-05-26 12:43:48 UTC (rev 51779)
@@ -3,7 +3,7 @@
 # We need to set a specific region in the
 # @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=1 res=10 res3=1 -p3
+g.region s=0 n=80 w=0 e=120 b=0 t=1 res=10 res3=10 -p3
 
 r.mapcalc --o expr="prec_1 = 100"
 r.mapcalc --o expr="prec_2 = 200"
@@ -18,14 +18,49 @@
 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"
 
-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.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="3 years"
 t.info type=strds input=precip_abs
 
 t.rast.to.rast3 --o input=precip_abs output=precipitation
 t.info type=rast3d input=precipitation
 r3.info precipitation
 
-t.register --o --v -i type=rast input=precip_rel maps=prec_4,prec_5,prec_6 start=0 increment=100 unit=years
+t.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="2 months"
+t.info type=strds input=precip_abs
+
+t.rast.to.rast3 --o input=precip_abs output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
+
+t.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="8 days"
+t.info type=strds input=precip_abs
+
+t.rast.to.rast3 --o input=precip_abs output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
+
+t.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="6 hours"
+t.info type=strds input=precip_abs
+
+t.rast.to.rast3 --o input=precip_abs output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
+
+t.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="30 minutes"
+t.info type=strds input=precip_abs
+
+t.rast.to.rast3 --o input=precip_abs output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
+
+t.register --o --v -i type=rast input=precip_abs maps=prec_1,prec_2,prec_3 start="2001-01-01" increment="1 seconds"
+t.info type=strds input=precip_abs
+
+t.rast.to.rast3 --o input=precip_abs output=precipitation
+t.info type=rast3d input=precipitation
+r3.info precipitation
+
+t.register --o --v -i type=rast input=precip_rel maps=prec_4,prec_5,prec_6 start=1000 increment=100 unit=years
 t.info type=strds input=precip_rel
 
 t.rast.to.rast3 --o input=precip_rel output=precipitation



More information about the grass-commit mailing list