pygetm.input package

Subpackages

Submodules

Module contents

class pygetm.input.Cache(source: LazyArray, idim: int, n: int)[source]

Bases: UnaryOperator

class pygetm.input.Concatenate(arrays, axis: int = 0, **kwargs)[source]

Bases: Operator

class pygetm.input.GETMAccessor(xarray_obj: DataArray)[source]

Bases: object

property coordinates: Mapping[str, DataArray][source]
property latitude: DataArray | None
property longitude: DataArray | None
property time: DataArray | None
property z: DataArray | None
class pygetm.input.HorizontalInterpolation(ip: Linear2DGridInterpolator, source: LazyArray, shape: Iterable[int], npre: int, npost: int, **kwargs)[source]

Bases: UnaryOperator

class pygetm.input.InputManager(logger: Logger)[source]

Bases: object

add(array: Array, value: Number | ndarray | DataArray | LazyArray, periodic_lon: bool = True, on_grid: bool | OnGrid = False, include_halos: bool | None = None, climatology: bool = False, mask: bool = False, updater_collection: list | None = None)[source]

Link an array to the provided input. If this input is constant in time, the value of the array will be set immediately.

Parameters:
  • array – array to assign a value to

  • value – input to assign. If this is time-dependent, the combination of the array and its linked input will be registered; the array will then be updated to the current time whenever update() is called.

  • periodic_lon – whether this input covers all longitudes (i.e., the entire globe in the horizontal) and therefore has a periodic boundary. This enables efficient spatial interpolation across longitude bounds of the input, for instance, accessing 10 degrees West to 5 degrees East for an input that spans 0 to 360 degrees East.

  • on_grid – whether the input is defined on the same grid (horizontal-only, or both horizontal and vertical) as the array that is being assigned to. If this is False, the value will be spatially interpolated to the array grid. True is equivalent to OnGrid.HORIZONTAL.

  • include_halos – whether to also update the halos of the array. If not provided, this default to True if the array has attributes _require_halos or _part_of_state; otherwise it defaults to False.

  • climatology – whether the input describes a single climatological year (at any temporal resolution, e.g., monthly, daily) that is representative for any true year. This argument is relevant only if the provided input is time-varying. It also requires that the input does not span more than one year.

  • mask – whether to set the array to its pygetm.core.Array.fill_value in all masked points. If not provided, only missing values in the input (NaNs) will be set to the fill value. This currently only has an effect when the input is non time-varying.

debug_nc_reads()[source]

Hook into xarray so that every read from a NetCDF file is written to the log.

update(time: datetime, macro: bool = True, fields: list | None = None)[source]

Update all arrays linked to time-dependent inputs to the current time.

Parameters:
  • time – current time

  • macro – whether to also update arrays that were marked as only relevant for the macro (3D) time step

class pygetm.input.LazyArray(shape: Iterable[int], dtype: DTypeLike, name: str)[source]

Bases: NDArrayOperatorsMixin

astype(dtype, **kwargs) ndarray[source]
is_time_varying() bool[source]
property size: int
update(time: datetime, numtime: longdouble) bool[source]
class pygetm.input.OnGrid(*values)[source]

Bases: Enum

ALL = 3

Horizontal and vertical grids match

HORIZONTAL = 2

Horizontal grid matches, but vertical does not. Vertically resolved data will require vertical interpolation.

NONE = 1

Grids do not match. Spatially explicit data will require horizontal and - if vertically resolved - vertical interpolation.

class pygetm.input.Operator(*args, passthrough=(), dtype: DTypeLike = None, shape: tuple[int] | None = None, name: str | None = None, kwslice: Iterable[str] = (), **kwargs)[source]

Bases: LazyArray

apply(*args: ndarray, dtype=None, **kwargs) ndarray[source]
is_time_varying() bool[source]
update(*args) bool[source]
class pygetm.input.Slice(source, shape: tuple[int], passthrough)[source]

Bases: UnaryOperator

