Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change weight calculations for water and sediment routing #29

Merged
merged 8 commits into from
May 18, 2020
6 changes: 3 additions & 3 deletions pyDeltaRCM/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ save_discharge_figs:
default: True
save_velocity_figs:
type: 'bool'
default: True
default: False
save_eta_grids:
type: 'bool'
default: False
Expand All @@ -96,10 +96,10 @@ save_depth_grids:
default: False
save_discharge_grids:
type: 'bool'
default: True
default: False
save_velocity_grids:
type: 'bool'
default: True
default: False
save_dt:
type: 'int'
default: 50
Expand Down
2 changes: 0 additions & 2 deletions pyDeltaRCM/deltaRCM_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def run_one_timestep(self):

for iteration in range(self.itermax):

self.count = 0

self.init_water_iteration()
self.run_water_iteration()

Expand Down
10 changes: 5 additions & 5 deletions pyDeltaRCM/sed_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def sed_route(self):
self.Vp_dep_mud[:] = 0

self.sand_route()

self.mud_route()

self.topo_diffusion()
Expand Down Expand Up @@ -195,16 +196,16 @@ def sed_parcel(self, theta_sed, sed, px, py):
weight = (w1 * w2 / self.distances)

weight[depth_ind <= self.dry_depth] = 0.0001
weight[cell_type_ind == -2] = np.nan
weight[cell_type_ind == -2] = 0

if ind[0] == 0:
weight[0, :] = np.nan
weight[0, :] = 0

new_cell = self.random_pick(weight)
new_cell = self.random_pick(np.cumsum(weight.flatten()))

jstep = self.iwalk.flat[new_cell]
istep = self.jwalk.flat[new_cell]
dist = np.sqrt(istep**2 + jstep**2)
dist = np.sqrt(istep * istep + jstep * jstep)

# deposition and erosion

Expand Down Expand Up @@ -254,7 +255,6 @@ def sand_route(self):

self.sed_parcel(theta_sed, 'sand', px, py)

# self.topo_diffusion()
def topo_diffusion(self):
"""
Diffuse topography after routing all coarse sediment parcels
Expand Down
18 changes: 6 additions & 12 deletions pyDeltaRCM/shared_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,13 @@ class shared_tools(object):

def random_pick(self, probs):
"""
Randomly pick a number weighted by array probs (len 8)
Randomly pick a number weighted by array probabilities (len 9)
Return the index of the selected weight in array probs
Takes a numpy array that is the precalculated cumulative probability
around the cell flattened to 1D.
"""

num_nans = sum(np.isnan(probs))

if np.nansum(probs) == 0:
probs[~np.isnan(probs)] = 1
probs[1, 1] = 0

probs[np.isnan(probs)] = 0
cutoffs = np.cumsum(probs)
idx = cutoffs.searchsorted(np.random.uniform(0, cutoffs[-1]))
idx = probs.searchsorted(np.random.uniform(0, probs[-1]))

return idx

Expand All @@ -36,7 +30,7 @@ def random_pick_inlet(self, choices, probs=None):
"""

if not probs:
probs = np.array([1 for i in range(len(choices))])
probs = np.ones(len(choices))

cutoffs = np.cumsum(probs)
idx = cutoffs.searchsorted(np.random.uniform(0, cutoffs[-1]))
Expand All @@ -49,4 +43,4 @@ def _get_version():
Extract version number from single file, and make it availabe everywhere.
"""
from . import _version
return _version.__version__()
return _version.__version__()
Loading