astropy / astropy-tutorials

Tutorials for the Astropy Project
BSD 3-Clause "New" or "Revised" License
288 stars 170 forks source link

AttributeError in creating SkyCoord object #596

Open SuCh50-Coder opened 1 month ago

SuCh50-Coder commented 1 month ago

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
pllim commented 1 month ago

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.

pllim commented 1 month ago

https://github.com/astropy/astropy-tutorials/blob/main/tutorials/astropy-coordinates/3-Coordinates-Velocities.ipynb

pllim commented 1 month ago

Also see another traceback here: