Utility Functions¶
Internal use utility functions.
Xarray Utilities¶
- rwguide.xarray.common.get_names(dct, *names)¶
Standard variable names or an override name if provided.
Use to support user-supplied variable name overrides in xarray wrappers.
- Parameters:
dct (Dict | None) – Variable name overrides, mapping variable shorthands to returned names.
names (str) – Shorthands of the variables to process.
- Returns:
Variables names.
- Return type:
Tuple[str, …]
- rwguide.xarray.common.require_lon(da, lon_coord, axis=-1)¶
Blow meridional profiles up to full lat-lon fields
Added in version 1.2.
- rwguide.xarray.common.standard_name(identifier)¶
Standard name corresponding to a variable shorthand of rwguide.
C Bindings with CFFI¶
- rwguide.bindings.as_pointer(arr)¶
Return a CFFI-compatible double pointer to the array.
- rwguide.bindings.empty(*shape, dtype=<class 'numpy.float64'>, order='C')¶
Wraps numpy.empty with default settings.
- rwguide.bindings.require(arr, dtype=<class 'numpy.float64'>, order='C', shape=None, fold=False)¶
Enforce a specification of shape and type for a given array.
- Parameters:
arr (array-like) – The input array.
dtype (data type, optional) – The required data-type. If None preserve the current dtype.
order ("C" | "F") – Ensure a C- or Fortran-contiguous array is returned.
shape (tuple, optional) – The desired output shape. Use None to mark a dimension of unknown size and integer to specify a dimension of known size (these will be enforced/verified). If the input array has fewer dimensions than specified in shape it is padded with size-1 dimensions from both sides until a compatible shape is found. If no compatible shape can be found, an exception is thrown.
fold (boolean, optional) – When folding is enabled and the input array as more dimensions than specified in shape, additional dimensions of the array are flattened into the first dimension.
- Returns:
out (numpy.array) – The output array matching the specification.
out_shape (tuple) – The shape of the output array.
orig_shape (tuple) – The shape of the input array.
- Raises:
ValueError – The specification cannot be enforced.