fremor.cmor_tripolar module
fremor: tripolar ocean grid helpers
This module provides functions for setting up and processing tripolar ocean grids
in the CMORization workflow. It is used by cmor_mixer when ocean data is being
processed on a native MOM6 tripolar grid.
Functions
load_tripolar_grid(ds, netcdf_file, prev_path)
Notes
Processing tripolar data requires an ocean statics file that contains the geographic lat/lon coordinates and their cell corner (vertex) equivalents. The function here handles locating that statics file, reading its coordinates, and writing the necessary grid coordinate variables into the working NetCDF dataset.
- fremor.cmor_tripolar.load_tripolar_grid(ds: netCDF4.Dataset, netcdf_file: str, prev_path: str | None = None) dict
Load tripolar ocean grid coordinates from an ocean statics file into the working dataset.
This function locates the appropriate ocean statics file (first attempting the gold-standard archived file, then falling back to the FRE-bronx directory convention), reads geographic lat/lon coordinates for cell centers and corners, and writes
lat,lon,lat_bnds,lon_bnds,yh_bnds, andxh_bndsvariables intodsin-place.- Parameters:
ds (netCDF4.Dataset) – Open (writable) NetCDF4 dataset for the variable being CMORized. This dataset is modified in-place to add the tripolar grid coordinate variables.
netcdf_file (str) – Path to the input NetCDF file being processed. Used to determine where to stage a local copy of the statics file.
prev_path (str, optional) – Path to the previous file (used as a hint for locating the statics file under the legacy FRE-bronx directory convention).
- Raises:
FileNotFoundError – If the ocean statics file cannot be found through any fallback.
ValueError – If the number of h-point coordinates is inconsistent with the number of q-point coordinates (i.e.
hpoint_dim != qpoint_dim - 1).
- Returns:
Dictionary containing the grid coordinate arrays written into
ds:lat: 2-D cell-center latitude variable (netCDF4.Variable).lon: 2-D cell-center longitude variable (netCDF4.Variable).lat_bnds: 2-D cell-corner latitude bounds variable (netCDF4.Variable).lon_bnds: 2-D cell-corner longitude bounds variable (netCDF4.Variable).yh: 1-D projected y-axis coordinate array (numpy.ndarray).xh: 1-D projected x-axis coordinate array (numpy.ndarray, offset by +300).yh_bnds: 1-D y-axis bounds variable (netCDF4.Variable).xh_bnds: 1-D x-axis bounds variable (netCDF4.Variable).
- Return type:
dict