[GRASS-SVN] r49075 - in grass/trunk/temporal: . t.sample

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 3 09:05:55 EDT 2011


Author: huhabla
Date: 2011-11-03 06:05:55 -0700 (Thu, 03 Nov 2011)
New Revision: 49075

Added:
   grass/trunk/temporal/t.sample/
   grass/trunk/temporal/t.sample/Makefile
   grass/trunk/temporal/t.sample/t.sample.html
   grass/trunk/temporal/t.sample/t.sample.py
   grass/trunk/temporal/t.sample/test.t.sample.sh
Log:
Generalized the sample algorithm, a single module can handle all sample
cases now.


Added: grass/trunk/temporal/t.sample/Makefile
===================================================================
--- grass/trunk/temporal/t.sample/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.sample/Makefile	2011-11-03 13:05:55 UTC (rev 49075)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../
+
+PGM = t.sample
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script $(TEST_DST)

Added: grass/trunk/temporal/t.sample/t.sample.html
===================================================================
Added: grass/trunk/temporal/t.sample/t.sample.py
===================================================================
--- grass/trunk/temporal/t.sample/t.sample.py	                        (rev 0)
+++ grass/trunk/temporal/t.sample/t.sample.py	2011-11-03 13:05:55 UTC (rev 49075)
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:	t.sample
+# AUTHOR(S):	Soeren Gebbert
+#               
+# PURPOSE:	Sample the input space time dataset with a sample space time dataset and print the result to stdout
+# COPYRIGHT:	(C) 2011 by the GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (version 2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+#############################################################################
+
+#%module
+#% description: Sample the input space time dataset with a sample space time dataset and print the result to stdout
+#% keywords: dataset
+#% keywords: spacetime
+#% keywords: raster
+#% keywords: sample
+#%end
+
+#%option
+#% key: input
+#% type: string
+#% description: Name of a space time dataset
+#% required: yes
+#% multiple: no
+#%end
+
+#%option
+#% key: sample
+#% type: string
+#% description: Name of the sample space time dataset 
+#% required: yes
+#% multiple: no
+#%end
+
+#%option
+#% key: intype
+#% type: string
+#% description: Type of the input space time dataset, default is space time raster dataset (strds)
+#% required: no
+#% options: strds, str3ds, stvds
+#% answer: strds
+#%end
+
+#%option
+#% key: samtype
+#% type: string
+#% description: Type of the sample space time dataset, default is space time raster dataset (strds)
+#% required: no
+#% options: strds, str3ds, stvds
+#% answer: strds
+#%end
+
+#%option
+#% key: method
+#% type: string
+#% description: The method to be used for sampling
+#% required: no
+#% multiple: yes
+#% options: start,during,overlap,contain,equal
+#% answer: during,overlap,contain,equal
+#%end
+
+#%option
+#% key: fs
+#% type: string
+#% description: The field separator character between the columns, default is tabular " | ". Do not use "," as this char is reserved to list several map ids in a sample granule
+#% required: no
+#%end
+
+#%flag
+#% key: h
+#% description: Print column names 
+#%end
+
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+def main():
+
+    # Get the options
+    input = options["input"]
+    sampler = options["sample"]
+    samtype = options["samtype"]
+    intype = options["intype"]
+    separator = options["fs"]
+    method = options["method"]
+    header = flags["h"]
+
+    method = method.split(",")
+
+    # Make sure the temporal database exists
+    tgis.create_temporal_database()
+
+    tgis.sample_stds_by_stds_topology(intype, samtype, input, sampler, header, separator, method)
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()


Property changes on: grass/trunk/temporal/t.sample/t.sample.py
___________________________________________________________________
Added: svn:executable
   + *

Added: grass/trunk/temporal/t.sample/test.t.sample.sh
===================================================================
--- grass/trunk/temporal/t.sample/test.t.sample.sh	                        (rev 0)
+++ grass/trunk/temporal/t.sample/test.t.sample.sh	2011-11-03 13:05:55 UTC (rev 49075)
@@ -0,0 +1,77 @@
+# This is a test to sample a space time raster dataset with a space time vector dataset
+
+# 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
+
+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)"
+
+v.random --o -z output=pnts1 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=pnts2 n=20 zmin=0 zmax=100 column=height
+
+v.random --o -z output=pnts3 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=pnts4 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=pnts5 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=pnts6 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=pnts7 n=20 zmin=0 zmax=100 column=height
+v.random --o -z output=pnts8 n=20 zmin=0 zmax=100 column=height
+
+n1=`g.tempfile pid=1 -d` 
+n2=`g.tempfile pid=2 -d`
+n3=`g.tempfile pid=3 -d`
+
+cat > $n1 << EOF
+prec_1
+prec_2
+prec_3
+prec_4
+prec_5
+prec_6
+EOF
+
+cat > $n2 << EOF
+pnts1|2001-01-01|2001-03-01
+pnts2|2001-05-01|2001-07-01
+EOF
+
+cat > $n3 << EOF
+pnts3|2001-01-01|2001-01-05
+pnts4|2001-01-05|2001-01-10
+pnts5|2001-01-10|2001-01-15
+pnts6|2001-01-15|2001-01-20
+pnts7|2001-01-20|2001-01-25
+pnts8|2001-01-25|2001-01-30
+EOF
+
+
+t.create --o type=strds temporaltype=absolute output=precip_abs0 title="A test with raster input files" descr="A test with raster input files"
+t.create --o type=stvds temporaltype=absolute output=pnts_abs0 title="A test with vector input files" descr="A test with vector input files"
+t.create --o type=stvds temporaltype=absolute output=pnts_abs1 title="A test with vector input files" descr="A test with vector input files"
+
+tr.register -i input=precip_abs0 file=$n1 start="2001-01-01" increment="1 months"
+tv.register    input=pnts_abs0 file=$n2 start=file end=file
+tv.register    input=pnts_abs1 file=$n3 start=file end=file
+
+# The @test
+t.sample method=equal   input=precip_abs0 samtype=stvds sample=pnts_abs0 -h
+t.sample method=during  input=precip_abs0 samtype=stvds sample=pnts_abs0 -h
+t.sample method=overlap input=precip_abs0 samtype=stvds sample=pnts_abs0 -h
+t.sample method=contain input=precip_abs0 samtype=stvds sample=pnts_abs0 -h
+t.sample input=precip_abs0 samtype=strds sample=precip_abs0 -h
+
+
+# Test with temporal point data
+tr.register    input=precip_abs0 file=$n1 start="2001-01-01" increment="1 months"
+t.sample input=precip_abs0 samtype=stvds sample=pnts_abs0 -h
+t.sample input=precip_abs0 samtype=stvds sample=pnts_abs1 -h
+
+t.remove type=rast input=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6
+t.remove type=strds input=precip_abs0
+t.remove type=stvds input=pnts_abs0,pnts_abs1



More information about the grass-commit mailing list