[GRASS-SVN] r61403 - in grass-addons/grass7/raster3d/r3.flow: . testsuite
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 25 12:42:31 PDT 2014
Author: annakrat
Date: 2014-07-25 12:42:30 -0700 (Fri, 25 Jul 2014)
New Revision: 61403
Added:
grass-addons/grass7/raster3d/r3.flow/test.r3flow.html
grass-addons/grass7/raster3d/r3.flow/test_main.c
grass-addons/grass7/raster3d/r3.flow/testsuite/
grass-addons/grass7/raster3d/r3.flow/testsuite/r3flow_test.py
Modified:
grass-addons/grass7/raster3d/r3.flow/Makefile
Log:
r3.flow: testing module and test added
Modified: grass-addons/grass7/raster3d/r3.flow/Makefile
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/Makefile 2014-07-25 15:21:47 UTC (rev 61402)
+++ grass-addons/grass7/raster3d/r3.flow/Makefile 2014-07-25 19:42:30 UTC (rev 61403)
@@ -1,12 +1,15 @@
MODULE_TOPDIR = ../..
-PGM=r3.flow
+PROGRAMS = r3.flow test.r3flow
LIBES = $(RASTER3DLIB) $(RASTERLIB) $(GISLIB) $(VECTORLIB)
DEPENDENCIES = $(RASTER3DDEP) $(RASTERDEP) $(GISDEP) $(VECTORDEP)
EXTRA_INC = $(VECT_INC)
EXTRA_CFLAGS = $(VECT_CFLAGS)
-include $(MODULE_TOPDIR)/include/Make/Module.make
+r3_flow_OBJS = main.o flowline.o gradient.o integrate.o interpolate.o voxel_traversal.o
+test_r3flow_OBJS = test_main.o flowline.o gradient.o integrate.o interpolate.o voxel_traversal.o
-default: cmd
+include $(MODULE_TOPDIR)/include/Make/Multi.make
+
+default: multi
Added: grass-addons/grass7/raster3d/r3.flow/test.r3flow.html
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/test.r3flow.html (rev 0)
+++ grass-addons/grass7/raster3d/r3.flow/test.r3flow.html 2014-07-25 19:42:30 UTC (rev 61403)
@@ -0,0 +1,14 @@
+<h2>DESCRIPTION</h2>
+Testing module for <em>r3.flow</em>.
+
+
+<h2>AUTHORS</h2>
+Anna Petrasova
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r3.flow.html">r3.flow</a>
+</em>
+
+<p><i>Last changed: $Date$</i>
Property changes on: grass-addons/grass7/raster3d/r3.flow/test.r3flow.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Added: grass-addons/grass7/raster3d/r3.flow/test_main.c
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/test_main.c (rev 0)
+++ grass-addons/grass7/raster3d/r3.flow/test_main.c 2014-07-25 19:42:30 UTC (rev 61403)
@@ -0,0 +1,105 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <grass/raster3d.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+#include "r3flow_structs.h"
+#include "flowline.h"
+#include "interpolate.h"
+
+static void test_interpolation(RASTER3D_Region * region,
+ RASTER3D_Map ** input_maps, double north,
+ double east, double top)
+{
+ double interpolated[3];
+
+ if (interpolate_velocity(region, input_maps, north, east, top,
+ &interpolated[0], &interpolated[1],
+ &interpolated[2]) < 0) {
+ fprintf(stdout, "return=-1\n");
+ }
+ else
+ fprintf(stdout, "return=0\nvalues=%.10f,%.10f,%.10f\n",
+ interpolated[0], interpolated[1], interpolated[2]);
+
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+ struct GModule *module;
+ struct Option *test_opt, *coordinates_opt, *input_opt;
+ RASTER3D_Region region;
+ RASTER3D_Map *input_3drasters[3];
+ double coordinates[3];
+
+ G_gisinit(argv[0]);
+ module = G_define_module();
+ G_add_keyword(_("raster3d"));
+ G_add_keyword(_("voxel"));
+ G_add_keyword(_("flowline"));
+ module->description = _("Testing flow lines.");
+
+ test_opt = G_define_option();
+ test_opt->key = "test";
+ test_opt->required = YES;
+ test_opt->type = TYPE_STRING;
+ test_opt->options = "interpolation,gradient";
+ test_opt->description = "Select what is tested";
+
+ coordinates_opt = G_define_option();
+ coordinates_opt->key = "coordinates";
+ coordinates_opt->required = NO;
+ coordinates_opt->type = TYPE_DOUBLE;
+ coordinates_opt->multiple = YES;
+ coordinates_opt->description = "x,y,z coordinates";
+
+ input_opt = G_define_standard_option(G_OPT_R3_INPUTS);
+ input_opt->required = NO;
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ Rast3d_init_defaults();
+ Rast3d_get_window(®ion);
+
+ if (strcmp(test_opt->answer, "interpolation") == 0) {
+
+
+ if (input_opt->answers) {
+ for (i = 0; i < 3; i++) {
+ input_3drasters[i] =
+ Rast3d_open_cell_old(input_opt->answers[i],
+ G_find_raster3d(input_opt->
+ answers[i], ""),
+ ®ion, RASTER3D_TILE_SAME_AS_FILE,
+ RASTER3D_USE_CACHE_DEFAULT);
+ if (input_3drasters[i] == NULL)
+ Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"),
+ input_opt->answers[i]);
+ }
+ }
+ else
+ G_fatal_error("No input map for interpolation test");
+ if (coordinates_opt->answers) {
+ for (i = 0; i < 3; i++) {
+ if (coordinates_opt->answers[i]) {
+ coordinates[i] = atof(coordinates_opt->answers[i]);
+ }
+ else
+ G_fatal_error("Provide 3 coordinates");
+ }
+ }
+ else
+ G_fatal_error("No coordinates for interpolation test");
+ test_interpolation(®ion, input_3drasters, coordinates[1],
+ coordinates[0], coordinates[2]);
+ }
+
+ return EXIT_SUCCESS;
+}
Property changes on: grass-addons/grass7/raster3d/r3.flow/test_main.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Added: grass-addons/grass7/raster3d/r3.flow/testsuite/r3flow_test.py
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/testsuite/r3flow_test.py (rev 0)
+++ grass-addons/grass7/raster3d/r3.flow/testsuite/r3flow_test.py 2014-07-25 19:42:30 UTC (rev 61403)
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+"""
+Test of r3.flow
+
+ at author Anna Petrasova
+"""
+from grass.gunittest import TestCase, test
+
+
+class FlowlineTest(TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Use temporary region settings"""
+ cls.use_temp_region()
+ cls.runModule("g.region", res=10, res3=10, n=80, s=0, w=0, e=120, b=0, t=50)
+ cls.runModule("r3.mapcalc", expression="map_1 = 100", overwrite=True)
+ cls.runModule("r3.mapcalc", expression="map_2 = -20", overwrite=True)
+ cls.runModule("r3.mapcalc", expression="map_3 = 0.01", overwrite=True)
+ cls.runModule("r3.mapcalc", expression="map_4 = col() + row() + depth()", overwrite=True)
+
+ @classmethod
+ def tearDownClass(cls):
+ """!Remove the temporary region"""
+ cls.del_temp_region()
+ cls.runModule('g.remove', rast3d=['map_1', 'map_2', 'map_3', 'map_4'])
+
+ def test_interpolation(self):
+ self.assertModuleKeyValue('test.r3flow', test='interpolation',
+ coordinates=[100, 55, 11], input=['map_1', 'map_2', 'map_3'],
+ reference={'return': 0, 'values': [100, -20, 0.01]},
+ precision=1e-10, sep='=')
+ self.assertModuleKeyValue('test.r3flow', test='interpolation',
+ coordinates=[5, 5, 5], input=['map_1', 'map_2', 'map_3'],
+ reference={'return': 0, 'values': [100, -20, 0.01]},
+ precision=1e-10, sep='=')
+ self.assertModuleKeyValue('test.r3flow', test='interpolation',
+ coordinates=[10, 10, 60], input=['map_1', 'map_2', 'map_3'],
+ reference={'return': -1},
+ precision=1e-10, sep='=')
+ self.assertModuleKeyValue('test.r3flow', test='interpolation',
+ coordinates=[25, 69, 17], input=['map_4', 'map_4', 'map_4'],
+ reference={'return': 0, 'values': [7.8, 7.8, 7.8]},
+ precision=1e-10, sep='=')
+ self.assertModuleKeyValue('test.r3flow', test='interpolation',
+ coordinates=[81, 30, 25], input=['map_4', 'map_4', 'map_4'],
+ reference={'return': 0, 'values': [18.1, 18.1, 18.1]},
+ precision=1e-10, sep='=')
+
+
+if __name__ == '__main__':
+ test()
Property changes on: grass-addons/grass7/raster3d/r3.flow/testsuite/r3flow_test.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list