rafem package

Submodules

rafem.FP module

rafem.FP.add_to_neighboring_cells(z, sub, inc, win=1)[source]

Add a value to all neighboring cells.

Parameters
  • z (ndarray) – 2D array of values.

  • sub (tuple of int) – Row/column subscripts into array.

  • inc (float) – Value to increment z by.

  • win (int) – Size of the window around sub.

Examples

>>> x = np.zeros((4, 5))
>>> add_around_cell(x, (0, 0), 1)
rafem.FP.dep_blanket(current_SL, blanket_rate, n, riv_i, riv_j, ch_depth)[source]
rafem.FP.dep_fines(n, riv_i, riv_j, dn_rc, frac_fines, SL)[source]
rafem.FP.dep_splay(n, ij_fail, splay_dep, splay_type=1)[source]

Deposit around a failed river cell.

Parameters
  • n (ndarray) – Elevation array.

  • ij_path (tuple of int) – Row and column of the river failure.

  • old_path (tuple of array_like) – Row and column indices for the old river path.

  • a (int) – River path index of the failure.

  • splay_depth (float) – Deposition depth.

  • splay_type ({1, 2}, optional) – Failure type

  • DEPTH-DEPENDENCE IN THE FUTURE (USE) – SE1 = (n[riv_x[a]/dx][riv_y[a]/dy] + ch_depth - n[new_riv_x[a]/dx][new_riv_y[a]/dy]) / ch_depth

  • LARGER SPLAY TYPE IN FUTURE? (ADD) –

  • be first two failed river cells + surrounding) ((could) –

  • could possibly be improved by comparing to find nearest beach routine (CEM) (This) –

  • using some sort of search radius (or) –

rafem.FP.distance_to_river(y, y0)[source]
rafem.FP.wetlands(current_SL, WL_Z, wetland_width, n, riv_i, riv_j, y, x)[source]
rafem.FP.within_wetland(y, riv_ind, wetland_width=0.0)[source]

rafem.SLR module

rafem.SLR.elev_change(current_SL, n, riv_i, riv_j, ch_depth, SLRR)[source]

Raise elevations to sea level if below sea level.

Set elevations of cells below sea level to sea level unless they are within the river channel.

Parameters
  • current_SL (float) – Sea level.

  • n (ndarray) – Array of elevations.

  • riv_i (ndarray of int) – Row indices into n for river cells.

  • riv_j (ndarray of int) – Column indices into n for river cells.

  • ch_depth (float) – Channel depth.

rafem.avulse module

rafem.avulse.avulse_to_new_path(z, old, new, sea_level, channel_depth, avulsion_type, slope, dx=1.0, dy=1.0)[source]

Avulse the river to a new path.

Given two river paths, old and new, avulse the river to a new river path. If the end point of the new path is contained in the old river path, the resulting path is the new path up until this point and then the old path. Otherwise, the resulting path is the new river path and will be downcut.

Parameters
  • z (ndarray) – 2D array of elevations.

  • old (tuple of array_like) – Tuple of i and j indices (into z) for the old path.

  • new (tuple of array_like) – Tuple of i and j indices (into z) for the new path.

  • sea_level (float) – Elevation of sea level.

  • channel_depth (float) – Depth of the channel.

  • avulsion_type ({0, 1, 2, 3}) – The type of the avulsion.

  • dx (float, optional) – Spacing of columns of z.

  • dy (float, optional) – Spacing of rows of z.

Returns

Tuple of the new river path (as i, j indices) and the, possibly changed, avulsion type.

Return type

tuple

Examples

The following example uses a grid that looks like:

o  +  *  *
*  o  +  *
*  *  +  *
*  *  o  *
*  o  *  *

The old path is marked by o, the new path but +. The paths overlap (2, 2).

>>> import numpy as np
>>> z = np.ones((5, 4), dtype=float)
>>> old = np.array((0, 1, 2, 3, 4)), np.array((0, 1, 2, 2, 1))
>>> new = np.array((0, 1, 2)), np.array((1, 2, 2))
>>> (new, atype) = avulse_to_new_path(z, old, new, 0., 0., 0)

The new path follows the new path until the common point and then follows the old path. The new avulsion type is now 2.

>>> new
(array([0, 1, 2, 3, 4]), array([1, 2, 2, 2, 1]))
>>> atype
2

In this example the old and new paths do not overlap:

o  +  *  *
*  o  +  *
*  *  o  +
*  *  o  +
*  o  *  +
>>> old = np.array((0, 1, 2, 3, 4)), np.array((0, 1, 2, 2, 1))
>>> new = np.array((0, 1, 2, 3, 4)), np.array((1, 2, 3, 3, 3))
>>> (new, atype) = avulse_to_new_path(z, old, new, 0., 0., 0)

The new path is now, in fact, the actual new path and the avulsion type is unchanged.

>>> new
(array([0, 1, 2, 3, 4]), array([1, 2, 3, 3, 3]))
>>> atype
0
rafem.avulse.find_avulsion(riv_i, riv_j, n, super_ratio, current_SL, ch_depth, short_path, splay_type, slope, splay_depth, nu, dt, dx=1.0, dy=1.0)[source]

rafem.avulsion_utils module

rafem.avulsion_utils.channel_is_superelevated(z, riv, behind, channel_depth, super_ratio, sea_level)[source]

Check if a channel location is super-elevated.

Parameters
  • z (ndarray) – 2D-array of elevations.

  • sub (tuple of int) – Row-column subscripts into z.

  • channel_depth (float) – The depth of the channel.

  • super_ratio (float) – Ratio of bankfull elevation to out-of-channel elevation for channel to be super-elevated.

Returns

True if channel is super-elevated. Otherwise, False.

Return type

boolean

rafem.avulsion_utils.fill_abandoned_channel(breach_loc, n, new, riv_i, riv_j, current_SL, ch_depth, slope, dx)[source]
rafem.avulsion_utils.fill_upstream(z, riv_ij, dx=1.0, dy=1.0)[source]

Fill depressions upstream of a pit.

Examples

>>> import numpy as np
>>> z = np.array([[3, 3, 3, 3, 3],
...               [2, 2, 2, 2, 2],
...               [1, 1, 0, 1, 1],
...               [0, 0, 1, 0, 0]], dtype=float)
>>> ij = [(0, 2), (1, 2), (2, 2), (3, 2)]
>>> fill_upstream(z, ij)
array([[ 3. ,  3. ,  3. ,  3. ,  3. ],
       [ 2. ,  2. ,  2. ,  2. ,  2. ],
       [ 1. ,  1. ,  1.5,  1. ,  1. ],
       [ 0. ,  0. ,  1. ,  0. ,  0. ]])
>>> z = np.array([[3, 3, 1, 3, 3],
...               [2, 2, 0, 2, 2],
...               [1, 1, 1, 1, 1],
...               [0, 0, 2, 0, 0]], dtype=float)
>>> ij = [(0, 2), (1, 2), (2, 2), (3, 2)]
>>> fill_upstream(z, ij)
rafem.avulsion_utils.find_beach_length_riv_cell(n, sub0, sub1, sea_level, channel_depth, slope, dx=1.0, dy=1.0)[source]

Find length of beach in shoreline cell with river.

Parameters
  • z (ndarray) – 2D-array of elevations.

  • sub0 (tuple of int) – Row-column subscripts into z. (cell prior to beach)

  • sub1 (tuple of int) – Row-column subscripts into z. (beach cell)

  • sea_level (float) – Elevation of current sea level.

  • channel_depth (float) – The depth of the channel.

Returns

Return type

Length of beach in a cell.

rafem.avulsion_utils.find_new_beach_length(n, sub0, sub1, sea_level, dx=1.0, dy=1.0)[source]
rafem.avulsion_utils.find_path_length(n, path, sea_level, ch_depth, slope, dx=1.0, dy=1.0)[source]
rafem.avulsion_utils.find_point_in_path(path, sub)[source]

Find a point in a path.

Parameters
  • path (tuple of array_like) – Tuple of arrays of int that represent indices into a matrix.

  • sub (tuple in int) – Indices to search path for.

Returns

Index into path if the indices are found. Otherwise, None.

Return type

int or None

Examples

>>> path = ((0, 1, 4, 6, 5), (3, 1, 7, 8, 10))
>>> find_point_in_path(path, (4, 7))
2
>>> find_point_in_path(path, (99, 2)) is None
True
rafem.avulsion_utils.find_riv_path_length(n, path, sea_level, ch_depth, slope, dx=1.0, dy=1.0)[source]
rafem.avulsion_utils.fix_elevations(z, riv_i, riv_j, ch_depth, sea_level, slope, dx, max_rand, SLRR)[source]
rafem.avulsion_utils.get_channel_distance(path, dx=1.0, dy=1.0)[source]
rafem.avulsion_utils.is_diagonal_neighbor(sub0, sub1)[source]
rafem.avulsion_utils.is_same_row(sub0, sub1)[source]
rafem.avulsion_utils.lowest_cell_elev(n, sub)[source]
rafem.avulsion_utils.lowest_face(n, sub)[source]
rafem.avulsion_utils.read_params_from_file(fname)[source]

Read model parameters from a file.

Parameters

fname (str) – Name of YAML-formatted parameters file.

Returns

A dict of parameters for the heat model.

Return type

dict

rafem.avulsion_utils.set_linear_profile(z, riv_ij, dx=1.0, dy=1.0)[source]

Set elevations along a path to be linear.

Examples

>>> import numpy as np
>>> z = np.array([[0, 0, 0, 0, 0],
...               [1, 2, 1, 1, 1],
...               [2, 2, 2, 2, 2],
...               [3, 3, 3, 3, 3]], dtype=float)
>>> ij = [(0, 2), (1, 2), (2, 2), (3, 2)]
>>> set_linear_profile(z, ij)
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 1.,  2.,  1.,  1.,  1.],
       [ 2.,  2.,  2.,  2.,  2.],
       [ 3.,  3.,  3.,  3.,  3.]])
>>> ij = [(0, 0), (1, 1), (2, 2), (3, 1)]
>>> set_linear_profile(z, ij, dx=3., dy=4.)
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 1.,  1.,  1.,  1.,  1.],
       [ 2.,  2.,  2.,  2.,  2.],
       [ 3.,  3.,  3.,  3.,  3.]])
rafem.avulsion_utils.set_linear_slope(z, riv_ij, dx=1.0, dy=1.0)[source]

Set slope along a path to be linear.

rafem.avulsion_utils.sort_lowest_neighbors(n, sub)[source]

Sort neighbor cells by elevation.

rafem.diffuse module

rafem.diffuse.calc_crevasse_dep(dx, dy, nu, dt, ch_depth, riv_i, riv_j, n, sea_level, slope, loc)[source]

Calculate crevasse splay deposition rate.

rafem.diffuse.smooth_rc(dx, dy, nu, dt, ch_depth, riv_i, riv_j, n, sea_level, slope)[source]

Smooth river channel elevations using the diffusion equation.

Parameters
  • dx (float) – Spacing of grid columns.

  • dy (float) – Spacing of grid rows.

  • nu (float) – Diffusion coefficient.

  • dt (float) – Time step (in seconds).

  • riv_i (ndarray) – Row indices for the river path.

  • riv_j (ndarray) – Column indices for the river path.

  • n (ndarray) – 2D array of grid elevations.

rafem.diffuse.solve_second_derivative(x, y)[source]

Solve the second derivative of y with respect to x.

Use finite difference to solve the second derivative of y with respect to x where x can be unevenly spaced.

Examples

Values can be evenly spaced.

>>> import numpy as np
>>> x = np.array([2., 3., 4.])
>>> y = np.array([4., 9., 16.])
>>> solve_second_derivative(x, y)
array([ 2.])

Values are unevenly spaced.

>>> x = np.array([2., 3., 5.])
>>> y = np.array([4., 9., 25.])
>>> solve_second_derivative(x, y)
array([ 2.])

rafem.downcut module

rafem.downcut.cut_init(riv_i, riv_j, n, init_cut)[source]
rafem.downcut.cut_local(riv_i, riv_j, n, dx=1.0, dy=1.0)[source]

Set elevations of new portions of a profile after local avulsion.

rafem.downcut.cut_new(riv_i, riv_j, n, sea_level, ch_depth, dx=1.0, dy=1.0)[source]

Set elevations of new portions of a profile.

rafem.flux module

rafem.flux.calc_qs(nu, riv_i, riv_j, n, sea_level, ch_depth, dx, dy, dt, slope)[source]

Calculate sediment flux at river mouth.

rafem.main module

class rafem.main.RafemOutputWriter(bmi, output_interval=1)[source]

Bases: object

property prefix
time_stamp()[source]
update(n_steps)[source]
rafem.main.empty_bmi_var_array(bmi, name)[source]
rafem.main.setup_yaml_with_canonical_dict()[source]

https://stackoverflow.com/a/8661021

rafem.prof module

rafem.prof.make_profile(n, riv_i, riv_j)[source]

Get elevations along the river profile.

rafem.riverbmi module

Basic Model Interface implementation for River Module

class rafem.riverbmi.BmiRiverModule[source]

Bases: bmipy.bmi.Bmi

The BMI for the River Avulsion Floodplain Evolution Model.

finalize()[source]

Perform tear-down tasks for the model.

Perform all tasks that take place after exiting the model’s time loop. This typically includes deallocating memory, closing files and printing reports.

get_component_name()[source]

Name of the component.

Returns

The name of the component.

Return type

str

get_current_time()[source]

Current time of the model.

Returns

The current model time.

Return type

float

get_end_time()[source]

End time of the model.

Returns

The maximum model time.

Return type

float

get_grid_edge_count(grid)[source]

Get the number of edges in the grid.

Parameters

grid (int) – A grid identifier.

Returns

The total number of grid edges.

Return type

int

get_grid_edge_nodes(grid, edge_nodes)[source]

Get the edge-node connectivity.

Parameters
  • grid (int) – A grid identifier.

  • edge_nodes (ndarray of int, shape (2 x nnodes,)) – A numpy array to place the edge-node connectivity. For each edge, connectivity is given as node at edge tail, followed by node at edge head.

Returns

The input numpy array that holds the edge-node connectivity.

Return type

ndarray of int

get_grid_face_count(grid)[source]

Get the number of faces in the grid.

Parameters

grid (int) – A grid identifier.

Returns

The total number of grid faces.

Return type

int

get_grid_face_edges(grid, face_edges)[source]

Get the face-edge connectivity.

Parameters
  • grid (int) – A grid identifier.

  • face_edges (ndarray of int) – A numpy array to place the face-edge connectivity.

Returns

