pygetm.input package
Subpackages
Submodules
Module contents
- 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.Trueis equivalent toOnGrid.HORIZONTAL.include_halos – whether to also update the halos of the array. If not provided, this default to
Trueif the array has attributes_require_halosor_part_of_state; otherwise it defaults toFalse.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_valuein 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.
- class pygetm.input.LazyArray(shape: Iterable[int], dtype: DTypeLike, name: str)[source]
Bases:
NDArrayOperatorsMixin- 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
- 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
- class pygetm.input.Transpose(a, axes: Iterable[int], **kwargs)[source]
Bases:
UnaryOperator
- class pygetm.input.VerticalInterpolation(source: LazyArray, z: ndarray, izdim: int, source_z: ndarray, axis: int = 0, **kwargs)[source]
Bases:
UnaryOperator
- class pygetm.input.Wrap(source: Variable, name: str)[source]
Bases:
UnaryOperator
- 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
xarrayso 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()andpygetm.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.Datasetopened 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.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]