Skip to content

Commit 9d6797d

Browse files
committed
Update building mapping files with moab
1 parent 0bad1fe commit 9d6797d

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

polaris/remap/mapping_file_step.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pyproj
44
import xarray as xr
5+
from mpas_tools.logging import check_call
56
from pyremap import (
67
LatLon2DGridDescriptor,
78
LatLonGridDescriptor,
@@ -411,11 +412,46 @@ def runtime_setup(self):
411412
dst_descriptor,
412413
self.dst_mesh_filename)
413414
elif map_tool == 'moab':
415+
src_mesh_filename = self._moab_partition_scrip_file(
416+
self.src_mesh_filename)
417+
dst_mesh_filename = self._moab_partition_scrip_file(
418+
self.dst_mesh_filename)
414419
self.args = _moab_build_map_args(remapper, self.method,
415-
src_descriptor,
416-
self.src_mesh_filename,
417-
dst_descriptor,
418-
self.dst_mesh_filename)
420+
src_mesh_filename,
421+
dst_mesh_filename)
422+
423+
def _moab_partition_scrip_file(self, in_filename):
424+
"""
425+
Partition SCRIP file for parallel mbtempest use
426+
"""
427+
logger = self.logger
428+
ntasks = self.ntasks
429+
430+
logger.info(f'Partition SCRIP file {in_filename}')
431+
432+
h5m_filename = in_filename.replace('.nc', '.h5m')
433+
h5m_part_filename = in_filename.replace('.nc', f'.p{ntasks}.h5m')
434+
435+
# Convert source SCRIP to mbtempest
436+
args = [
437+
'mbconvert', '-B',
438+
in_filename,
439+
h5m_filename,
440+
]
441+
check_call(args, logger)
442+
443+
# Partition source SCRIP
444+
args = [
445+
'mbpart', f'{ntasks}',
446+
'-z', 'RCB',
447+
h5m_filename,
448+
h5m_part_filename,
449+
]
450+
check_call(args, logger)
451+
452+
logger.info(' Done.')
453+
454+
return h5m_part_filename
419455

420456

421457
def _check_remapper(remapper, method, map_tool):
@@ -462,8 +498,8 @@ def _esmf_build_map_args(remapper, method, src_descriptor, src_mesh_filename,
462498
return [args]
463499

464500

465-
def _moab_build_map_args(remapper, method, src_descriptor, src_mesh_filename,
466-
dst_descriptor, dst_mesh_filename):
501+
def _moab_build_map_args(remapper, method, src_mesh_filename,
502+
dst_mesh_filename):
467503
"""
468504
Get command-line arguments for making a mapping file with mbtempest
469505
"""
@@ -472,40 +508,22 @@ def _moab_build_map_args(remapper, method, src_descriptor, src_mesh_filename,
472508
'bilinear': 'bilin'}
473509

474510
map_filename = remapper.mappingFileName
475-
intx_filename = \
476-
f'moab_intx_{src_descriptor.meshName}_to_{dst_descriptor.meshName}.h5m'
477-
478-
intx_args = [
479-
'mbtempest',
480-
'--type', '5',
481-
'--load', src_mesh_filename,
482-
'--load', dst_mesh_filename,
483-
'--intx', intx_filename
484-
]
485511

486-
if src_descriptor.regional or dst_descriptor.regional:
487-
intx_args.append('--rrmgrids')
488-
489-
map_args = [
490-
'mbtempest',
491-
'--type', '5',
512+
args = [
513+
'mbtempest', '--type', '5',
492514
'--load', src_mesh_filename,
493515
'--load', dst_mesh_filename,
494-
'--intx', intx_filename,
495-
'--weights',
516+
'--file', map_filename,
517+
'--weights', '--gnomonic',
518+
'--boxeps', '1e-9',
496519
'--method', 'fv',
497520
'--method', 'fv',
498-
'--file', map_filename,
499521
'--order', '1',
500522
'--order', '1',
501523
'--fvmethod', fvmethod[method]
502524
]
503525

504-
if method == 'conserve' and (src_descriptor.regional or
505-
dst_descriptor.regional):
506-
map_args.append('--rrmgrids')
507-
508-
return [intx_args, map_args]
526+
return [args]
509527

510528

511529
def _get_descriptor(info):

0 commit comments

Comments
 (0)