cmomy.wrap_reduce_vals

cmomy.wrap_reduce_vals#

cmomy.wrap_reduce_vals(x, *y, mom, axis=MISSING, dim=MISSING, weight=None, mom_dims=None, mom_axes=None, mom_params=None, out=None, dtype=None, casting='same_kind', order=None, parallel=None, axes_to_end=False, keep_attrs=None, apply_ufunc_kwargs=None)[source]#

Create wrapped object from values.

Overloads:
  • x (DataT), y (ArrayLike | xr.DataArray | DataT), weight (ArrayLike | xr.DataArray | DataT | None), out (NDArrayAny | None), dtype (DTypeLike), kwargs (Unpack[ReduceValsKwargs]) → CentralMomentsData[DataT]

  • x (ArrayLikeArg[FloatT]), y (ArrayLike), weight (ArrayLike | None), out (None), dtype (None), kwargs (Unpack[ReduceValsKwargs]) → CentralMomentsArray[FloatT]

  • x (ArrayLike), y (ArrayLike), weight (ArrayLike | None), out (NDArray[FloatT]), dtype (DTypeLike), kwargs (Unpack[ReduceValsKwargs]) → CentralMomentsArray[FloatT]

  • x (ArrayLike), y (ArrayLike), weight (ArrayLike | None), out (None), dtype (DTypeLikeArg[FloatT]), kwargs (Unpack[ReduceValsKwargs]) → CentralMomentsArray[FloatT]

  • x (ArrayLike), y (ArrayLike), weight (ArrayLike | None), out (NDArrayAny | None), dtype (DTypeLike), kwargs (Unpack[ReduceValsKwargs]) → CentralMomentsArrayAny

  • x (ArrayLike | DataT), y (ArrayLike | xr.DataArray | DataT), weight (ArrayLike | xr.DataArray | DataT | None), out (NDArrayAny | None), dtype (DTypeLike), kwargs (Unpack[ReduceValsKwargs]) → CentralMomentsArrayAny | CentralMomentsData[DataT]

Parameters:
  • x (Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str], TypeVar(DataT, DataArray, Dataset, xr.DataArray | xr.Dataset)]) – Values to reduce.

  • *y (Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str], DataArray, TypeVar(DataT, DataArray, Dataset, xr.DataArray | xr.Dataset)]) – Additional values (needed if len(mom)==2). y has same type restrictions and broadcasting rules as weight.

  • mom (int | tuple[int] | tuple[int, int]) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variables

  • weight (Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str], DataArray, TypeVar(DataT, DataArray, Dataset, xr.DataArray | xr.Dataset), None], default: None) –

    Optional weight. The type of weight must be “less than” the type of x.

    In the case that weight is array-like, it must broadcast to x using usual broadcasting rules (see numpy.broadcast_to()), with the following exceptions: If weight is a 1d array of length x.shape[axis]], it will be formatted to broadcast along the other dimensions of x. For example, if x has shape (10, 2, 3) and weight has shape (10,), then weight will be converted to the broadcastable shape (10, 1, 1). If weight is a scalar, it will be broadcast to x.shape.

  • axis (Union[complex, None, Literal[MISSING]], default: MISSING) – Axis to reduce/sample along.

  • dim (Union[DimsReduce, Literal[MISSING]], default: MISSING) – Dimension to reduce/sample along.

  • mom_dims (Optional[MomDims], default: None) – Name of moment dimensions. Defaults to ("mom_0",) for mom_ndim==1 and (mom_0, mom_1) for mom_ndim==2

  • mom_axes (Optional[MomAxes], default: None) – Location of the moment dimensions. Default to (-mom_ndim, -mom_ndim+1, ...). If specified and mom_ndim is None, set mom_ndim to len(mom_axes). Note that if mom_axes is specified, negative values are relative to the end of the array. This is also the case for axes if mom_axes is specified.

  • mom_params (Union[MomParams, MomParamsBase, MomParamsDict, None], default: None) – Moment parameters. You can set moment parameters axes and dims using this option. For example, passing mom_params={"dim": ("a", "b")} is equivalent to passing mom_dims=("a", "b"). You can also pass as a MomParams object with mom_params=cmomy.MomParams(dims=("a", "b")).

  • out (ndarray[tuple[Any, ...], dtype[Any]] | None, default: None) – Optional output array. If specified, output will be a reference to this array. Note that if the output if method returns a Dataset, then this option is ignored.

  • dtype (Union[type[Any], dtype[Any], _SupportsDType[dtype[Any]], tuple[Any, Any], list[Any], _DTypeDict, str, None], default: None) – Optional dtype for output data.

  • casting (Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'], default: 'same_kind') –

    Controls what kind of data casting may occur.

    • ’no’ means the data types should not be cast at all.

    • ’equiv’ means only byte-order changes are allowed.

    • ’safe’ means only casts which can preserve values are allowed.

    • ’same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.

    • ’unsafe’ (default) means any data conversions may be done.

  • order (Optional[Literal['C', 'F']], default: None) – Order argument. See numpy.asarray().

  • parallel (bool | None, default: None) – If True, use parallel numba numba.njit or numba.guvectorized code if possible. If None, use a heuristic to determine if should attempt to use parallel method.

  • keep_attrs (KeepAttrs, default: None) –

    • ‘drop’ or False: empty attrs on returned xarray object.

    • ’identical’: all attrs must be the same on every object.

    • ’no_conflicts’: attrs from all objects are combined, any that have the same name must also have the same value.

    • ’drop_conflicts’: attrs from all objects are combined, any that have the same name but different values are dropped.

    • ’override’ or True: skip comparing and copy attrs from the first object to the result.

  • apply_ufunc_kwargs (Mapping[str, Any] | None, default: None) – Extra parameters to xarray.apply_ufunc(). One useful option is on_missing_core_dim, which can take the value "copy" (the default), "raise", or "drop" and controls what to do with variables of a Dataset missing core dimensions. Other options are join, dataset_join, dataset_fill_value, and dask_gufunc_kwargs. Unlisted options are handled internally.

Returns:

wrapped (CentralMomentsArray or CentralMomentsData) – Wrapped object. If input data is an xarray object, then return CentralMomentsData instance. Otherwise, return CentralMomentsArray instance.

See also

reduce_vals, wrap

Examples

>>> import cmomy
>>> rng = cmomy.default_rng(0)
>>> x = rng.random((100, 3))
>>> da = cmomy.wrap_reduce_vals(x, axis=0, mom=2)
>>> da
<CentralMomentsArray(mom_ndim=1)>
array([[1.0000e+02, 5.5313e-01, 8.8593e-02],
       [1.0000e+02, 5.5355e-01, 7.1942e-02],
       [1.0000e+02, 5.1413e-01, 1.0407e-01]])