Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError in creating SkyCoord object #596

Open
SuCh50-Coder opened this issue May 19, 2024 · 3 comments
Open

AttributeError in creating SkyCoord object #596

SuCh50-Coder opened this issue May 19, 2024 · 3 comments
Labels

Comments

@SuCh50-Coder
Copy link

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
Copy link
Member

pllim commented May 19, 2024

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 pllim transferred this issue from astropy/astropy May 19, 2024
@pllim
Copy link
Member

pllim commented May 19, 2024

Also see another traceback here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants