-
Notifications
You must be signed in to change notification settings - Fork 94
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
Incorrect net_cdf serialisation for top level attributes #614
Comments
Did some extra digging around. The core of the issue is that the netCDF standard does not really consider attributes as anything more than single values per key (https://cfconventions.org/cf-conventions/cf-conventions.html#_attributes).
I'm playing around with using pre-defined encoders for this, but so far the produced string is too big for Here's an example: import codecs
import pickle
import calliope
model = calliope.examples.national_scale()
attrs_orignial = model._model_data.attrs.copy()
pickled_attrs = codecs.encode(pickle.dumps(attrs_orignial), "base64").decode()
model._model_data.attrs.clear()
model._model_data.attrs["encoded"] = pickled_attrs
unpickled_attrs = pickle.loads(codecs.decode(pickled_attrs.encode(), "base64"))
assert attrs_orignial == unpickled_attrs |
Saving a full calliope model is as easy as: import calliope
import xarray
model = calliope.examples.national_scale()
model._model_data.to_netcdf("outputs/model.zarr")
test = xarray.open_zarr("outputs/model.zarr") In this case, It seems like |
Summary of summary table: zarr is better than netcdf in every way 😄 netcdf storing single list elements as strings is a bit of a pain. We manage all the other formats that need converting before storing in Happy for you to add functionality to convert to |
I agree on keeping netCDF for a while, its too popular. I suspect our current serialisation will be enough once #619 is fixed, but it's a toss. I'll come back to this one afterwards. |
What happened?
When saving models into net_cdf files, our serialization algorithm will convert single list elements at the top level into strings.
Replication steps:
Here,
"applied_math"
will be a string, not a list.Which operating systems have you used?
Version
v0.7
Relevant log output
No response
The text was updated successfully, but these errors were encountered: