mom6_bathy.grid module
- class mom6_bathy.grid.Grid(lenx: float, leny: float, nx: int = None, ny: int = None, resolution: float | None = None, xstart: float = 0.0, ystart: float | None = None, cyclic_x: bool = False, tripolar_n: bool = False, displace_pole: bool = False, name: str | None = None)
Bases:
objectHorizontal MOM6 grid. The first step of constructing a MOM6 grid within the CESM simpler models framework is to create a Grid instance.
- tlon
array of t-grid longitudes
- Type:
xr.DataArray
- tlat
array of t-grid latitudes
- Type:
xr.DataArray
- ulon
array of u-grid longitudes
- Type:
xr.DataArray
- ulat
array of u-grid latitudes
- Type:
xr.DataArray
- vlon
array of v-grid longitudes
- Type:
xr.DataArray
- vlat
array of v-grid latitudes
- Type:
xr.DataArray
- qlon
array of corner longitudes
- Type:
xr.DataArray
- qlat
array of corner latitudes
- Type:
xr.DataArray
- dxt
x-distance between U points, centered at t
- Type:
xr.DataArray
- dyt
y-distance between V points, centered at t
- Type:
xr.DataArray
- dxCv
x-distance between q points, centered at v
- Type:
xr.DataArray
- dyCu
y-distance between q points, centered at u
- Type:
xr.DataArray
- dxCu
x-distance between y points, centered at u
- Type:
xr.DataArray
- dyCv
y-distance between t points, centered at v
- Type:
xr.DataArray
- angle
angle grid makes with latitude line
- Type:
xr.DataArray
- angle_q
angle q-grid makes with latitude line
- Type:
xr.DataArray
- tarea
T-cell area
- Type:
xr.DataArray
Grid instance constructor.
- Parameters:
lenx (float) – grid length in x direction, e.g., 360.0 (degrees)
leny (float) – grid length in y direction, e.g., 160.0 (degrees)
nx (int, optional) – Number of grid points in x direction
ny (int, optional) – Number of grid points in y direction
resolution (float, optional) – grid resolution in degrees. If provided, the grid dimensions are computed based on the resolution: nx = int(lenx / resolution) and ny = int(leny / resolution)
xstart (float, optional) – starting x coordinate. 0.0 by default.
ystart (float, optional) – starting y coordinate. -0.5*leny by default.
cyclic_x (bool, optional) – flag to make the grid cyclic in x direction. False by default.
tripolar_n (bool, optional) – flag to make the grid tripolar. False by default.
displace_pole (bool, optional) – flag to make the grid displaced polar. False by default.
name (str, optional) – name of the grid. None by default.
- static check_supergrid(supergrid: Dataset) None
Check if a given supergrid contains the necessary attributes and has consistent units.
- Parameters:
supergrid (xarray.Dataset) – MOM6 Supergrid dataset
- classmethod from_supergrid(path: str, name: str | None = None) Grid
Create a Grid instance from a supergrid file.
- Parameters:
path (str) – Path to the supergrid file to be written
name (str, optional) – Name of the new grid. If provided, it will be used as the name of the grid. If not provided, the name will be derived from the file name.
- Returns:
The Grid instance created from the supergrid file.
- Return type:
- classmethod from_supergrid_ds(ds: Dataset, name: str | None = None) Grid
Create a Grid instance from a supergrid file.
- Parameters:
ds (xr.Dataset) – xarray Dataset of the supergrid file to be written
name (str, optional) – Name of the new grid. If provided, it will be used as the name of the grid.
- Returns:
The Grid instance created from the supergrid file.
- Return type:
- gen_supergrid_ds(author: str | None = None) Dataset
Generate supergrid to a xarray Dataset file. The supergrid file is to be read in by MOM6 during runtime.
- Parameters:
author (str, optional) – Name of the author. If provided, the name will appear in files as metadata.
- classmethod get_bounding_boxes_of_rectangular_grid()
Extract lat/lon bounding boxes for each edge of a rectangular regional MOM6 grid. This function is used when subsetting global datasets (e.g. GLORYS) down to the lat/lon ranges required for efficient regridding:
north, south, east, west boundaries
Entire domain initial condition files
- Parameters:
hgrid (Grid or xarray.Dataset in the supergrid format)
- Returns:
- A dictionary containing bounding boxes for:
”east”
”west”
”north”
”south”
”ic” (full domain for initial conditions)
- Return type:
dict
- get_indices(tlat: float, tlon: float) tuple[int, int]
Get the i, j indices of a given tlat and tlon pair.
- Parameters:
tlat (float) – The latitude value.
tlon (float) – The longitude value.
- Returns:
The j, i indices of the given tlat and tlon pair.
- Return type:
Tuple[int, int]
- static is_cyclic_x(supergrid) bool
Check if a given supergrid x coordinate array is cyclic along the x-axis.
- Parameters:
supergrid (xr.DataArray or np.array or MidasSupergrid) – Supergrid to check for cyclic x.
- is_rectangular(rtol=0.001) bool
Check if the grid is a rectangular lat-lon grid by comparing the first and last rows and columns of the tlon and tlat arrays.
- static is_tripolar(supergrid) bool
Check if the given supergrid x coordinates form a tripolar grid.
- Parameters:
supergrid (xr.DataArray or np.array or MidasSupergrid) – Supergrid to check if tripolar.
- property kdtree: cKDTree
KDTree for fast nearest neighbor search.
- property name: str
Name of the grid.
- property nx
Number of cells in x-direction.
- property ny
Number of cells in y-direction.
- plot(property_name)
Plot a given grid property using cartopy. Warning: cartopy module must be installed seperately
- Parameters:
property_name (str) – The name of the grid property to plot, e.g., ‘tlat’.
- plot_cross_section(property_name, iy=None, ix=None)
Plot the cross-section of a given grid metric.
- Parameters:
property_name (str) – The name of the grid property to plot, e.g., ‘tlat’.
iy (int) – y-index of the cross section
ix (int) – x-inted of the cross section
- classmethod subgrid_from_supergrid(path: str, llc: tuple[float, float], urc: tuple[float, float], name: str) Grid
Create a Grid instance from a subset of a supergrid file.
- Parameters:
path (str) – Path to the full supergrid file to be carved out.
llc (tuple[float, float]) – Lower left corner coordinates (lat, lon) of the subdomain to extract
urc (tuple[float, float]) – Upper right corner coordinates (lat, lon) of the subset to extract
name (str) – Name of the subgrid
- Returns:
The Grid instance created from the supergrid file.
- Return type:
- property supergrid: supergrid
MOM6 supergrid contains the grid metrics and the areas at twice the nominal resolution (by default) of the actual computational grid.
- update_supergrid(xdat: array, ydat: array) None
Update the supergrid x and y coordinates. Running this method also updates the nominal grid coordinates and metrics.
- Parameters:
xdat (np.array) – 2-dimensional array of the new x coordinates.
ydat (np.array) – 2-dimensional array of the new y coordinates.
- write_supergrid(path: str | None = None, author: str | None = None) None
Write supergrid to a netcdf file. The supergrid file is to be read in by MOM6 during runtime.
- Parameters:
path (str, optional) – Path to the supergrid file to be written.
author (str, optional) – Name of the author. If provided, the name will appear in files as metadata.