コード例 #1
0
    def get_observation_descriptor(self, fileName):  # {{{
        '''
        get a MeshDescriptor for the observation grid

        Parameters
        ----------
        fileName : str
            observation file name describing the source grid

        Returns
        -------
        obsDescriptor : ``MeshDescriptor``
            The descriptor for the observation grid
        '''
        # Authors
        # -------
        # Xylar Asay-Davis, Luke Van Roekel

        # Load Argo observational Data
        dsObs = self.build_observational_dataset(fileName)

        # create a descriptor of the observation grid using Lat/Lon
        # coordinates
        obsDescriptor = LatLonGridDescriptor.read(ds=dsObs,
                                                  latVarName='latCoord',
                                                  lonVarName='lonCoord')
        dsObs.close()
        return obsDescriptor  # }}}
コード例 #2
0
    def get_latlon_file_descriptor(self):
        latLonGridFileName = str(self.datadir.join('SST_annual_1870-1900.nc'))
        descriptor = LatLonGridDescriptor.read(latLonGridFileName,
                                               latVarName='lat',
                                               lonVarName='lon')

        return (descriptor, latLonGridFileName)
コード例 #3
0
    def get_observation_descriptor(self, fileName):  # {{{
        '''
        get a MeshDescriptor for the observation grid

        Parameters
        ----------
        fileName : str
            observation file name describing the source grid

        Returns
        -------
        obsDescriptor : ``MeshDescriptor``
            The descriptor for the observation grid

        Authors
        -------
        Xylar Asay-Davis
        '''

        # create a descriptor of the observation grid using the lat/lon
        # coordinates
        obsDescriptor = LatLonGridDescriptor.read(fileName=fileName,
                                                  latVarName='lat',
                                                  lonVarName='lon')
        return obsDescriptor  # }}}
コード例 #4
0
    def get_observation_descriptor(self, fileName):  # {{{
        '''
        get a MeshDescriptor for the observation grid

        Parameters
        ----------
        fileName : str
            observation file name describing the source grid

        Returns
        -------
        obsDescriptor : ``MeshDescriptor``
            The descriptor for the observation grid
        '''
        # Authors
        # -------
        # Riley X. Brady, Xylar Asay-Davis

        # create a descriptor of the observation grid using the lat/lon
        # coordinates
        dsObs = self.build_observational_dataset(fileName)
        obsDescriptor = LatLonGridDescriptor.read(ds=dsObs,
                                                  latVarName='lat',
                                                  lonVarName='lon')
        return obsDescriptor  # }}}
コード例 #5
0
    def setup_obs_remapper(self, config, fieldName):
        gridFileName = '{}/obsGrid.nc'.format(self.datadir)

        comparisonDescriptor = \
            get_lat_lon_comparison_descriptor(config)

        obsDescriptor = LatLonGridDescriptor()
        obsDescriptor.read(fileName=gridFileName, latVarName='lat',
                           lonVarName='lon')

        remapper = \
            get_remapper(
                config=config, sourceDescriptor=obsDescriptor,
                comparisonDescriptor=comparisonDescriptor,
                mappingFileSection='oceanObservations',
                mappingFileOption='sstClimatologyMappingFile',
                mappingFilePrefix='map_obs_{}'.format(fieldName),
                method=config.get('oceanObservations',
                                  'interpolationMethod'))

        return remapper
コード例 #6
0
def remap_v(prefix, inGridName, inGridFileName, inDir, inVPrefix):
    cacheVFileName = '{}_merid_vel_{}.nc'.format(prefix, inGridName)

    config = MpasAnalysisConfigParser()
    config.read('mpas_analysis/config.default')

    matGrid = loadmat(inGridFileName)
    # lat/lon is a tensor grid so we can use 1-D arrays
    lon = matGrid['XC'][:, 0]
    lat = matGrid['YG'][0, :]
    z = matGrid['RC'][:, 0]
    cellFraction = matGrid['hFacS']

    botIndices = get_bottom_indices(cellFraction)

    with sose_v_to_nc('{}/{}'.format(inDir, inVPrefix),
                      cacheVFileName, lon, lat, z, cellFraction, botIndices) \
            as dsV:
        inDescriptor = LatLonGridDescriptor()

        inDescriptor = LatLonGridDescriptor.read(cacheVFileName,
                                                 latVarName='lat',
                                                 lonVarName='lon')

        outDescriptor = get_comparison_descriptor(config, 'antarctic')
        outGridName = outDescriptor.meshName

        outVFileName = '{}_merid_vel_{}.nc'.format(prefix, outGridName)

        mappingFileName = '{}/map_V_{}_to_{}.nc'.format(
            inDir, inGridName, outGridName)

        remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

        remapper.build_mapping_file(method='bilinear')

        if not os.path.exists(outVFileName):
            print('Remapping meridional velocity...')
            with remapper.remap(dsV, renormalizationThreshold=0.01) \
                    as remappedV:
                print('Done.')
                remappedV.attrs['history'] = ' '.join(sys.argv)
                write_netcdf(remappedV, outVFileName)
