astropy/astropy-tutorials

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

rr34 opened this issue · 6 comments

rr34 commented

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

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 feedback@astropy.org.

pllim commented

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

What is the full error message?

rr34 commented

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.

adrn commented

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