Skip to content

Commit

Permalink
Allow user specified temp directory during remap
Browse files Browse the repository at this point in the history
This should solve some problems on compute nodes.

Also, switch to the more up-to-date tempfile approach by making
a temp directory.
  • Loading branch information
xylar committed Mar 10, 2020
1 parent 65ae240 commit a270dda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyremap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

from pyremap.polar import get_polar_descriptor_from_file, get_polar_descriptor

__version_info__ = (0, 0, 4)
__version_info__ = (0, 0, 5)
__version__ = '.'.join(str(vi) for vi in __version_info__)
26 changes: 19 additions & 7 deletions pyremap/remapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Xylar Asay-Davis

import subprocess
import tempfile
from backports.tempfile import TemporaryDirectory
import os
from distutils.spawn import find_executable
import numpy
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self, sourceDescriptor, destinationDescriptor,
# }}}

def build_mapping_file(self, method='bilinear', additionalArgs=None,
logger=None, mpiTasks=1): # {{{
logger=None, mpiTasks=1, tempdir=None): # {{{
'''
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 @@ -121,6 +121,12 @@ def build_mapping_file(self, method='bilinear', additionalArgs=None,
The number of MPI tasks (a number > 1 implies that
ESMF_RegridWeightGen will be called with ``mpirun``)
tempdir: str, optional
A temporary directory. By default, a temporary directory is
created, typically in ``/tmp`` but on some systems such as compute
nodes this may not be visible to all processors in the subsequent
``ESMF_RegridWeightGen`` call
Raises
------
OSError
Expand Down Expand Up @@ -156,8 +162,15 @@ def build_mapping_file(self, method='bilinear', additionalArgs=None,
'channel.')

# Write source and destination SCRIP files in temporary locations
self.sourceDescriptor.to_scrip(_get_temp_path())
self.destinationDescriptor.to_scrip(_get_temp_path())
if tempdir is None:
tempobj = TemporaryDirectory()
tempdir = tempobj.name
else:
tempobj = None

self.sourceDescriptor.to_scrip('{}/src_mesh.nc'.format(tempdir))
self.destinationDescriptor.to_scrip(
'{}/dst_mesh.nc'.format(tempdir))

args = [rwgPath,
'--source', self.sourceDescriptor.scripFileName,
Expand Down Expand Up @@ -214,9 +227,8 @@ def build_mapping_file(self, method='bilinear', additionalArgs=None,
raise subprocess.CalledProcessError(process.returncode,
' '.join(args))

# remove the temporary SCRIP files
os.remove(self.sourceDescriptor.scripFileName)
os.remove(self.destinationDescriptor.scripFileName)
if tempobj is not None:
tempobj.cleanup()

# }}}

Expand Down

0 comments on commit a270dda

Please sign in to comment.