Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
find_node_in_direction_of_max_slope. That method does not do
any boundary checking. It needs to be done somewhere, maybe here,
maybe there? Alternatively, if boundary elevations are always set
in a consistent way depending on the type of bounary, maybe no boundary
checking is needed?
Last updated NG 8/2013
"""
#from landlab.model_grid import RasterModelGrid
from numpy import *
from landlab import Component
class RouteFlowD8(Component):
"""
This class finds the steepest path among 8 possible directions, so
diagonals are considered.
The class assumes that the model is using a rectangular, uniform (raster)
grid.
"""
def __init__(self, num_nodes):
"""
This sets the num_cells parameter.
This class assumes that the number of cells does not change after a
class item has been instantiated.
"""
self.num_nodes = num_nodes
self.initialize()
'Steepest': FlowDirectorSteepest,
'D8': FlowDirectorD8,
'MFD': FlowDirectorMFD,
'DINF': FlowDirectorDINF
}
try:
FlowDirector = DIRECTOR_METHODS[flow_director]
except KeyError:
raise ValueError('String provided in flow_director is not a '
'valid method or component name. The following'
'components are valid imputs:\n'\
+ str(PERMITTED_DIRECTORS))
self.flow_director = FlowDirector(self._grid, self.surface, **kw)
# flow director is provided as an instantiated flow director
elif isinstance(flow_director, Component):
if flow_director._name in PERMITTED_DIRECTORS:
self.flow_director = flow_director
else:
raise ValueError('String provided in flow_director is not a '
'valid method or component name. The following'
'components are valid imputs:\n'\
+ str(PERMITTED_DIRECTORS))
# flow director is provided as an uninstantiated flow director
else:
if flow_director._name in PERMITTED_DIRECTORS:
FlowDirector = flow_director
self.flow_director = FlowDirector(self._grid, self.surface, **kw)
else:
raise ValueError('String provided in flow_director is not a '
'valid method or component name. The following'
'components are valid imputs:\n'\
_VALID_METHODS = set(['Grid'])
GRASS = 0
SHRUB = 1
TREE = 2
BARE = 3
SHRUBSEEDLING = 4
TREESEEDLING = 5
def assert_method_is_valid(method):
if method not in _VALID_METHODS:
raise ValueError('%s: Invalid method name' % method)
class VegCA(Component):
"""
Landlab component that simulates inter-species plant competition using
a 2D cellular automata model.
Construction::
VegCA(grid, Pemaxg=0.35, ING=2., ThetaGrass=0.62, PmbGrass=0.05,
Pemaxsh=0.2, ThetaShrub=0.8, PmbShrub=0.01, tpmaxShrub=600,
Pemaxtr=0.25, ThetaTree=0.72, PmbTree=0.01, tpmaxTree=350,
ThetaShrubSeedling=0.64, PmbShrubSeedling=0.03,
tpmaxShrubSeedling=18, ThetaTreeSeedling=0.64,
PmbTreeSeedling=0.03, tpmaxTreeSeedling=18)
Parameters
----------
grid: RasterModelGrid
"""
This metacomponent combines a pit filling operation with a kinematic wave
shallow water flow routing algorithm and soil infiltration to produce a
simple bare-landscape hydrological model, after Rengers et al., in review,
and Julien et al., 1995.
"""
import numpy as np
from landlab.components import SinkFiller
from landlab.components import KinematicWave, SoilInfiltrationGreenAmpt
from ...utils.decorators import use_file_name_or_kwds
from landlab import Component
class FillInfiltrateKinematicWave(Component):
"""
Takes a topography, fills in any pits across it, then routes water across
it using a kinematic wave and allowing soil infiltration following a Green-
Ampt scheme. Component is after Rengers et al., in review.
Examples
--------
>>> from landlab import RasterModelGrid
>>> from landlab import CLOSED_BOUNDARY, FIXED_GRADIENT_BOUNDARY
>>> import numpy as np
>>> mg = RasterModelGrid((5, 10), spacing=10.)
>>> mg.status_at_node[mg.nodes_at_left_edge] = FIXED_GRADIENT_BOUNDARY
>>> mg.status_at_node[mg.nodes_at_top_edge] = CLOSED_BOUNDARY
>>> mg.status_at_node[mg.nodes_at_bottom_edge] = CLOSED_BOUNDARY
>>> mg.status_at_node[mg.nodes_at_right_edge] = CLOSED_BOUNDARY
>>> _ = mg.add_field('node', 'topographic__elevation', 0.05*mg.node_x)
"""
TaylorNonLinearDiffuser Component
@author: R Glade
@author: K Barnhart
@author: G Tucker
"""
# Cubic hillslope flux component
import numpy as np
from landlab import INACTIVE_LINK, Component
class TaylorNonLinearDiffuser(Component):
"""
Hillslope evolution using a Taylor Series expansion of the Andrews-Bucknam
formulation of nonlinear hillslope flux derived following following Ganti et
al., 2012. The flux is given as:
qs = KS ( 1 + (S/Sc)**2 + (S / Sc)**4 + .. + (S / Sc)**2(n - 1) )
where K is is the diffusivity, S is the slope, Sc is the critical slope, and
n is the number of terms.
The default behavior uses two terms to produce a flux law as described by
Equation 6 of Ganti et al., (2012).
Parameters
----------
grid: ModelGrid
Last edit June 7, 2017
"""
# %% Import Libraries
from landlab import Component
from landlab.utils.decorators import use_file_name_or_kwds
import numpy as np
import scipy.constants
from scipy import interpolate
from statsmodels.distributions.empirical_distribution import ECDF
import copy
# %% Instantiate Object
class LandslideProbability(Component):
"""Landslide probability component using the infinite slope stability
model.
Landlab component designed to calculate probability of failure at
each grid node based on the infinite slope stability model
stability index (Factor of Safety).
The driving force for failure is provided by the user in the form of
groundwater recharge; four options for providing recharge are supported.
The model uses topographic and soil characteristics provided as input
by the user.
The main method of the LandslideProbability class is
calculate_landslide_probability(), which calculates the mean soil relative
wetness, probability of soil saturation, and probability of failure at
each node based on a Monte Carlo simulation.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 11 10:13:38 2017
@author: margauxmouchene
"""
import numpy as np
from landlab import Component
class TransportLengthHillslopeDiffuser(Component):
"""
Hillslope diffusion component in the style of Carretier et al. (2016,
ESurf), and Davy and Lague (2009)
dz/dt = - E + D (+ Uplift)
D = qs / L
E = k * S
L = dx / (1 - (S / Sc)^2)
Works on regular raster-type grid (RasterModelGrid, dx=dy).
To be coupled with FlowDirectorSteepest for the calculation of steepest
slope at each timestep.
Component written by Margaux Mouchene, 2017
from landlab import Component
from ...utils.decorators import use_file_name_or_kwds
import numpy as np
_VALID_METHODS = set(['Constant', 'PriestleyTaylor', 'MeasuredRadiationPT',
'Cosine'])
def _assert_method_is_valid(method):
if method not in _VALID_METHODS:
raise ValueError('%s: Invalid method name' % method)
class PotentialEvapotranspiration(Component):
"""
Potential Evapotranspiration Component calculates spatially distributed
potential evapotranspiration based on input radiation factor (spatial
distribution of incoming radiation) using chosen method such as constant
or Priestley Taylor. Ref: Xiaochi et. al. 2013 for 'Cosine' method and
ASCE-EWRI Task Committee Report Jan 2005 for 'PriestleyTaylor' method.
Note: Calling 'PriestleyTaylor' method would generate/overwrite shortwave &
longwave radiation fields.
.. codeauthor:: Sai Nudurupati and Erkan Istanbulluoglu
Construction::
PotentialEvapotranspiration(grid, method='Cosine',
Priestley_taylor_const=1.26, albedo=0.6,
0. , 0. , 0. , 0. ,
0. , 1. , 1. , 1. , 0. ,
0. , 0. , 0. , 0. ,
0. , 1.1, 1.1, 1.1, 0. ,
0. , 0. , 0. , 0. ])
"""
from landlab import Component, FieldError
import numpy as np
from landlab.grid.structured_quad import links
from landlab.utils.decorators import use_file_name_or_kwds
_SEVEN_OVER_THREE = 7.0 / 3.0
class OverlandFlow(Component):
"""Simulate overland flow using de Almeida approximations.
Landlab component that simulates overland flow using the de Almeida
et al., 2012 approximations of the 1D shallow water equations to be used
for 2D flood inundation modeling.
This component calculates discharge, depth and shear stress after some
precipitation event across any raster grid. Default input file is named
"overland_flow_input.txt' and is contained in the
landlab.components.overland_flow folder.
The primary method of this class is :func:`run_one_step`.
"""
_name = 'OverlandFlow'
Provides the _FlowDirector component which does grid type testing, adds
the surface over which flow will be routed to the component, and sets up
part of the boundary condition testing.
"""
from __future__ import print_function
import numpy
import six
from landlab import RasterModelGrid # for type tests
from landlab import Component
from landlab.utils.return_array import return_array_at_node
class _FlowDirector(Component):
"""Private class for creating components to calculate flow directions.
This class is not meant to be used directly in modeling efforts.
Instead it has the functionality that all flow direction calculators need
to initialize and check boundary conditions.
It also creates the following field used by all FlowDirectors.
- Link array identifing if flow goes with (1) or against (-1) the link
direction: *'flow_link_direction'*
The primary method of this class, :func:`run_one_step` is not implemented.
Parameters
----------