Skip to content

Commit

Permalink
Apply suggestions from Xylar's code review
Browse files Browse the repository at this point in the history
Co-authored-by: Xylar Asay-Davis <[email protected]>
  • Loading branch information
cbegeman and xylar committed Sep 2, 2023
1 parent 9715be6 commit a5a8c6b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 35 deletions.
6 changes: 3 additions & 3 deletions compass/ocean/iceshelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def compute_land_ice_pressure_and_draft(ssh, modify_mask, ref_density):


def adjust_ssh(variable, iteration_count, step, update_pio=True,
convert_to_cdf5=False, deltaSSH_threshold=None):
convert_to_cdf5=False, delta_ssh_threshold=None):
"""
Adjust the sea surface height or land-ice pressure to be dynamically
consistent with one another. A series of short model runs are performed,
Expand Down Expand Up @@ -187,8 +187,8 @@ def adjust_ssh(variable, iteration_count, step, update_pio=True,
logger.info(f' {string}')
log_file.write(f'{string}\n')

if deltaSSH_threshold is not None:
if abs(deltaSSHMax) < deltaSSH_threshold:
if delta_ssh_threshold is not None:
if abs(deltaSSHMax) < delta_ssh_threshold:
break

logger.info(" - Complete\n")
Expand Down
4 changes: 2 additions & 2 deletions compass/ocean/tests/ice_shelf_2d/default/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def __init__(self, test_group, resolution, coord_type,
self.resolution = resolution
self.coord_type = coord_type
if resolution >= 1e3:
res_name = f'{int(resolution / 1e3)}km'
res_name = f'{resolution / 1e3:g}km'
else:
res_name = f'{int(resolution)}m'
res_name = f'{resolution:g}m'
subdir = f'{res_name}/{coord_type}/{name}'
super().__init__(test_group=test_group, name=name,
subdir=subdir)
Expand Down
4 changes: 2 additions & 2 deletions compass/ocean/tests/ice_shelf_2d/restart_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def __init__(self, test_group, resolution, coord_type):
self.resolution = resolution
self.coord_type = coord_type
if resolution >= 1e3:
res_name = f'{int(resolution / 1e3)}km'
res_name = f'{resolution / 1e3:g}km'
else:
res_name = f'{int(resolution)}m'
res_name = f'{resolution:g}m'
subdir = f'{res_name}/{coord_type}/{name}'
super().__init__(test_group=test_group, name=name,
subdir=subdir)
Expand Down
2 changes: 1 addition & 1 deletion compass/ocean/tests/ice_shelf_2d/ssh_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ def run(self):
self.update_namelist_at_runtime({'config_dt': dt_str})
iteration_count = config.getint('ssh_adjustment', 'iterations')
adjust_ssh(variable='landIcePressure', iteration_count=iteration_count,
step=self, deltaSSH_threshold=1.e-10)
step=self, delta_ssh_threshold=1.e-10)
59 changes: 32 additions & 27 deletions compass/ocean/tests/ice_shelf_2d/viz.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import xarray
import xarray as xr

from compass.ocean.tests.isomip_plus.viz.plot import MoviePlotter
from compass.step import Step
Expand Down Expand Up @@ -36,9 +36,9 @@ def run(self):
Run this step of the test case
"""

