Skip to content

module grid


class GRID

Class that provides methods to handle and regrid gridded datasets for NEMO.

method __init__

__init__(
    data_filename=None,
    dataset=None,
    ds_lon_name=None,
    ds_lat_name=None,
    ds_z_name=None,
    ds_time_counter="time_counter",
    convert_to_z_grid=False,
    z_kwargs={},
    equation_of_state=None,
)

Initialize the GRID class with the specified dataset and coordinate names.

Args:

  • data_filename (str, optional): Path to the dataset file on the desired grid.
  • dataset (xarray.Dataset, optional): xarray Dataset object
  • ds_lon_name (str, optional): The name of the longitude variable in the dataset. If None, it will be inferred from common names.
  • ds_lat_name (str, optional): The name of the latitude variable in the dataset. If None, it will be inferred from common names.
  • ds_z_name (str, optional): The name of the depth coordinate, assume z.
  • ds_time_counter (str, optional): The name of the time counter variable in the dataset, assume time_counter.
  • convert_to_z_grid (bool, optional): whether to convert from a sigma-level grid to a z-level grid.
  • z_kwargs (dict, optional): additional details required for vertical conversion
  • equation_of_state (str, optional): the equation of state of the data.

method extract_lonlat

extract_lonlat(lon_name=None, lat_name=None)

Extract longitude and latitude data arrays from the dataset.

Args:

  • lon_name (str, optional): The name of the longitude variable. If None, it will be inferred.
  • lat_name (str, optional): The name of the latitude variable. If None, it will be inferred.

Returns:

  • tuple: A tuple containing the longitude DataArray, latitude DataArray, and their respective names.

Raises:

  • Exception: If the specified longitude or latitude variable is not found in the dataset.

method get_dim_varname

get_dim_varname(dimtype)

Retrieve the variable name corresponding to a specified dimension type (longitude or latitude).

Args:

  • dimtype (str): The type of dimension ('longitude' or 'latitude').

Returns:

  • str: The variable name for the specified dimension.

Raises:

  • Exception: If the variable name for the specified dimension is not found in the dataset.

method make_common_coords

make_common_coords(z_name, lon_name, lat_name, time_counter="time_counter")

Align the grid dataset with common coordinate names for regridding.

Args:

  • z_name (str): name of the depth coordinate.
  • lon_name (str): The name of the longitude coordinate.
  • lat_name (str): The name of the latitude coordinate.
  • time_counter (str, optional): The name of the time counter variable. Defaults to "time_counter".

Returns:

  • xarray.Dataset: The dataset with standardized coordinate names and attributes for regridding.

method open_dataset

open_dataset(filename, convert_to_z, z_kwargs)

Open a dataset from a specified filename using xarray.

Args:

  • filename (str): The path to the dataset file.
  • convert_to_z (bool): whether to convert data to a z grid
  • z_kwargs (dict): arguments for vertical conversion

Returns:

  • xarray.Dataset: The opened dataset.

method vertical_convert

vertical_convert(ds_grid, z_kwargs, periodic=False)

Vertical conversion of data using xgcm's built in vertical conversion with their Grid class.

Args:

  • ds_grid (xarray.Dataset): data set on some metric of depth (let's say salinity)
  • z_kwargs (dict): dict containing at least {'variable':str/list of strs,'target':array_like}. Other arguments are as in the xgcm documentation:
  • https: //xgcm.readthedocs.io/en/latest/transform.html?highlight=vertical
  • periodic (bool): passed to xgcm.Grid.

Returns:

  • xarray.Dataset: Vertically regridded data set.

This file was automatically generated via lazydocs.