xarray.DataArray.from_dict

xarray.DataArray.from_dict#

classmethod DataArray.from_dict(d)[source]#

Convert a dictionary into an xarray.DataArray

Parameters:

d (dict) – Mapping with a minimum structure of {“dims”: […], “data”: […]}

Returns:

obj (xarray.DataArray)

Examples

>>> d = {"dims": "t", "data": [1, 2, 3]}
>>> da = xr.DataArray.from_dict(d)
>>> da
<xarray.DataArray (t: 3)>
array([1, 2, 3])
Dimensions without coordinates: t
>>> d = {
...     "coords": {
...         "t": {"dims": "t", "data": [0, 1, 2], "attrs": {"units": "s"}}
...     },
...     "attrs": {"title": "air temperature"},
...     "dims": "t",
...     "data": [10, 20, 30],
...     "name": "a",
... }
>>> da = xr.DataArray.from_dict(d)
>>> da
<xarray.DataArray 'a' (t: 3)>
array([10, 20, 30])
Coordinates:
  * t        (t) int64 0 1 2
Attributes:
    title:    air temperature