MCPcopy
hub / github.com/pydata/xarray / map_blocks

Method map_blocks

xarray/core/dataarray.py:5668–5774  ·  view source on GitHub ↗

Apply a function to each block of this DataArray. .. warning:: This method is experimental and its signature may change. Parameters ---------- func : callable User-provided function that accepts a DataArray as its first p

(
        self,
        func: Callable[..., T_Xarray],
        args: Sequence[Any] = (),
        kwargs: Mapping[str, Any] | None = None,
        template: DataArray | Dataset | None = None,
    )

Source from the content-addressed store, hash-verified

5666 return unify_chunks(self)[0]
5667
5668 def map_blocks(
5669 self,
5670 func: Callable[..., T_Xarray],
5671 args: Sequence[Any] = (),
5672 kwargs: Mapping[str, Any] | None = None,
5673 template: DataArray | Dataset | None = None,
5674 ) -> T_Xarray:
5675 """
5676 Apply a function to each block of this DataArray.
5677
5678 .. warning::
5679 This method is experimental and its signature may change.
5680
5681 Parameters
5682 ----------
5683 func : callable
5684 User-provided function that accepts a DataArray as its first
5685 parameter. The function will receive a subset or 'block' of this DataArray (see below),
5686 corresponding to one chunk along each chunked dimension. ``func`` will be
5687 executed as ``func(subset_dataarray, *subset_args, **kwargs)``.
5688
5689 This function must return either a single DataArray or a single Dataset.
5690
5691 This function cannot add a new chunked dimension.
5692 args : sequence
5693 Passed to func after unpacking and subsetting any xarray objects by blocks.
5694 xarray objects in args must be aligned with this object, otherwise an error is raised.
5695 kwargs : mapping
5696 Passed verbatim to func after unpacking. xarray objects, if any, will not be
5697 subset to blocks. Passing dask collections in kwargs is not allowed.
5698 template : DataArray or Dataset, optional
5699 xarray object representing the final result after compute is called. If not provided,
5700 the function will be first run on mocked-up data, that looks like this object but
5701 has sizes 0, to determine properties of the returned object such as dtype,
5702 variable names, attributes, new dimensions and new indexes (if any).
5703 ``template`` must be provided if the function changes the size of existing dimensions.
5704 When provided, ``attrs`` on variables in `template` are copied over to the result. Any
5705 ``attrs`` set by ``func`` will be ignored.
5706
5707 Returns
5708 -------
5709 A single DataArray or Dataset with dask backend, reassembled from the outputs of the
5710 function.
5711
5712 Notes
5713 -----
5714 This function is designed for when ``func`` needs to manipulate a whole xarray object
5715 subset to each block. Each block is loaded into memory. In the more common case where
5716 ``func`` can work on numpy arrays, it is recommended to use ``apply_ufunc``.
5717
5718 If none of the variables in this object is backed by dask arrays, calling this function is
5719 equivalent to calling ``func(obj, *args, **kwargs)``.
5720
5721 See Also
5722 --------
5723 :func:`dask.array.map_blocks <dask.array.map_blocks>`
5724 :func:`xarray.apply_ufunc <xarray.apply_ufunc>`
5725 :func:`xarray.Dataset.map_blocks <xarray.Dataset.map_blocks>`

Callers

nothing calls this directly

Calls 1

map_blocksFunction · 0.90

Tested by

no test coverage detected