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

Website errors for Chapters 5-8 #246

Closed
shriv opened this issue Sep 8, 2024 · 22 comments
Closed

Website errors for Chapters 5-8 #246

shriv opened this issue Sep 8, 2024 · 22 comments

Comments

@shriv
Copy link

shriv commented Sep 8, 2024

Hi there,
I cannot see Chapters 5-8. I get the following error.

image

@michaeldorman
Copy link
Collaborator

Thanks!

I guess that there is an error in the code of Chapter 5 on GitHub actions. Locally it works fine for me.

Where can we see the errors log of the Python code in GitHub actions to figure out what's different there?
@Robinlovelace , @Nowosad, @anitagraser

🙏

@Nowosad
Copy link
Member

Nowosad commented Sep 9, 2024

 OverflowError                             Traceback (most recent call last)
File /usr/local/lib/python3.11/site-packages/numpy/ma/core.py:489, in _check_fill_value(fill_value, ndtype)
    488 try:
--> 489     fill_value = np.asarray(fill_value, dtype=ndtype)
    490 except (OverflowError, ValueError) as e:
    491     # Raise TypeError instead of OverflowError or ValueError.
    492     # OverflowError is seldom used, and the real problem here is
    493     # that the passed fill_value is not compatible with the ndtype.

OverflowError: Python integer 9999 out of bounds for uint8

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
Cell In[33], line 1
----> 1 out_image, out_transform = rasterio.mask.mask(
      2     src_nlcd, 
      3     zion.geometry.to_crs(src_nlcd.crs), 
      4     crop=False, 
      5     nodata=9999
      6 )
      7 counts = np.unique(out_image, return_counts=True)
      8 counts

@Nowosad
Copy link
Member

Nowosad commented Sep 9, 2024

@michaeldorman you can find this error by clicking on "Render" at https:/geocompx/geocompy/actions/runs/10767927445/job/29856118003 and then scrolling down.

@Robinlovelace
Copy link
Contributor

Probably a Python package version issue, although surprised it didn't result in Actions failing.

Also affects other the gh-pages workflow: https:/geocompx/geocompy/actions/runs/10767927441/job/29856117885#step:4:413

@Robinlovelace
Copy link
Contributor

Logical next step would be to test locally with the python image:

container: ghcr.io/geocompx/docker:python

Also in our devcontainer:

"image": "ghcr.io/geocompx/docker:python",

@Robinlovelace
Copy link
Contributor

Testing in GitHub codespaces which uses the image listed above.

Anyone can do by clicking this link, I think:

https:/codespaces/new?hide_repo_select=true&ref=main&repo=447558863

@Robinlovelace
Copy link
Contributor

Failing command:

out_image, out_transform = rasterio.mask.mask(

@Robinlovelace
Copy link
Contributor

Can reproduce in devcontainer:

image

@Robinlovelace
Copy link
Contributor

Removing

    nodata=9999

Fixes it. Will put in PR.

@Robinlovelace
Copy link
Contributor

I think it's numpy2 related:

  Cell 76/78: ''................................Done
  Cell 77/78: ''................................ERROR: 

An error occurred while executing the following cell:
------------------
image = rasterio.features.rasterize(
    distances,
    out_shape=r.shape,
    dtype=np.float_,
    transform=new_transform,
    fill=np.nan
)
image
------------------


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[109], line 4
      1 image = rasterio.features.rasterize(
      2     distances,
      3     out_shape=r.shape,
----> 4     dtype=np.float_,
      5     transform=new_transform,
      6     fill=np.nan
      7 )
      8 image

File /usr/local/lib/python3.11/site-packages/numpy/__init__.py:397, in __getattr__(attr)
    394     raise AttributeError(__former_attrs__[attr])
    396 if attr in __expired_attributes__:
--> 397     raise AttributeError(
    398         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    399         f"{__expired_attributes__[attr]}"
    400     )
    402 if attr == "chararray":
    403     warnings.warn(
    404         "`np.chararray` is deprecated and will be removed from "
    405         "the main namespace in the future. Use an array with a string "
    406         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.

Can you try installing NumPy 2.0 @michaeldorman ?

@Robinlovelace
Copy link
Contributor

In the container we have 2.0.1:

pip install numpy
Requirement already satisfied: numpy in /usr/local/lib/python3.11/site-packages (2.0.1)

@Robinlovelace
Copy link
Contributor

And that matches our requirements.txt:

numpy==2.0.1

So I think we need to update the offending code. Thanks for the report @shriv and do let us know anyone ideas of fixes. I imagine there are lots of issues in the rasterio GitHub related to NumPy 2.

@Robinlovelace
Copy link
Contributor

Yes, there are lots of issues: https:/search?q=repo%3Arasterio%2Frasterio+numpy&type=issues

Notably this one by @sgillies: rasterio/rasterio#2819

Should we upgrade to 1.4.0 when ready?

@Robinlovelace
Copy link
Contributor

Currently we're on 1.3:

rasterio==1.3.10

@michaeldorman
Copy link
Collaborator

@michaeldorman you can find this error by clicking on "Render" at https:/geocompx/geocompy/actions/runs/10767927445/job/29856118003 and then scrolling down.

Got it, thanks @Nowosad !

@Robinlovelace
Copy link
Contributor

Any comments on this very welcome @sgillies and great to see 1.4.0rc1 is due out today!

Do you have an ETA for 1.4.0, without the rc (release candidate I think) bit?

@michaeldorman
Copy link
Collaborator

I think it's numpy2 related:

  Cell 76/78: ''................................Done
  Cell 77/78: ''................................ERROR: 

An error occurred while executing the following cell:
------------------
image = rasterio.features.rasterize(
    distances,
    out_shape=r.shape,
    dtype=np.float_,
    transform=new_transform,
    fill=np.nan
)
image
------------------


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[109], line 4
      1 image = rasterio.features.rasterize(
      2     distances,
      3     out_shape=r.shape,
----> 4     dtype=np.float_,
      5     transform=new_transform,
      6     fill=np.nan
      7 )
      8 image

File /usr/local/lib/python3.11/site-packages/numpy/__init__.py:397, in __getattr__(attr)
    394     raise AttributeError(__former_attrs__[attr])
    396 if attr in __expired_attributes__:
--> 397     raise AttributeError(
    398         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    399         f"{__expired_attributes__[attr]}"
    400     )
    402 if attr == "chararray":
    403     warnings.warn(
    404         "`np.chararray` is deprecated and will be removed from "
    405         "the main namespace in the future. Use an array with a string "
    406         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.

Can you try installing NumPy 2.0 @michaeldorman ?

Thanks @Robinlovelace 🙏

@Robinlovelace
Copy link
Contributor

Use `np.float64` instead

Could be good idea from above.

@michaeldorman
Copy link
Collaborator

Interesting... I tried installing numpy 2.1.1, but it conflicts with matplotlib. If I try to install matplotlib or both, then pip downgrades to numpy 1.26.4

@Robinlovelace
Copy link
Contributor

You need to upgrade a load of pkgs I think Michael. The Docker container has the following, as you'd be able to find out with

docker run -it ghcr.io/geocompx/docker:python /bin/bash
pip install matplotlib
Requirement already satisfied: matplotlib in /usr/local/lib/python3.11/site-packages (3.9.0)

@michaeldorman
Copy link
Collaborator

Thanks @Robinlovelace , seems to be solved. I also needed pip install -U pyarrow numexpr bottleneck

@michaeldorman
Copy link
Collaborator

Solved, thanks @Nowosad and @Robinlovelace !

The issue was using 9999 instead of src_nlcd.nodata in this code section:

out_image, out_transform = rasterio.mask.mask(
    src_nlcd, 
    zion.geometry.to_crs(src_nlcd.crs), 
    crop=False, 
    nodata=src_nlcd.nodata
)

b4c5fc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants