Skip to content

Commit 76c6700

Browse files
authored
Merge pull request #101 from xylar/fix-max-level-cell-in-horiz-viz
Get maxLevelCell from ds, not ds_mesh in viz
2 parents 90a8a9a + ff9e229 commit 76c6700

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

polaris/ocean/tests/baroclinic_channel/init.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ def run(self):
9090

9191
init_vertical_coord(config, ds)
9292

93-
ds_mesh['maxLevelCell'] = ds.maxLevelCell
94-
9593
x_min = x_cell.min().values
9694
x_max = x_cell.max().values
9795
y_min = y_cell.min().values

polaris/ocean/tests/baroclinic_channel/viz.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def __init__(self, test_case):
2424
self.add_input_file(
2525
filename='mesh.nc',
2626
target='../init/culled_mesh.nc')
27+
self.add_input_file(
28+
filename='init.nc',
29+
target='../init/initial_state.nc')
2730
self.add_input_file(
2831
filename='output.nc',
2932
target='../forward/output.nc')
@@ -33,7 +36,9 @@ def run(self):
3336
Run this step of the test case
3437
"""
3538
ds_mesh = xr.load_dataset('mesh.nc')
39+
ds_init = xr.load_dataset('init.nc')
3640
ds = xr.load_dataset('output.nc')
41+
ds['maxLevelCell'] = ds_init.maxLevelCell
3742
t_index = ds.sizes['Time'] - 1
3843
plot_horiz_field(ds, ds_mesh, 'temperature',
3944
'final_temperature.png', t_index=t_index)

polaris/ocean/tests/inertial_gravity_wave/init.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def run(self):
7979
ds['fEdge'] = f0 * xr.ones_like(ds_mesh.xEdge)
8080
ds['fVertex'] = f0 * xr.ones_like(ds_mesh.xVertex)
8181

82-
ds_mesh['maxLevelCell'] = ds.maxLevelCell
8382
exact_solution = ExactSolution(ds, config)
8483

8584
ssh = exact_solution.ssh(0.0)

polaris/ocean/tests/inertial_gravity_wave/viz.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, test_case, resolutions):
4040
for resolution in resolutions:
4141
self.add_input_file(
4242
filename=f'mesh_{resolution}km.nc',
43-
target=f'../{resolution}km/initial_state/culled_mesh.nc')
43+
target=f'../{resolution}km/init/culled_mesh.nc')
4444
self.add_input_file(
4545
filename=f'init_{resolution}km.nc',
4646
target=f'../{resolution}km/init/initial_state.nc')
@@ -69,6 +69,7 @@ def run(self):
6969
ds_mesh = xr.open_dataset(f'mesh_{res}km.nc')
7070
ds_init = xr.open_dataset(f'init_{res}km.nc')
7171
ds = xr.open_dataset(f'output_{res}km.nc')
72+
ds['maxLevelCell'] = ds_init.maxLevelCell
7273
exact = ExactSolution(ds_init, config)
7374

7475
t0 = datetime.datetime.strptime(ds.xtime.values[0].decode(),

polaris/ocean/tests/manufactured_solution/init.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def run(self):
7979
ds['fEdge'] = coriolis_parameter * xr.ones_like(ds_mesh.xEdge)
8080
ds['fVertex'] = coriolis_parameter * xr.ones_like(ds_mesh.xVertex)
8181

82-
ds_mesh['maxLevelCell'] = ds.maxLevelCell
83-
8482
# Evaluate the exact solution at time=0
8583
exact_solution = ExactSolution(config, ds)
8684
ssh = exact_solution.ssh(0.0)

polaris/ocean/tests/manufactured_solution/viz.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, test_case, resolutions):
4040
for resolution in resolutions:
4141
self.add_input_file(
4242
filename=f'mesh_{resolution}km.nc',
43-
target=f'../{resolution}km/initial_state/culled_mesh.nc')
43+
target=f'../{resolution}km/init/culled_mesh.nc')
4444
self.add_input_file(
4545
filename=f'init_{resolution}km.nc',
4646
target=f'../{resolution}km/init/initial_state.nc')
@@ -68,6 +68,7 @@ def run(self):
6868
ds_mesh = xr.open_dataset(f'mesh_{res}km.nc')
6969
ds_init = xr.open_dataset(f'init_{res}km.nc')
7070
ds = xr.open_dataset(f'output_{res}km.nc')
71+
ds['maxLevelCell'] = ds_init.maxLevelCell
7172
exact = ExactSolution(config, ds_init)
7273

7374
t0 = datetime.datetime.strptime(ds.xtime.values[0].decode(),

polaris/viz/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def plot_horiz_field(ds, ds_mesh, field_name, out_file_name=None, # noqa: C901
3131
A data set containing fieldName
3232
3333
ds_mesh : xarray.Dataset
34-
A data set containing mesh variables
34+
A data set containing horizontal mesh variables
3535
3636
field_name: str
3737
The name of the variable to plot, which must be present in ds
@@ -83,9 +83,9 @@ def plot_horiz_field(ds, ds_mesh, field_name, out_file_name=None, # noqa: C901
8383
if title is None:
8484
title = field_name
8585

86-
if 'maxLevelCell' not in ds_mesh:
86+
if 'maxLevelCell' not in ds:
8787
raise ValueError(
88-
'maxLevelCell must be added to ds_mesh before plotting.')
88+
'maxLevelCell must be added to ds before plotting.')
8989
if field_name not in ds:
9090
raise ValueError(
9191
f'{field_name} must be present in ds before plotting.')
@@ -102,7 +102,7 @@ def plot_horiz_field(ds, ds_mesh, field_name, out_file_name=None, # noqa: C901
102102
field = field.isel(nVertLevels=z_index)
103103

104104
if 'nCells' in field.dims:
105-
ocean_mask = ds_mesh.maxLevelCell - 1 >= 0
105+
ocean_mask = ds.maxLevelCell - 1 >= 0
106106
ocean_patches, ocean_mask = _compute_cell_patches(ds_mesh, ocean_mask)
107107
elif 'nEdges' in field.dims:
108108
ocean_mask = np.ones_like(field, dtype='bool')

0 commit comments

Comments
 (0)