corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
528 stars 84 forks source link

merge_arrays: ignores CF conventions all versions >0.15.5 are affected #814

Closed jparal closed 3 weeks ago

jparal commented 1 month ago

Code Sample, a copy-pastable example if possible

This example uses MODIS in HDF4 data, available on request.

import numpy as np 
import xarray as xr 
from rioxarray.merge import merge_arrays

filename = "MYD21A2.A2020289.h12v11.061.2020349230516.hdf"
modis_tile = xr.open_dataset(filename, engine='rasterio').squeeze(drop=True)
tile = modis_tile['LST_Day_1KM']
data = merge_arrays([tile], nodata=np.nan)
print(np.unique(data))
# [13744. 13805. 13931. ... 20096. 20116.   nan]  <= WRONG

tile = 1.0*modis_tile['LST_Day_1KM']   # applies CF conventions before merge_array
data = merge_arrays([tile], nodata=np.nan) 
print(np.unique(data))
# [274.88   276.1    278.62   ... 401.91998 402.31998      nan]   <= CORRECT

Problem description

After updating to rioxarray from >0.15.5 to any later version, merge_arrays fails to apply CF conventions. Both 0.16.x and 0.17.x are affected.

This is the only thing which looks relevant, could it be the culprit here?

https://github.com/corteva/rioxarray/compare/0.15.5...0.15.6#diff-a5cbac5348d8946289580aa7cc146328084dc0ae31e6ed5b970d1484757fff5bL52

Expected Output

In both examples, the output should be the same:

# [274.88   276.1    278.62   ... 401.91998 402.31998      nan]

Environment Information

rioxarray (0.15.6) deps:
rasterio: 1.4.1
xarray: 2024.7.0
GDAL: 3.8.4
GEOS: 3.12.1
PROJ: 9.4.0
PROJ DATA: /home/USER/.local/share/proj:/usr/share/proj
GDAL DATA: None

Other python deps:
scipy: 1.12.0
pyproj: 3.6.1

System:
python: 3.10.4 (main, Jan 11 2023, 11:01:58) [GCC 11.3.0]
executable: /home/USER/.pyenv/versions/default/bin/python
machine: Linux-6.8.0-45-generic-x86_64-with-glibc2.39
snowman2 commented 3 weeks ago

Thanks for the report :+1:. See #817

jparal commented 3 weeks ago

Thank you for your help!