xcompare.mom module#

mom.py - module for bringing MOM output into CF compliance

xcompare.mom.area_fields_from_static(dset, area='areacello')#

Function to find cell area fields from static file

This function extracts cell area fields whose names contain a specified string.

The CF standard_name attribute cell_area is added to the fields.

Parameters:
  • dset (xarray.core.dataset.Dataset) – Dataset containing time-invariant (static) grid coordinates

  • area (str) – Naming convention for cell area, by default ‘areacello’

Returns:

Dataset containing cell area fields

Return type:

xarray.core.dataset.Dataset

xcompare.mom.map_coords_to_vars(dset, dset_coords, reset_index_coords=True)#

Function to assign multi-dimensional coords to variables

This function iterates over variables in a dataset and adds coordinate variables contained in a separate dataset. Matching is performed based on like dimensions.

Parameters:
  • dset (xarray.core.dataset.Dataset) – Input dataset

  • dset_coords (xarray.core.dataset.Dataset) – Dataset containing coordinates

  • reset_index_coords (bool, optional) – Reset index coordinates with integer values, by default True

Returns:

Similar to input dataset with added coordinates

Return type:

xarray.core.dataset.Dataset

xcompare.mom.refine_cf_fields(dset, dset_static, include_area=True, reset_index_coords=True)#

Function to refine/fix CF attributes for MOM ocean data

This function combines an xarray dataset containing MOM ocean output with a dataset containing static information.

The multi-dimensional coordinates (geolon,geolat) are combined with each variable and the appropriate cell area fields are included in the resulting dataset.

Parameters:
  • dset (xarray.core.dataset.Dataset) – Input dataset

  • dset_static (xarray.core.dataset.Dataset) – Dataset containing static grid information

  • include_area (bool, optional) – Include cell areas in resulting dataset, by default True

  • reset_index_coords (bool, optional) – Reset index coordinates (e.g. xh/yh) to integer values, by default True

Returns:

Corrected CF-compliant dataset

Return type:

xarray.core.dataset.Dataset

xcompare.mom.xy_coords_from_static(dset, xcoord='geolon', ycoord='geolat', reset_index_coords=True)#

Function to extract x-y multi-dimensional coordinates from ocean static file

This function identifies coordinate variables whose names contain specified strings and returns them in a stand-alone dataset

Exising index coordinates are reset to integer values but this behavior can be turned off.

Parameters:
  • dset (xarray.core.dataset.Dataset) – Dataset containing time-invariant (static) grid coordinates

  • xcoord (str, optional) – Naming convention for x-coordinate, by default ‘geolon’

  • ycoord (str, optional) – Naming convention for y-coordinate, by default ‘geolat’

  • reset_index_coords (bool, optional) – Reset index coordinates with integer values, by default True

Returns:

Dataset containing coordinate variables

Return type:

xarray.core.dataset.Dataset