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.

property all_mask: ndarray

Boolean array indicating invalid data points, including halos

property all_shape: tuple[int, ...]
allgather() → ndarray[source]
as_xarray(mask: bool = False) → DataArray[source]

Return this array wrapped in an xarray.DataArray that includes coordinates and can be used for plotting

attrs: Mapping[str, Any]
compare_halos(group: Neighbor = Neighbor.ALL)[source]
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. False for a 2D array, CENTERS (or True) for an array defined at the layer centers, INTERFACES for an array defined at the layer interfaces. None to detect from fill.

  • 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

property fill_value: float | int | None

Fill value

finish_initialization()[source]

This is called by the underlying cython implementation after the array receives a value (all_values is valid)

gather(out: ndarray | None = None) → ndarray | None[source]
global_mean(reproducible: bool = False, where: Array | None = None) → ndarray | None[source]
global_sum(reproducible: bool = False, where: Array | None = None, to_all: bool = False) → ndarray | None[source]
gradient_x(target: Array | None = None) → Array[source]
gradient_y(target: Array | None = None) → Array[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.

Parameters:

target – either the Array that will hold the interpolated data, or the Grid to interpolate to. If a Grid is provided, a new array will be created to hold the interpolated values.

isel(*, z: int, **kwargs) → Array[source]

Select a single depth level. The data in the returned 2D Array will be a view of the relevant data of the original 3D array. Thus, changes in one will affect the other.

property long_name: str | None

Long name

property ma: MaskedArray

Masked array representation that combines the data and the mask associated with the array’s native grid

property mask: ndarray

Boolean array indicating invalid data points, excluding halos

mirror(target: Array | None = None)[source]
property name: str | None

Name

property ndim: int

Number of dimensions

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()

register()[source]
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.

property saved: bool

Whether the values of this variable are needed for output (or any internal purpose). Set this to True to ensure values for this array are computed.

scatter(global_data: ndarray | None)[source]
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:
set_fabm_standard_name(fabm_standard_name)[source]
property shape: tuple[int, ...]

Shape excluding halos

property size: int

Total number of values, excluding halos

property units: str | None

Units

update_halos(group: Neighbor = Neighbor.ALL)[source]
values
property xarray: DataArray

Return this array wrapped in an xarray.DataArray that includes coordinates and can be used for plotting

property z

False if the array has no vertical dimension, CENTERS for layer centers, INTERFACES for 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)

array(*args, **kwargs) → Array[source]
bottom_indices
close_flux_interfaces()[source]

Mask U and V points that do not have two bordering wet T points

property cor

Coriolis parameter (s-1)

create_array(name: str) → Array | None[source]
default_output_transforms
property dx

cell length in x-direction (m)

property dy

cell length in y-direction (m)

extra_output_coordinates
fields: Mapping[str, 'Array']
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_gather_info(shape: tuple[int, ...], on_boundary: bool, dtype: DTypeLike, fill_value)[source]
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
horizontal_coordinates: list['Array']
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)

infer_water_contact()[source]
input_grid_mappers
input_manager
interpolator(target: Grid) → Callable[[ndarray, ndarray], None][source]
ioffset
joffset
property lat

latitude (degrees_north)

property lon

longitude (degrees_east)

property mask
mask3d
open_boundaries: pygetm.open_boundaries.LocalOpenBoundaryCollection
overlap
postfix
rivers: pygetm.rivers.LocalRiverCollection
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)

class pygetm.core.Rotator(rotation: ArrayLike)[source]

Bases: object

Rotator for velocity fields (geocentric to model-centric and vice versa)

Parameters:

rotation – clockwise rotation of grid relative to true North

class pygetm.core.ZSlice(base: Array, k: int, **kwargs)[source]

Bases: Array

property saved: bool

Whether the values of this variable are needed for output (or any internal purpose). Set this to True to ensure values for this array are computed.