astropy / astropy-healpix

BSD-licensed HEALPix for Astropy - maintained by @astrofrog and @lpsinger
https://astropy-healpix.readthedocs.io
BSD 3-Clause "New" or "Revised" License
52 stars 22 forks source link

Method healpix_to_skycoord fails with simple example #156

Closed tasymons closed 2 years ago

tasymons commented 3 years ago

Description

The method healpix_to_skycoord fails instead of giving the skycoord.

Expected behavior

skycoord_obj = hp.healpix_to_skycoord(55)

Actual behavior

Using hp = HEALPix(nside=256, order='nested',frame=Galactic)

Traceback (most recent call last):
  File "<ipython-input-2-1186f979e0c4>", line 1, in <module>
    hp.healpix_to_skycoord(55)
  File ".../anaconda3/lib/python3.7/site-packages/astropy_healpix/high_level.py", line 339, in healpix_to_skycoord
    return SkyCoord(self.frame.realize_frame(representation))
TypeError: realize_frame() missing 1 required positional argument: 'data'

Using hp = HEALPix(nside=256, order='nested',frame='galactic')

Traceback (most recent call last):
  File ".../anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-24f6cd72e44c>", line 1, in <module>
    hp.healpix_to_skycoord(55)
  File ".../anaconda3/lib/python3.7/site-packages/astropy_healpix/high_level.py", line 339, in healpix_to_skycoord
    return SkyCoord(self.frame.realize_frame(representation)) #original
AttributeError: 'str' object has no attribute 'realize_frame'

Steps to Reproduce

Code to cause the error:

from astropy_healpix import HEALPix
from astropy.coordinates import Galactic
hp = HEALPix(nside=256, order='nested',frame=Galactic)
skycoord_obj = hp.healpix_to_skycoord(55)
from astropy_healpix import HEALPix
hp = HEALPix(nside=256, order='nested',frame='galactic') #string form does not work
skycoord_obj = hp.healpix_to_skycoord(55)

System Details

System 1: Linux-5.1.7-300.fc30.x86_64-x86_64-with-fedora-30-Thirty Python 3.7.10 | packaged by conda-forge | (default, Feb 19 2021, 16:07:37) [GCC 9.3.0] Numpy 1.20.3 astropy 4.3.1 Scipy 1.7.1 astropy_healpix 0.6

System 2: Windows-10-10.0.19041-SP0 Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] Numpy 1.18.1 astropy 4.0 Scipy 1.4.1 astropy_healpix 0.5 (errors on line 330 instead of 339 in this version)

Same error on both systems.

Unsuccessful attempt to fix

On System 1, changed .../astropy_healpix/high_level.py at line number 339

return SkyCoord(self.frame.realize_frame(representation))

to be

return SkyCoord(self.frame.realize_frame(self.frame,data=representation))

which bypasses the error and enters the method realize_frame.

Unfortunately this still leads to an error in .../astropy/coordinates/baseframe.py at line number 989

return self._replicate(data, **kwargs)

With the accompanying traceback:

Traceback (most recent call last):
  File "<ipython-input-1-24f6cd72e44c>", line 1, in <module>
    hp.healpix_to_skycoord(55)
  File ".../anaconda3/lib/python3.7/site-packages/astropy_healpix/high_level.py", line 340, in healpix_to_skycoord
    return SkyCoord(self.frame.realize_frame(self.frame,data=representation)) #new edit
  File ".../anaconda3/lib/python3.7/site-packages/astropy/coordinates/baseframe.py", line 989, in realize_frame
    return self._replicate(data, **kwargs)
TypeError: _replicate() missing 1 required positional argument: 'data'

I am not a Python expert so I'm out of ideas on what to try. Additionally, editing baseframe.py in astropy breaks other astropy functions so I can't keep following that rabbit hole.

Any help figuring this out would be greatly appreciated!

lpsinger commented 3 years ago

Replace this:

hp = HEALPix(nside=256, order='nested',frame=Galactic)

with this:

hp = HEALPix(nside=256, order='nested',frame=Galactic())
astrofrog commented 3 years ago

It might be nice to have the string (and maybe class) argument work transparently as the string arguments at least would be more user friendly than having to import the frame classes?

lpsinger commented 3 years ago

Yes, that's a good idea. Would you like to do a PR, or shall I?