ds = xarray.open_dataset('initial_state.nc')
dsOut = xarray.open_dataset('output.nc')
dsAdj = xarray.open_dataset('output_ssh.nc')
ds = xr.open_dataset('initial_state.nc')
dsOut = xr.open_dataset('output.nc')
dsAdj = xr.open_dataset('output_ssh.nc')
plotter = MoviePlotter(inFolder='../forward',
streamfunctionFolder='',
outFolder='./plots',
Expand All @@ -54,17 +54,17 @@ def run(self):
nCells = ds.sizes['yCell']
nVertLevels = ds.sizes['nVertLevels']

zIndex = xarray.DataArray(data=np.arange(nVertLevels),
dims='nVertLevels')
zIndex = xr.DataArray(data=np.arange(nVertLevels),
dims='nVertLevels')

minLevelCell = ds.minLevelCell - 1
maxLevelCell = ds.maxLevelCell - 1

cellMask = np.logical_and(zIndex >= minLevelCell,
zIndex <= maxLevelCell)

zIndex = xarray.DataArray(data=np.arange(nVertLevels + 1),
dims='nVertLevelsP1')
zIndex = xr.DataArray(data=np.arange(nVertLevels + 1),
dims='nVertLevelsP1')

interfaceMask = np.logical_and(zIndex >= minLevelCell,
zIndex <= maxLevelCell + 1)
Expand All @@ -79,8 +79,8 @@ def run(self):
zInterface[:, zIndex + 1] = \
zInterface[:, zIndex] - thickness.values

zInterface = xarray.DataArray(data=zInterface,
dims=('yCell', 'nVertLevelsP1'))
zInterface = xr.DataArray(data=zInterface,
dims=('yCell', 'nVertLevelsP1'))
zInterface = zInterface.where(interfaceMask)

y = ds.yCell.values / 1.e3
Expand All @@ -91,11 +91,10 @@ def run(self):
plt.plot(y, -ds.bottomDepth.values, '--r', label='zBed')
plt.xlabel('Distance (km)')
plt.ylabel('Depth (m)')
plt.legend()
plt.savefig('vert_grid.png', dpi=200)
plt.close()

ds = xarray.open_dataset('initial_state.nc')
ds = xr.open_dataset('initial_state.nc')

# Plot the time series of max velocity
plt.figure(figsize=[12, 6], dpi=100)
Expand All @@ -117,46 +116,52 @@ def run(self):
delssh = dsOut.ssh - dsOut.ssh[0, :]
s_vmin = np.nanmin(delssh.values)
s_vmax = np.nanmax(delssh.values)
plotter.plot_horiz_series(delssh, 'delssh', 'delssh', True,
plotter.plot_horiz_series(da=delssh, nameInTitle='delssh',
prefix='delssh', oceanDomain=True,
cmap='cmo.curl',
vmin=-1. * max(abs(s_vmin), abs(s_vmax)),
vmax=max(abs(s_vmin), abs(s_vmax)),
figsize=figsize)

u_vmin = np.nanmin(dsOut.velocityX[:, :, 0].values)
u_vmax = np.nanmax(dsOut.velocityX[:, :, 0].values)
plotter.plot_horiz_series(dsOut.velocityX[:, :, 0], 'u', 'u', True,
plotter.plot_horiz_series(da=dsOut.velocityX[:, :, 0], nameInTitle='u',
prefix='u', oceanDomain=True,
cmap='cmo.balance',
vmin=-1. * max(abs(u_vmin), abs(u_vmax)),
vmax=max(abs(u_vmin), abs(u_vmax)),
figsize=figsize)

v_vmin = np.nanmin(dsOut.velocityY[:, :, 0].values)
v_vmax = np.nanmax(dsOut.velocityY[:, :, 0].values)
plotter.plot_horiz_series(dsOut.velocityY[:, :, 0], 'v', 'v', True,
plotter.plot_horiz_series(da=dsOut.velocityY[:, :, 0], nameInTitle='v',
prefix='v', oceanDomain=True,
cmap='cmo.balance',
vmin=-1. * max(abs(v_vmin), abs(v_vmax)),
vmax=max(abs(v_vmin), abs(v_vmax)),
figsize=figsize)

plotter.plot_horiz_series(dsOut.landIcePressure, 'landIcePressure',
'landIcePressure',
True, vmin=1e3,
vmax=1e7, cmap_set_under='r',
cmap_scale='log',
figsize=figsize)
plotter.plot_horiz_series(da=dsOut.landIcePressure,
nameInTitle='landIcePressure',
prefix='landIcePressure', oceanDomain=True,
vmin=1e3, vmax=1e7, cmap_set_under='r',
cmap_scale='log', figsize=figsize)

plotter.plot_horiz_series(dsOut.ssh + ds.bottomDepth, 'H', 'H',
True, vmin=min_column_thickness + 1e-10,
plotter.plot_horiz_series(da=dsOut.ssh + ds.bottomDepth,
nameInTitle='H', prefix='H',
oceanDomain=True,
vmin=min_column_thickness + 1e-10,
vmax=2000, cmap_set_under='r',
cmap_scale='log',
figsize=figsize)
cmap_scale='log', figsize=figsize)

delssh = dsAdj.ssh - ds.ssh
s_vmin = np.nanmin(delssh.values)
s_vmax = np.nanmax(delssh.values)
plotter.plot_horiz_series(delssh, 'delssh_adjust', 'delssh_adjust',
True, cmap='cmo.curl', time_indices=[0],
plotter.plot_horiz_series(da=delssh,
nameInTitle='delssh_adjust',
prefix='delssh_adjust',
oceanDomain=True,
cmap='cmo.curl', time_indices=[0],
vmin=-1. * max(abs(s_vmin), abs(s_vmax)),
vmax=max(abs(s_vmin), abs(s_vmax)),
figsize=figsize)

0 comments on commit a5a8c6b

Please sign in to comment.