From 0e8677c9f2a811c172c1d9b9ac3e4969f7f16ca6 Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Tue, 20 Aug 2024 10:36:02 -0500 Subject: [PATCH 1/2] Add script for adding mask to scrip file for ocn-glc fjord coupling This script defines a mask of ocean cells that are deeper than a threshold. This is to be used for updating a scrip file so that it only remaps from ocean cells deeper than that threshold. The resulting mapping file can be used as an OCN2GLC_TF_SMAPNAME mapping file in E3SM. Note that config_2d_thermal_forcing_depth in the MPAS-Ocean namelist needs to match the depth used here! --- ...ask_for_sufficiently_deep_ocean_mapping.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 ocean/ocn_glc_fjord_coupling_mapping/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py diff --git a/ocean/ocn_glc_fjord_coupling_mapping/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py b/ocean/ocn_glc_fjord_coupling_mapping/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py new file mode 100755 index 000000000..1dc376a82 --- /dev/null +++ b/ocean/ocn_glc_fjord_coupling_mapping/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +""" +Script for defining mask of ocean cells that are deeper than a threshold. +To be used for updating a scrip file so that it only remaps +from ocean cells deeper than that threshold. +The resulting mapping file can be used as an OCN2GLC_TF_SMAPNAME +mapping file in E3SM. +Note that config_2d_thermal_forcing_depth in the MPAS-Ocean namelist +needs to match the depth used here! +""" + +import argparse +import sys +from datetime import datetime +from netCDF4 import Dataset + +parser = argparse.ArgumentParser( + description=__doc__) +parser.add_argument("-s", dest="scrip", + required=True, + help="scrip file to which to add mask") +parser.add_argument("-m", dest="mpas", + required=True, + help="MPAS-Ocean mesh file") +parser.add_argument("-d", dest="depth", + required=True, + help="depth threshold (m), should be a positive value", + type=float) +args = parser.parse_args() + +assert args.depth > 0.0, "'depth' argument should be a positive value" + +# open mesh file +fmesh = Dataset(args.mpas, 'r') +nCells = len(fmesh.dimensions['nCells']) +bottomDepth = fmesh.variables['bottomDepth'][:] + +# identify cells shallower than target depth +mask = bottomDepth > args.depth + +# insert mask into scrip file +fscrip = Dataset(args.scrip, 'r+') +if 'grid_imask' not in fscrip.variables: + fscrip.createVariable('grid_imask', 'i', ('nCells',)) +fscrip.variables['grid_imask'][:] = mask + +# Update history attribute of scrip netCDF file +thiscommand = datetime.now().strftime("%a %b %d %H:%M:%S %Y") + ": " + " ".join(sys.argv[:]) +if hasattr(fscrip, 'history'): + newhist = '\n'.join([thiscommand, getattr(fscrip, 'history')]) +else: + newhist = thiscommand +setattr(fscrip, 'history', newhist ) + +fmesh.close() +fscrip.close() From 9abfc4c0909d3ea0ea2cd934a22ac85d834558a8 Mon Sep 17 00:00:00 2001 From: Matthew Hoffman Date: Tue, 20 Aug 2024 10:55:16 -0500 Subject: [PATCH 2/2] Move script to scrip generation subdirectory This is a more logical place to keep it --- .../create_scrip_mask_for_sufficiently_deep_ocean_mapping.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {ocean/ocn_glc_fjord_coupling_mapping => mesh_tools/create_SCRIP_files}/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py (100%) diff --git a/ocean/ocn_glc_fjord_coupling_mapping/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py b/mesh_tools/create_SCRIP_files/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py similarity index 100% rename from ocean/ocn_glc_fjord_coupling_mapping/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py rename to mesh_tools/create_SCRIP_files/create_scrip_mask_for_sufficiently_deep_ocean_mapping.py