I have a large (262615,3)
array of values that all have units attached to them. Specifically originating from this function:
def coordconvert(data):
from astropy.coordinates import SkyCoord
from astropy import units as u
import numpy as np
R = data[:,0]
ra = data[:,1]
dec = data[:,2]
c = SkyCoord(ra=ra*u.degree,dec=dec*u.degree,distance=R*u.mpc)
outdata = c.cartesian.xyz
return outdata
I would like for this array to be unit less so I can easily write it into a textfile. Before anyone links the Stack Exchange question asking something similar, I have tried using .magnitude and it doesn't work. Also I would like to add, due to the nature of my array I would prefer the most efficient possible way of doing so, if possible.
A sample of data:
<Quantity -473.698 mpc> <Quantity -38.3794 mpc> <Quantity -1832.23 mpc>
<Quantity -2269.57 mpc> <Quantity -842.855 mpc> <Quantity -2445.88 mpc>
Your c.cartesian.xyz
is a Quantity object. It has a unit
attribute and a value
attribute.
The value
attribute is a Numpy array and I think is what you want.
Example:
>>> from astropy.coordinates import SkyCoord
>>> c = SkyCoord(10, 20, unit='deg')
>>> c.cartesian.xyz
<Quantity [0.92541658, 0.16317591, 0.34202014]>
>>> c.cartesian.xyz.value
array([0.92541658, 0.16317591, 0.34202014])
>>> type(c.cartesian.xyz.value)
numpy.ndarray
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With