rioxarray
rioxarray copied to clipboard
xr.open_dataset(engine = 'rasterio') data type bug
After reading this warning:
/tmp/ipykernel_26083/965058138.py:2: DeprecationWarning: open_rasterio is Deprecated in favor of rioxarray. For information about transitioning, see: https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html
print(xr.open_rasterio(filepath,chunks={}))
I've decided to try the new way of opening rasters, but there seems to be a bug.
The input data type is Int16, and all the different methods but xr.open_dataset(engine = 'rasterio')
or xr.open_dataarray(engine = 'rasterio')
reads it correctly. Using the xr. methods the input data is read as Float32 instead of Int16.
Code Sample, a copy-pastable example if possible
The input data can be found here: https://drive.google.com/drive/folders/1R8EYB6f793nuPdRE4m-UMFTalqeigtQb?usp=sharing
import xarray as xr
import rioxarray
import rasterio
print(xr.__version__)
print(rioxarray.__version__)
print(rasterio.__version__)
filepath = 'pixel_classif_flags.img'
print(xr.open_rasterio(filepath,chunks={}).dtype)
print(xr.open_dataarray(filepath,chunks={},engine='rasterio').dtype)
print(xr.open_dataset(filepath,chunks={},engine='rasterio').band_data.dtype)
print(rioxarray.open_rasterio(filepath,chunks={}).dtype)
!gdalinfo pixel_classif_flags.img
Output:
2022.3.0
0.11.1
1.2.10
int16
float32
float32
int16
Driver: ENVI/ENVI .hdr Labelled
Files: /mnt/CEPH_PROJECTS/ALPSNOW/Albedo_Grain_Size/01_code/sample_output/S3B_OL_1_EFR____20200101T092946_20200101T093246_20200102T142802_0179_034_036_2160_LN1_O_NT_002.SEN3_idepix.data/pixel_classif_flags.img
/mnt/CEPH_PROJECTS/ALPSNOW/Albedo_Grain_Size/01_code/sample_output/S3B_OL_1_EFR____20200101T092946_20200101T093246_20200102T142802_0179_034_036_2160_LN1_O_NT_002.SEN3_idepix.data/pixel_classif_flags.hdr
Size is 4865, 4090
Metadata:
Band_1=pixel_classif_flags
Image Structure Metadata:
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 4090.0)
Upper Right ( 4865.0, 0.0)
Lower Right ( 4865.0, 4090.0)
Center ( 2432.5, 2045.0)
Band 1 Block=4865x1 Type=Int16, ColorInterp=Undefined
Description = pixel_classif_flags
Related to #495, if you set mask_and_scale=False
, then it will behave as expected.