Skip to content

Commit

Permalink
comments and tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-seaice committed Apr 25, 2024
1 parent b229945 commit 5a71eae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
13 changes: 8 additions & 5 deletions esmgrids/cice_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import netCDF4 as nc
from warnings import warn

from esmgrids.base_grid import BaseGrid

Expand Down Expand Up @@ -91,6 +90,8 @@ def write(self, grid_filename, mask_filename, metadata=None, variant=None):
The name of the mask file to write
metadata: dict
Any global or variable metadata attributes to add to the files being written
variant: str
Use variant='cice5-auscom' for access-om2/cice5-auscom builds, otherwise use None
"""

if variant is not None and variant != "cice5-auscom":
Expand All @@ -100,10 +101,12 @@ def write(self, grid_filename, mask_filename, metadata=None, variant=None):
f = nc.Dataset(grid_filename, "w")

# Create dimensions.
f.createDimension("ni", self.num_lon_points)
# ni is the grid_longitude but doesn't have a value other than its index
f.createDimension("nj", self.num_lat_points)
# nj is the grid_latitude but doesn't have a value other than its index
f.createDimension(
"ni", self.num_lon_points
) # ni is the grid_longitude but doesn't have a value other than its index
f.createDimension(
"nj", self.num_lat_points
) # nj is the grid_latitude but doesn't have a value other than its index

# Make all CICE grid variables.
# names are based on https://cfconventions.org/Data/cf-standard-names/current/build/cf-standard-name-table.html
Expand Down
4 changes: 3 additions & 1 deletion esmgrids/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def cice_from_mom():
parser.add_argument("--ocean_mask", type=str, help="Input MOM ocean_mask.nc mask file")
parser.add_argument("--cice_grid", type=str, default="grid.nc", help="Output CICE grid file")
parser.add_argument("--cice_kmt", type=str, default="kmt.nc", help="Output CICE kmt file")
parser.add_argument("--cice_variant", type=str, default=None, help="Cice variant")
parser.add_argument(
"--cice_variant", type=str, default=None, help="Cice variant, valid options = [None, 'cice5-auscom'] "
)

args = parser.parse_args()
ocean_hgrid = os.path.abspath(args.ocean_hgrid)
Expand Down
5 changes: 4 additions & 1 deletion test/test_cice_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
import xarray as xr
import warnings
from numpy.testing import assert_allclose
from numpy import deg2rad
from subprocess import run
Expand All @@ -14,6 +13,7 @@
# going higher resolution than 0.1 has too much computational cost
_test_resolutions = [4, 0.1]

# run test using the valid cice variants
_variants = ["cice5-auscom", None]


Expand Down Expand Up @@ -254,14 +254,17 @@ def test_variant(mom_grid, tmp_path):
mom = MomGrid.fromfile(mom_grid.path, mask_file=mom_grid.mask_path)
cice = CiceGrid.fromgrid(mom)

# invalid variant (="andrew")
with pytest.raises(NotImplementedError, match="andrew not recognised"):
cice.write(str(tmp_path) + "/grid2.nc", str(tmp_path) + "/kmt2.nc", variant="andrew")

# valid variant (="cice5-auscom")
try:
cice.write(str(tmp_path) + "/grid2.nc", str(tmp_path) + "/kmt2.nc", variant="cice5-auscom")
except:
assert False, "Failed to write cice grid with valid input arguments provided"

# valid variant (default = None)
try:
cice.write(str(tmp_path) + "/grid2.nc", str(tmp_path) + "/kmt2.nc")
except:
Expand Down
3 changes: 0 additions & 3 deletions test/test_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import os
import sys
import numpy as np
import netCDF4 as nc

my_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(my_dir, "../"))

from esmgrids.mom_grid import MomGrid # noqa
from esmgrids.core2_grid import Core2Grid # noqa
from esmgrids.cice_grid import CiceGrid # noqa
from esmgrids.util import calc_area_of_polygons # noqa

data_tarball = "test_data.tar.gz"
Expand Down

0 comments on commit 5a71eae

Please sign in to comment.