def _setup_remappers(self):  # {{{
        """
        Set up the remappers for remapping from the MPAS to the comparison
        grids.
        """
        # Authors
        # -------
        # Xylar Asay-Davis

        config = self.config

        # make reamppers
        mappingFilePrefix = 'map'
        self.remappers = {}
        for comparisonGridName in self.comparisonDescriptors:

            comparisonDescriptor = \
                self.comparisonDescriptors[comparisonGridName]
            self.comparisonGridName = comparisonDescriptor.meshName
            mpasDescriptor = MpasMeshDescriptor(self.restartFileName,
                                                meshName=config.get(
                                                    'input', 'mpasMeshName'))
            self.mpasMeshName = mpasDescriptor.meshName

            self.remappers[comparisonGridName] = get_remapper(
                config=config,
                sourceDescriptor=mpasDescriptor,
                comparisonDescriptor=comparisonDescriptor,
                mappingFilePrefix=mappingFilePrefix,
                method=config.get('climatology', 'mpasInterpolationMethod'),
                logger=self.logger)
def make_analysis_polar_map(config, mesh_name, projection):
    # {{{
    mesh_filename = '../mesh.nc'

    upperProj = projection[0].upper() + projection[1:]

    inDescriptor = MpasMeshDescriptor(mesh_filename, mesh_name)

    comparisonStereoWidth = config.getfloat(
        'mapping_analysis', 'comparison{}StereoWidth'.format(upperProj))
    comparisonStereoResolution = config.getfloat(
        'mapping_analysis', 'comparison{}StereoResolution'.format(upperProj))

    outDescriptor = get_polar_descriptor(Lx=comparisonStereoWidth,
                                         Ly=comparisonStereoWidth,
                                         dx=comparisonStereoResolution,
                                         dy=comparisonStereoResolution,
                                         projection=projection)

    outGridName = '{}x{}km_{}km_{}_stereo'.format(comparisonStereoWidth,
                                                  comparisonStereoWidth,
                                                  comparisonStereoResolution,
                                                  upperProj)

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

    remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

    mpiTasks = config.getint('main', 'nprocs')
    remapper.build_mapping_file(method='bilinear',
                                mpiTasks=mpiTasks,
                                tempdir='.')
    def setup_mpas_remapper(self, config):
        mpasMeshFileName = '{}/mpasMesh.nc'.format(self.datadir)

        comparisonDescriptor = \
            get_comparison_descriptor(config, comparisonGridName='latlon')

        mpasDescriptor = MpasMeshDescriptor(
            mpasMeshFileName, meshName=config.get('input', 'mpasMeshName'))

        remapper = get_remapper(
            config=config, sourceDescriptor=mpasDescriptor,
            comparisonDescriptor=comparisonDescriptor,
            mappingFilePrefix='map', method=config.get(
                'climatology', 'mpasInterpolationMethod'))

        return remapper
Exemplo n.º 4
0
def _make_analysis_lat_lon_map(config, mesh_name, cores, logger):
    mesh_filename = 'restart.nc'

    inDescriptor = MpasMeshDescriptor(mesh_filename, mesh_name)

    comparisonLatResolution = config.getfloat('files_for_e3sm',
                                              'comparisonLatResolution')
    comparisonLonResolution = config.getfloat('files_for_e3sm',
                                              'comparisonLonResolution')

    # modify the resolution of the global lat-lon grid as desired
    outDescriptor = get_lat_lon_descriptor(dLon=comparisonLatResolution,
                                           dLat=comparisonLonResolution)
    outGridName = outDescriptor.meshName

    _make_mapping_file(mesh_name, outGridName, inDescriptor, outDescriptor,
                       cores, config, logger)
Exemplo n.º 5
0
def make_analysis_lat_lon_map(config, mesh_name):
    # {{{
    mesh_filename = '../mesh.nc'

    inDescriptor = MpasMeshDescriptor(mesh_filename, mesh_name)

    comparisonLatResolution = config.getfloat('mapping_analysis',
                                              'comparisonLatResolution')
    comparisonLonResolution = config.getfloat('mapping_analysis',
                                              'comparisonLonResolution')

    # modify the resolution of the global lat-lon grid as desired
    outDescriptor = get_lat_lon_descriptor(dLon=comparisonLatResolution,
                                           dLat=comparisonLonResolution)
    outGridName = outDescriptor.meshName

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

    remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

    mpiTasks = config.getint('main', 'nprocs')
    remapper.build_mapping_file(method='bilinear', mpiTasks=mpiTasks,
                                tempdir='.')
Exemplo n.º 6
0
def _make_analysis_polar_map(config, mesh_name, projection, cores, logger):
    mesh_filename = 'restart.nc'

    upperProj = projection[0].upper() + projection[1:]

    inDescriptor = MpasMeshDescriptor(mesh_filename, mesh_name)

    comparisonStereoWidth = config.getfloat(
        'files_for_e3sm', 'comparison{}StereoWidth'.format(upperProj))
    comparisonStereoResolution = config.getfloat(
        'files_for_e3sm', 'comparison{}StereoResolution'.format(upperProj))

    outDescriptor = get_polar_descriptor(Lx=comparisonStereoWidth,
                                         Ly=comparisonStereoWidth,
                                         dx=comparisonStereoResolution,
                                         dy=comparisonStereoResolution,
                                         projection=projection)

    outGridName = '{}x{}km_{}km_{}_stereo'.format(
        comparisonStereoWidth,  comparisonStereoWidth,
        comparisonStereoResolution, upperProj)

    _make_mapping_file(mesh_name, outGridName, inDescriptor, outDescriptor,
                       cores, config, logger)
def remap_rignot(inFileName,
                 meshFileName,
                 meshName,
                 outFileName,
                 mappingDirectory='.',
                 method='conserve',
                 renormalizationThreshold=None,
                 inVarName='melt_actual',
                 mpiTasks=1):
    # {{{
    """
    Remap the Rignot et al. (2013) melt rates at 1 km resolution to an MPAS
    mesh

    Parameters
    ----------
    inFileName : str
        The original Rignot et al. (2013) melt rates

    meshFileName : str
        The MPAS mesh

    meshName : str
        The name of the mesh (e.g. oEC60to30wISC), used in the name of the
        mapping file

    outFileName : str
        The melt rates interpolated to the MPAS mesh with ocean sensible heat
        fluxes added on (assuming insulating ice)

    mappingDirectory : str
        The directory where the mapping file should be stored (if it is to be
        computed) or where it already exists (if not)

    method : {'bilinear', 'neareststod', 'conserve'}, optional
        The method of interpolation used, see documentation for
        `ESMF_RegridWeightGen` for details.

    renormalizationThreshold : float, optional
        The minimum weight of a denstination cell after remapping, below
        which it is masked out, or ``None`` for no renormalization and
        masking.

    inVarName : {'melt_actual', 'melt_steadystate'}
        Whether to use the melt rate for the time period covered in Rignot et
        al. (2013) with observed thinning/thickening or the melt rates that
        would be required if ice shelves were in steady state.

    mpiTasks : int, optional
        The number of MPI tasks to use to compute the mapping file
    """

    ds = xr.open_dataset(inFileName)
    lx = np.abs(1e-3 * (ds.xaxis.values[-1] - ds.xaxis.values[0]))
    ly = np.abs(1e-3 * (ds.yaxis.values[-1] - ds.yaxis.values[0]))

    inGridName = '{}x{}km_1.0km_Antarctic_stereo'.format(lx, ly)

    projection = pyproj.Proj('+proj=stere +lat_ts=-71.0 +lat_0=-90 +lon_0=0.0 '
                             '+k_0=1.0 +x_0=0.0 +y_0=0.0 +ellps=WGS84')

    inDescriptor = ProjectionGridDescriptor.read(projection,
                                                 inFileName,
                                                 xVarName='xaxis',
                                                 yVarName='yaxis',
                                                 meshName=inGridName)

    # convert to the units and variable names expected in MPAS-O
    rho_fw = 1000.
    s_per_yr = 365. * 24. * 60. * 60.
    latent_heat_of_fusion = 3.337e5
    ds['prescribedLandIceFreshwaterFlux'] = ds[inVarName] * rho_fw / s_per_yr
    ds['prescribedLandIceHeatFlux'] = (latent_heat_of_fusion *
                                       ds['prescribedLandIceFreshwaterFlux'])
    ds = ds.drop_vars(['melt_actual', 'melt_steadystate', 'lon', 'lat'])

    outDescriptor = MpasMeshDescriptor(meshFileName, meshName)

    mappingFileName = '{}/map_{}_to_{}.nc'.format(mappingDirectory, inGridName,
                                                  meshName)

    remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

    remapper.build_mapping_file(method=method, mpiTasks=mpiTasks)

    dsRemap = remapper.remap(ds,
                             renormalizationThreshold=renormalizationThreshold)

    for field in [
            'prescribedLandIceFreshwaterFlux', 'prescribedLandIceHeatFlux'
    ]:
        # zero out the field where it's currently NaN
        dsRemap[field] = dsRemap[field].where(dsRemap[field].nonnull(), 0.)

    dsRemap.attrs['history'] = ' '.join(sys.argv)
    write_netcdf(dsRemap, outFileName)  # }}}
Exemplo n.º 8
0
    def get_mpas_descriptor(self):
        mpasMeshFileName = str(self.datadir.join('mpasMesh.nc'))
        timeSeriesFileName = str(self.datadir.join('timeSeries.0002-01-01.nc'))
        descriptor = MpasMeshDescriptor(mpasMeshFileName, meshName='oQU240')

        return (descriptor, mpasMeshFileName, timeSeriesFileName)
resolution.
'''

import xarray

from pyremap import MpasMeshDescriptor, Remapper, get_polar_descriptor

# replace with the MPAS mesh name
inGridName = 'oQU240'

# replace with the path to the desired mesh or restart file
# As an example, use:
# https://web.lcrc.anl.gov/public/e3sm/inputdata/ocn/mpas-o/oQU240/ocean.QU.240km.151209.nc
inGridFileName = 'ocean.QU.240km.151209.nc'

inDescriptor = MpasMeshDescriptor(inGridFileName, inGridName)

# modify the size and resolution of the Antarctic grid as desired
outDescriptor = get_polar_descriptor(Lx=6000.,
                                     Ly=6000.,
                                     dx=10.,
                                     dy=10.,
                                     projection='antarctic')
outGridName = outDescriptor.meshName

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

remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

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