From bf5807494755222c399f89763cb4fe9db710b528 Mon Sep 17 00:00:00 2001 From: anton-climate Date: Tue, 19 Mar 2024 13:47:30 +1100 Subject: [PATCH 1/4] make cice grid --- .gitmodules | 3 ++ grid_generation/esmgrids | 1 + grid_generation/make_cice_grid.py | 78 +++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 .gitmodules create mode 160000 grid_generation/esmgrids create mode 100644 grid_generation/make_cice_grid.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e89ac58 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "grid_generation/esmgrids"] + path = grid_generation/esmgrids + url = https://github.com/COSIMA/esmgrids.git diff --git a/grid_generation/esmgrids b/grid_generation/esmgrids new file mode 160000 index 0000000..c042278 --- /dev/null +++ b/grid_generation/esmgrids @@ -0,0 +1 @@ +Subproject commit c042278d427d278719ab6277b76070357362674d diff --git a/grid_generation/make_cice_grid.py b/grid_generation/make_cice_grid.py new file mode 100644 index 0000000..53d723d --- /dev/null +++ b/grid_generation/make_cice_grid.py @@ -0,0 +1,78 @@ +""" +Script: make_cice_grid.py +Description: +This script generates a CICE grid from the MOM super grid provided in the input NetCDF file. + +Usage: +python make_cice_grid.py +- ocean_hgrid: Path to the MOM super grid NetCDF file. +- ocean_hgrid: Path to the corresponding hgrid NetCDF file. + +""" + + +#!/usr/bin/env python3 +# File based on https://github.com/COSIMA/access-om2/blob/29118914d5224152ce286e0590394b231fea632e/tools/make_cice_grid.py + +import sys +import os +import argparse + +my_dir = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(my_dir, 'esmgrids')) + +from esmgrids.mom_grid import MomGrid # noqa +from esmgrids.cice_grid import CiceGrid # noqa + + +def md5sum(filename): + from hashlib import md5 + from mmap import mmap, ACCESS_READ + + with open(filename) as file, mmap(file.fileno(), 0, access=ACCESS_READ) as file: + return md5(file).hexdigest() + +""" +Create CICE grid.nc and kmt.nc from MOM ocean_hgrid.nc and ocean_mask.nc +""" + +def main(): + + parser = argparse.ArgumentParser() + parser.add_argument('ocean_hgrid', help='ocean_hgrid.nc file') + parser.add_argument('ocean_mask', help='ocean_mask.nc file') + + args = parser.parse_args() + + mom = MomGrid.fromfile(args.ocean_hgrid, mask_file=args.ocean_mask) + + cice = CiceGrid.fromgrid(mom) + + + grid_file = os.path.join('grid.nc') + mask_file = os.path.join('kmt.nc') + + cice.create_gridnc(grid_file) + + # Add versioning information + cice.grid_f.inputfile = f"{args.ocean_hgrid}" + cice.grid_f.inputfile_md5 = md5sum(args.ocean_hgrid) + cice.grid_f.history_command = f"python make_CICE_grid.py {args.ocean_hgrid} {args.ocean_mask}" + + crs = cice.grid_f.createVariable('crs', 'int') + crs.grid_mapping_name = "latitude_longitude" + # crs.crs_wkt = #TBA + + cice.write() + + cice.create_masknc(mask_file) + + # Add versioning information + cice.mask_f.inputfile = f"{args.ocean_mask}" + cice.mask_f.inputfile_md5 = md5sum(args.ocean_mask) + cice.mask_f.history_command = f"python make_CICE_grid.py {args.ocean_hgrid} {args.ocean_mask}" + + cice.write_mask() + +if __name__ == '__main__': + sys.exit(main()) \ No newline at end of file From 386b73e43208414ba2185948c584aa4cf0bcb63b Mon Sep 17 00:00:00 2001 From: anton-climate Date: Wed, 20 Mar 2024 15:50:46 +1100 Subject: [PATCH 2/4] attempt at adding crs --- grid_generation/README.md | 5 ++++ grid_generation/esmgrids | 2 +- grid_generation/make_cice_grid.py | 36 +++++++++++++++++++++++--- grid_generation/pbs_make_cice_grids.sh | 33 +++++++++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 grid_generation/README.md create mode 100644 grid_generation/pbs_make_cice_grids.sh diff --git a/grid_generation/README.md b/grid_generation/README.md new file mode 100644 index 0000000..9f426a7 --- /dev/null +++ b/grid_generation/README.md @@ -0,0 +1,5 @@ +# CICE Grid Generation + +These two scripts usign the 'esmgrids' package developed for ACCESS-OM2, to make the CICE grid files from the MOM super grid file. + +As executing `python3 make_cice_grid.py` can fail on the login node, a shell script to use with pbs is provided. The shell script also captures the hh5 module used and the input files used. Run `qsub pbs_make_cice_grids.sh` to make the cice grids and kmt file at all 3 model resolutions. \ No newline at end of file diff --git a/grid_generation/esmgrids b/grid_generation/esmgrids index c042278..24dd693 160000 --- a/grid_generation/esmgrids +++ b/grid_generation/esmgrids @@ -1 +1 @@ -Subproject commit c042278d427d278719ab6277b76070357362674d +Subproject commit 24dd693d3b623c58132583636d8fb96e46da154d diff --git a/grid_generation/make_cice_grid.py b/grid_generation/make_cice_grid.py index 53d723d..92e6c74 100644 --- a/grid_generation/make_cice_grid.py +++ b/grid_generation/make_cice_grid.py @@ -6,7 +6,7 @@ Usage: python make_cice_grid.py - ocean_hgrid: Path to the MOM super grid NetCDF file. -- ocean_hgrid: Path to the corresponding hgrid NetCDF file. +- ocean_mask: Path to the corresponding mask NetCDF file. """ @@ -59,9 +59,37 @@ def main(): cice.grid_f.inputfile_md5 = md5sum(args.ocean_hgrid) cice.grid_f.history_command = f"python make_CICE_grid.py {args.ocean_hgrid} {args.ocean_mask}" - crs = cice.grid_f.createVariable('crs', 'int') - crs.grid_mapping_name = "latitude_longitude" - # crs.crs_wkt = #TBA + #AS: based on https://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/build/ch05s06.html + crs = cice.grid_f.createVariable('tripolar', 'S1') + crs.grid_mapping_name = "tripolar_latitude_longitude" + crs.crs_wkt = """ + GEOGCRS["WGS 84", + ENSEMBLE["World Geodetic System 1984 ensemble", + MEMBER["World Geodetic System 1984 (Transit)"], + MEMBER["World Geodetic System 1984 (G730)"], + MEMBER["World Geodetic System 1984 (G873)"], + MEMBER["World Geodetic System 1984 (G1150)"], + MEMBER["World Geodetic System 1984 (G1674)"], + MEMBER["World Geodetic System 1984 (G1762)"], + MEMBER["World Geodetic System 1984 (G2139)"], + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]], + ENSEMBLEACCURACY[2.0]], + PRIMEM["Greenwich",0, + ANGLEUNIT["radian",1]], + CS[ellipsoidal,2], + AXIS["geodetic latitude (Lat)",north, + ORDER[1], + ANGLEUNIT["radian",1]], + AXIS["geodetic longitude (Lon)",east, + ORDER[2], + ANGLEUNIT["radian",1]], + USAGE[ + SCOPE["Horizontal component of 3D system."], + AREA["World."], + BBOX[-80,80,90,80]], + ID["EPSG",4326]] + """ cice.write() diff --git a/grid_generation/pbs_make_cice_grids.sh b/grid_generation/pbs_make_cice_grids.sh new file mode 100644 index 0000000..bbf2643 --- /dev/null +++ b/grid_generation/pbs_make_cice_grids.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +#PBS -W umask=0022 +#PBS -l mem=24gb +#PBS -l storage=gdata/ik11+gdata/tm70+gdata/hh5 +#PBS -l wd +#PBS -j oe + +umask 0003 + +module purge +module use /g/data/hh5/public/modules +module load conda/analysis3-23.10 + +echo "1 degree" +python3 make_cice_grid.py /g/data/ik11/inputs/access-om2/input_20201102/mom_1deg/ocean_hgrid.nc /g/data/ik11/inputs/access-om2/input_20201102/mom_1deg/ocean_mask.nc + +mkdir 1deg +mv grid.nc kmt.nc 1deg + + +echo "0.25 deg" + +python3 make_cice_grid.py /g/data/ik11/inputs/access-om2/input_20201102/mom_025deg/ocean_hgrid.nc /g/data/ik11/inputs/access-om2/input_20201102/mom_025deg/ocean_mask.nc + +mkdir 025deg +mv grid.nc kmt.nc 025deg + +echo "01 deg" +python3 make_cice_grid.py /g/data/ik11/inputs/access-om2/input_20201102/mom_01deg/ocean_hgrid.nc /g/data/ik11/inputs/access-om2/input_20201102/mom_01deg/ocean_mask.nc + +mkdir 01deg +mv grid.nc kmt.nc 01deg \ No newline at end of file From 377ea07f56c42c22aeee243584ea41777df260ff Mon Sep 17 00:00:00 2001 From: anton-climate Date: Fri, 22 Mar 2024 10:11:10 +1100 Subject: [PATCH 3/4] Move CRS to within esmgrids package for neatness --- grid_generation/esmgrids | 2 +- grid_generation/make_cice_grid.py | 34 +------------------------------ 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/grid_generation/esmgrids b/grid_generation/esmgrids index 24dd693..5ca8760 160000 --- a/grid_generation/esmgrids +++ b/grid_generation/esmgrids @@ -1 +1 @@ -Subproject commit 24dd693d3b623c58132583636d8fb96e46da154d +Subproject commit 5ca87608a34464521729bfb87607b0931bfe6da0 diff --git a/grid_generation/make_cice_grid.py b/grid_generation/make_cice_grid.py index 92e6c74..979b656 100644 --- a/grid_generation/make_cice_grid.py +++ b/grid_generation/make_cice_grid.py @@ -59,38 +59,6 @@ def main(): cice.grid_f.inputfile_md5 = md5sum(args.ocean_hgrid) cice.grid_f.history_command = f"python make_CICE_grid.py {args.ocean_hgrid} {args.ocean_mask}" - #AS: based on https://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/build/ch05s06.html - crs = cice.grid_f.createVariable('tripolar', 'S1') - crs.grid_mapping_name = "tripolar_latitude_longitude" - crs.crs_wkt = """ - GEOGCRS["WGS 84", - ENSEMBLE["World Geodetic System 1984 ensemble", - MEMBER["World Geodetic System 1984 (Transit)"], - MEMBER["World Geodetic System 1984 (G730)"], - MEMBER["World Geodetic System 1984 (G873)"], - MEMBER["World Geodetic System 1984 (G1150)"], - MEMBER["World Geodetic System 1984 (G1674)"], - MEMBER["World Geodetic System 1984 (G1762)"], - MEMBER["World Geodetic System 1984 (G2139)"], - ELLIPSOID["WGS 84",6378137,298.257223563, - LENGTHUNIT["metre",1]], - ENSEMBLEACCURACY[2.0]], - PRIMEM["Greenwich",0, - ANGLEUNIT["radian",1]], - CS[ellipsoidal,2], - AXIS["geodetic latitude (Lat)",north, - ORDER[1], - ANGLEUNIT["radian",1]], - AXIS["geodetic longitude (Lon)",east, - ORDER[2], - ANGLEUNIT["radian",1]], - USAGE[ - SCOPE["Horizontal component of 3D system."], - AREA["World."], - BBOX[-80,80,90,80]], - ID["EPSG",4326]] - """ - cice.write() cice.create_masknc(mask_file) @@ -103,4 +71,4 @@ def main(): cice.write_mask() if __name__ == '__main__': - sys.exit(main()) \ No newline at end of file + sys.exit(main()) From bbc2a563d06dc7b4eb3c6e6d0fd7d3f5a97dfbb5 Mon Sep 17 00:00:00 2001 From: anton-climate Date: Tue, 26 Mar 2024 15:21:12 +1100 Subject: [PATCH 4/4] Update to newer ocean mask for 0.25 deg --- grid_generation/pbs_make_cice_grids.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/grid_generation/pbs_make_cice_grids.sh b/grid_generation/pbs_make_cice_grids.sh index bbf2643..8aa30a5 100644 --- a/grid_generation/pbs_make_cice_grids.sh +++ b/grid_generation/pbs_make_cice_grids.sh @@ -18,10 +18,8 @@ python3 make_cice_grid.py /g/data/ik11/inputs/access-om2/input_20201102/mom_1deg mkdir 1deg mv grid.nc kmt.nc 1deg - echo "0.25 deg" - -python3 make_cice_grid.py /g/data/ik11/inputs/access-om2/input_20201102/mom_025deg/ocean_hgrid.nc /g/data/ik11/inputs/access-om2/input_20201102/mom_025deg/ocean_mask.nc +python3 make_cice_grid.py /g/data/ik11/inputs/access-om2/input_20230515_025deg_topog/mom_025deg/ocean_hgrid.nc /g/data/ik11/inputs/access-om2/input_20230515_025deg_topog/mom_025deg/ocean_mask.nc mkdir 025deg mv grid.nc kmt.nc 025deg