-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
netCDF + lazy backend: Error when sel is used with slice, reverse arrange #6560
Comments
@jesieleo — I'm probably being unclear, and I'm sure you're well-intentioned, but this & the previous issues aren't constructive for either of us so far. In the politest possible way: please make an issue that is complete and "copy & pastes into an IPython prompt or Binder notebook, returning the result.". You cannot reference data that is only on your computer. This will require work from your end to take the example you have there, and reduce it to the bare minimum. |
Sorry, this is the first time I use Github to report a problem, I don't understand it very well, it seems that I need to learn more.
I have added a zip dile with a .ipynb file , don't know if it is ok?
…------------------ 原始邮件 ------------------
发件人: "Maximilian ***@***.***>;
发送时间: 2022年5月2日(星期一) 下午4:32
收件人: ***@***.***>;
抄送: ***@***.***>; ***@***.***>;
主题: Re: [pydata/xarray] error when using .sel() and [:, ::10, ::10][:, ::-1, :] (Issue #6560)
@jesieleo — I'm probably being unclear, and I'm sure you're well-intentioned, but this & the previous issues aren't constructive for either of us so far.
In the politest possible way: please make an issue that is complete and "copy & pastes into an IPython prompt or Binder notebook, returning the result.". You cannot reference data that is only on your computer. This will require work from your end to take the example you have there, and reduce it to the bare minimum.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
OK — I would like to make your experience GitHub a good one! It's a magical place.
But no, this is not sufficient — can you show your problem on an array like |
Ok ,thanks. I try to simplify the problem on an array |
What is |
I packed them in one |
Don't bundle data — build a new example from a basic array and demonstrate the bug. |
Since I don't know how the grib file is generated, I can't reproduce it. But the data I use is the ECWMF official website data converted by engine='cfgrib', this problem may be caused by the 'cfgrib' engine, although it is not very big wrong, but it's a hidden danger. |
OK turns out my attempts at a minimal example didn't work. There's some bug here (on xarray main)
@jesieleo here's how I tried to create a "minimal example" import xarray as xr
import numpy as np
ds = xr.Dataset(
{
"z": (
("time", "isoBaricInhPa", "latitude", "longitude"),
np.ones((1, 5, 721, 1440)), # use numpy.ones to create array of same shape.
)
},
coords={"latitude": np.linspace(-90, 90, 721)},
)
ds.isel(isoBaricInhPa=1).z[:, ::10, :][:, ::-1, :] Though this doesn't replicate it! |
OK it has to do with the lazy backend. Calling Though I still can't make a minimal example. The example below works fine. import numpy as np
import xarray as xr
ds = xr.Dataset(
{
"z": (
("time", "isoBaricInhPa", "latitude", "longitude"),
np.ones((1, 5, 721, 1440)),
)
},
coords={"latitude": np.linspace(-90, 90, 721)},
).to_netcdf("test.nc")
ds = xr.open_dataset('test.nc')
ds.isel(time=[0], isoBaricInhPa=1).z[:, ::10, :][:, ::-1, :] |
First of all, thank you for your help @dcherian @max-sixty . I finally reproduced this problem.
|
There was a bug in estimating the last index of the slice. Index a range object instead. Closes pydata#6560
* Fix lazy slice rewriting. There was a bug in estimating the last index of the slice. Index a range object instead. Closes #6560 * Support reversed slices with Zarr * Update xarray/core/indexing.py * Fix test * bring back xfail * Smaller test * Better? * fix typing
What happened?
It seem that when use sel() , [: , ::-1 , :] and [: , ::10 , ::10] at the same time will cause the second coord will wrong like this.
Why just when use sel and[: , ::10 , ::10][: , ::-1 , :] ,it will goes wrong in axis=2( the data DO NOT correspond to the coordinates) ?
What did you expect to happen?
The data correspond to the coordinates on Latitude.
Minimal Complete Verifiable Example
problem_example.zip
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: AMD64 Family 25 Mod
el 33 Stepping 0, AuthenticAMD
byteorder: little
LC_ALL: None
LANG: en
LOCALE: ('Chinese (Simplified)_China', '936')
libhdf5: 1.12.1
libnetcdf: 4.8.1
xarray: 2022.3.0
pandas: 1.4.2
numpy: 1.22.3
scipy: 1.7.3
netCDF4: 1.5.7
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.2.10
cfgrib: 0.9.10.1
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.5.1
cartopy: 0.20.2
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
setuptools: 56.0.0
pip: 22.0.4
conda: None
pytest: None
IPython: 8.3.0
sphinx: 4.5.0
The text was updated successfully, but these errors were encountered: