Skip to content
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

Size 0 axis error with subspacing #799

Open
moonbooks73 opened this issue Aug 8, 2024 · 2 comments
Open

Size 0 axis error with subspacing #799

moonbooks73 opened this issue Aug 8, 2024 · 2 comments
Labels
bug Something isn't working numpy-2

Comments

@moonbooks73
Copy link

When I try to create a subspace within a region and for a specific longitudean Index error occures, stating the field has a size 0 axis, I did this in VS code

> import cfplot as cfp
> import cf
> import numpy
> import matplotlib.pyplot as plt
> 
> orog = cf.read('~/cfplot_data/1km_elevation.nc')[0]
> print(orog)
> region = [(-6, 3), (50, 53)]
> orog_region = orog.subspace(longitude=cf.wi(*region[0]), latitude=cf.wi(*region[1]))
> print(orog_region.construct("latitude").array)
> elevation = orog_region.subspace(longitude = 2.9875)
> Exception has occurred: IndexError
> Indices [slice(None, None, None), array([], dtype=int64)] result in a subspaced shape of (360, 0), but can't create a subspace of Field that has a size 0 axis
>   File "/home/natalia/cfplot_data/orography_vertical_try.py", line 17, in <module>
>     elevation = orog_region.subspace(longitude = 2.9875)

However when I try the same code in the terminal, it works fine and produces the graph I want with the rest of the code.

Environment

cf.environment(paths=False)
In VS code (not working)

Platform: Linux-5.4.0-131-generic-x86_64-with-glibc2.31
HDF5 library: 1.14.3
netcdf library: 4.9.2
udunits2 library: /home/natalia/cfplot_data/.conda/lib/libudunits2.so.0
esmpy/ESMF: 8.6.1
Python: 3.10.14
dask: 2024.7.1
netCDF4: 1.6.5
psutil: 6.0.0
packaging: 24.1
numpy: 2.0.1
scipy: 1.14.0
matplotlib: 3.9.1
cftime: 1.6.4
cfunits: 3.3.7
cfplot: 3.3.0
cfdm: 1.11.1.0
cf: 3.16.2

In the terminal

Platform: Linux-5.4.0-131-generic-x86_64-with-glibc2.31
HDF5 library: 1.12.1
netcdf library: 4.8.1
udunits2 library: /home/natalia/anaconda3/lib/libudunits2.so.0
esmpy/ESMF: not available
Python: 3.12.2
dask: 2024.5.0
netCDF4: 1.6.2
psutil: 5.9.0
packaging: 23.2
numpy: 1.26.4
scipy: 1.13.1
matplotlib: 3.8.4
cftime: 1.6.4
cfunits: 3.3.7
cfplot: 3.3.0
cfdm: 1.11.1.0
cf: 3.16.1
@moonbooks73 moonbooks73 added the bug Something isn't working label Aug 8, 2024
@sadielbartholomew
Copy link
Member

Thanks Natalia, really useful report. We will investigate this shortly and let you know what we find here.

@sadielbartholomew
Copy link
Member

Ah, I have now realised the reason for this behaviour difference! It is not a bug in cf per se, though it is a downstream effect that is leading to, at present, some errors such as this one which shouldn't be occurring and which are also obscure in terms of the user-facing message.

It is due to NumPy 2 and its backwards-incompatible API and other bevhaviour differences from v1 to v2: notice the environment with the error has numpy: 2.0.1 and the working environment has numpy: 1.26.4.

@davidhassell I am going to create a numpy-2 label to mark Issues arising relating to that, so we can keep track and discuss how to handle them. Today Sharar was also seeing funky error messages I have never seen before with cf-plot, which I have only just clocked are due to her using an environment with NumPy 2. So NumPy 2 is starting to cause trouble for users already - would be good to review any updates we need for our libraries sooner rather than later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working numpy-2
Projects
None yet
Development

No branches or pull requests

2 participants