corteva / rioxarray

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

Loading netCDF from remote source fails #829

Open StijnCaerts opened 2 weeks ago

StijnCaerts commented 2 weeks ago

Code Sample, a copy-pastable example if possible

import rioxarray

local_file = "/tmp/c_gls_NDVI_202004010000_GLOBE_PROBAV_V3.0.1.nc"
with rioxarray.open_rasterio(local_file) as src:
    print(src.data_vars)

remote_file = "https://globalland.vito.be/download/netcdf/ndvi/ndvi_1km_v3_10daily/2020/20200401/c_gls_NDVI_202004010000_GLOBE_PROBAV_V3.0.1.nc"
with rioxarray.open_rasterio(remote_file) as src:
    print(src.data_vars)

Problem description

Loading netCDF files containing a time dimension fails when the file is located on a 'remote' source. For remote sources, like HTTP but also NFS shares, the NETCDF_DIM_time_VALUES tag is not set. This raises the following exception:

Traceback (most recent call last):
  File "/home/stijn/PycharmProjects/scratch/rioxarray_bug.py", line 8, in <module>
    with rioxarray.open_rasterio(remote_file) as src:
  File "/home/stijn/PycharmProjects/scratch/.venv/lib/python3.10/site-packages/rioxarray/_io.py", line 1147, in open_rasterio
    subdataset_result = _load_subdatasets(
  File "/home/stijn/PycharmProjects/scratch/.venv/lib/python3.10/site-packages/rioxarray/_io.py", line 829, in _load_subdatasets
    rioda: DataArray = open_rasterio(  # type: ignore
  File "/home/stijn/PycharmProjects/scratch/.venv/lib/python3.10/site-packages/rioxarray/_io.py", line 1192, in open_rasterio
    coords = _load_netcdf_1d_coords(attrs)
  File "/home/stijn/PycharmProjects/scratch/.venv/lib/python3.10/site-packages/rioxarray/_io.py", line 609, in _load_netcdf_1d_coords
    dim_values = _parse_netcdf_attr_array(tags[f"NETCDF_DIM_{dim_name}_VALUES"])
KeyError: 'NETCDF_DIM_time_VALUES'

Related topics in GDAL repository:

Expected Output

Data variables:
    NDVI       (time, y, x) uint8 632MB ...
    NDVI_unc   (time, y, x) int16 1GB ...
    NOBS       (time, y, x) uint8 632MB ...
    QFLAG      (time, y, x) uint8 632MB ...
    TIME_GRID  (time, y, x) int16 1GB ...

Environment Information

rioxarray (0.18.1) deps:
  rasterio: 1.3.10
    xarray: 2024.10.0
      GDAL: 3.8.4
      GEOS: 3.11.1
      PROJ: 9.3.1
 PROJ DATA: /home/stijn/PycharmProjects/scratch/.venv/lib/python3.10/site-packages/rasterio/proj_data
 GDAL DATA: /home/stijn/PycharmProjects/scratch/.venv/lib/python3.10/site-packages/rasterio/gdal_data

Other python deps:
     scipy: 1.14.1
    pyproj: 3.6.1

System:
    python: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
executable: /home/stijn/PycharmProjects/scratch/.venv/bin/python
   machine: Linux-6.9.3-76060903-generic-x86_64-with-glibc2.35

Installation method