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/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 new file mode 160000 index 0000000..5ca8760 --- /dev/null +++ b/grid_generation/esmgrids @@ -0,0 +1 @@ +Subproject commit 5ca87608a34464521729bfb87607b0931bfe6da0 diff --git a/grid_generation/make_cice_grid.py b/grid_generation/make_cice_grid.py new file mode 100644 index 0000000..979b656 --- /dev/null +++ b/grid_generation/make_cice_grid.py @@ -0,0 +1,74 @@ +""" +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_mask: Path to the corresponding mask 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}" + + 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()) diff --git a/grid_generation/pbs_make_cice_grids.sh b/grid_generation/pbs_make_cice_grids.sh new file mode 100644 index 0000000..8aa30a5 --- /dev/null +++ b/grid_generation/pbs_make_cice_grids.sh @@ -0,0 +1,31 @@ +#!/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_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 + +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