commit 1a5a3056676e890a1bb8924f0290be3566cd1648
parent 0d87e7f51ab71bc4832b9cb19bfcbda63990f5ad
Author: Anders Damsgaard Christensen <adc@geo.au.dk>
Date: Sat, 14 Jan 2017 09:00:01 -0800
improve plotting
Diffstat:
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/granular_channel_drainage/model.py b/granular_channel_drainage/model.py
@@ -63,22 +63,19 @@ class model:
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)
+ 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)
else:
raise Exception('generateVoronoiDelaunayGrid: ' +
- 'distribution type ' + distribution +
- ' not understood.')
+ 'distribution type "' + distribution +
+ '" not understood.')
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, field='nodes',
save=False, saveformat='pdf'):
fig = plt.figure()
@@ -89,12 +86,31 @@ class model:
landlab.plot.imshow_grid(self.grid, field)
plt.tight_layout()
if save:
- plt.savefig('grid.' + saveformat)
+ plt.savefig(self.name + '-' + field + '.' + saveformat)
else:
plt.show()
plt.clf()
plt.close()
+ def gridCoordinates(self):
+ '''
+ Returns the grid coordinates.
+ '''
+ return self.grid.node_x, self.grid.node_y
+
+ def addScalarField(self, name, values, units):
+ '''
+ Add scalar field to the model grid.
+
+ :param name: A uniquely identifying name for the scalar field.
+ :type name: str
+ :param values: The values to be inserted to the scalar field.
+ :type name: ndarray
+ :param units: The unit associated with the values, e.g. 's' or 'm'
+ :type units: str
+ '''
+ self.grid.add_field('node', name, values, units=units, copy=True)
+