pylag.regrid.regridder module

Regridder objects can be used to regrid input data.

Note

regridder is implemented in Cython. Only a small portion of the API is exposed in Python with accompanying documentation.

class pylag.regrid.regridder.Regridder(config, lons, lats, depths, datetime_start, datetime_end)

Bases: object

A Regridder object

An object of type Regridder can be used to interpolate data onto a new given grid. Regridder’s leverage PyLag’s interpolation routines to facilitate the task.

Parameters
  • config (configparser.ConfigParser) – PyLag configuration object

  • lons (1D ND Array) – 1D array of longitudes to interpolate data to in deg. E.

  • lats (1D ND Array) – 1D array of latitudes to interpolate data to in deg. N.

  • depths (1D NDArray) – 1D array of depths to interpolate data to.

  • datetime_start (datetime.datetime) – The earliest date and time at which regridded data is desired. Requested here as PyLag will first check that the given date and time is covered by the input data.

  • datetime_end (datetime.datetime) – The latest date and time at which regridded data is desired. Requested here as PyLag will first check that the given date and time is covered by the input data.

Variables
  • config (configparser.ConfigParser) – PyLag configuration object.

  • datetime_start (datetime.datetime) – The earliest date and time at which regridded data is desired. Requested here as PyLag will first check that the given date and time is covered by the input data.

  • datetime_end (datetime.datetime) – The latest date and time at which regridded data is desired. Requested here as PyLag will first check that the given date and time is covered by the input data.

  • data_reader (pylag.data_reader.DataReader) – A PyLag DataReader object.

  • depths (1D Memory View) – Depth coordinates to interpolate to.

  • lats (1D Memory View) – Latitude coordinates to interpolate to.

  • lons (1D Memory View) – Longitude coordinates to interpolate to.

get_grid_names(self)

Return a list of grid names

interpolate(self, datetime_now, var_names)

Return values for the given variables at the specified time point

Parameters
  • time (datetime.datetime) – The date/time at which the interpolation should be performed.

  • var_names (list[str]) – List of variable names that for which interpolated data is required. Names should correspond to PyLag standard names (see pylag.variable_library.standard_variable_names for the full list.

Returns

interpolated_vars – Dictionary giving the interpolated data.

Return type

dict(str : 1D NumPy array)

set_spatial_coordinates(self, lons, lats, depths)

Set coordinates to interpolate to

Internally, a PyLag particle set is created with one particle located at each of the specified coordinates. Interpolation coefficients are set at the same time. Some of these may be time dependent (e.g. vertical coordinates, which may vary with changes in free surface elevation. Thus, when interpolating data at different time points, these should be reset as required. This is achieved by passing the time/date to the function that performs the interpolation.

Parameters
  • lons (1D NumPy array) – 1D array of longitudes to interpolate data to.

  • lats (1D NumPy array) – 1D array of latitudes to interpolate data to.

  • depths (1D NumPy array) – 1D array of depths to interpolate data to. Depths should be negative down relative to the sea surface.