i7aof.remap

Remapping utilities and CMIP workflows. See i7aof.remap for developer details.

i7aof.remap.add_periodic_lon(ds, threshold=1e-10, lon_var='lon', periodic_dim=None)

Add a periodic longitude to a dataset if the longitude range is not approximately 360 degrees. This is typically needed for bilinear remapping to prevent there from being a seam between the first and last longitude values.

Parameters:
  • ds (xarray.Dataset) – The dataset containing the longitude variable.

  • threshold (float, optional) – The threshold to determine if the longitude range is approximately 360 degrees. Default is 1e-10.

  • lon_var (str, optional) – The name of the longitude variable in the dataset. Default is ‘lon’.

  • periodic_dim (str, optional) – The name of the dimension along which to add periodicity. For 1D longitude, periodic_dim is found automatically and this parameter is ignored. For 2D longitude, the default is the same as lon_var.

Returns:

The dataset with periodic longitude added if necessary.

Return type:

xarray.Dataset

i7aof.remap.remap_lat_lon_to_ismip(in_filename, in_grid_name, out_filename, map_dir, method, config, logger, lon_var='lon', lat_var='lat', renormalize=None)

Remap a dataset on a lat-lon grid to the ISMIP grid, creating a mapping file if one does not already exist. Latitude and longitude can be 1D or 2D arrays.

Parameters:
  • in_filename (str) – The input dataset filename.

  • in_grid_name (str) – The name of the input grid.

  • out_filename (str) – The output dataset filename.

  • map_dir (str) – The directory where the mapping file will be stored.

  • method ({'bilinear', 'neareststod', 'conserve'}) – The remapping method to use.

  • config (mpas_tools.config.MpasConfigParser) – Configuration object with remapping parameters.

  • logger (logging.Logger) – Logger object for logging messages.

  • lon_var (str, optional) – The name of the longitude variable in the input dataset (default is ‘lon’).

  • lat_var (str, optional) – The name of the latitude variable in the input dataset (default is ‘lat’).

  • renormalize (float, optional) – If provided, a threshold to use to renormalize the data

i7aof.remap.remap_projection_to_ismip(in_filename, in_grid_name, out_filename, map_dir, method, config, logger, in_proj4='epsg:3031', renormalize=None)

Remap a dataset to the ISMIP grid, creating a mapping file if one does not already exist.

Parameters:
  • in_filename (str) – The input dataset filename.

  • in_grid_name (str) – The name of the input grid.

  • out_filename (str) – The output dataset filename.

  • map_dir (str) – The directory where the mapping file will be stored.

  • method ({'bilinear', 'neareststod', 'conserve'}) – The remapping method to use.

  • config (mpas_tools.config.MpasConfigParser) – Configuration object with remapping parameters.

  • logger (logging.Logger) – Logger object for logging messages.

  • in_proj4 (str, optional) – The projection string for the input projection (default is ‘epsg:3031’). This can be any string that pyproj.Proj accepts.

  • renormalize (float, optional) – If provided, a threshold to use to renormalize the data

i7aof.remap.cmip.main()
i7aof.remap.cmip.remap_cmip(model, scenario, workdir=None, user_config_filename=None)

Remap pre-converted CMIP ct/sa to the ISMIP grid in two stages:

  1. vertical interpolation to ISMIP ‘z_extrap’ levels, then

  2. horizontal remapping to the ISMIP lat/lon grid.

Prerequisite - Run the conversion step first so inputs contain variables ‘ct’ and

‘sa’ on the native grid. Use either:
  • Python: i7aof.convert.cmip.convert_cmip

  • CLI: ismip7-antarctic-convert-cmip

Then run the remap CLI: ismip7-antarctic-remap-cmip.

This function orchestrates the basic flow per input file: - Prepare output dirs and ensure the ISMIP grid exists. - For each monthly file:

  • Vertical pipeline (see _vert_mask_interp_norm): mask invalid source points -> interpolate in z -> normalize.

  • Horizontal remap of the vertically processed data to ISMIP grid.

Parameters:
  • model (str) – Name of the CMIP model to remap

  • scenario (str) – The name of the scenario (‘historical’, ‘ssp585’, etc.)

  • workdir (str, optional) – The base work directory within which the remapped files will be placed

  • user_config_filename (str, optional) – The path to a file with user config options that override the defaults

i7aof.remap.clim.main()
i7aof.remap.clim.remap_climatology(clim_name, inputdir=None, workdir=None, user_config_filename=None, overwrite=False)

Remap an observational climatology data to the ISMIP grid with two stages:

  1. vertical interpolation to ISMIP z_extrap levels, then

  2. horizontal remapping to the ISMIP lat/lon grid.

This function orchestrates the basic flow per input file:

  • Prepare output dirs and ensure the ISMIP grid exists.

  • For each monthly file:

    • Vertical pipeline (see _vert_mask_interp_norm): mask invalid source points -> interpolate in z -> normalize.

    • Horizontal remap of the vertically processed data to ISMIP grid.

Parameters:
  • clim_name (str) – The name of the climatology to remap

  • inputdir (str, optional) – The base input directory where the CMIP monthly input files are located

  • workdir (str, optional) – The base work directory within which the remapped files will be placed

  • user_config_filename (str, optional) – The path to a file with user config options that override the defaults

  • overwrite (bool, optional) – Whether to overwrite the output file if it exists