Skip to content

Commit 34f32e4

Browse files
committed
Do not drop indexes when computing rmax
1 parent 51ee3ad commit 34f32e4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pydomcfg/tests/bathymetry.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,30 @@ def _calc_rmax(depth):
147147
Parameters
148148
----------
149149
depth: float
150-
Bottom depth (units: m).
150+
Bottom depth (units: m).
151151
152152
Returns
153153
-------
154154
rmax: float
155-
Slope steepness value (units: None)
155+
Slope steepness value (units: None)
156156
"""
157-
depth = depth.reset_index(list(depth.dims))
158157

159158
both_rmax = []
160159
for dim in depth.dims:
161160

162-
# (H[0] - H[1]) / (H[0] + H[1])
163-
depth_diff = depth.diff(dim)
164-
depth_rolling_sum = depth.rolling({dim: 2}).sum().dropna(dim)
165-
rmax = depth_diff / depth_rolling_sum
161+
rolled = depth.rolling({dim: 2}).construct("tmp_dim")
162+
163+
# |(H[0] - H[1])| / (H[0] + H[1])
164+
# First value is NaN
165+
diff = rolled.diff("tmp_dim").squeeze("tmp_dim")
166+
rmax = diff / rolled.sum("tmp_dim")
166167

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

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

173175
both_rmax.append(np.abs(rmax))
174176

0 commit comments

Comments
 (0)