commit 2d67c5273687771f252c74c50e75732c5bafe7a4
parent 1a5a3056676e890a1bb8924f0290be3566cd1648
Author: Anders Damsgaard Christensen <adc@geo.au.dk>
Date: Sat, 14 Jan 2017 11:06:37 -0800
add documentation to plotGrid, remove old code
Diffstat:
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/granular_channel_drainage/model.py b/granular_channel_drainage/model.py
@@ -46,28 +46,23 @@ class model:
if structure == 'random':
x = numpy.random.rand(Nx*Ny)*Lx
y = numpy.random.rand(Nx*Ny)*Ly
+
elif structure == 'pseudorandom':
- #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)
dx = Lx/Nx
dy = Ly/Ny
xPoints = numpy.linspace(dx*.5, Lx - dx*.5, Nx)
yPoints = numpy.linspace(dy*.5, Ly - dy*.5, Ny)
gridPoints = numpy.array([[x,y] for y in yPoints for x in xPoints])
N = len(gridPoints[:, 0])
+
if distribution == 'normal':
gridPoints[::2, 1] = gridPoints[::2, 1] + dy*0.5
x = gridPoints[:, 0] + numpy.random.normal(0., dx*0.10, N)
y = gridPoints[:, 1] + numpy.random.normal(0., dy*0.10, N)
+
elif distribution == 'uniform':
- x = gridPoints[:, 0] + numpy.random.uniform(-dx*.5, dx*.5, N)
- y = gridPoints[:, 1] + numpy.random.uniform(-dy*.5, dy*.5, N)
+ x = gridPoints[:, 0] + numpy.random.uniform(-dx*.4, dx*.4, N)
+ y = gridPoints[:, 1] + numpy.random.uniform(-dy*.4, dy*.4, N)
else:
raise Exception('generateVoronoiDelaunayGrid: ' +
@@ -78,6 +73,18 @@ class model:
def plotGrid(self, field='nodes',
save=False, saveformat='pdf'):
+ '''
+ Plot the grid nodes or one of the fields associated with the grid.
+
+ :param field: Field to plot (e.g., 'bed_elevation')
+ :type field: str
+ :param save: Save figure to file (default) or show in interactive
+ window?
+ :type save: bool
+ :param saveformat: File format to save the plot as if ``save=True``.
+ :type saveformat: str
+ '''
+
fig = plt.figure()
if field == 'nodes':
plt.plot(self.grid.node_x, self.grid.node_y, '.')
@@ -110,7 +117,3 @@ class model:
:type units: str
'''
self.grid.add_field('node', name, values, units=units, copy=True)
-
-
-
-