Skip to content

Commit

Permalink
Added argument serialize_coords_to_attrs to data_to_xarray. This allo…
Browse files Browse the repository at this point in the history
…ws the user to choose whether to save coordinates.asdict() in xarray.Dataset.attrs.

PiperOrigin-RevId: 646529756
  • Loading branch information
kochkov92 authored and Dinosaur authors committed Jun 25, 2024
1 parent 7e9d533 commit 1fcfb9e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dinosaur/xarray_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def data_to_xarray(
sample_ids: typing.Array | None = None,
additional_coords: MutableMapping[str, typing.Array] | None = None,
attrs: Mapping[str, Any] | None = None,
serialize_coords_to_attrs: bool = True,
) -> xarray.Dataset:
"""Returns a sample/time referenced xarray.Dataset of primitive equation data.
Expand All @@ -371,6 +372,7 @@ def data_to_xarray(
sample_ids: xarray coordinates to use for `sample` axis.
additional_coords: additional coordinates to include.
attrs: additional attributes to include in the xarray.Dataset metadata.
serialize_coords_to_attrs: whether to save serialized coords to attrs.
Returns:
xarray.Dataset with containing `data`.
Expand Down Expand Up @@ -429,7 +431,7 @@ def data_to_xarray(
data_vars[key] = (dims, value)
dims_in_state.update(set(dims))

dataset_attrs = coords.asdict()
dataset_attrs = coords.asdict() if serialize_coords_to_attrs else {}
if attrs is not None:
for key in dataset_attrs.keys():
if key in attrs:
Expand Down

0 comments on commit 1fcfb9e

Please sign in to comment.