brandondube / prysm

physical optics: integrated modeling, phase retrieval, segmented systems, polynomials and fitting, sequential raytracing...
https://prysm.readthedocs.io/en/stable/
MIT License
259 stars 44 forks source link

HST in "Notable Telescope Apertures" not working due to numpy deprecation? #115

Closed egemenimre closed 2 days ago

egemenimre commented 3 days ago

I'm trying the HST example in the Notable Telescope Apertures.

I simply copied all the code in it. I get an error at the line defining spider. It looks like np.bool has been deprecated by numpy.

  "name": "AttributeError",
  "message": "module 'numpy' has no attribute 'bool'.
  `np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations",
  "stack": "---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  Cell In[6], line 1
  ----> 1 spider_ = spider(4, 0.038, x, y, 45)
      2 pads_r = 0.90*2.4/2
      3 pad_angles = [np.radians(a) for a in [-45, -165, 75]]

  File ~/miniforge3/envs/opticks/lib/python3.12/site-packages/prysm/geometry.py:351, in spider(vanes, width, x, y, rotation, center)
    348 rotation = np.radians(360 / vanes)
    350 # initialize a blank mask
  --> 351 mask = np.zeros(x.shape, dtype=np.bool)
    352 for multiple in range(vanes):
    353     # iterate through the vanes and generate a mask for each
    354     # adding it to the initialized mask
    355     offset = rotation * multiple

  File ~/miniforge3/envs/opticks/lib/python3.12/site-packages/prysm/mathops.py:15, in BackendShim.__getattr__(self, key)
     12 if key == '_srcmodule':
     13     return self._srcmodule
  ---> 15 return getattr(self._srcmodule, key)

  File ~/miniforge3/envs/opticks/lib/python3.12/site-packages/numpy/__init__.py:324, in __getattr__(attr)
    319     warnings.warn(
    320         f\"In the future `np.{attr}` will be defined as the \"
    321         \"corresponding NumPy scalar.\", FutureWarning, stacklevel=2)
    323 if attr in __former_attrs__:
  --> 324     raise AttributeError(__former_attrs__[attr])
    326 if attr == 'testing':
    327     import numpy.testing as testing

  AttributeError: module 'numpy' has no attribute 'bool'.
  `np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations"
egemenimre commented 3 days ago

np.bool exists only in spider and this should fix the issue: mask = np.zeros(x.shape, dtype=bool) instead of the current mask = np.zeros(x.shape, dtype=np.bool)

brandondube commented 2 days ago

This one was fixed quite a long time ago (December 2022) in 93cb41681651e35c564b760408d5d01280f8f7c6 -- I am not exactly sure when I will go through the process of making the next formal release, but the code is stable on the master branch if you want to use that directly. Just waiting on a few things to get finished before making a new release (notably, polynomials/laguerre.py)