The input numpy array that holds the face-edge connectivity.

Return type

ndarray of int

get_grid_face_nodes(grid, face_nodes)[source]

Get the face-node connectivity.

Parameters
  • grid (int) – A grid identifier.

  • face_nodes (ndarray of int) – A numpy array to place the face-node connectivity. For each face, the nodes (listed in a counter-clockwise direction) that form the boundary of the face.

Returns

The input numpy array that holds the face-node connectivity.

Return type

ndarray of int

get_grid_node_count(grid)[source]

Get the number of nodes in the grid.

Parameters

grid (int) – A grid identifier.

Returns

The total number of grid nodes.

Return type

int

get_grid_nodes_per_face(grid, nodes_per_face)[source]

Get the number of nodes for each face.

Parameters
  • grid (int) – A grid identifier.

  • nodes_per_face (ndarray of int, shape (nfaces,)) – A numpy array to place the number of edges per face.

Returns

The input numpy array that holds the number of nodes per edge.

Return type

ndarray of int

get_grid_origin(grid, origin)[source]

Get coordinates for the lower-left corner of the computational grid.

Parameters
  • grid (int) – A grid identifier.

  • origin (ndarray of float, shape (ndim,)) – A numpy array to hold the coordinates of the lower-left corner of the grid.

Returns

The input numpy array that holds the coordinates of the grid’s lower-left corner.

Return type

ndarray of float

get_grid_rank(grid)[source]

Get number of dimensions of the computational grid.

Parameters

grid (int) – A grid identifier.

Returns

Rank of the grid.

Return type

int

get_grid_shape(grid, shape)[source]

Get dimensions of the computational grid.

Parameters
  • grid (int) – A grid identifier.

  • shape (ndarray of int, shape (ndim,)) – A numpy array into which to place the shape of the grid.

Returns

The input numpy array that holds the grid’s shape.

Return type

ndarray of int

get_grid_size(grid)[source]

Get the total number of elements in the computational grid.

Parameters

grid (int) – A grid identifier.

Returns

Size of the grid.

Return type

int

get_grid_spacing(grid, spacing)[source]

Get distance between nodes of the computational grid.

Parameters
  • grid (int) – A grid identifier.

  • spacing (ndarray of float, shape (ndim,)) – A numpy array to hold the spacing between grid rows and columns.

Returns

The input numpy array that holds the grid’s spacing.

Return type

ndarray of float

get_grid_type(grid)[source]

Get the grid type as a string.

Parameters

grid (int) – A grid identifier.

Returns

Type of grid as a string.

Return type

str

get_grid_x(grid, x)[source]

Get coordinates of grid nodes in the x direction.

Parameters
  • grid (int) – A grid identifier.

  • x (ndarray of float, shape (nrows,)) – A numpy array to hold the x-coordinates of the grid node columns.

Returns

The input numpy array that holds the grid’s column x-coordinates.

Return type

ndarray of float

get_grid_y(grid, y)[source]

Get coordinates of grid nodes in the y direction.

Parameters
  • grid (int) – A grid identifier.

  • y (ndarray of float, shape (ncols,)) – A numpy array to hold the y-coordinates of the grid node rows.

Returns

The input numpy array that holds the grid’s row y-coordinates.

Return type

ndarray of float

get_grid_z(grid, z)[source]

Get coordinates of grid nodes in the z direction.

Parameters
  • grid (int) – A grid identifier.

  • z (ndarray of float, shape (nlayers,)) – A numpy array to hold the z-coordinates of the grid nodes layers.

Returns

The input numpy array that holds the grid’s layer z-coordinates.

Return type

ndarray of float

get_input_item_count()[source]

Count of a model’s input variables.

Returns

The number of input variables.

Return type

int

get_input_var_names()[source]

List of a model’s input variables.

Input variable names must be CSDMS Standard Names, also known as long variable names.

Returns

The input variables for the model.

Return type

list of str

Notes

Standard Names enable the CSDMS framework to determine whether an input variable in one model is equivalent to, or compatible with, an output variable in another model. This allows the framework to automatically connect components.

Standard Names do not have to be used within the model.

get_output_item_count()[source]

Count of a model’s output variables.

Returns

The number of output variables.

Return type

int

get_output_var_names()[source]

List of a model’s output variables.

Output variable names must be CSDMS Standard Names, also known as long variable names.

Returns

The output variables for the model.

Return type

list of str

get_start_time()[source]

Start time of the model.

Model times should be of type float.

Returns

The model start time.

Return type

float

get_time_step()[source]

Current time step of the model.

The model time step should be of type float.

Returns

The time step used in model.

Return type

float

get_time_units()[source]

Time units of the model.

Returns

The model time unit; e.g., days or s.

Return type

float

Notes

CSDMS uses the UDUNITS standard from Unidata.

get_value(name, dest)[source]

Get a copy of values of the given variable.

This is a getter for the model, used to access the model’s current state. It returns a copy of a model variable, with the return type, size and rank dependent on the variable.

Parameters
  • name (str) – An input or output variable name, a CSDMS Standard Name.

  • dest (ndarray) – A numpy array into which to place the values.

Returns

The same numpy array that was passed as an input buffer.

Return type

ndarray

get_value_at_indices(name, dest, inds)[source]

Get values at particular indices.

Parameters
  • name (str) – An input or output variable name, a CSDMS Standard Name.

  • dest (ndarray) – A numpy array into which to place the values.

  • indices (array_like) – The indices into the variable array.

Returns

Value of the model variable at the given location.

Return type

array_like

get_value_ptr(name)[source]

Get a reference to values of the given variable.

This is a getter for the model, used to access the model’s current state. It returns a reference to a model variable, with the return type, size and rank dependent on the variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

A reference to a model variable.

Return type

array_like

get_var_grid(name)[source]

Get grid identifier for the given variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The grid identifier.

Return type

int

get_var_itemsize(name)[source]

Get memory use for each array element in bytes.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

Item size in bytes.

Return type

int

get_var_location(name)[source]

Get the grid element type that the a given variable is defined on.

The grid topology can be composed of nodes, edges, and faces.

node

A point that has a coordinate pair or triplet: the most basic element of the topology.

edge

A line or curve bounded by two nodes.

face

A plane or surface enclosed by a set of edges. In a 2D horizontal application one may consider the word “polygon”, but in the hierarchy of elements the word “face” is most common.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The grid location on which the variable is defined. Must be one of “node”, “edge”, or “face”.

Return type

str

Notes

CSDMS uses the ugrid conventions to define unstructured grids.

get_var_nbytes(name)[source]

Get size, in bytes, of the given variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The size of the variable, counted in bytes.

Return type

int

get_var_type(name)[source]

Get data type of the given variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The Python variable type; e.g., str, int, float.

Return type

str

get_var_units(name)[source]

Get units of the given variable.

Standard unit names, in lower case, should be used, such as meters or seconds. Standard abbreviations, like m for meters, are also supported. For variables with compound units, each unit name is separated by a single space, with exponents other than 1 placed immediately after the name, as in m s-1 for velocity, W m-2 for an energy flux, or km2 for an area.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The variable units.

Return type

str

Notes

CSDMS uses the UDUNITS standard from Unidata.

initialize(config_file)[source]

Perform startup tasks for the model.

Perform all tasks that take place before entering the model’s time loop, including opening files and initializing the model state. Model inputs are read from a text-based configuration file, specified by filename.

Parameters

config_file (str, optional) – The path to the model configuration file.

Notes

Models should be refactored, if necessary, to use a configuration file. CSDMS does not impose any constraint on how configuration files are formatted, although YAML is recommended. A template of a model’s configuration file with placeholder values is used by the BMI.

set_value(var_name, new_vals)[source]

Set model values.

set_value_at_indices(name, ids, src)[source]

Specify a new value for a model variable at particular indices.

Parameters
  • var_name (str) – An input or output variable name, a CSDMS Standard Name.

  • indices (array_like) – The indices into the variable array.

  • src (array_like) – The new value for the specified variable.

update()[source]

Advance model state by one time step.

Perform all tasks that take place within one pass through the model’s time loop. This typically includes incrementing all of the model’s state variables. If the model’s state variables don’t change in time, then they can be computed by the initialize() method and this method can return with no action.

update_frac(time_frac)[source]

Update model by a fraction of a time step.

update_until(then)[source]

Update model until a particular time.

rafem.rivermodule module

class rafem.rivermodule.RiverModule(rand_seed=1945, spacing=0.1, 0.1, shape=100, 120, n0=5.0, nslope=0.001, max_rand=0.1, dt_day=0.05, Initial_SL=0.0, SLRR_m=0.0, SubRate_m=0.0, Sub_Start=0, ch_width=10.0, ch_depth=1.0, ch_discharge=10.0, A=1.0, c_f=0.01, C_0=1.0, sed_sg=2.65, init_cut_frac=1.0, super_ratio=1.0, short_path=1, WL_Z=0.0, WL_dist=0, blanket_rate_m=0.0, fine_dep_frac=0.0, splay_type=2, saveavulsions=False, savecourseupdates=False)[source]

Bases: object

advance_in_time()[source]

Update avulsion model one time step.

property avulsions
property elevation
classmethod from_path(fname)[source]

Create a RiverModule object from a file-like object.

property grid_shape
property grid_spacing
property profile
property river_x_coordinates
property river_y_coordinates
property sea_level
property sediment_flux
property time

Current model time (converted from seconds to days).

property time_step

Model time step (converted from seconds to days).

to_yaml()[source]
rafem.rivermodule.make_empty_file(path)[source]

Create an empty file.

Create an empty file along with all of its parent folders, if necessary. Note that if the file already exists, it will be clobbered.

Parameters

path (str) – Path to the file to create.

rafem.steep_desc module

rafem.steep_desc.at_end_of_domain(z, sub)[source]

Check if a cell a river mouth at the end of domain. :param z: 2D-array of elevations. :type z: ndarray :param sub: Row and column subscript into z. :type sub: tuple of int

Returns

True if the cell at the given subscript is at the river mouth.

Return type

boolean

rafem.steep_desc.at_river_mouth(z, sub, z0)[source]

Check if a cell is at the river mouth. :param z: 2D-array of elevations. :type z: ndarray :param sub: Row and column subscript into z. :type sub: tuple of int :param z0: Elevation of sea level (or None). :type z0: float

Returns

True if the cell at the given subscript is at the river mouth.

Return type

boolean

rafem.steep_desc.below_sea_level(z, sea_level)[source]

Check if an elevation is below sea level. :param z: Elevation. :type z: float :param sea_level: Elevation of sea level. :type sea_level: float

Returns

True if at or below sea level. Otherwise, False.

Return type

boolean

rafem.steep_desc.find_course(z, riv_i, riv_j, SE_loc, channel_depth, sea_level=None)[source]

Find the course of a river. Given a river course as subscripts, (i, j), into an array of elevations, (z), find the river path until the coast (sea_level) or the end of the domain. :param z: Grid elevations. :type z: ndarray :param riv_i: Row subscripts (into n) for river. :type riv_i: array_like of int :param riv_j: Column subscripts (into n) for river. :type riv_j: array_like of int :param sea_level: The current sea level. :type sea_level: None, optional

Returns

Row and column indices of the new river path.

Return type

tuple of array_like

Examples

>>> import numpy as np
>>> z = np.array([[4., 3., 4.],
...               [2., 3., 3.],
...               [2., 1., 2.]])
>>> riv_i, riv_j = np.zeros(9, dtype=int), np.zeros(9, dtype=int)
>>> riv_i[0], riv_j[0] = 0, 1
>>> find_course(z, riv_i[:1], riv_j[:1], 1)
(array([0, 1, 2]), array([1, 0, 1]))
>>> find_course(z, riv_i[:1], riv_j[:1], sea_level=2.)
(array([0, 1]), array([1, 0]))
>>> z = np.array([[4., 3., 4.],
...               [2., 3., 3.],
...               [2., 1., 2.],
...               [2., 1.5, 2]])
>>> find_course(z, riv_i[:1], riv_j[:1], sea_level=0.)
(array([0, 1, 2, 3]), array([1, 0, 1, 1]))
>>> z
rafem.steep_desc.lowest_neighbor(n, sub)[source]

Find lowest neighbor value around a point. :param n: Grid of elevations. :type n: ndarray :param sub: Row/column subscript into elevation matrix. :type sub: tuple of int

Returns

Subscripts into elevation matrix of the lowest neighbor.

Return type

tuple of int

rafem.steep_desc.lowest_neighbor_prograde(n, sub)[source]
rafem.steep_desc.riv_cell_at_sea_level(z, sub, z0)[source]

Check if a river cell is at sea level. :param z: 2D-array of elevations. :type z: ndarray :param sub: Row and column subscript into z. :type sub: tuple of int :param z0: Elevation of sea level (or None). :type z0: float

Returns

True if the cell at the given subscript is at the river mouth.

Return type

boolean

rafem.steep_desc.update_course(z, riv_i, riv_j, ch_depth, slope, sea_level=None, dx=1.0, dy=1.0)[source]

rafem.subside module

rafem.subside.linear_subsidence(n, riv_i, riv_j, ch_depth, sub_rate, sub_start, SL)[source]

Subside cells in rows beyond start location by linear rate. Updated version could be to subside at an increasing rate towards ocean.

Module contents

River Avulsion Module.

class rafem.BmiRiverModule[source]

Bases: bmipy.bmi.Bmi

The BMI for the River Avulsion Floodplain Evolution Model.

finalize()[source]

Perform tear-down tasks for the model.

Perform all tasks that take place after exiting the model’s time loop. This typically includes deallocating memory, closing files and printing reports.

get_component_name()[source]

Name of the component.

Returns

The name of the component.

Return type

str

get_current_time()[source]

Current time of the model.

Returns

The current model time.

Return type

float

get_end_time()[source]

End time of the model.

Returns

The maximum model time.

Return type

float

get_grid_edge_count(grid)[source]

Get the number of edges in the grid.

Parameters

grid (int) – A grid identifier.

Returns

The total number of grid edges.

Return type

int

get_grid_edge_nodes(grid, edge_nodes)[source]

Get the edge-node connectivity.

Parameters
  • grid (int) – A grid identifier.

  • edge_nodes (ndarray of int, shape (2 x nnodes,)) – A numpy array to place the edge-node connectivity. For each edge, connectivity is given as node at edge tail, followed by node at edge head.

Returns

The input numpy array that holds the edge-node connectivity.

Return type

ndarray of int

get_grid_face_count(grid)[source]

Get the number of faces in the grid.

Parameters

grid (int) – A grid identifier.

Returns

