Skip to content

Commit

Permalink
Merge pull request #499 from xylar/allow_external_mapping_file_in_sea…
Browse files Browse the repository at this point in the history
…ice_partitioning

Allow external mapping file for sea-ice partitioning
  • Loading branch information
xylar authored Mar 11, 2023
2 parents 0d2124c + c249d5d commit 73b7255
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
41 changes: 27 additions & 14 deletions conda_package/mpas_tools/seaice/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,26 @@ def prepare_partitions():
"""
# parsing input
parser = argparse.ArgumentParser(
description='Perform preparatory work for making seaice partitions.')

parser.add_argument('-i', '--inputmesh', dest="meshFilenameSrc", required=True,
help='MPAS mesh file for source regridding mesh.')
parser.add_argument('-p', '--presence', dest="filenameData", required=True,
help='Input ice presence file for source mesh.')
parser.add_argument('-m', '--outputmesh', dest="meshFilenameDst", required=True,
help='MPAS mesh file for destination regridding mesh.')
parser.add_argument('-o', '--outputDir', dest="outputDir", required=True,
help='Output directory for temporary files and partition files.')
description="Perform preparatory work for making seaice partitions.")

parser.add_argument("-i", "--inputmesh", dest="meshFilenameSrc",
required=True,
help="MPAS mesh file for source regridding mesh.")
parser.add_argument("-p", "--presence", dest="filenameData",
required=True,
help="Input ice presence file for source mesh.")
parser.add_argument("-m", "--outputmesh", dest="meshFilenameDst",
required=True,
help="MPAS mesh file for destination regridding mesh.")
parser.add_argument("-o", "--outputDir", dest="outputDir",
required=True,
help="Output directory for temporary files and "
"partition files.")
parser.add_argument("-w", "--weightsFilename", dest="weightsFilename",
required=False,
help="A mapping file between the input and output "
"MPAS meshes. One will be generated if it is "
"not supplied.")

args = parser.parse_args()

Expand All @@ -209,11 +219,14 @@ def prepare_partitions():
# 1) Regrid the ice presence from the input data mesh to the grid of choice
print("Regrid to desired mesh...")
filenameOut = args.outputDir + "/icePresent_regrid.nc"

regrid_to_other_mesh(
args.meshFilenameSrc,
args.filenameData,
args.meshFilenameDst,
filenameOut)
meshFilenameSrc=args.meshFilenameSrc,
filenameData=args.filenameData,
meshFilenameDst=args.meshFilenameDst,
filenameOut=filenameOut,
generateWeights=(args.weightsFilename is None),
weightsFilename=args.weightsFilename)

# 2) create icePresence variable
print("fix_regrid_output...")
Expand Down
18 changes: 12 additions & 6 deletions conda_package/mpas_tools/seaice/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@


def regrid_to_other_mesh(meshFilenameSrc, filenameData,
meshFilenameDst, filenameOut):
meshFilenameDst, filenameOut,
generateWeights=True, weightsFilename=None):

# make scrip files
print("Make scrip files...")
Expand All @@ -22,11 +23,16 @@ def regrid_to_other_mesh(meshFilenameSrc, filenameData,
make_mpas_scripfile_on_cells(meshFilenameSrc, SCRIPFilenameSrc, titleSrc)
make_mpas_scripfile_on_cells(meshFilenameDst, SCRIPFilenameDst, titleDst)

# generate weights file
print("Generate weights...")
weightsFilename = os.getcwd() + "/weights_tmp.nc"
_generate_weights_file(SCRIPFilenameSrc, SCRIPFilenameDst,
weightsFilename, reuseWeights=False)
if weightsFilename is None:
weightsFilename = os.getcwd() + "/weights_tmp.nc"

if generateWeights:
# generate weights file
print("Generate weights...")
_generate_weights_file(SCRIPFilenameSrc, SCRIPFilenameDst,
weightsFilename, reuseWeights=False)
else:
assert os.path.exists(weightsFilename)

# load output mesh
print("Load output mesh...")
Expand Down

0 comments on commit 73b7255

Please sign in to comment.