[GRASS-SVN] r51277 - in grass/trunk/temporal: . t.rast.out.vtk
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 5 17:06:06 EDT 2012
Author: huhabla
Date: 2012-04-05 14:06:06 -0700 (Thu, 05 Apr 2012)
New Revision: 51277
Added:
grass/trunk/temporal/t.rast.out.vtk/
grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.html
grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py
grass/trunk/temporal/t.rast.out.vtk/test.t.rast.out.vtk.sh
Removed:
grass/trunk/temporal/t.rast.out.vtk/test.tr.out.vtk.sh
grass/trunk/temporal/t.rast.out.vtk/tr.out.vtk.html
grass/trunk/temporal/t.rast.out.vtk/tr.out.vtk.py
Modified:
grass/trunk/temporal/t.rast.out.vtk/Makefile
Log:
Using new naming scheme
Modified: grass/trunk/temporal/t.rast.out.vtk/Makefile
===================================================================
--- grass/trunk/temporal/tr.out.vtk/Makefile 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.out.vtk/Makefile 2012-04-05 21:06:06 UTC (rev 51277)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../../
-PGM = tr.out.vtk
+PGM = t.rast.out.vtk
include $(MODULE_TOPDIR)/include/Make/Script.make
Copied: grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.html (from rev 51264, grass/trunk/temporal/tr.out.vtk/tr.out.vtk.html)
===================================================================
Copied: grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py (from rev 51264, grass/trunk/temporal/tr.out.vtk/tr.out.vtk.py)
===================================================================
--- grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py (rev 0)
+++ grass/trunk/temporal/t.rast.out.vtk/t.rast.out.vtk.py 2012-04-05 21:06:06 UTC (rev 51277)
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE: t.rast.out.vtk
+# AUTHOR(S): Soeren Gebbert
+#
+# PURPOSE: Export space time raster dataset as VTK time series
+# 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: Export space time raster dataset as VTK time series
+#% keywords: dataset
+#% keywords: spacetime
+#% keywords: raster
+#% keywords: export
+#% keywords: VTK
+#%end
+
+#%option G_OPT_STRDS_INPUT
+#%end
+
+#%option
+#% key: expdir
+#% type: string
+#% description: Path to the export directory
+#% required: yes
+#% multiple: no
+#%end
+
+#%option G_OPT_R_ELEV
+#% required: no
+#%end
+
+#%option G_OPT_T_WHERE
+#%end
+
+#%option
+#% key: null
+#% type: double
+#% description: Value to represent no data cell
+#% required: no
+#% multiple: no
+#% answer: -10.0
+#%end
+
+#%flag
+#% key: p
+#% description: Create VTK point data instead of VTK cell data (if no elevation map is given)
+#%end
+
+#%flag
+#% key: c
+#% description: Correct the coordinates to fit the VTK-OpenGL precision
+#%end
+
+#%flag
+#% key: g
+#% description: Export files using the space time dataset granularity for equidistant time between maps, where statement will be ignored
+#%end
+
+
+
+import os
+import grass.script as grass
+import grass.temporal as tgis
+
+############################################################################
+
+def main():
+
+ # Get the options
+ input = options["input"]
+ elevation = options["elevation"]
+ expdir = options["expdir"]
+ where = options["where"]
+ null = options["null"]
+ use_pdata = flags["p"]
+ coorcorr = flags["c"]
+ use_granularity = flags["g"]
+
+ # Make sure the temporal database exists
+ tgis.create_temporal_database()
+
+ if not os.path.exists(expdir):
+ grass.fatal(_("Export directory <%s> not found.") % expdir)
+
+ os.chdir(expdir)
+
+ mapset = grass.gisenv()["MAPSET"]
+
+ if input.find("@") >= 0:
+ id = input
+ else:
+ id = input + "@" + mapset
+
+ sp = tgis.space_time_raster_dataset(id)
+
+ if sp.is_in_db() == False:
+ grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
+
+ sp.select()
+
+ if use_granularity:
+ # Attention: A list of lists of maps will be returned
+ maps = sp.get_registered_maps_as_objects_by_granularity()
+ # Create a NULL map in case of granularity support
+ null_map = "temporary_null_map_%i" % os.getpid()
+ grass.mapcalc("%s = null()" % (null_map))
+ else:
+ maps = sp.get_registered_maps_as_objects(where, "start_time", None)
+
+ # To have scalar values with the same name, we need to copy the raster maps using a single name
+ map_name = "%s_%i" % (sp.base.get_name(), os.getpid())
+
+ count = 0
+ if maps:
+ for map in maps:
+ if use_granularity:
+ id = map[0].get_map_id()
+ else:
+ id = map.get_map_id()
+ # None ids will be replaced by NULL maps
+ if id == None:
+ id = null_map
+
+ grass.run_command("g.copy", rast="%s,%s" % (id, map_name), overwrite=True)
+ out_name = "%6.6i_%s.vtk" % (count, sp.base.get_name())
+
+ mflags=""
+ if use_pdata:
+ mflags += "p"
+ if coorcorr:
+ mflags += "c"
+
+ # Export the raster map with r.out.vtk
+ if elevation:
+ ret = grass.run_command("r.out.vtk", flags=mflags, null=null, input=map_name, elevation=elevation, output=out_name, overwrite=grass.overwrite())
+ else:
+ ret = grass.run_command("r.out.vtk", flags=mflags, null=null, input=map_name, output=out_name, overwrite=grass.overwrite())
+
+ if ret != 0:
+ grass.fatal(_("Unable to export raster map <%s>" % name))
+
+ count += 1
+
+ if use_granularity:
+ grass.run_command("g.remove", rast=null_map)
+ grass.run_command("g.remove", rast=map_name)
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
Copied: grass/trunk/temporal/t.rast.out.vtk/test.t.rast.out.vtk.sh (from rev 51264, grass/trunk/temporal/tr.out.vtk/test.tr.out.vtk.sh)
===================================================================
--- grass/trunk/temporal/t.rast.out.vtk/test.t.rast.out.vtk.sh (rev 0)
+++ grass/trunk/temporal/t.rast.out.vtk/test.t.rast.out.vtk.sh 2012-04-05 21:06:06 UTC (rev 51277)
@@ -0,0 +1,53 @@
+# This is a test to export space time raster datasets as VTK time series data
+
+# 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 res=0.5 -p
+
+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 --o expr="elevation = sin(row() + col()) * 10"
+
+n1=`g.tempfile pid=1 -d`
+
+cat > "${n1}" << EOF
+prec_1|2001-01-01|2001-02-01
+prec_2|2001-02-01|2001-03-01
+prec_3|2001-03-01|2001-04-01
+prec_4|2001-05-01|2001-06-01
+prec_5|2001-07-01|2001-08-01
+prec_6|2001-08-01|2001-09-01
+EOF
+
+t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test with input files" descr="A test with input files"
+t.create --o type=strds temporaltype=absolute output=precip_abs2 title="A test with input files" descr="A test with input files"
+t.create --o type=strds temporaltype=absolute output=precip_abs3 title="A test with input files" descr="A test with input files"
+
+# The first @test
+mkdir /tmp/test1
+t.register -i type=rast input=precip_abs1 file="${n1}"
+t.rast.out.vtk input=precip_abs1 expdir=/tmp/test1
+ls -al /tmp/test1
+
+mkdir /tmp/test2
+t.register -i type=rast input=precip_abs2 file="${n1}"
+t.rast.out.vtk input=precip_abs2 expdir=/tmp/test2 elevation=elevation
+ls -al /tmp/test2
+
+mkdir /tmp/test3
+t.register -i type=rast input=precip_abs3 file="${n1}"
+t.rast.out.vtk -g input=precip_abs3 expdir=/tmp/test3 elevation=elevation
+ls -al /tmp/test3
+
+rm -rf /tmp/test1
+rm -rf /tmp/test2
+rm -rf /tmp/test3
+
+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
Deleted: grass/trunk/temporal/t.rast.out.vtk/test.tr.out.vtk.sh
===================================================================
--- grass/trunk/temporal/tr.out.vtk/test.tr.out.vtk.sh 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.out.vtk/test.tr.out.vtk.sh 2012-04-05 21:06:06 UTC (rev 51277)
@@ -1,53 +0,0 @@
-# This is a test to export space time raster datasets as VTK time series data
-
-# 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 res=0.5 -p
-
-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 --o expr="elevation = sin(row() + col()) * 10"
-
-n1=`g.tempfile pid=1 -d`
-
-cat > "${n1}" << EOF
-prec_1|2001-01-01|2001-02-01
-prec_2|2001-02-01|2001-03-01
-prec_3|2001-03-01|2001-04-01
-prec_4|2001-05-01|2001-06-01
-prec_5|2001-07-01|2001-08-01
-prec_6|2001-08-01|2001-09-01
-EOF
-
-t.create --o type=strds temporaltype=absolute output=precip_abs1 title="A test with input files" descr="A test with input files"
-t.create --o type=strds temporaltype=absolute output=precip_abs2 title="A test with input files" descr="A test with input files"
-t.create --o type=strds temporaltype=absolute output=precip_abs3 title="A test with input files" descr="A test with input files"
-
-# The first @test
-mkdir /tmp/test1
-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
-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
-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
-
-rm -rf /tmp/test1
-rm -rf /tmp/test2
-rm -rf /tmp/test3
-
-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
Deleted: grass/trunk/temporal/t.rast.out.vtk/tr.out.vtk.html
===================================================================
Deleted: grass/trunk/temporal/t.rast.out.vtk/tr.out.vtk.py
===================================================================
--- grass/trunk/temporal/tr.out.vtk/tr.out.vtk.py 2012-04-04 21:20:55 UTC (rev 51264)
+++ grass/trunk/temporal/t.rast.out.vtk/tr.out.vtk.py 2012-04-05 21:06:06 UTC (rev 51277)
@@ -1,159 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE: tr.out.vtk
-# AUTHOR(S): Soeren Gebbert
-#
-# PURPOSE: Export space time raster dataset as VTK time series
-# 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: Export space time raster dataset as VTK time series
-#% keywords: dataset
-#% keywords: spacetime
-#% keywords: raster
-#% keywords: export
-#% keywords: VTK
-#%end
-
-#%option G_OPT_STRDS_INPUT
-#%end
-
-#%option
-#% key: expdir
-#% type: string
-#% description: Path to the export directory
-#% required: yes
-#% multiple: no
-#%end
-
-#%option G_OPT_R_ELEV
-#% required: no
-#%end
-
-#%option G_OPT_T_WHERE
-#%end
-
-#%option
-#% key: null
-#% type: double
-#% description: Value to represent no data cell
-#% required: no
-#% multiple: no
-#% answer: -10.0
-#%end
-
-#%flag
-#% key: p
-#% description: Create VTK point data instead of VTK cell data (if no elevation map is given)
-#%end
-
-#%flag
-#% key: c
-#% description: Correct the coordinates to fit the VTK-OpenGL precision
-#%end
-
-#%flag
-#% key: g
-#% description: Export files using the space time dataset granularity for equidistant time between maps, where statement will be ignored
-#%end
-
-
-
-import os
-import grass.script as grass
-import grass.temporal as tgis
-
-############################################################################
-
-def main():
-
- # Get the options
- input = options["input"]
- elevation = options["elevation"]
- expdir = options["expdir"]
- where = options["where"]
- null = options["null"]
- use_pdata = flags["p"]
- coorcorr = flags["c"]
- use_granularity = flags["g"]
-
- # Make sure the temporal database exists
- tgis.create_temporal_database()
-
- if not os.path.exists(expdir):
- grass.fatal(_("Export directory <%s> not found.") % expdir)
-
- os.chdir(expdir)
-
- mapset = grass.gisenv()["MAPSET"]
-
- if input.find("@") >= 0:
- id = input
- else:
- id = input + "@" + mapset
-
- sp = tgis.space_time_raster_dataset(id)
-
- if sp.is_in_db() == False:
- grass.fatal(_("Space time %s dataset <%s> not found") % (sp.get_new_map_instance(None).get_type(), id))
-
- sp.select()
-
- if use_granularity:
- # Attention: A list of lists of maps will be returned
- maps = sp.get_registered_maps_as_objects_by_granularity()
- # Create a NULL map in case of granularity support
- null_map = "temporary_null_map_%i" % os.getpid()
- grass.mapcalc("%s = null()" % (null_map))
- else:
- maps = sp.get_registered_maps_as_objects(where, "start_time", None)
-
- # To have scalar values with the same name, we need to copy the raster maps using a single name
- map_name = "%s_%i" % (sp.base.get_name(), os.getpid())
-
- count = 0
- if maps:
- for map in maps:
- if use_granularity:
- id = map[0].get_map_id()
- else:
- id = map.get_map_id()
- # None ids will be replaced by NULL maps
- if id == None:
- id = null_map
-
- grass.run_command("g.copy", rast="%s,%s" % (id, map_name), overwrite=True)
- out_name = "%6.6i_%s.vtk" % (count, sp.base.get_name())
-
- mflags=""
- if use_pdata:
- mflags += "p"
- if coorcorr:
- mflags += "c"
-
- # Export the raster map with r.out.vtk
- if elevation:
- ret = grass.run_command("r.out.vtk", flags=mflags, null=null, input=map_name, elevation=elevation, output=out_name, overwrite=grass.overwrite())
- else:
- ret = grass.run_command("r.out.vtk", flags=mflags, null=null, input=map_name, output=out_name, overwrite=grass.overwrite())
-
- if ret != 0:
- grass.fatal(_("Unable to export raster map <%s>" % name))
-
- count += 1
-
- if use_granularity:
- grass.run_command("g.remove", rast=null_map)
- grass.run_command("g.remove", rast=map_name)
-
-if __name__ == "__main__":
- options, flags = grass.parser()
- main()
More information about the grass-commit
mailing list