pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.61k stars 1.08k forks source link

Opendap access problem when subsetting via latitude and longitude... #4052

Open cwerner opened 4 years ago

cwerner commented 4 years ago

I am trying to access a subset of a netcdf files hosted on a THREDDS server. I can inspect the metadata, but I cannot subset the file via lat and lon slices. A download via the http link provided on the page works...

MCVE Code Sample

import xarray as xr

# this works
test1 = xr.open_dataset(URL)
display(test1)

# this also works
test2 = xr.open_dataset(URL).sel(lat=slice(30,40))
display(test2)

# this also works
test3 = xr.open_dataset(URL).sel(lon=slice(100,110))
display(test3)

# this fails
test4 = xr.open_dataset(URL).sel(lat=slice(30,40), lon=slice(100,110))
display(test4)

Problem Description

Error:

~/.pyenv/versions/miniconda3-latest/envs/datascience/lib/python3.7/site-packages/xarray/backends/common.py in robust_getitem(array, key, catch, max_retries, initial_delay)
     52     for n in range(max_retries + 1):
     53         try:
---> 54             return array[key]
     55         except catch:
     56             if n == max_retries:

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable.__getitem__()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable._get()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4._ensure_nc_success()

RuntimeError: NetCDF: Access failure

I also tried to use the pydap engine, but I'm not sure if this tells me something about the problem or if I use this option incorrectly...


URL = "https://thredds.daac.ornl.gov/thredds/dodsC/ornldaac/1247/T_CLAY.nc4"
test1 = xr.open_dataset(URL, engine='pydap')
test1

result:

UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)

Versions

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.4 (default, Aug 13 2019, 15:17:50) 
[Clang 4.0.1 (tags/RELEASE_401/final)]
python-bits: 64
OS: Darwin
OS-release: 19.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.1

xarray: 0.15.1
pandas: 1.0.1
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.4.2
pydap: installed
h5netcdf: None
h5py: None
Nio: None
zarr: 2.4.0
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.0.21
cfgrib: None
iris: None
bottleneck: None
dask: 2.11.0
distributed: 2.11.0
matplotlib: 3.1.3
cartopy: 0.17.0
seaborn: 0.10.0
numbagg: None
setuptools: 45.2.0.post20200210
pip: 20.0.2
conda: None
pytest: None
IPython: 7.12.0
sphinx: None
stale[bot] commented 2 years ago

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically