Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports building mapping files with multiple MPI tasks #3

Merged
merged 3 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions examples/make_mpas_to_Antarctic_stereo_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
projection='antarctic')
outGridName = outDescriptor.meshName

mappingFileName = 'map_{}_to_{}.nc'.format(inGridName, outGridName)
mappingFileName = 'map_{}_to_{}_conserve.nc'.format(inGridName, outGridName)

remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

remapper.build_mapping_file(method='bilinear')
# conservative remapping with 4 MPI tasks (using mpirun)
remapper.build_mapping_file(method='conserve', mpiTasks=4)

outFileName = 'temp_{}.nc'.format(outGridName)
ds = xarray.open_dataset(inGridFileName)
Expand Down
2 changes: 1 addition & 1 deletion examples/make_mpas_to_lat_lon_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
outDescriptor = get_lat_lon_descriptor(dLon=0.5, dLat=0.5)
outGridName = outDescriptor.meshName

mappingFileName = 'map_{}_to_{}.nc'.format(inGridName, outGridName)
mappingFileName = 'map_{}_to_{}_bilinear.nc'.format(inGridName, outGridName)


remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)
Expand Down
12 changes: 10 additions & 2 deletions examples/remap_stereographic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
help="Output file name")
parser.add_argument('-r', dest='resolution', required=True, type=float,
help="Output resolution")
parser.add_argument('-m', dest='method', required=False, default="bilinear",
help="Method: {'bilinear', 'neareststod', 'conserve'}")
parser.add_argument('-t', dest='mpiTasks', required=False, type=int, default=1,
help="Number of MPI tasks (default = 1)")
args = parser.parse_args()


if args.method not in ['bilinear', 'neareststod', 'conserve']:
raise ValueError('Unexpected method {}'.format(args.method))

dsIn = xarray.open_dataset(args.inFileName)

x = dsIn.x.values
Expand Down Expand Up @@ -56,11 +63,12 @@
outDescriptor = ProjectionGridDescriptor.create(projection, xOut, yOut,
outMeshName)

mappingFileName = 'map_{}_to_{}.nc'.format(inMeshName, outMeshName)
mappingFileName = 'map_{}_to_{}_{}.nc'.format(inMeshName, outMeshName,
args.method)

remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

remapper.build_mapping_file(method='bilinear')
remapper.build_mapping_file(method=args.method, mpiTasks=args.mpiTasks)

dsOut = remapper.remap(dsIn, renormalizationThreshold=0.01)
dsOut.to_netcdf(args.outFileName)
Binary file removed pyremap/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/descriptor.cpython-36.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/descriptor.cpython-37.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/grid.cpython-36.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/interp1d.cpython-36.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/polar.cpython-36.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/polar.cpython-37.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/remapper.cpython-36.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/remapper.cpython-37.pyc
Binary file not shown.
Binary file removed pyremap/__pycache__/res.cpython-36.pyc
Binary file not shown.
17 changes: 13 additions & 4 deletions pyremap/remapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def __init__(self, sourceDescriptor, destinationDescriptor,

# }}}

def build_mapping_file(self, method='bilinear',
additionalArgs=None, logger=None): # {{{
def build_mapping_file(self, method='bilinear', additionalArgs=None,
logger=None, mpiTasks=1): # {{{
'''
Given a source file defining either an MPAS mesh or a lat-lon grid and
a destination file or set of arrays defining a lat-lon grid, constructs
Expand All @@ -117,6 +117,10 @@ def build_mapping_file(self, method='bilinear',
logger : ``logging.Logger``, optional
A logger to which ncclimo output should be redirected

mpiTasks : int, optional
The number of MPI tasks (a number > 1 implies that
ESMF_RegridWeightGen will be called with ``mpirun``)

Raises
------
OSError
Expand All @@ -141,7 +145,9 @@ def build_mapping_file(self, method='bilinear',
# a valid weight file already exists, so nothing to do
return

if find_executable('ESMF_RegridWeightGen') is None:
rwgPath = find_executable('ESMF_RegridWeightGen')

if rwgPath is None:
raise OSError('ESMF_RegridWeightGen not found. Make sure esmf '
'package is installed via\n'
'latest nco: \n'
Expand All @@ -153,14 +159,17 @@ def build_mapping_file(self, method='bilinear',
self.sourceDescriptor.to_scrip(_get_temp_path())
self.destinationDescriptor.to_scrip(_get_temp_path())

args = ['ESMF_RegridWeightGen',
args = [rwgPath,
'--source', self.sourceDescriptor.scripFileName,
'--destination', self.destinationDescriptor.scripFileName,
'--weight', self.mappingFileName,
'--method', method,
'--netcdf4',
'--no_log']

if mpiTasks > 1:
args = ['mpirun', '-np', '{}'.format(mpiTasks)] + args

if self.sourceDescriptor.regional:
args.append('--src_regional')

Expand Down
Binary file removed pyremap/test/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file not shown.