-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change updates the workflow to generate a cice grid from a mom-supergrid file containing a tripolar grid. - fixes angle T - adds cf compliant variable names - add versioning to output - adds an end-end test COSIMA/om3-utils#5 describes full scope of changes --------- Co-authored-by: dougiesquire <[email protected]> Co-authored-by: Dougie Squire <[email protected]>
- Loading branch information
1 parent
e9d1c14
commit 1b6837d
Showing
11 changed files
with
424 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
import warnings | ||
from importlib.metadata import version, PackageNotFoundError | ||
|
||
try: | ||
__version__ = version("esmgrids") | ||
except PackageNotFoundError: | ||
# package is not installed | ||
pass | ||
|
||
|
||
def safe_version(): | ||
""" | ||
Returns the version, issuing a warning if there are revisions since the last tag | ||
and an error if there are uncommitted changes | ||
This function assumes the setuptools_scm default versioning scheme - see | ||
https://setuptools-scm.readthedocs.io/en/latest/usage/#default-versioning-scheme | ||
""" | ||
if re.match(r".*\d{8}$", __version__): | ||
warnings.warn( | ||
( | ||
"There are uncommitted changes! Commit, push and release these changes before " | ||
"generating any production files." | ||
) | ||
) | ||
elif re.match(r".*dev.*", __version__): | ||
warnings.warn(("There are unreleased commits! Do a release before generating any production files.")) | ||
|
||
return __version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import argparse | ||
|
||
from esmgrids import safe_version | ||
from esmgrids.util import md5sum | ||
from esmgrids.mom_grid import MomGrid | ||
from esmgrids.cice_grid import CiceGrid | ||
|
||
|
||
def cice_from_mom(): | ||
"""Script for creating CICE grid files from MOM grid files""" | ||
|
||
parser = argparse.ArgumentParser(description="Create CICE grid files from MOM grid files") | ||
parser.add_argument("--ocean_hgrid", type=str, help="Input MOM ocean_hgrid.nc supergrid file") | ||
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") | ||
|
||
args = parser.parse_args() | ||
ocean_hgrid = os.path.abspath(args.ocean_hgrid) | ||
ocean_mask = os.path.abspath(args.ocean_mask) | ||
cice_grid = os.path.abspath(args.cice_grid) | ||
cice_kmt = os.path.abspath(args.cice_kmt) | ||
|
||
version = safe_version() | ||
runcmd = ( | ||
f"Created using https://github.com/COSIMA/esmgrids {version}: " | ||
f"cice_from_mom --ocean_hgrid={ocean_hgrid} --ocean_mask={ocean_mask} " | ||
f"--cice_grid={cice_grid} --cice_kmt={cice_kmt}" | ||
) | ||
provenance_metadata = { | ||
"inputfile": ( | ||
f"{ocean_hgrid} (md5 hash: {md5sum(ocean_hgrid)}), " f"{ocean_mask} (md5 hash: {md5sum(ocean_mask)})" | ||
), | ||
"history": runcmd, | ||
} | ||
|
||
mom = MomGrid.fromfile(ocean_hgrid, mask_file=ocean_mask) | ||
cice = CiceGrid.fromgrid(mom) | ||
cice.write(cice_grid, cice_kmt, metadata=provenance_metadata) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.