From 1fcfb9e9b5631f4c9d6631eb5f8cfa92f28868ef Mon Sep 17 00:00:00 2001 From: Dmitrii Kochkov Date: Tue, 25 Jun 2024 10:39:45 -0700 Subject: [PATCH] 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. PiperOrigin-RevId: 646529756 --- dinosaur/xarray_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dinosaur/xarray_utils.py b/dinosaur/xarray_utils.py index 98b1f97..2ec2634 100644 --- a/dinosaur/xarray_utils.py +++ b/dinosaur/xarray_utils.py @@ -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. @@ -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`. @@ -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: