Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make cice grid #8

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "grid_generation/esmgrids"]
path = grid_generation/esmgrids
url = https://github.com/COSIMA/esmgrids.git
5 changes: 5 additions & 0 deletions grid_generation/README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions grid_generation/esmgrids
Submodule esmgrids added at 5ca876
74 changes: 74 additions & 0 deletions grid_generation/make_cice_grid.py
Original file line number Diff line number Diff line change
@@ -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> <ocean_hgrid>
- 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())
31 changes: 31 additions & 0 deletions grid_generation/pbs_make_cice_grids.sh
Original file line number Diff line number Diff line change
@@ -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