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

旧巷老猫 提交于 2019-12-12 03:36:44

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/35094743/how-to-covert-np-ndarray-into-astropy-coordinates-angle-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!