Convert a dictionary into an xarray.Dataset. Parameters ---------- d : dict-like Mapping with a minimum structure of ``{"var_0": {"dims": [..], "data": [..]}, \ ...}`` Returns ------- obj : Data
(cls, d: Mapping[Any, Any])
| 7623 | |
| 7624 | @classmethod |
| 7625 | def from_dict(cls, d: Mapping[Any, Any]) -> Self: |
| 7626 | """Convert a dictionary into an xarray.Dataset. |
| 7627 | |
| 7628 | Parameters |
| 7629 | ---------- |
| 7630 | d : dict-like |
| 7631 | Mapping with a minimum structure of |
| 7632 | ``{"var_0": {"dims": [..], "data": [..]}, \ |
| 7633 | ...}`` |
| 7634 | |
| 7635 | Returns |
| 7636 | ------- |
| 7637 | obj : Dataset |
| 7638 | |
| 7639 | See Also |
| 7640 | -------- |
| 7641 | Dataset.to_dict |
| 7642 | DataArray.from_dict |
| 7643 | |
| 7644 | Examples |
| 7645 | -------- |
| 7646 | >>> d = { |
| 7647 | ... "t": {"dims": ("t"), "data": [0, 1, 2]}, |
| 7648 | ... "a": {"dims": ("t"), "data": ["a", "b", "c"]}, |
| 7649 | ... "b": {"dims": ("t"), "data": [10, 20, 30]}, |
| 7650 | ... } |
| 7651 | >>> ds = xr.Dataset.from_dict(d) |
| 7652 | >>> ds |
| 7653 | <xarray.Dataset> Size: 60B |
| 7654 | Dimensions: (t: 3) |
| 7655 | Coordinates: |
| 7656 | * t (t) int64 24B 0 1 2 |
| 7657 | Data variables: |
| 7658 | a (t) <U1 12B 'a' 'b' 'c' |
| 7659 | b (t) int64 24B 10 20 30 |
| 7660 | |
| 7661 | >>> d = { |
| 7662 | ... "coords": { |
| 7663 | ... "t": {"dims": "t", "data": [0, 1, 2], "attrs": {"units": "s"}} |
| 7664 | ... }, |
| 7665 | ... "attrs": {"title": "air temperature"}, |
| 7666 | ... "dims": "t", |
| 7667 | ... "data_vars": { |
| 7668 | ... "a": {"dims": "t", "data": [10, 20, 30]}, |
| 7669 | ... "b": {"dims": "t", "data": ["a", "b", "c"]}, |
| 7670 | ... }, |
| 7671 | ... } |
| 7672 | >>> ds = xr.Dataset.from_dict(d) |
| 7673 | >>> ds |
| 7674 | <xarray.Dataset> Size: 60B |
| 7675 | Dimensions: (t: 3) |
| 7676 | Coordinates: |
| 7677 | * t (t) int64 24B 0 1 2 |
| 7678 | Data variables: |
| 7679 | a (t) int64 24B 10 20 30 |
| 7680 | b (t) <U1 12B 'a' 'b' 'c' |
| 7681 | Attributes: |
| 7682 | title: air temperature |