lpsinger / ligo.skymap

Localization of gravitational-wave transients. Mirror of https://git.ligo.org/lscsoft/ligo.skymap
22 stars 18 forks source link

Example in allsky.py give error "TypeError: unhashable type: 'SkyCoord'" #9

Closed ferrigno closed 3 years ago

ferrigno commented 3 years ago
from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy import units as u
import ligo.skymap.plot
from matplotlib import pyplot as plt
url = 'https://dcc.ligo.org/public/0146/G1701985/001/bayestar_no_virgo.fits.gz'
center = SkyCoord.from_name('NGC 4993')
fig = plt.figure(figsize=(4, 4), dpi=100)
ax = plt.axes(
    [0.05, 0.05, 0.9, 0.9],
    projection='astro globe',
    center=center)

TypeError Traceback (most recent call last)

in 8 center = SkyCoord.from_name('NGC 4993') 9 fig = plt.figure(figsize=(4, 4), dpi=100) ---> 10 ax = plt.axes( 11 [0.05, 0.05, 0.9, 0.9], 12 projection='astro globe', ~/.venv/myVE/lib/python3.8/site-packages/matplotlib/pyplot.py in axes(arg, **kwargs) 964 return subplot(111, **kwargs) 965 else: --> 966 return gcf().add_axes(arg, **kwargs) 967 968 ~/.venv/myVE/lib/python3.8/site-packages/matplotlib/figure.py in add_axes(self, *args, **kwargs) 1222 # with the exact args/kwargs exists, return it immediately. 1223 key = self._make_key(*args, **kwargs) -> 1224 ax = self._axstack.get(key) 1225 if ax is not None: 1226 self.sca(ax) ~/.venv/myVE/lib/python3.8/site-packages/matplotlib/figure.py in get(self, key) 76 If it is not present, return *None*. 77 """ ---> 78 item = dict(self._elements).get(key) 79 if item is None: 80 return None TypeError: unhashable type: 'SkyCoord'
lpsinger commented 3 years ago

This is due to an API change in Astropy 4.1 that broke compatibility with Matplotlib by making SkyCoord instances unhashable. I've submitted a patch to Matplotlib to fix this (see matplotlib/matplotlib#18832, matplotlib/matplotlib#18978, matplotlib/matplotlib#19153). As a temporary workaround until the Matplotlib issue is fixed, please downgrade to an older version of Astropy:

pip install 'astropy < 4.1'
ferrigno commented 3 years ago

Thanks.

My workaround has been center = SkyCoord.from_name('NGC 4993') center_str = '%fd %fd'%(center.ra.deg, center.dec.deg) ... ax = plt.axes( [0.05, 0.05, 0.9, 0.9], projection='astro globe', center=center_str)

lpsinger commented 3 years ago

Yes, that's a clever workaround!