コード例 #7
0
def remap(ds, outDescriptor, mappingFileName, inDir, outFileName):

    tempFileName1 = '{}/temp_transpose.nc'.format(inDir)
    tempFileName2 = '{}/temp_remap.nc'.format(inDir)
    if 'z' in ds:
        print('  transposing and fixing periodicity...')
        ds = ds.chunk({'Time': 4})
        ds = ds.transpose('Time', 'z', 'lat', 'lon')
    ds = add_periodic_lon(ds)
    write_netcdf(ds, tempFileName1)
    ds.close()

    inDescriptor = LatLonGridDescriptor.read(tempFileName1,
                                             latVarName='lat',
                                             lonVarName='lon')

    remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

    remapper.build_mapping_file(method='bilinear')

    remapper.remap_file(inFileName=tempFileName1,
                        outFileName=tempFileName2,
                        overwrite=True,
                        renormalize=0.01)

    ds = xarray.open_dataset(tempFileName2)
    if 'z' in ds:
        print('  transposing back...')
        ds = ds.chunk({'Time': 4})
        ds = ds.transpose('Time', 'x', 'y', 'z', 'nvertices')
    ds.attrs['meshName'] = outDescriptor.meshName

    for coord in ['x', 'y']:
        ds.coords[coord] = xarray.DataArray.from_dict(
            outDescriptor.coords[coord])

    ds = ds.set_coords(names=['month', 'year'])

    write_netcdf(ds, outFileName)
    ds.close()
コード例 #8
0
def remap(inDir, outDir):

    inGridName = 'SouthernOcean_0.25x0.125degree'
    inFileName = '{}/Schmidtko_et_al_2014_bottom_PT_S_PD_{}.nc'.format(
        inDir, inGridName)

    config = MpasAnalysisConfigParser()
    config.read('mpas_analysis/config.default')

    inDescriptor = LatLonGridDescriptor()

    inDescriptor = LatLonGridDescriptor.read(inFileName,
                                             latVarName='lat',
                                             lonVarName='lon')

    outDescriptor = get_comparison_descriptor(config, 'antarctic')
    outGridName = outDescriptor.meshName

    outFileName = '{}/Schmidtko_et_al_2014_bottom_PT_S_PD_{}.nc'.format(
        outDir, outGridName)

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

    remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

    remapper.build_mapping_file(method='bilinear')

    if not os.path.exists(outFileName):
        print('Remapping...')
        with xarray.open_dataset(inFileName) as dsIn:
            with remapper.remap(dsIn, renormalizationThreshold=0.01) \
                    as remappedMLD:
                print('Done.')
                remappedMLD.attrs['history'] = ' '.join(sys.argv)
                write_netcdf(remappedMLD, outFileName)
コード例 #9
0
# Copyright (c) 2018 UT-Battelle, LLC. All rights reserved.
#
# Additional copyright and license information can be found in the LICENSE file
# distributed with this code, or at
# https://raw.githubusercontent.com/MPAS-Dev/MPAS-Analysis/master/LICENSE
import numpy

from mpas_analysis.shared.interpolation import Remapper
from mpas_analysis.shared.grid import LatLonGridDescriptor
from mpas_analysis.shared.constants import constants

inputFileName = '/media/xylar/extra_data/analysis/output/GMPAS-QU240/' \
    'remap_obs/clim/obs/mld_1.0x1.0degree.nc'

obsDescriptor = LatLonGridDescriptor.read(fileName=inputFileName,
                                          latVarName='lat',
                                          lonVarName='lon')

comparisonLatRes = 4.
comparisonLonRes = 4.

nLat = int((constants.latmax - constants.latmin) / comparisonLatRes) + 1
nLon = int((constants.lonmax - constants.lonmin) / comparisonLonRes) + 1
lat = numpy.linspace(constants.latmin, constants.latmax, nLat)
lon = numpy.linspace(constants.lonmin, constants.lonmax, nLon)

comparisonDescriptor = LatLonGridDescriptor.create(lat, lon, units='degrees')

remapper = Remapper(obsDescriptor,
                    comparisonDescriptor,
                    mappingFileName='map.nc')