class pygetm.input.TemporalInterpolation(source: ~pygetm.input.LazyArray, itimedim: int, times: ArrayLike, climatology: bool, dtype: DTypeLike = <class 'float'>, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, logger: ~logging.Logger | None = None, **kwargs)[source]

Bases: UnaryOperator

MAX_CACHE_SIZE = 0
NTIME_CACHE = 1
climatology
is_time_varying() bool[source]
update(time: datetime, numtime: longdouble | None = None) bool[source]
class pygetm.input.Transpose(a, axes: Iterable[int], **kwargs)[source]

Bases: UnaryOperator

class pygetm.input.UFunc(ufunc, method: str, *args, **kwargs)[source]

Bases: Operator

apply(*args: ndarray, **kwargs) ndarray[source]
class pygetm.input.UnaryOperator(arg, **kwargs)[source]

Bases: Operator

class pygetm.input.VerticalInterpolation(source: LazyArray, z: ndarray, izdim: int, source_z: ndarray, axis: int = 0, **kwargs)[source]

Bases: UnaryOperator

apply(source: ndarray, dtype=None) ndarray[source]
class pygetm.input.Wrap(source: Variable, name: str)[source]

Bases: UnaryOperator

apply(source: ndarray, dtype=None) ndarray[source]
update(*args) bool[source]
pygetm.input.concatenate_slices(source: DataArray, idim: int, slices: Iterable[slice], verbose=False) DataArray[source]
pygetm.input.debug_nc_reads(logger: Logger | None = None)[source]

Hook into xarray so that every read from a NetCDF file is written to the log.

pygetm.input.from_nc(paths: str | PathLike[str] | Iterable[str | PathLike[str]], name: str, preprocess: Callable[[Dataset], Dataset] | None = None, **kwargs) DataArray[source]

Obtain a variable from one or more NetCDF files that can be used as value provided to InputManager.add() and pygetm.core.Array.set().

Parameters:
  • paths – single file path, a pathname pattern containing * and/or ?, or a sequence of file paths. If multiple paths are provided (or the pattern resolves to multiple valid path names), the files will be concatenated along their time dimension.

  • preprocess – function that transforms the xarray.Dataset opened for every path provided. This can be used to modify the datasets before concatenation in time is attempted, for instance, to cut off time indices that overlap between files.

  • **kwargs – additional keyword arguments to be passed to xarray.open_dataset()

pygetm.input.horizontal_interpolation(source: DataArray, x: DataArray, y: DataArray, *, mask: ArrayLike | None = None, xp: str | DataArray | None = None, yp: str | DataArray | None = None) DataArray[source]

Two-dimensional linear interpolation

For target coordinates that fall into cells with one or more masked corners, nearest-neighbor interpolation is used to find the nearest unmasked point.

Parameters:
  • source – source variable

  • x – x-coordinates at which to evaluate the interpolated values

  • y – y-coordinates at which to evaluate the interpolated values

  • mask – mask for the source variable. If None, all points of the source variable are assumed to be valid.

  • xp – x-coordinates of the source variable. If None, the longitudes of the source variable are used.

  • yp – y-coordinates of the source variable. If None, the latitudes of the source variable are used.

pygetm.input.isel(source: DataArray, **indices) DataArray[source]

Index named dimensions with integers, slice objects or integer arrays

pygetm.input.limit_region(source: DataArray, minlon: float, maxlon: float, minlat: float, maxlat: float, periodic_lon: bool = False, verbose: bool = False, require_2d: bool = True) DataArray[source]
pygetm.input.slicespec2string(s: tuple | slice | int) str[source]
pygetm.input.temporal_interpolation(source: ~xarray.core.dataarray.DataArray, climatology: bool = False, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, logger: ~logging.Logger | None = None) DataArray[source]
pygetm.input.transpose(source: DataArray, axes: Iterable[int] | None = None) DataArray[source]
pygetm.input.vertical_interpolation(source: DataArray, target_z: ArrayLike, itargetdim: int = 0) DataArray[source]
pygetm.input.wrap(array: DataArray, name: str | None = None) DataArray[source]