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

Do not drop indexes when computing rmax #40

Merged
merged 8 commits into from
Jun 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions pydomcfg/tests/bathymetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,30 @@ def _calc_rmax(depth):
Parameters
----------
depth: float
Bottom depth (units: m).
Bottom depth (units: m).

Returns
-------
rmax: float
Slope steepness value (units: None)
Slope steepness value (units: None)
"""
depth = depth.reset_index(list(depth.dims))

both_rmax = []
for dim in depth.dims:

# (H[0] - H[1]) / (H[0] + H[1])
depth_diff = depth.diff(dim)
depth_rolling_sum = depth.rolling({dim: 2}).sum().dropna(dim)
rmax = depth_diff / depth_rolling_sum
rolled = depth.rolling({dim: 2}).construct("tmp_dim")

# |(H[0] - H[1])| / (H[0] + H[1])
# First value is NaN
diff = rolled.diff("tmp_dim").squeeze("tmp_dim")
rmax = diff / rolled.sum("tmp_dim")
malmans2 marked this conversation as resolved.
Show resolved Hide resolved

# (R[0] + R[1]) / 2
rmax = rmax.rolling({dim: 2}).mean().dropna(dim)
# (rmax[0] + rmax[1]) / 2
# First two values are NaN
rmax = rmax.rolling({dim: 2}).mean()

# Fill first row and column
rmax = rmax.pad({dim: (1, 1)}, constant_values=0)
# First and last values are zero
rmax = rmax.shift({dim: -1}).fillna(0)

both_rmax.append(np.abs(rmax))

Expand Down