コード例 #10
0
def remap_pt_s(prefix, inGridName, inGridFileName, inDir, inTPrefix, inSPrefix,
               inGammaNPrefix):
    cacheTFileName = '{}_pot_temp_{}.nc'.format(prefix, inGridName)
    cacheSFileName = '{}_salinity_{}.nc'.format(prefix, inGridName)
    cacheGammaNFileName = '{}_neut_den_{}.nc'.format(prefix, inGridName)

    config = MpasAnalysisConfigParser()
    config.read('mpas_analysis/config.default')

    matGrid = loadmat(inGridFileName)
    # lat/lon is a tensor grid so we can use 1-D arrays
    lon = matGrid['XC'][:, 0]
    lat = matGrid['YC'][0, :]
    z = matGrid['RC'][:, 0]
    cellFraction = matGrid['hFacC']

    botIndices = get_bottom_indices(cellFraction)

    with sose_pt_to_nc('{}/{}'.format(inDir, inTPrefix),
                       cacheTFileName, lon, lat, z, cellFraction, botIndices) \
            as dsT:
        inDescriptor = LatLonGridDescriptor()

        inDescriptor = LatLonGridDescriptor.read(cacheTFileName,
                                                 latVarName='lat',
                                                 lonVarName='lon')

        outDescriptor = get_comparison_descriptor(config, 'antarctic')
        outGridName = outDescriptor.meshName

        outTFileName = '{}_pot_temp_{}.nc'.format(prefix, outGridName)
        outSFileName = '{}_salinity_{}.nc'.format(prefix, outGridName)
        outGammaNFileName = '{}_neut_den_{}.nc'.format(prefix, outGridName)

        mappingFileName = '{}/map_C_{}_to_{}.nc'.format(
            inDir, inGridName, outGridName)

        remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

        remapper.build_mapping_file(method='bilinear')

        if not os.path.exists(outTFileName):
            dsT.reset_coords(names='zBot', inplace=True)
            print('Remapping potential temperature...')
            with remapper.remap(dsT, renormalizationThreshold=0.01) \
                    as remappedT:
                print('Done.')
                remappedT.attrs['history'] = ' '.join(sys.argv)
                remappedT.set_coords(names='zBot', inplace=True)
                write_netcdf(remappedT, outTFileName)

    with sose_s_to_nc('{}/{}'.format(inDir, inSPrefix),
                      cacheSFileName, lon, lat, z, cellFraction, botIndices) \
            as dsS:
        if not os.path.exists(outSFileName):
            dsS.reset_coords(names='zBot', inplace=True)
            print('Remapping salinity...')
            with remapper.remap(dsS, renormalizationThreshold=0.01) \
                    as remappedS:
                print('Done.')
                remappedS.attrs['history'] = ' '.join(sys.argv)
                remappedS.set_coords(names='zBot', inplace=True)
                write_netcdf(remappedS, outSFileName)

    with sose_gammaN_to_nc('{}/{}'.format(inDir, inGammaNPrefix),
                           cacheGammaNFileName, lon, lat, z, cellFraction,
                           botIndices) \
            as dsGammaN:
        if not os.path.exists(outGammaNFileName):
            dsGammaN.reset_coords(names='zBot', inplace=True)
            print('Remapping neutral density...')
            with remapper.remap(dsGammaN, renormalizationThreshold=0.01) \
                    as remappedGammaN:
                print('Done.')
                remappedGammaN.attrs['history'] = ' '.join(sys.argv)
                remappedGammaN.set_coords(names='zBot', inplace=True)
                write_netcdf(remappedGammaN, outGammaNFileName)
コード例 #11
0
                                      'attrs': {'units': 'm'}}},
                 'data_vars': {'salinity':
                               {'dims': ('Time', 'lat', 'lon', 'depth'),
                                'data': field,
                                'attrs': {'units': 'PSU',
                                          'description': description}},
                               'botSalinity':
                               {'dims': ('Time', 'lat', 'lon'),
                                'data': botField,
                                'attrs': {'units': 'PSU',
                                          'description': botDescription}}}}

    dsS = xarray.Dataset.from_dict(dictonary)
    dsS.to_netcdf(cacheSFileName)

inDescriptor = LatLonGridDescriptor.read(cacheTFileName,  latVarName='lat',
                                         lonVarName='lon')

outDescriptor = get_antarctic_stereographic_comparison_descriptor(config)
outGridName = outDescriptor.meshName

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

remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

remapper.build_mapping_file(method='bilinear')

remappedT = remapper.remap(dsT, renormalizationThreshold=0.01)

remappedT.attrs['history'] = ' '.join(sys.argv)
remappedT.to_netcdf(outTFileName)