aplpy / aplpy

Astronomical Plotting Library in Python
http://aplpy.github.com
Other
169 stars 82 forks source link

runtime failure seems to trace to astropy 5.0 reorganization #472

Open jrthorstensen opened 2 years ago

jrthorstensen commented 2 years ago

I'm trying to run a python 3 script calling APLpy from a conda python 3.9 environment on Linux. It fails with:

  File "/home/thorsten/bin/makeNotionCharts.py", line 39, in <module>
    from aplpy import *
  File "/usr/local/anaconda3/envs/py3/lib/python3.9/site-packages/aplpy/__init__.py", line 14, in <module>
    from .core import FITSFigure  # noqa
  File "/usr/local/anaconda3/envs/py3/lib/python3.9/site-packages/aplpy/core.py", line 20, in <module>
    from astropy.nddata.utils import block_reduce
ImportError: cannot import name 'block_reduce' from 'astropy.nddata.utils' (/usr/local/anaconda3/envs/py3/lib/python3.9/site-packages/astropy/nddata/utils.py)

I looked at this and it appears that block_reduce is now in astropy/nddata, not in astropy/nddata/utils:

>>> import astropy
>>> astropy.__version__
'5.0'
>>> 
>>> import astropy.nddata as nd
>>> dir(nd)
['BitFlagNameMap', 'CCDData', 'Conf', 'Cutout2D', 'FlagCollection', 'IncompatibleUncertaintiesException', 'InvalidBitFlag', 'InverseVariance', 'MissingDataAssociationException', 'NDArithmeticMixin', 'NDData', 'NDDataArray', 'NDDataBase', 'NDDataRef', 'NDIOMixin', 'NDSlicingMixin', 'NDUncertainty', 'NoOverlapError', 'PartialOverlapError', 'StdDevUncertainty', 'UnknownUncertainty', 'VarianceUncertainty', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_config', 'add_array', 'bitfield_to_boolean_mask', 'bitmask', 'block_reduce', 'block_replicate', 'blocks', 'ccddata', 'compat', 'conf', 'decorators', 'extend_bit_flag_map', 'extract_array', 'fits_ccddata_reader', 'fits_ccddata_writer', 'flag_collection', 'interpret_bit_flags', 'mixins', 'nddata', 'nddata_base', 'nddata_withmixins', 'nduncertainty', 'overlap_slices', 'reshape_as_blocks', 'subpixel_indices', 'support_nddata', 'utils']
>>> dir(nd.utils)
['Cutout2D', 'NoOverlapError', 'PartialOverlapError', 'Sip', 'SkyCoord', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'add_array', 'deepcopy', 'extract_array', 'lazyproperty', 'np', 'overlap_slices', 'proj_plane_pixel_scales', 'skycoord_to_pixel', 'subpixel_indices', 'u']

I suppose I could try to fix my own code by taking out the blanket-import and importing just the part of aplpy I need, which might work, but in the meatime I figured the maintainers would want to know about this. -- John Thorstensen

jrthorstensen commented 2 years ago

Tiny update -- I think everything I'm doing here is with FITSFigure, so I tried changing the import to

from aplpy import FITSFigure

and it fails in the same way.

jrthorstensen commented 2 years ago

Sure enough, I got it running by changing the import line in aplpy's "core.py" from

from astropy.nddata.utils import block_reduce

to

from astropy.nddata import block_reduce

I'm only using FITSFigure, so I haven't run any extensive tests. - John

dhomeier commented 2 years ago

Thanks for reporting this. This is actually the incompatibility fixed in e8c72f0 for the 2.1 release, but the conda channels might need a little more time yet to update to the newest version. In urgent cases you may already install the current release using pip install 'aplpy>=2.1.0'.

jrthorstensen commented 2 years ago

Thanks! I forced the upgrade as you suggested and it now runs without complaining.

cgobat commented 1 year ago

Just an FYI @dhomeier @astrofrog, I just did a brand new install of aplpy via conda-forge today and it seems 2.0.3 is still the latest version available there.

thatastroguy commented 1 year ago

Chiming in here. I just upgraded my astropy to 5.2.2 and ran into this same conflict ImportError: cannot import name 'block_reduce' from 'astropy.nddata.utils' (/Users/ryan/anaconda3/lib/python3.9/site-packages/astropy/nddata/utils.py). Even after ensuring my aplpy version is 2.1.0 (via a forced upgrade), I hit the same error. I'm running Mac OS Monterey v12.4.

I attempted the quick fix provided above by @jrthorstensen above, but I then encounter a different error with a traceback:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 10
      8 from astroquery.skyview import SkyView
      9 import matplotlib.pyplot as plt
---> 10 import aplpy
     11 import wget
     12 import urllib.request

File ~/anaconda3/lib/python3.9/site-packages/aplpy/__init__.py:14
     10 # ----------------------------------------------------------------------------
     12 if not _ASTROPY_SETUP_:  # noqa
---> 14     from .core import FITSFigure  # noqa
     15     from .rgb import make_rgb_image, make_rgb_cube  # noqa
     17     from .frame import Frame  # noqa

File ~/anaconda3/lib/python3.9/site-packages/aplpy/core.py:30
     27 from . import slicer
     29 from .compat import simple_norm
---> 30 from .layers import Layers
     31 from .grid import Grid
     32 from .ticks import Ticks

File ~/anaconda3/lib/python3.9/site-packages/aplpy/layers.py:9
      5 from matplotlib.contour import ContourSet
      6 from matplotlib.collections import RegularPolyCollection, \
      7     PatchCollection, CircleCollection, LineCollection
----> 9 from .regions import ArtistCollection
     10 from .decorators import auto_refresh
     13 class Layers(object):

File ~/anaconda3/lib/python3.9/site-packages/aplpy/regions.py:6
      3 from astropy import log
      4 from astropy import wcs
----> 6 from .decorators import auto_refresh
      9 class Regions(object):
     10     """
     11     Regions sub-class of APLpy.
     12 
   (...)
     41 
     42     """

File ~/anaconda3/lib/python3.9/site-packages/aplpy/decorators.py:5
      1 from __future__ import absolute_import, print_function, division
      3 import threading
----> 5 from astropy.utils.decorators import wraps
      7 mydata = threading.local()
      9 __all__ = ['auto_refresh', 'fixdocstring']

ImportError: cannot import name 'wraps' from 'astropy.utils.decorators' (/Users/ryan/anaconda3/lib/python3.9/site-packages/astropy/utils/decorators.py)

Other than trying to roll back my astropy installation, I'm not quite sure what to do. Correction: the solution outlined by bencooper1 in open issue #474 solved this additional issue. Aplpy can now be imported.

dhomeier commented 1 year ago

Both these issues have been fixed in 2.1.0 (#469 and #471); you could install the latest release through pip, but I am also only getting 2.0.3 from mambaforge. @astrofrog do you have an idea how to poke conda/condaforge to pull the current version?

thatastroguy commented 1 year ago

Thanks for the response, @dhomeier. I ran into these issues even after installing 2.1.0 through pip, which is why I was rather confused about running into these errors.

dhomeier commented 1 year ago

You mean you have an installation that reports aplpy.version.version == '2.1.0' and are still getting those errors?

thatastroguy commented 1 year ago

So I had thought. I attempted pip install 'aplpy>=2.1.0', and once I checked the version number using conda list, it appeared that I had the correct version number (2.1.0). But loading a python session, importing aplpy, and checking aplpy.version.version returned 2.0.3 just a moment ago. Using pip install --force-reinstall aplpy has now brought it up to the correct version number: aplpy.version.version=='2.1.0'.

I appreciate the help and I apologize for my confusion!

dhomeier commented 1 year ago

Thanks for the feedback; pip installs on top of conda can create confusion over what is already installed, so it is indeed regrettable condaforge has still not been able to update its package!

thriveth commented 10 months ago

Thanks, I have faced the same problem and fixed it installing via pip. I really wish the Conda folks would bump the version in the repositories so it would be, like, not broken.

cgobat commented 10 months ago

The merging of conda-forge/aplpy-feedstock#10 earlier this morning has now made APLpy v2.1.0 available through conda-forge. It seems that should likely resolve all of the issues discussed here.