我正在为Raspberry Pi开发一个应用程序来控制AltAzimutal坐骑上的业余望远镜。
方位角轴与天顶不完全对齐。在这种情况下,可以指向2或3颗星,并找到明显望远镜和赤道坐标之间的变换矩阵。可以看到该方法here。我想用astropy
实现这个方法,但我不明白如何定义倾斜望远镜的参考系。
我计算transformatin矩阵并将其作为新帧的参数。但是我得到了一个错误。
以下是代码:
# coding: utf-8
""" Astropy coordinate class for the tilted telescope coordinate system """
from __future__ import division, print_function
# Third-party
import numpy as np
from numpy import cos, sin
from astropy.coordinates import frame_transform_graph
from astropy.coordinates.angles import rotation_matrix
import astropy.coordinates as coord
import astropy.units as u
__all__ = ["MyFrame"]
import astropy.coordinates as coord
class MyFrame(coord.BaseCoordinateFrame):
"""
A topocentric spherical coordinate system defined by the telescope on tilted Altzimutal mount
http://www.geocities.jp/toshimi_taki/aim/aim.htm
Parameters
----------
matrix: the transformation matrix obtained by 2 stars method ( http://www.geocities.jp/toshimi_taki/aim/aim.htm)
representation : `BaseRepresentation` or None
A representation object or None to have no data (or use the other keywords)
Lambda : `Angle`, optional, must be keyword
The longitude-like angle corresponding to Sagittarius' orbit.
Beta : `Angle`, optional, must be keyword
The latitude-like angle corresponding to Sagittarius' orbit.
"""
default_representation = coord.UnitSphericalRepresentation
frame_specific_representation_info = {
'spherical': [coord.RepresentationMapping('lon', 'az'),
coord.RepresentationMapping('lat', 'alt'),
coord.RepresentationMapping('distance', 'distance')],
'unitspherical': [coord.RepresentationMapping('lon', 'az'),
coord.RepresentationMapping('lat', 'alt')]
}
def __init__(self,matrix,*args, **kwargs):
super(MyFrame, self).__init__(*args, **kwargs)
self.matrix=matrix
# equatorial (ICRS ) to tilted telescope AltAz coordinates
@frame_transform_graph.transform(coord.FunctionTransform, coord.ICRS, MyFrame)
def equatorial_to_telescope(icrs_frame, telescope_frame):
""" Compute the transformation from icrs spherical to
topocentric telescope coordinates.
"""
matrix=np.matrix(([1,0,0],[0,1,0],[0,0,1]))
C0=icrs_frame.represent_as(coord.CartesianRepresentation).xyz.value
l0=matrix.dot(C0)
altAZ=coord.SkyCoord(x=l0[0,0],y=l0[0,1],z=l0[0,2],frame='altaz',representation='cartesian').represent_as(coord.UnitSphericalRepresentation)
return MyFrame(az=altAZ.lon.to(u.deg), alt=altAZ.lat.to(*u.deg))
以下是本课程的致电:
import myFrame as fr
import astropy.coordinates as coord
import astropy.units as u
import numpy as np
matrix=np.matrix(([1,0,0],[0,1,0],[0,0,1]))
m=fr.MyFrame()
icrs = coord.ICRS(152.88572*u.degree, 11.57281*u.degree)
mfr=icrs.transform_to(m)
以下是错误代码:
TypeError Traceback (most recent call last)
<ipython-input-14-33f2cd1fa087> in <module>()
----> 1 mfr=icrs.transform_to(m)
/home/maksim/MyPython/astropy/coordinates/baseframe.pyc in transform_to(self, new_frame)
839 msg = 'Cannot transform from {0} to {1}'
840 raise ConvertError(msg.format(self.__class__, new_frame.__class__))
--> 841 return trans(self, new_frame)
842
843 def is_transformable_to(self, new_frame):
/home/maksim/MyPython/astropy/coordinates/transformations.pyc in __call__(self, fromcoord, toframe)
915 frattrs[inter_frame_attr_nm] = attr
916
--> 917 curr_toframe = t.tosys(**frattrs)
918 curr_coord = t(curr_coord, curr_toframe)
919
TypeError: __init__() takes at least 2 arguments (1 given)
我理解错误消息:我的构造函数的定义与astropy
BaseFrame的期望不符。
如何将extern矩阵传输到BaseCoordinateFrame实例?
答案 0 :(得分:4)
您不需要或想要覆盖帧类的__init__
以包含转换矩阵作为参数。相反,因为帧类中定义的特定帧依赖于此矩阵,所以应将其定义为FrameAttribute
,如文档中的示例所示:http://docs.astropy.org/en/stable/coordinates/frames.html#defining-a-new-frame
查看这些文档,我可以看到定义框架属性的目的并不尽如人意。但简而言之,仅仅添加一个__init__
参数就告诉坐标机器没有关于该参数/属性的目的 - 它不以任何方式表明这是这类帧中帧的定义参数。这是框架需要了解和跟踪的信息。
当您在类上定义matrix
作为帧属性时,它将自动设置属性的访问器(即self.matrix
),并且还接受矩阵作为帧初始化器的参数。
我不确定这会立即支持的一件事是FrameAttribute
是必需来初始化帧(通常每个属性都有一个默认值)。这可以通过基础__init__
周围的简单包装器来实现,尽管对于功能请求也可能不是一个坏主意。