question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

netCDF + lazy backend: Error when sel is used with slice, reverse arrange

See original GitHub issue

What happened?

import xarray as xr
data = xr.open_dataset('data_example.nc')

# wrong
a = data.sel(time='1979-1',isobaricInhPa=200).z[:,  ::10,::10][:, ::-1,:]

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

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jesieleocommented, Nov 4, 2022

First of all, thank you for your help @dcherian @max-sixty . I finally reproduced this problem. I put the ds.isel(time=[0], isoBaricInhPa=1).z[:, ::10, :][:, ::-1, :] to ds.isel(time=[0], isoBaricInhPa=1).z[:, ::10, ::10][:, ::-1, :] can make a minimal example.

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')
a = ds.isel(time=[0], isoBaricInhPa=1).z[:, ::10, ::10][:, ::-1, :]
print(a.sizes)
print(a.shape)
print(a)

Frozen({'time': 1, 'latitude': 73, 'longitude': 144})
(1, 73, 144)
<xarray.DataArray 'z' (time: 1, latitude: 72, longitude: 144)>
array([[[1., 1., ..., 1., 1.],
        [1., 1., ..., 1., 1.],
        ...,
        [1., 1., ..., 1., 1.],
        [1., 1., ..., 1., 1.]]])
Coordinates:
  * latitude  (latitude) float64 90.0 87.5 85.0 82.5 ... -82.5 -85.0 -87.5 -90.0
Dimensions without coordinates: time, longitude
捕获
1reaction
max-sixtycommented, May 5, 2022

@dcherian thanks a lot for looking into this. @jesieleo thanks for your patience in us finding the bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pypec.data — GPEC 1.3.0 documentation
GPEC data is migrating to netcdf, and this module uses the xarray module for its python netcdf interface. The xarray module is very...
Read more >
Satpy Documentation
Satpy is a python library for reading, manipulating, and writing data from remote-sensing earth-observing satellite instruments.
Read more >
CRAN Packages By Name - The Comprehensive R Archive Network
ADPF, Use Least Squares Polynomial Regression and Statistical Testing to Improve ... BAEssd, Bayesian Average Error approach to Sample Size Determination.
Read more >
Simple index - piwheels
... backend-ai-console-server simple-virtuoso-migrate sql-schema-builder apitest365 messi-nmr kl-audit-supportv1-3 soufi delicious-nbdev geokey-webresources ...
Read more >
550 kB - Hugging Face
... t Ġ error Ġ- > m b Ġ use B lock Ġlog ger T ree Un it Up date Tra cing s...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found