The total number of grid faces.

Return type

int

get_grid_face_edges(grid, face_edges)[source]

Get the face-edge connectivity.

Parameters
  • grid (int) – A grid identifier.

  • face_edges (ndarray of int) – A numpy array to place the face-edge connectivity.

Returns

The input numpy array that holds the face-edge connectivity.

Return type

ndarray of int

get_grid_face_nodes(grid, face_nodes)[source]

Get the face-node connectivity.

Parameters
  • grid (int) – A grid identifier.

  • face_nodes (ndarray of int) – A numpy array to place the face-node connectivity. For each face, the nodes (listed in a counter-clockwise direction) that form the boundary of the face.

Returns

The input numpy array that holds the face-node connectivity.

Return type

ndarray of int

get_grid_node_count(grid)[source]

Get the number of nodes in the grid.

Parameters

grid (int) – A grid identifier.

Returns

The total number of grid nodes.

Return type

int

get_grid_nodes_per_face(grid, nodes_per_face)[source]

Get the number of nodes for each face.

Parameters
  • grid (int) – A grid identifier.

  • nodes_per_face (ndarray of int, shape (nfaces,)) – A numpy array to place the number of edges per face.

Returns

The input numpy array that holds the number of nodes per edge.

Return type

ndarray of int

get_grid_origin(grid, origin)[source]

Get coordinates for the lower-left corner of the computational grid.

Parameters
  • grid (int) – A grid identifier.

  • origin (ndarray of float, shape (ndim,)) – A numpy array to hold the coordinates of the lower-left corner of the grid.

Returns

The input numpy array that holds the coordinates of the grid’s lower-left corner.

Return type

ndarray of float

get_grid_rank(grid)[source]

Get number of dimensions of the computational grid.

Parameters

grid (int) – A grid identifier.

Returns

Rank of the grid.

Return type

int

get_grid_shape(grid, shape)[source]

Get dimensions of the computational grid.

Parameters
  • grid (int) – A grid identifier.

  • shape (ndarray of int, shape (ndim,)) – A numpy array into which to place the shape of the grid.

Returns

The input numpy array that holds the grid’s shape.

Return type

ndarray of int

get_grid_size(grid)[source]

Get the total number of elements in the computational grid.

Parameters

grid (int) – A grid identifier.

Returns

Size of the grid.

Return type

int

get_grid_spacing(grid, spacing)[source]

Get distance between nodes of the computational grid.

Parameters
  • grid (int) – A grid identifier.

  • spacing (ndarray of float, shape (ndim,)) – A numpy array to hold the spacing between grid rows and columns.

Returns

The input numpy array that holds the grid’s spacing.

Return type

ndarray of float

get_grid_type(grid)[source]

Get the grid type as a string.

Parameters

grid (int) – A grid identifier.

Returns

Type of grid as a string.

Return type

str

get_grid_x(grid, x)[source]

Get coordinates of grid nodes in the x direction.

Parameters
  • grid (int) – A grid identifier.

  • x (ndarray of float, shape (nrows,)) – A numpy array to hold the x-coordinates of the grid node columns.

Returns

The input numpy array that holds the grid’s column x-coordinates.

Return type

ndarray of float

get_grid_y(grid, y)[source]

Get coordinates of grid nodes in the y direction.

Parameters
  • grid (int) – A grid identifier.

  • y (ndarray of float, shape (ncols,)) – A numpy array to hold the y-coordinates of the grid node rows.

Returns

The input numpy array that holds the grid’s row y-coordinates.

Return type

ndarray of float

get_grid_z(grid, z)[source]

Get coordinates of grid nodes in the z direction.

Parameters
  • grid (int) – A grid identifier.

  • z (ndarray of float, shape (nlayers,)) – A numpy array to hold the z-coordinates of the grid nodes layers.

Returns

The input numpy array that holds the grid’s layer z-coordinates.

Return type

ndarray of float

get_input_item_count()[source]

Count of a model’s input variables.

Returns

The number of input variables.

Return type

int

get_input_var_names()[source]

List of a model’s input variables.

Input variable names must be CSDMS Standard Names, also known as long variable names.

Returns

The input variables for the model.

Return type

list of str

Notes

Standard Names enable the CSDMS framework to determine whether an input variable in one model is equivalent to, or compatible with, an output variable in another model. This allows the framework to automatically connect components.

Standard Names do not have to be used within the model.

get_output_item_count()[source]

Count of a model’s output variables.

Returns

The number of output variables.

Return type

int

get_output_var_names()[source]

List of a model’s output variables.

Output variable names must be CSDMS Standard Names, also known as long variable names.

Returns

The output variables for the model.

Return type

list of str

get_start_time()[source]

Start time of the model.

Model times should be of type float.

Returns

The model start time.

Return type

float

get_time_step()[source]

Current time step of the model.

The model time step should be of type float.

Returns

The time step used in model.

Return type

float

get_time_units()[source]

Time units of the model.

Returns

The model time unit; e.g., days or s.

