[AstroPy] How do you create a dimensionless Cartesian coordinate?

Erik Tollerud erik.tollerud at gmail.com
Wed Oct 23 13:59:39 EDT 2013


You probably want this:

from astropy import units as u
from astropy.coordinates import CartesianPoints
cp = CartesianPoints(1, 0, 0, u.dimensionless_unscaled)

`dimensionless_unscaled` is an ordinary unit (with a string
representation of just '', the empty string), so you just pass that in
to indicate the units are supposed to be dimensionless. The reason
this is necessary is that the default argument to `unit` is None, and
None means "no unit given", rather than "dimensionless".




On Tue, Oct 22, 2013 at 1:34 AM, Leo Singer <lsinger at caltech.edu> wrote:
> Hello,
>
> How do you create a dimensionless Cartesian coordinate? If I try the obvious way, by passing pure numbers to the constructor, I get the following exception:
>
> $ python -c "import astropy.coordinates; astropy.coordinates.CartesianPoints(1, 0, 0)"
> ERROR: UnitsError: None is not a valid Unit [astropy.coordinates.distances]
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
>   File "/Users/.../local/lib/python2.7/site-packages/astropy/coordinates/distances.py", line 279, in __new__
>     raise u.UnitsError(str(e))
> astropy.units.core.UnitsError: None is not a valid Unit
>
> This is using the latest build from master, by the way.
>
> Thank you,
> Leo Singer
> Graduate Student @ LIGO-Caltech
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy



-- 
Erik



More information about the AstroPy mailing list