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 x/y polar # stereographic coordinates projection = get_antarctic_stereographic_projection() obsDescriptor = ProjectionGridDescriptor.read(projection, fileName=fileName, xVarName='x', yVarName='y') return obsDescriptor # }}}
def get_stereographic_array_descriptor(self): # projection for BEDMAP2 and other common Antarctic data sets 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') # a square 61x61 cell map with 100 km resolution and xMax = 3000e3 res = 100e3 nx = 2 * int(xMax / res) + 1 x = numpy.linspace(-xMax, xMax, nx) meshName = '{}km_Antarctic_stereo'.format(int(res * 1e-3)) descriptor = ProjectionGridDescriptor.create(projection, x, x, meshName) return descriptor
def _get_arctic_stereographic_comparison_descriptor(config): # {{{ """ Get a descriptor of an Arctic stereographic comparison grid, used for remapping and determining the grid name Parameters ---------- config : instance of ``MpasAnalysisConfigParser`` Contains configuration options Returns ------- descriptor : ``ProjectionGridDescriptor`` object A descriptor of the Arctic comparison grid """ # Authors # ------- # Milena Veneziani climSection = 'climatology' comparisonStereoWidth = config.getfloat(climSection, 'comparisonArcticStereoWidth') comparisonStereoResolution = config.getfloat( climSection, 'comparisonArcticStereoResolution') projection = get_arctic_stereographic_projection() xMax = 0.5 * comparisonStereoWidth * 1e3 nx = int(comparisonStereoWidth / comparisonStereoResolution) + 1 x = numpy.linspace(-xMax, xMax, nx) meshName = '{}x{}km_{}km_Arctic_stereo'.format(comparisonStereoWidth, comparisonStereoWidth, comparisonStereoResolution) descriptor = ProjectionGridDescriptor.create(projection, x, x, meshName) return descriptor # }}}
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) # }}}
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 y = dsIn.y.values dx = int((x[1] - x[0]) / 1000.) Lx = int((x[-1] - x[0]) / 1000.) Ly = int((y[-1] - y[0]) / 1000.) inMeshName = '{}x{}km_{}km_Antarctic_stereo'.format(Lx, Ly, dx) projection = get_antarctic_stereographic_projection() inDescriptor = ProjectionGridDescriptor.create(projection, x, y, inMeshName) outRes = args.resolution * 1e3 nxOut = int((x[-1] - x[0]) / outRes + 0.5) + 1 nyOut = int((y[-1] - y[0]) / outRes + 0.5) + 1 xOut = x[0] + outRes * numpy.arange(nxOut) yOut = y[0] + outRes * numpy.arange(nyOut) outMeshName = '{}x{}km_{}km_Antarctic_stereo'.format(Lx, Ly, args.resolution) outDescriptor = ProjectionGridDescriptor.create(projection, xOut, yOut, outMeshName) mappingFileName = 'map_{}_to_{}_{}.nc'.format(inMeshName, outMeshName,