Return type

float

Notes

CSDMS uses the UDUNITS standard from Unidata.

get_value(name, dest)[source]

Get a copy of values of the given variable.

This is a getter for the model, used to access the model’s current state. It returns a copy of a model variable, with the return type, size and rank dependent on the variable.

Parameters
  • name (str) – An input or output variable name, a CSDMS Standard Name.

  • dest (ndarray) – A numpy array into which to place the values.

Returns

The same numpy array that was passed as an input buffer.

Return type

ndarray

get_value_at_indices(name, dest, inds)[source]

Get values at particular indices.

Parameters
  • name (str) – An input or output variable name, a CSDMS Standard Name.

  • dest (ndarray) – A numpy array into which to place the values.

  • indices (array_like) – The indices into the variable array.

Returns

Value of the model variable at the given location.

Return type

array_like

get_value_ptr(name)[source]

Get a reference to values of the given variable.

This is a getter for the model, used to access the model’s current state. It returns a reference to a model variable, with the return type, size and rank dependent on the variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

A reference to a model variable.

Return type

array_like

get_var_grid(name)[source]

Get grid identifier for the given variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The grid identifier.

Return type

int

get_var_itemsize(name)[source]

Get memory use for each array element in bytes.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

Item size in bytes.

Return type

int

get_var_location(name)[source]

Get the grid element type that the a given variable is defined on.

The grid topology can be composed of nodes, edges, and faces.

node

A point that has a coordinate pair or triplet: the most basic element of the topology.

edge

A line or curve bounded by two nodes.

face

A plane or surface enclosed by a set of edges. In a 2D horizontal application one may consider the word “polygon”, but in the hierarchy of elements the word “face” is most common.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The grid location on which the variable is defined. Must be one of “node”, “edge”, or “face”.

Return type

str

Notes

CSDMS uses the ugrid conventions to define unstructured grids.

get_var_nbytes(name)[source]

Get size, in bytes, of the given variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The size of the variable, counted in bytes.

Return type

int

get_var_type(name)[source]

Get data type of the given variable.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The Python variable type; e.g., str, int, float.

Return type

str

get_var_units(name)[source]

Get units of the given variable.

Standard unit names, in lower case, should be used, such as meters or seconds. Standard abbreviations, like m for meters, are also supported. For variables with compound units, each unit name is separated by a single space, with exponents other than 1 placed immediately after the name, as in m s-1 for velocity, W m-2 for an energy flux, or km2 for an area.

Parameters

name (str) – An input or output variable name, a CSDMS Standard Name.

Returns

The variable units.

Return type

str

Notes

CSDMS uses the UDUNITS standard from Unidata.

initialize(config_file)[source]

Perform startup tasks for the model.

Perform all tasks that take place before entering the model’s time loop, including opening files and initializing the model state. Model inputs are read from a text-based configuration file, specified by filename.

Parameters

config_file (str, optional) – The path to the model configuration file.

Notes

Models should be refactored, if necessary, to use a configuration file. CSDMS does not impose any constraint on how configuration files are formatted, although YAML is recommended. A template of a model’s configuration file with placeholder values is used by the BMI.

set_value(var_name, new_vals)[source]

Set model values.

set_value_at_indices(name, ids, src)[source]

Specify a new value for a model variable at particular indices.

Parameters
  • var_name (str) – An input or output variable name, a CSDMS Standard Name.

  • indices (array_like) – The indices into the variable array.

  • src (array_like) – The new value for the specified variable.

update()[source]

Advance model state by one time step.

Perform all tasks that take place within one pass through the model’s time loop. This typically includes incrementing all of the model’s state variables. If the model’s state variables don’t change in time, then they can be computed by the initialize() method and this method can return with no action.

update_frac(time_frac)[source]

Update model by a fraction of a time step.

update_until(then)[source]

Update model until a particular time.

class rafem.RiverModule(rand_seed=1945, spacing=0.1, 0.1, shape=100, 120, n0=5.0, nslope=0.001, max_rand=0.1, dt_day=0.05, Initial_SL=0.0, SLRR_m=0.0, SubRate_m=0.0, Sub_Start=0, ch_width=10.0, ch_depth=1.0, ch_discharge=10.0, A=1.0, c_f=0.01, C_0=1.0, sed_sg=2.65, init_cut_frac=1.0, super_ratio=1.0, short_path=1, WL_Z=0.0, WL_dist=0, blanket_rate_m=0.0, fine_dep_frac=0.0, splay_type=2, saveavulsions=False, savecourseupdates=False)[source]

Bases: object

advance_in_time()[source]

Update avulsion model one time step.

property avulsions
property elevation
classmethod from_path(fname)[source]

Create a RiverModule object from a file-like object.

property grid_shape
property grid_spacing
property profile
property river_x_coordinates
property river_y_coordinates
property sea_level
property sediment_flux
property time

Current model time (converted from seconds to days).

property time_step

Model time step (converted from seconds to days).

to_yaml()[source]