[AstroPy] why the warning about Converting Quantity?
Jonathan Slavin
jslavin at cfa.harvard.edu
Fri Mar 22 12:32:59 EDT 2013
Hi Erik,
In my case I'm actually using AU to convert from data that was returned
from another routine and has units of km to AU (the data are numpy
arrays.) e.g.
AU = constants.au.to('km')
xe = xem/AU # xem is in km, I want xe in AU
I could give xem the units of km in this example, though in fact the
actual expressions are a bit more complicated, but I just wanted to use
the constant value without bothering to look it up. So I'm not, in this
instance, wanting to take advantage of the object's associated units
checking. I think that that should not be so difficult. Often one will
not want to bother to convert all one's data arrays to Quantity objects.
As I said, the constants are convenient for their values as well as the
units checking and it doesn't seem so unlikely that many would like to
use those values in contexts in which they won't want to bother to
define the units of all the other data.
Jon
On Fri, 2013-03-22 at 10:57 -0400, Erik Tollerud wrote:
> Hello Jonathan et al.,
>
> I think some confusion here stems from the fact that ``AU`` is a bit
> of a special constant - in most cases, you're probably better off
> using the AU *unit*, rather than the constant. That is, if you were
> doing something like
>
> arrinau = arr * constants.au
>
> That gives exactly the warning you mentioned, whereas
>
> arrinau = arr * units.au
>
> won't give out a warning, because it creates a `Quantity` object with
> the units `AU`, rather than a regular array without any units.
>
>
> Does that make sense, or am I still misunderstanding how you're using
> this? If the latter, can you give an actual example of the line that
> actually produces this warning? That'll make it easier to understand
> exactly what you're suggesting.
--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________
More information about the AstroPy
mailing list