Skip to content

Commit 91541b8

Browse files
authored
Merge pull request #247 from xylar/update-mbtempest
Update building mapping files with moab
2 parents 8521e97 + e732484 commit 91541b8

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed

polaris/remap/mapping_file_step.py

Lines changed: 52 additions & 41 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,
@@ -448,15 +449,52 @@ def runtime_setup(self):
448449
self.dst_mesh_filename,
449450
)
450451
elif map_tool == 'moab':
452+
src_mesh_filename = self._moab_partition_scrip_file(
453+
self.src_mesh_filename
454+
)
455+
dst_mesh_filename = self._moab_partition_scrip_file(
456+
self.dst_mesh_filename
457+
)
451458
self.args = _moab_build_map_args(
452-
remapper,
453-
self.method,
454-
src_descriptor,
455-
self.src_mesh_filename,
456-
dst_descriptor,
457-
self.dst_mesh_filename,
459+
remapper, self.method, src_mesh_filename, dst_mesh_filename
458460
)
459461

462+
def _moab_partition_scrip_file(self, in_filename):
463+
"""
464+
Partition SCRIP file for parallel mbtempest use
465+
"""
466+
logger = self.logger
467+
ntasks = self.ntasks
468+
469+
logger.info(f'Partition SCRIP file {in_filename}')
470+
471+
h5m_filename = in_filename.replace('.nc', '.h5m')
472+
h5m_part_filename = in_filename.replace('.nc', f'.p{ntasks}.h5m')
473+
474+
# Convert source SCRIP to mbtempest
475+
args = [
476+
'mbconvert',
477+
'-B',
478+
in_filename,
479+
h5m_filename,
480+
]
481+
check_call(args, logger)
482+
483+
# Partition source SCRIP
484+
args = [
485+
'mbpart',
486+
f'{ntasks}',
487+
'-z',
488+
'RCB',
489+
h5m_filename,
490+
h5m_part_filename,
491+
]
492+
check_call(args, logger)
493+
494+
logger.info(' Done.')
495+
496+
return h5m_part_filename
497+
460498

461499
def _check_remapper(remapper, method, map_tool):
462500
"""
@@ -519,55 +557,33 @@ def _esmf_build_map_args(
519557

520558

521559
def _moab_build_map_args(
522-
remapper,
523-
method,
524-
src_descriptor,
525-
src_mesh_filename,
526-
dst_descriptor,
527-
dst_mesh_filename,
560+
remapper, method, src_mesh_filename, dst_mesh_filename
528561
):
529562
"""
530563
Get command-line arguments for making a mapping file with mbtempest
531564
"""
532565
fvmethod = {'conserve': 'none', 'bilinear': 'bilin'}
533566

534567
map_filename = remapper.mappingFileName
535-
intx_filename = (
536-
f'moab_intx_{src_descriptor.meshName}_to_{dst_descriptor.meshName}.h5m'
537-
)
538-
539-
intx_args = [
540-
'mbtempest',
541-
'--type',
542-
'5',
543-
'--load',
544-
src_mesh_filename,
545-
'--load',
546-
dst_mesh_filename,
547-
'--intx',
548-
intx_filename,
549-
]
550568

551-
if src_descriptor.regional or dst_descriptor.regional:
552-
intx_args.append('--rrmgrids')
553-
554-
map_args = [
569+
args = [
555570
'mbtempest',
556571
'--type',
557572
'5',
558573
'--load',
559574
src_mesh_filename,
560575
'--load',
561576
dst_mesh_filename,
562-
'--intx',
563-
intx_filename,
577+
'--file',
578+
map_filename,
564579
'--weights',
580+
'--gnomonic',
581+
'--boxeps',
582+
'1e-9',
565583
'--method',
566584
'fv',
567585
'--method',
568586
'fv',
569-
'--file',
570-
map_filename,
571587
'--order',
572588
'1',
573589
'--order',
@@ -576,12 +592,7 @@ def _moab_build_map_args(
576592
fvmethod[method],
577593
]
578594

579-
if method == 'conserve' and (
580-
src_descriptor.regional or dst_descriptor.regional
581-
):
582-
map_args.append('--rrmgrids')
583-
584-
return [intx_args, map_args]
595+
return [args]
585596

586597

587598
def _get_descriptor(info):

0 commit comments

Comments
 (0)