astropy-tutorials
astropy-tutorials copied to clipboard
AttributeError in creating SkyCoord object
Description
I am following the tutorial https://learn.astropy.org/tutorials/3-Coordinates-Velocities.html.
But unable to create the object, it's showing an error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[63], [line 4](vscode-notebook-cell:?execution_count=63&line=4)
[1](vscode-notebook-cell:?execution_count=63&line=1) hd219829_coord = SkyCoord(
[2](vscode-notebook-cell:?execution_count=63&line=2) ra=hd219829_row['ra'],
[3](vscode-notebook-cell:?execution_count=63&line=3) dec=hd219829_row['dec'],
----> [4](vscode-notebook-cell:?execution_count=63&line=4) distance=Distance(parallax=hd219829_row['parallax']),
[5](vscode-notebook-cell:?execution_count=63&line=5) pm_ra_cosdec=hd219829_row['pmra'],
[6](vscode-notebook-cell:?execution_count=63&line=6) pm_dec=hd219829_row['pmdec'],
[7](vscode-notebook-cell:?execution_count=63&line=7) obstime=Time(hd219829_row['ref_epoch'], format='jyear'))
[9](vscode-notebook-cell:?execution_count=63&line=9) hd219829_coord
File c:\Users\hello\anaconda3\Lib\site-packages\astropy\coordinates\distances.py:148, in Distance.__new__(cls, value, unit, z, cosmology, distmod, parallax, dtype, copy, order, subok, ndmin, allow_negative)
[146](file:///C:/Users/hello/anaconda3/Lib/site-packages/astropy/coordinates/distances.py:146) if unit is None:
[147](file:///C:/Users/hello/anaconda3/Lib/site-packages/astropy/coordinates/distances.py:147) unit = u.pc
--> [148](file:///C:/Users/hello/anaconda3/Lib/site-packages/astropy/coordinates/distances.py:148) value = parallax.to_value(unit, equivalencies=u.parallax())
[150](file:///C:/Users/hello/anaconda3/Lib/site-packages/astropy/coordinates/distances.py:150) if np.any(parallax < 0):
[151](file:///C:/Users/hello/anaconda3/Lib/site-packages/astropy/coordinates/distances.py:151) if allow_negative:
AttributeError: 'numpy.float64' object has no attribute 'to_value'
why is this error occuring? I am on windows 11.
Expected behavior
It is expected to create the SkyCoord object
How to Reproduce
import warnings
warnings.filterwarnings("ignore", module="astropy.io.votable.*")
warnings.filterwarnings("ignore", module="pyvo.utils.xml.*")
warnings.filterwarnings('ignore', '.*RADECSYS=*', append=True)
import numpy as np
from astropy import units as u
from astropy.coordinates import SkyCoord, Distance, Galactic
import astropy.coordinates as coord
from astropy.io import fits
from astropy.table import QTable
from astropy.time import Time
from astroquery.gaia import Gaia
gaia_tbl = Gaia.query_object(SkyCoord.from_name('HD 219829'),
radius=1*u.arcmin)
hd219829_row = gaia_tbl[gaia_tbl['phot_g_mean_mag'].argmin()]
hd219829_coord = SkyCoord(
ra=hd219829_row['ra'],
dec=hd219829_row['dec'],
distance=Distance(parallax=hd219829_row['parallax']),
pm_ra_cosdec=hd219829_row['pmra'],
pm_dec=hd219829_row['pmdec'],
obstime=Time(hd219829_row['ref_epoch'], format='jyear'))
Versions
Windows-10-10.0.22631-SP0
Python 3.11.3 | packaged by Anaconda, Inc. | (main, Apr 19 2023, 23:46:34) [MSC v.1916 64 bit (AMD64)]
astropy 5.1
Numpy 1.24.3
pyerfa 2.0.0
Scipy 1.10.1
Matplotlib 3.7.1
Hello. astropy 5.1 is very old and the 5.x series is no longer supported. I am transferring this issue to the tutorials repo, as I feel like this is a matter of the tutorial contents need updating. Thank you for your patience.
https://github.com/astropy/astropy-tutorials/blob/main/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb
Also see another traceback here:
- https://github.com/astropy/astropy/issues/16471
Hi and thank you for raising this issue. I'm sorry no one here has answered this sooner, but as was mentioned, using a more recent version of astropy resolves the issue; I've confirmed the cell you were trying to execute runs on the current version, astropy 7.0.0.
We will update the tutorial requirements to specify a minimum compatible version of astropy for the tutorials. I'm going to close this issue and open another specifically for updating the astropy requirement. Feel free to open another issue if you have any further questions.