-
Notifications
You must be signed in to change notification settings - Fork 49
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
Keep xarray attributes and dtype after regridding #66
Comments
Thanks for bringing this up. PRs are welcome!
The only reason is that regridder(indata) # doesn't keep attributes
regridder(indata, keep_attrs=True) # keeps attributes Regarding the data type, that's because ESMF stores regridding weights in import numpy as np
import xarray as xr
a = np.array([1, 2, 3], dtype=np.float64)
x = np.array([1, 2, 3], dtype=np.float32)
out = a * x
out.dtype # float64
out2 = xr.apply_ufunc(lambda x: a * x, x, output_dtypes=[np.float32])
out2.dtype # still float64 You can cast |
Is it useful to have a method to set weights dtype in the def set_dtype(self, dtype)
self.weights = self.weights.astype(dtype) |
I created a pull request to implement keep_attrs. |
Regrid xarray by matching dimension names
Currently, the regridding seems to delete the attributes of the original dataset. I assume the happens during
xr.apply_ufunc
. Is there any reason not usekeep_attrs=True
?Similarly, all data is converted to 64 bit floats, even if the input data is 32 bit. Would it be reasonable to use
output_dtypes=[dr_in.dtype]
instead ofoutput_dtypes=[float]
?I am happy to create a pull request of this if nothing speaks against these changes.
The text was updated successfully, but these errors were encountered: