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

unable to retrive Dataset with converted units #109

Closed
raybellwaves opened this issue Jun 1, 2021 · 4 comments
Closed

unable to retrive Dataset with converted units #109

raybellwaves opened this issue Jun 1, 2021 · 4 comments

Comments

@raybellwaves
Copy link
Member

raybellwaves commented Jun 1, 2021

This is a strange and i'm not sure if I can make a MCVE. I'll try later.

The tutorial equations works fine so must be something else i'm doing

VAR = "air"
OUNIT = "degC"

ds = xr.tutorial.open_dataset("air_temperature")
ds["lat"].attrs["units"] = "degree"
ds["lon"].attrs["units"] = "degree"

ds = ds.pint.quantify({VAR: ds[VAR].attrs["units"]})
ds = ds.pint.to({VAR: OUNIT})
ds = ds.pint.dequantify(format="~P")

ds[VAR].isel(time=0).plot()

ds.to_netcdf("/tmp/tmp.nc")
ds = xr.open_dataset("/tmp/tmp.nc")

ds[VAR].isel(time=0).plot()

I'm trying to save a Dataset where I can converted the units.

I'm unable to see the converted units after loading straight after saving.

The code is something like the example above but with a few extra ETL steps.

Screen Shot 2021-05-31 at 11 56 28 PM

@raybellwaves
Copy link
Member Author

Closing as seems to be ok with pickle. It's a temp store anyway.

pickle.dump(ds, open("/tmp/ds.pkl", "wb"), protocol=-1)
ds = pickle.load(open("/tmp/ds.pkl", "rb"))

@raybellwaves
Copy link
Member Author

@keewis
Copy link
Collaborator

keewis commented Jun 1, 2021

does that mean your code works if you clear .encoding before saving?

@raybellwaves
Copy link
Member Author

does that mean your code works if you clear .encoding before saving?

Correct that was my work around

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants