radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
95 stars 62 forks source link

imshow of LDOs gives error #768

Open keflavich opened 2 years ago

keflavich commented 2 years ago

Even with quantity support enabled, imshow results in tracebacks like this. Astropy quantity objects don't have this problem. What do we need to do to fix it?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/.local/lib/python3.9/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/.local/lib/python3.9/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
    149         FigureCanvasBase(fig)
    150 
--> 151     fig.canvas.print_figure(bytes_io, **kw)
    152     data = bytes_io.getvalue()
    153     if fmt == 'svg':

~/.local/lib/python3.9/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2228                        else suppress())
   2229                 with ctx:
-> 2230                     self.figure.draw(renderer)
   2231 
   2232             if bbox_inches:

~/.local/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     72     @wraps(draw)
     73     def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74         result = draw(artist, renderer, *args, **kwargs)
     75         if renderer._rasterizing:
     76             renderer.stop_rasterizing()

~/.local/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/lib/python3.9/site-packages/matplotlib/figure.py in draw(self, renderer)
   2788 
   2789             self.patch.draw(renderer)
-> 2790             mimage._draw_list_compositing_images(
   2791                 renderer, self, artists, self.suppressComposite)
   2792 

~/.local/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130     if not_composite or not has_images:
    131         for a in artists:
--> 132             a.draw(renderer)
    133     else:
    134         # Composite any adjacent images together

~/.local/lib/python3.9/site-packages/astropy/visualization/wcsaxes/core.py in draw(self, renderer, **kwargs)
    457         self.coords.frame._update_patch_path()
    458 
--> 459         super().draw(renderer, **kwargs)
    460 
    461         self._drawn = True

~/.local/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/lib/python3.9/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
    429                          else deprecation_addendum,
    430                 **kwargs)
--> 431         return func(*inner_args, **inner_kwargs)
    432 
    433     return wrapper

~/.local/lib/python3.9/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
   2919             renderer.stop_rasterizing()
   2920 
-> 2921         mimage._draw_list_compositing_images(renderer, self, artists)
   2922 
   2923         renderer.close_group('axes')

~/.local/lib/python3.9/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    130     if not_composite or not has_images:
    131         for a in artists:
--> 132             a.draw(renderer)
    133     else:
    134         # Composite any adjacent images together

~/.local/lib/python3.9/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     49                 renderer.start_filter()
     50 
---> 51             return draw(artist, renderer, *args, **kwargs)
     52         finally:
     53             if artist.get_agg_filter() is not None:

~/.local/lib/python3.9/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
    638                 renderer.draw_image(gc, l, b, im, trans)
    639         else:
--> 640             im, l, b, trans = self.make_image(
    641                 renderer, renderer.get_image_magnification())
    642             if im is not None:

~/.local/lib/python3.9/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
    924         clip = ((self.get_clip_box() or self.axes.bbox) if self.get_clip_on()
    925                 else self.figure.bbox)
--> 926         return self._make_image(self._A, bbox, transformed_bbox, clip,
    927                                 magnification, unsampled=unsampled)
    928 

~/.local/lib/python3.9/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
    477                 vrange = np.array([vmin, vmax], dtype=scaled_dtype)
    478 
--> 479                 A_scaled -= a_min
    480                 vrange -= a_min
    481                 # a_min and a_max might be ndarray subclasses so use

~/.local/lib/python3.9/site-packages/astropy/units/quantity.py in __array_ufunc__(self, function, method, *inputs, **kwargs)
    493             return result
    494 
--> 495         return self._result_as_quantity(result, unit, out)
    496 
    497     def _result_as_quantity(self, result, unit, out):

~/.local/lib/python3.9/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out)
    533         # the output is of the correct Quantity subclass, as it was passed
    534         # through check_output.
--> 535         out._set_unit(unit)
    536         return out
    537 

AttributeError: 'numpy.ndarray' object has no attribute '_set_unit'