rioxarray.open_rasterio and xr.open_dataset have different defaults for the mask_and_scale kwarg
#867
Replies: 1 comment
-
|
It is inconsistent, yet it is consistent.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This can be confusing when using one or the other. Is there a particular reason for the different default?
Also, even when a DataArray does not have
add_offsetnorscale_factorattributes set in theirencoding(removed explicitly from the attrs), it seems an automaticscale_factorof1.0andadd_offsetof0.0are generated (not sure if it is upon writing nor reading?) that, if applied, will likely convert the data to floats, which is unwanted, for instance if working withuint8, I do not want it to be converted tofloat32. So even ifmask_and_scalewhere enabled, the absence of such attributes should make themask_and_scalea noop and preserve the dtype.Note: I actually prefers the
rioxarray.open_rasteriodefault of NOT masking and scaling it by default, leaving it as an opt-in for the user, but maybe this can be changed in the xarray's backend too?Below are examples of multiple ways to open a TIF file with a single band, and the different results:
Recap:
xr.open_datasetrioxarray.open_rasteriomask_and_scaleprovided'dtype': 'uint8', 'scale_factor': 1.0, 'add_offset': 0.0mask_and_scale=Falsemask_and_scale=True'dtype': 'uint8', 'scale_factor': 1.0, 'add_offset': 0.0'dtype': 'uint8', 'scale_factor': 1.0, 'add_offset': 0.0Beta Was this translation helpful? Give feedback.
All reactions