astropy-tutorials icon indicating copy to clipboard operation
astropy-tutorials copied to clipboard

Error "... object has no attribute 'to_value'" in distances.py

Open rr34 opened this issue 2 years ago • 6 comments

Description

Error during the Astronomical Coordinates Astropy tutorial on step 27 where it converts from parallax to parsecs. Error "... object has no attribute 'to_value'" in distances.py on line 148.

Expected behavior

I copy-pasted the code from the tutorial so I expected no errors. Looks like an update that didn't get implemented in that one particular instance in distances.py

Actual behavior

Error, but I think I fixed it on my own system. I found the appropriate wording for equivalency conversions here. I made the change in my local library and successfully completed the tutorial. I suggested the change with a fork on GitHub here.

Steps to Reproduce

  1. Astropy tutorial here.
  2. See step 27.
# Put your Python code snippet here.

System Details

The error and correction occurred the same both on my Windows computer running PyCharm below and Raspberry Pi Zero W.

"C:\Users\nate\PycharmProjects\pythonProject\HelloWorld\Raspberry Pi Zero W\Scripts\python.exe" C:/Users/nate/PycharmProjects/pythonProject/HelloWorld/systemdetails.py Windows-10-10.0.19042-SP0 Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] Numpy 1.21.5 pyerfa 2.0.0.1 astropy 5.0 Scipy 1.7.3 Matplotlib 3.5.1

rr34 avatar Dec 27 '21 16:12 rr34

Welcome to Astropy 👋 and thank you for your first issue!

A project member will respond to you as soon as possible; in the meantime, please double-check the guidelines for submitting issues and make sure you've provided the requested details.

GitHub issues in the Astropy repository are used to track bug reports and feature requests; If your issue poses a question about how to use Astropy, please instead raise your question in the Astropy Discourse user forum and close this issue.

If you feel that this issue has not been responded to in a timely manner, please leave a comment mentioning our software support engineer @embray, or send a message directly to the development mailing list. If the issue is urgent or sensitive in nature (e.g., a security vulnerability) please send an e-mail directly to the private e-mail [email protected].

github-actions[bot] avatar Dec 27 '21 16:12 github-actions[bot]

FYI -- I tranferred this to tutorial repo, in case this is something that can be fixed on the tutorial side. cc @adrn

pllim avatar Dec 27 '21 16:12 pllim

What is the full error message?

eerovaher avatar Dec 27 '21 16:12 eerovaher

Traceback (most recent call last): File "C:\Users\nate\PycharmProjects\pythonProject\HelloWorld\main.py", line 80, in gaia_dist = Distance(parallax=ngc188_table_3d['parallax']) File "C:\Users\nate\PycharmProjects\pythonProject\HelloWorld\Raspberry Pi Zero W\lib\site-packages\astropy\coordinates\distances.py", line 149, in new value = parallax.to_value(u.pc, equivalencies=u.parallax()) AttributeError: 'MaskedColumn' object has no attribute 'to_value'

Sorry. There is the full error.

Nathan Ruffing +1-614-205-1285 https://nathanruffing.com/

----- Original message ----- From: Eero Vaher @.> To: astropy/astropy-tutorials @.> Cc: rr34 @.>, Author @.> Subject: Re: [astropy/astropy-tutorials] Error "... object has no attribute 'to_value'" in distances.py (Issue #512) Date: Monday, December 27, 2021 11:14

What is the full error message?

— Reply to this email directly, view it on GitHub https://github.com/astropy/astropy-tutorials/issues/512#issuecomment-1001638981, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJSGCHUFOBQUDOFSQZN3L5TUTCGFRANCNFSM5K2SVXQQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

rr34 avatar Dec 27 '21 17:12 rr34

The fact that the error mentions MaskedColumn indicates that your data is in a Table, not a QTable, and that is the reason why creating Distance objects fails.

The tutorial writes the Gaia archive query result to a file and then reads it in as a QTable:

In[16]:
ngc188_table = QTable.read('gaia_results.fits')

This ensures that the relevant columns get converted to Quantity (or MaskedQuantity) instances, as explained a few paragraphs below (beginning with "Note that, because the Gaia archive..."). It should be pointed out that writing and reading the data is not required to perform the conversion, it would be enough to do:

ngc188_table = QTable(ngc188_table)

That being said it might be better if astroquery output would already be a QTable instead of a Table, and it might also be a good idea to update the Distance constructor if it becomes less picky about the type of its inputs as a result.

eerovaher avatar Dec 27 '21 18:12 eerovaher

I think the tutorial link you found is a slightly out of date version of the tutorial, so thanks for finding and reporting this, I'll have to track down how to get rid of those pages or at least put a warning up! The newer version of the tutorial is here, which I believe handles the masking issue: https://learn.astropy.org/tutorials/1-Coordinates-Intro.html

adrn avatar Dec 27 '21 19:12 adrn