Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bad_director_instance():
mg = RasterModelGrid((5, 5), xy_spacing=(1, 1))
mg.add_field("topographic__elevation", mg.node_x + mg.node_y, at="node")
ld = LinearDiffuser(mg, linear_diffusivity=1.0)
with pytest.raises(ValueError):
LossyFlowAccumulator(mg, flow_director=ld)
def test_depression_finder_bad_instance():
mg = RasterModelGrid((5, 5), xy_spacing=(1, 1))
mg.add_field("topographic__elevation", mg.node_x + mg.node_y, at="node")
ld = LinearDiffuser(mg, linear_diffusivity=1.0)
with pytest.raises(ValueError):
FlowAccumulator(mg, flow_director="D8", depression_finder=ld)
self.tlam = self.trans * self.grid._dx # assumes raster
# Run flow routing and lake filler
self.flow_accumulator.run_one_step()
# Instantiate a FastscapeEroder component
self.eroder = FastscapeEroder(
self.grid,
K_sp=self.K,
m_sp=self.m,
n_sp=self.m,
discharge_name="surface_water__discharge",
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=regolith_transport_parameter
)
"node", "water_erosion_rule__threshold"
)
self.threshold[:] = self.threshold_value
# Instantiate a FastscapeEroder component
self.eroder = StreamPowerSmoothThresholdEroder(
self.grid,
m_sp=self.m,
n_sp=self.n,
K_sp=self.K,
use_Q="surface_water__discharge",
threshold_sp=self.threshold,
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=regolith_transport_parameter
)
phi=sediment_porosity,
v_s=settling_velocity,
m_sp=self.m,
n_sp=self.n,
sp_crit="water_erosion_rule__threshold",
discharge_field="surface_water__discharge",
solver=solver,
)
# Get the parameter for rate of threshold increase with erosion depth
self.thresh_change_per_depth = (
water_erosion_rule__thresh_depth_derivative
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=regolith_transport_parameter
)
# Instantiate an ErosionDeposition ("hybrid") component
self.eroder = ErosionDeposition(
self.grid,
K="substrate__erodibility",
F_f=fraction_fines,
phi=sediment_porosity,
v_s=settling_velocity,
m_sp=self.m,
n_sp=self.n,
discharge_field="surface_water__discharge",
solver=solver,
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=self.regolith_transport_parameter
)
self.grid,
K=self.K,
phi=self.params["phi"],
F_f=self.params["F_f"],
v_s=v_sc,
m_sp=self.params["m_sp"],
n_sp=self.params["n_sp"],
sp_crit=sp_crit,
method="threshold_stream_power",
discharge_method="drainage_area",
area_field="drainage_area",
solver=solver,
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=regolith_transport_parameter
)
# Instantiate an ErosionDeposition component
self.eroder = ErosionDeposition(
self.grid,
K=self.K,
F_f=fraction_fines,
phi=sediment_porosity,
v_s=settling_velocity,
m_sp=self.m,
n_sp=self.n,
discharge_field="surface_water__discharge",
solver=solver,
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=regolith_transport_parameter
)
self._verify_fields(self._required_fields)
# Set up rock-till boundary and associated grid fields.
self._setup_rock_and_till()
# Instantiate a FastscapeEroder component
self.eroder = FastscapeEroder(
self.grid,
K_sp=self.erody,
m_sp=self.m,
n_sp=self.n,
discharge_name="surface_water__discharge",
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=self.regolith_transport_parameter
)
if float(self.n) != 1.0:
raise ValueError("Model only supports n equals 1.")
# Instantiate a FastscapeEroder component
self.eroder = StreamPowerSmoothThresholdEroder(
self.grid,
K_sp=self.K,
m_sp=self.m,
n_sp=self.n,
threshold_sp=water_erosion_rule__threshold,
use_Q="surface_water__discharge",
)
# Instantiate a LinearDiffuser component
self.diffuser = LinearDiffuser(
self.grid, linear_diffusivity=regolith_transport_parameter
)