tfix grid generation, increase random variability of point positioning - granular-channel-hydro - subglacial hydrology model for sedimentary channels
 (HTM) git clone git://src.adamsgaard.dk/granular-channel-hydro
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 8983440e41f994aedaf6b34648e690dedb03818a
 (DIR) parent 6ce83970ccaba7dd7c4f0ad316ce4f25f1e38e30
 (HTM) Author: Anders Damsgaard Christensen <adc@geo.au.dk>
       Date:   Fri, 13 Jan 2017 22:35:01 -0800
       
       fix grid generation, increase random variability of point positioning
       
       Diffstat:
         M granular_channel_drainage/model.py  |      53 +++++++++++++++++++------------
       
       1 file changed, 32 insertions(+), 21 deletions(-)
       ---
 (DIR) diff --git a/granular_channel_drainage/model.py b/granular_channel_drainage/model.py
       t@@ -14,7 +14,8 @@ class model:
                '''
                self.name = name
        
       -    def generateVoronoiDelaunayGrid(self, Lx, Ly, N, structure='pseudorandom'):
       +    def generateVoronoiDelaunayGrid(self, Lx, Ly, Nx, Ny,
       +                                    structure='pseudorandom'):
                '''
                Generate a Voronoi Delaunay grid with randomly positioned nodes using
                Landlab.
       t@@ -25,8 +26,10 @@ class model:
                :param Ly: A tuple containing the length along y of the model
                    domain.
                :type Ly: float
       -        :param N: The number of random model nodes in the model.
       -        :type N: int
       +        :param Nx: The number of random model nodes along ``x`` in the model.
       +        :type Nx: int
       +        :param Ny: The number of random model nodes along ``y`` in the model.
       +        :type Ny: int
                :param structure: The type of numeric distribution used to seed the
                    grid. A ``random`` grid will produce uniformly random-distributed
                    grid points, while ``pseudorandom`` (default) will add random noise
       t@@ -36,36 +39,44 @@ class model:
                self.grid_type = 'VoronoiDelaunay'
        
                if structure == 'random':
       -            x = numpy.random.rand(N)*Lx
       -            y = numpy.random.rand(N)*Ly
       +            x = numpy.random.rand(Nx*Ny)*Lx
       +            y = numpy.random.rand(Nx*Ny)*Ly
                elif structure == 'pseudorandom':
       -            noise_amplitude = Lx/(N**0.5)*0.01
       -            x = numpy.linspace(0, Lx, N) + \
       -                numpy.random.normal(0., noise_amplitude, N)
       -            y = numpy.linspace(0, Ly, N) + \
       -                numpy.random.normal(0., noise_amplitude, N)
       -            print x
       -            print y
       -            x = numpy.random.shuffle(x) # why does this return an empty array?
       -            y = numpy.random.shuffle(y)
       -            print x
       -            print y
       +            #noise_amplitude = Lx/(N**0.5)*0.001
       +            #noise_amplitude = 1.
       +            #x = numpy.linspace(0, Lx, N) #+ \
       +                #numpy.random.normal(0., noise_amplitude, N)
       +            #y = numpy.linspace(0, Ly, N) #+ \
       +                #numpy.random.normal(0., noise_amplitude, N)
       +            #numpy.random.shuffle(x)
       +            #numpy.random.shuffle(y)
       +            xPoints = numpy.linspace(0., Lx, Nx)
       +            yPoints = numpy.linspace(0., Ly, Ny)
       +            gridPoints = numpy.array([[x,y] for y in yPoints for x in xPoints])
       +            gridPoints[::2, 1] = gridPoints[::2, 1] + Lx/Nx*0.5
       +            N = len(gridPoints[:, 0])
       +            x = gridPoints[:, 0] + numpy.random.normal(0, Lx/Nx*0.10, N)
       +            y = gridPoints[:, 1] + numpy.random.normal(0, Ly/Ny*0.10, N)
        
                self.grid = landlab.grid.VoronoiDelaunayGrid(x, y)
        
                self.grid.add_zeros('node', 'bed__topographic__elevation')
                self.grid.add_zeros('node', 'surface__topographic__elevation')
        
       -    def plotGrid(self, save=False, saveformat='pdf'):
       -        #landlab.plot.imshow_grid(self.grid, self.grid.node_x)
       +    def plotGrid(self, field='nodes',
       +                 save=False, saveformat='pdf'):
                fig = plt.figure()
       -        plt.plot(self.grid.x_of_node, self.grid.y_of_node, '.')
       -        plt.xlabel('$x$ [m]')
       -        plt.ylabel('$y$ [m]')
       +        if field == 'nodes':
       +            plt.plot(self.grid.node_x, self.grid.node_y, '.')
       +            plt.axis('equal')
       +        else:
       +            landlab.plot.imshow_grid(self.grid, field)
       +        plt.tight_layout()
                if save:
                    plt.savefig('grid.' + saveformat)
                else:
                    plt.show()
       +        plt.clf()
                plt.close()