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

xr.open_dataset(engine = 'rasterio') data type bug #533

Closed
clausmichele opened this issue Jun 15, 2022 · 1 comment
Closed

xr.open_dataset(engine = 'rasterio') data type bug #533

clausmichele opened this issue Jun 15, 2022 · 1 comment
Labels
question Further information is requested

Comments

@clausmichele
Copy link
Contributor

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
@clausmichele clausmichele added the bug Something isn't working label Jun 15, 2022
@snowman2
Copy link
Member

Related to #495, if you set mask_and_scale=False, then it will behave as expected.

@snowman2 snowman2 added question Further information is requested and removed bug Something isn't working labels Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants