xarray.Dataset.from_dict

xarray.Dataset.from_dict#

classmethod Dataset.from_dict(d)[source]#

Convert a dictionary into an xarray.Dataset.

Parameters:

d (dict-like) –

Mapping with a minimum structure of

{"var_0": {"dims": [..], "data": [..]},                             ...}

Returns:

obj (Dataset)

Examples

>>> d = {
...     "t": {"dims": ("t"), "data": [0, 1, 2]},
...     "a": {"dims": ("t"), "data": ["a", "b", "c"]},
...     "b": {"dims": ("t"), "data": [10, 20, 30]},
... }
>>> ds = xr.Dataset.from_dict(d)
>>> ds
<xarray.Dataset> Size: 60B
Dimensions:  (t: 3)
Coordinates:
  * t        (t) int64 24B 0 1 2
Data variables:
    a        (t) <U1 12B 'a' 'b' 'c'
    b        (t) int64 24B 10 20 30
>>> d = {
...     "coords": {
...         "t": {"dims": "t", "data": [0, 1, 2], "attrs": {"units": "s"}}
...     },
...     "attrs": {"title": "air temperature"},
...     "dims": "t",
...     "data_vars": {
...         "a": {"dims": "t", "data": [10, 20, 30]},
...         "b": {"dims": "t", "data": ["a", "b", "c"]},
...     },
... }
>>> ds = xr.Dataset.from_dict(d)
>>> ds
<xarray.Dataset> Size: 60B
Dimensions:  (t: 3)
Coordinates:
  * t        (t) int64 24B 0 1 2
Data variables:
    a        (t) int64 24B 10 20 30
    b        (t) <U1 12B 'a' 'b' 'c'
Attributes:
    title:    air temperature