Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added argument serialize_coords_to_attrs to data_to_xarray. This allows the user to choose whether to save coordinates.asdict() in xarray.Dataset.attrs. #42

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading