Skip to content

Commit

Permalink
Fix depth slicing with non-ocean cells
Browse files Browse the repository at this point in the history
Previously, when there were cells with `maxLevelCell = 0`, this
caused a failure because there was no valid depth coordinate
for that cell and therefore no closest depth index could be found.

This fix simply skips cells that are not in the ocean and masks
them out.
  • Loading branch information
xylar committed Jan 18, 2023
1 parent b1ba6af commit 149f8ea
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mpas_analysis/ocean/remap_depth_slices_subtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def run_task(self):

zMid = compute_zmid(ds.bottomDepth, ds.maxLevelCell-1,
ds.layerThickness)
ocean_mask = (ds.maxLevelCell > 0)

print(f'zMid min: {zMid.min().values}, max: {zMid.max().values}')
print(f'maxLevelCell min: {ds.maxLevelCell.min().values}')

nVertLevels = zMid.shape[1]
zMid.coords['verticalIndex'] = \
Expand All @@ -135,6 +139,8 @@ def run_task(self):

for depthIndex, depth in enumerate(self.depths):
depth = self.depths[depthIndex]
print(f'depth: {depth}')

if depth == 'top':
# switch to zero-based index
verticalIndices[depthIndex, :] = 0
Expand All @@ -144,10 +150,12 @@ def run_task(self):
verticalIndices[depthIndex, :] = self.maxLevelCell.values
mask[depthIndex, :] = self.maxLevelCell.values >= 0
else:

diff = np.abs(zMid - depth).where(ocean_mask, drop=True)
verticalIndex = diff.argmin(dim='nVertLevels')

verticalIndex = np.abs(zMid - depth).argmin(dim='nVertLevels')

verticalIndices[depthIndex, :] = verticalIndex.values
verticalIndices[depthIndex, ocean_mask.values] = \
verticalIndex.values
mask[depthIndex, :] = np.logical_and(depth <= zTop,
depth >= zBot).values

Expand Down

0 comments on commit 149f8ea

Please sign in to comment.