granular-channel-hydro

Subglacial hydrology model for sedimentary channels
git clone git://src.adamsgaard.dk/granular-channel-hydro
Log | Files | Refs | README | LICENSE

commit 6ce83970ccaba7dd7c4f0ad316ce4f25f1e38e30
Author: Anders Damsgaard Christensen <adc@geo.au.dk>
Date:   Fri, 13 Jan 2017 21:02:16 -0800

first commit

Diffstat:
AREADME.md | 2++
Agranular_channel_drainage/__init__.py | 5+++++
Agranular_channel_drainage/model.py | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arequirements.txt | 4++++
4 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,2 @@ +# README + diff --git a/granular_channel_drainage/__init__.py b/granular_channel_drainage/__init__.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +__all__ = ['model'] +__version__ = '0.01' + +from model import model diff --git a/granular_channel_drainage/model.py b/granular_channel_drainage/model.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +import numpy +import matplotlib.pyplot as plt +import landlab + +class model: + def __init__(self, name='unnamed'): + ''' + Initialize a blank hydrology model object and optionally assign a + simulation name to it. + + :param name: A uniquely identifying simulation name + :type name: str + ''' + self.name = name + + def generateVoronoiDelaunayGrid(self, Lx, Ly, N, structure='pseudorandom'): + ''' + Generate a Voronoi Delaunay grid with randomly positioned nodes using + Landlab. + + :param Lx: A tuple containing the length along x of the model + domain. + :type Lx: float + :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 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 + to a regular grid. + :type structure: str + ''' + self.grid_type = 'VoronoiDelaunay' + + if structure == 'random': + x = numpy.random.rand(N)*Lx + y = numpy.random.rand(N)*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 + + 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) + fig = plt.figure() + plt.plot(self.grid.x_of_node, self.grid.y_of_node, '.') + plt.xlabel('$x$ [m]') + plt.ylabel('$y$ [m]') + if save: + plt.savefig('grid.' + saveformat) + else: + plt.show() + plt.close() + + + + diff --git a/requirements.txt b/requirements.txt @@ -0,0 +1,4 @@ +scipy>=0.14 +numpy +landlab +matplotlib