pulsar100
pulsar100

Reputation: 41

How to covert np.ndarray into astropy.coordinates.Angle class?

What is the quickest/most efficient way to convert a np.ndarray (importing numpy as np) into the astropy.coordinates.Angle class? I am having trouble keeping it as np.ndarray because the .wrap_at() operation will not work.

Upvotes: 0

Views: 424

Answers (1)

MSeifert
MSeifert

Reputation: 152725

What exactly is your intention? np.asarray is quite ambiguous. If you are dealing with np.ndarray it is quite easy:

from astropy.coordinates import Angle
import astropy.units as u
import numpy as np

angles = np.array([100,200,300,400])
angles_quantity = a * u.degree # Could also be u.radian, u.arcmin, etc.
Angle(angles_quantity).wrap_at('360d')

But I'm not really sure if that solves your problem.

Converting such an Angle object back to a simple np.ndarray can be done with the .value attribute:

Angle(angles_quantity).wrap_at('360d').value # This returns a simple ndarray again.

Upvotes: 4

Related Questions