pygetm.core module
- class pygetm.core.Array(name: str | None = None, units: str | None = None, long_name: str | None = None, fill_value: float | int | None = None, shape: tuple[int, ...] | None = None, dtype: DTypeLike | None = None, grid: Grid = None, fabm_standard_name: str | None = None, attrs: Mapping[str, Any] = {})[source]
Bases:
Array,NDArrayOperatorsMixin- __array__(dtype: DTypeLike | None = None, copy=None) ndarray[source]
Return interior of the array as a NumPy array. No copy will be made unless the requested data type differs from that of the underlying array.
- Parameters:
dtype – data type
- __getitem__(key) ndarray[source]
Retrieve values from the interior of the array (excluding halos). For access to the halos, use
all_values.
- __setitem__(key, values)[source]
Assign values to the interior of the array (excluding halos). For access to the halos, use
all_values.
- as_xarray(mask: bool = False) DataArray[source]
Return this array wrapped in an
xarray.DataArraythat includes coordinates and can be used for plotting
- static create(grid: Grid, fill: ArrayLike | None = None, z: Literal[None, True, False, 1, 2] = None, dtype: DTypeLike = None, on_boundary: bool = False, register: bool = True, **kwargs) Array[source]
Create a new
Array- Parameters:
grid – grid associated with the new array
fill – value to set the new array to
z – vertical dimension of the new array.
Falsefor a 2D array,CENTERS(orTrue) for an array defined at the layer centers,INTERFACESfor an array defined at the layer interfaces.Noneto detect fromfill.dtype – data type
on_boundary – whether to describe data along the open boundaries (1D), instead of the 2D x-y model domain
register – whether to register the array as field available for output
**kwargs – additional keyword arguments passed to
Array
- property dtype: DTypeLike
Data type
- property fabm_standard_name
- fill(value)[source]
Set array to specified value, while respecting the mask: masked points are set to
fill_value
- finish_initialization()[source]
This is called by the underlying cython implementation after the array receives a value (
all_valuesis valid)
- global_sum(reproducible: bool = False, where: Array | None = None, to_all: bool = False) ndarray | None[source]
- halo_updaters: Sequence[BaseHaloUpdater]
- interp(target: Array | Grid, z: Literal[None, True, False, 1, 2] = None) Array[source]
Interpolate the array to another grid.
- isel(*, z: int, **kwargs) Array[source]
Select a single depth level. The data in the returned 2D
Arraywill be a view of the relevant data of the original 3D array. Thus, changes in one will affect the other.
- property ma: MaskedArray
Masked array representation that combines the data and the mask associated with the array’s native grid
- open_boundaries
- plot(mask: bool = True, **kwargs)[source]
Plot the array with
xarray.DataArray.plot()- Parameters:
**kwargs – additional keyword arguments passed to
xarray.DataArray.plot()
- require_set(logger: Logger | None = None)[source]
Assess whether all non-masked cells of this field have been set. If not, an error message is written to the log and False is returned.
- saved
to be set if this variable is requested for output
- set(value: float | ndarray | DataArray, **kwargs)[source]
Link this array to a field or value using
input_manager, which will perform temporal and spatial interpolation as required.- Parameters:
value – value to assign to this array. If it is time-dependent (if you pass an instance of
xarray.DataArraywith a time dimension), the array’s value will be updated during the simulation wheneverpygetm.input.InputManager.update()is called.**kwargs – keyword arguments passed to
pygetm.input.InputManager.add()
- values
- property xarray: DataArray
Return this array wrapped in an
xarray.DataArraythat includes coordinates and can be used for plotting
- property z
Falseif the array has no vertical dimension,CENTERSfor layer centers,INTERFACESfor layer interfaces.- Type:
Vertical dimension
- class pygetm.core.Grid(nx: int, ny: int, nz: int | None = None, *, halox: int = 0, haloy: int = 0, postfix: str = '', ugrid: Grid | None = None, vgrid: Grid | None = None, xgrid: Grid | None = None, ioffset: int = 1, joffset: int = 1, overlap: int = 0, istart: int = 1, jstart: int = 1, fields: Mapping[str, Array] | None = None, tiling: Tiling | None = None)[source]
Bases:
Grid- property D
water depth (m)
- Dclip
- property H
water depth at rest (m)
- property alpha
dampening (1)
- property area
cell area (m2)
- bottom_indices
- property cor
Coriolis parameter (s-1)
- default_output_transforms
- property dx
cell length in x-direction (m)
- property dy
cell length in y-direction (m)
- extra_output_coordinates
- freeze()[source]
Freeze all grid attributes. This will calculate derived metrics such as the inverse of cell height/width/area and initialize elevation and water depth. It subsequently makes most attributes read-only.
- get_mask(values: Iterable[CellType], z: Literal[None, 1, 2] = None) ndarray[source]
Get a Boolean mask that indicates where the cell type differs from the specified values.
- Parameters:
values – cell types that should not be masked
z – if CENTERS or INTERFACES, return a 3D mask for the specified vertical coordinate type
- global_to_local(i: int, j: int, *, include_halos: bool = False) tuple[int | None, int | None][source]
Convert global indices (i, j) to local indices in the subdomain.
- property gradient_x_calculator
- property gradient_y_calculator
- hhalf
- property hn
cell thickness (m)
- ho
- property iarea
inverse of cell area (m-2)
- property idx
inverse of cell length in x-direction (m-1)
- property idy
inverse of cell length in y-direction (m-1)
- input_grid_mappers
- input_manager
- ioffset
- joffset
- property lat
latitude (degrees_north)
- property lon
longitude (degrees_east)
- property mask
- mask3d
- open_boundaries: pygetm.open_boundaries.LocalOpenBoundaryCollection
- overlap
- postfix
- rotate(u: ArrayLike, v: ArrayLike, to_grid: bool = True) tuple[ArrayLike, ArrayLike][source]
Rotate a geocentric velocity field to the model coordinate system, or a model velocity field to the geocentric coordinate system.
- Parameters:
u – velocity in x-direction in source coordinate system (eastward velocity if the source is a geocentric velocity field)
v – velocity in y-direction in source coordinate system (northward velocity if the source is a geocentric velocity field)
to_grid – rotate from geocentric to model coordinate system, not vice versa
- property rotation
grid rotation with respect to true North (rad)
- tiling
- ugrid
- vgrid
- property x
x-coordinate (m)
- xgrid
- property y
y-coordinate (m)
- z
- property z0b
hydrodynamic bottom roughness (m)
- property z0b_min
minimum hydrodynamic bottom roughness (m)
- property zc
height (m)
- property zf
interface height (m)
- zin
- zio
- zo
- class pygetm.core.Locator(mask: ndarray, *, x: ndarray | None = None, y: ndarray | None = None, lon: ndarray | None = None, lat: ndarray | None = None)[source]
Bases:
object- __call__(x: ArrayLike, y: ArrayLike, *, coordinate_type: CoordinateType, valid_cell_types: Iterable[CellType] | None = None) tuple[int, int][source]
Locate the unmasked grid cell nearest to the specified location.
- Parameters:
x – x coordinate of the location
y – y coordinate of the location
coordinate_type – type of coordinates (LONLAT for spherical, XY for Cartesian coordinates)
- Returns:
indices of the nearest unmasked grid cell
- Return type:
(i, j)