From 5a71eaeb57d455e16558672c5b9d375e0227a7c5 Mon Sep 17 00:00:00 2001 From: anton-climate Date: Fri, 26 Apr 2024 08:57:34 +1000 Subject: [PATCH] comments and tidy --- esmgrids/cice_grid.py | 13 ++++++++----- esmgrids/cli.py | 4 +++- test/test_cice_grid.py | 5 ++++- test/test_grids.py | 3 --- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/esmgrids/cice_grid.py b/esmgrids/cice_grid.py index 8317f35..6639b2d 100644 --- a/esmgrids/cice_grid.py +++ b/esmgrids/cice_grid.py @@ -1,6 +1,5 @@ import numpy as np import netCDF4 as nc -from warnings import warn from esmgrids.base_grid import BaseGrid @@ -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": @@ -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 diff --git a/esmgrids/cli.py b/esmgrids/cli.py index 676c549..15adfc5 100644 --- a/esmgrids/cli.py +++ b/esmgrids/cli.py @@ -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) diff --git a/test/test_cice_grid.py b/test/test_cice_grid.py index 0af5d59..654f815 100644 --- a/test/test_cice_grid.py +++ b/test/test_cice_grid.py @@ -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 @@ -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] @@ -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: diff --git a/test/test_grids.py b/test/test_grids.py index 410b034..26114eb 100644 --- a/test/test_grids.py +++ b/test/test_grids.py @@ -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"