[GRASS-SVN] r61124 - sandbox/annakrat/r3.flow

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 2 12:02:12 PDT 2014


Author: annakrat
Date: 2014-07-02 12:02:12 -0700 (Wed, 02 Jul 2014)
New Revision: 61124

Modified:
   sandbox/annakrat/r3.flow/r3.flow.py
   sandbox/annakrat/r3.flow/rast3d_functions.py
Log:
r3.flow: renamed variables, better region handling

Modified: sandbox/annakrat/r3.flow/r3.flow.py
===================================================================
--- sandbox/annakrat/r3.flow/r3.flow.py	2014-07-02 18:33:32 UTC (rev 61123)
+++ sandbox/annakrat/r3.flow/r3.flow.py	2014-07-02 19:02:12 UTC (rev 61124)
@@ -99,7 +99,7 @@
 from grass.pygrass.vector.geometry import Line, Point
 
 from integrate import rk4_integrate_next, rk45_integrate_next, get_time_step, MIN_STEP, MAX_STEP
-from rast3d_functions import get_velocity, norm, rast3d_location2coord
+from rast3d_functions import get_velocity, norm, rast3d_location2coord, get_region_info
 from voxel_traversal import traverse
 
 EPSILON = 1e-8
@@ -120,9 +120,8 @@
         self.compute_gradient = False
         self.vector_arrays = None
         self.scalar_array = None
-        self.last_neighbors_values = None
-        self.last_neighbors_extent = None
-        self.last_shift = None
+        self.neighbors_values = None
+        self.neighbors_pos = None
 
 
 def main():
@@ -139,14 +138,12 @@
         for inp, vel in zip((v_x, v_y, v_z), velocity_arrays):
             if vel.read(mapname=inp) != 0:
                 gcore.fatal(_("Error when reading input 3D raster maps"))
-        map_info = grast3d.raster3d_info(v_x)
         velocity_obj.vector_arrays = velocity_arrays
         velocity_obj.compute_gradient = False
 
     elif options['input']:
         scalar_array = garray.array3d()
         scalar_array.read(mapname=options['input'])
-        map_info = grast3d.raster3d_info(options['input'])
         velocity_obj.compute_gradient = True
         velocity_obj.scalar_array = scalar_array
     else:
@@ -156,6 +153,7 @@
     if not (options['flowaccumulation'] or options['flowline']):
         gcore.fatal("At least one of output options flowline or flowaccumulation must be specified.")
 
+    map_info = get_region_info()
     # integrating forward means upstream, backward means downstream
     if flags['u']:
         direction = 1

Modified: sandbox/annakrat/r3.flow/rast3d_functions.py
===================================================================
--- sandbox/annakrat/r3.flow/rast3d_functions.py	2014-07-02 18:33:32 UTC (rev 61123)
+++ sandbox/annakrat/r3.flow/rast3d_functions.py	2014-07-02 19:02:12 UTC (rev 61124)
@@ -6,9 +6,18 @@
 import math
 import numpy
 from gradient import gradient
-#from grass.script import raster3d as grast3d
 
+from grass.script import core as gcore
 
+
+def get_region_info():
+    region = gcore.region(region3d=True)
+    for old, new in zip(['n', 's', 'e', 'w', 't', 'b'],
+                        ['north', 'south', 'east', 'west', 'top', 'bottom']):
+        region[new] = region.pop(old)
+    return region
+
+
 def get_velocity(rast3d_region, velocity_obj, point):
     if velocity_obj.compute_gradient:
         return get_gradient(rast3d_region, velocity_obj, point)
@@ -30,12 +39,10 @@
     minx, maxx = nearest[0][0], nearest[7][0]
     miny, maxy = nearest[7][1], nearest[0][1]
     minz, maxz = nearest[0][2], nearest[7][2]
-    # min, max of x, y, z neighboring voxels
-    neighbors_extent = [minx, maxx,
-                        miny, maxy,
-                        minz, maxz]
-    if not velocity_obj.last_neighbors_extent or neighbors_extent != velocity_obj.last_neighbors_extent:
-        velocity_obj.last_neighbors_extent = neighbors_extent
+    # position of x, y, z neighboring voxels
+    neighbors_pos = [minx, miny, minz]
+    if not velocity_obj.neighbors_pos or neighbors_pos != velocity_obj.neighbors_pos:
+        velocity_obj.neighbors_pos = neighbors_pos
 
         # just to be sure, we check that at least one voxel is inside
         if maxx < 0 or minx >= rast3d_region['cols'] or \
@@ -103,9 +110,9 @@
                         else:
                             array_values[i].append(xyz_gradients[i][z + zshift][y + yshift][x + xshift])
 
-        velocity_obj.last_neighbors_values = array_values
+        velocity_obj.neighbors_values = array_values
     else:
-        array_values = velocity_obj.last_neighbors_values
+        array_values = velocity_obj.neighbors_values
 
     x, y, z = get_relative_coords_for_interp(rast3d_region, point[1], point[0], point[2])
 



More information about the grass-commit mailing list