Skip to content
Merged
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
93 changes: 52 additions & 41 deletions polaris/remap/mapping_file_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pyproj
import xarray as xr
from mpas_tools.logging import check_call
from pyremap import (
LatLon2DGridDescriptor,
LatLonGridDescriptor,
Expand Down Expand Up @@ -448,15 +449,52 @@ def runtime_setup(self):
self.dst_mesh_filename,
)
elif map_tool == 'moab':
src_mesh_filename = self._moab_partition_scrip_file(
self.src_mesh_filename
)
dst_mesh_filename = self._moab_partition_scrip_file(
self.dst_mesh_filename
)
self.args = _moab_build_map_args(
remapper,
self.method,
src_descriptor,
self.src_mesh_filename,
dst_descriptor,
self.dst_mesh_filename,
remapper, self.method, src_mesh_filename, dst_mesh_filename
)

def _moab_partition_scrip_file(self, in_filename):
"""
Partition SCRIP file for parallel mbtempest use
"""
logger = self.logger
ntasks = self.ntasks

logger.info(f'Partition SCRIP file {in_filename}')

h5m_filename = in_filename.replace('.nc', '.h5m')
h5m_part_filename = in_filename.replace('.nc', f'.p{ntasks}.h5m')

# Convert source SCRIP to mbtempest
args = [
'mbconvert',
'-B',
in_filename,
h5m_filename,
]
check_call(args, logger)

# Partition source SCRIP
args = [
'mbpart',
f'{ntasks}',
'-z',
'RCB',
h5m_filename,
h5m_part_filename,
]
check_call(args, logger)

logger.info(' Done.')

return h5m_part_filename


def _check_remapper(remapper, method, map_tool):
"""
Expand Down Expand Up @@ -519,55 +557,33 @@ def _esmf_build_map_args(


def _moab_build_map_args(
remapper,
method,
src_descriptor,
src_mesh_filename,
dst_descriptor,
dst_mesh_filename,
remapper, method, src_mesh_filename, dst_mesh_filename
):
"""
Get command-line arguments for making a mapping file with mbtempest
"""
fvmethod = {'conserve': 'none', 'bilinear': 'bilin'}

map_filename = remapper.mappingFileName
intx_filename = (
f'moab_intx_{src_descriptor.meshName}_to_{dst_descriptor.meshName}.h5m'
)

intx_args = [
'mbtempest',
'--type',
'5',
'--load',
src_mesh_filename,
'--load',
dst_mesh_filename,
'--intx',
intx_filename,
]

if src_descriptor.regional or dst_descriptor.regional:
intx_args.append('--rrmgrids')

map_args = [
args = [
'mbtempest',
'--type',
'5',
'--load',
src_mesh_filename,
'--load',
dst_mesh_filename,
'--intx',
intx_filename,
'--file',
map_filename,
'--weights',
'--gnomonic',
'--boxeps',
'1e-9',
'--method',
'fv',
'--method',
'fv',
'--file',
map_filename,
'--order',
'1',
'--order',
Expand All @@ -576,12 +592,7 @@ def _moab_build_map_args(
fvmethod[method],
]

if method == 'conserve' and (
src_descriptor.regional or dst_descriptor.regional
):
map_args.append('--rrmgrids')

return [intx_args, map_args]
return [args]


def _get_descriptor(info):
Expand Down
Loading