[AstroPy] Design Pattern

Russell Osterlund russellosterlund at gmail.com
Mon Jun 26 18:37:33 EDT 2017


Hi.

When I execute the following:

print( 'v:', np.sqrt( ( G * u.M_sun.to( u.kilogram ) ) / u.au.to( u.meter )
) / 1000 )

this is the output:

v: 29.788833564362875 m(3/2) / (kg(1/2) s)

But when I change the code to this:

print( 'v:', np.sqrt( ( ( G * u.M_sun ) / u.au ) ).to( u.km / u.second ) )

I see this:

v: 29.788833564362875 km / s

The differing output suggests that the correct design pattern is to work
with the constants as-is and only convert using the "to" method when
required, e.g., np.sqrt(), or displaying output. Is this correct?

Thanks in advance.

Russ Osterlund
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170626/1c04ee35/attachment.html>


More information about the AstroPy mailing list