Astropy:初始化用户定义的坐标系
我正在为Raspberry Pi开发一个应用程序,用于控制AltAzimutal山上的业余望远镜 方位轴与天顶不完全对齐。在这种情况下,可以指向2或3颗恒星,并找到视在望远镜和赤道坐标之间的变换矩阵。这种方法是显而易见的。我想用astropy实现这个方法,但我不明白如何定义倾斜望远镜的参考框架 我计算了transformatin矩阵,并将其作为新框架的参数。但是我犯了一个错误 代码如下:Astropy:初始化用户定义的坐标系,astropy,Astropy,我正在为Raspberry Pi开发一个应用程序,用于控制AltAzimutal山上的业余望远镜 方位轴与天顶不完全对齐。在这种情况下,可以指向2或3颗恒星,并找到视在望远镜和赤道坐标之间的变换矩阵。这种方法是显而易见的。我想用astropy实现这个方法,但我不明白如何定义倾斜望远镜的参考框架 我计算了transformatin矩阵,并将其作为新框架的参数。但是我犯了一个错误 代码如下: # coding: utf-8 """ Astropy coordinate class for th
# 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)
TypeError回溯(最近一次调用)
在()
---->1 mfr=icrs。转换为(m)
/home/maksim/MyPython/astropy/coordinates/baseframe.pyc在转换到(self,new_frame)中
839 msg='无法从{0}转换到{1}'
840 raise CONVERTTERROR(消息格式(self.\uuuuuuu class\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
-->841回程变速器(自、新机架)
842
843 def可转换为(自身、新框架):
/home/maksim/MyPython/astropy/coordinates/transformations.pyc在调用中(self、fromcoord、toframe)
915 frattrs[帧间属性]=属性
916
-->917当前帧=t.tosys(**frattrs)
918当前坐标=t(当前坐标,当前坐标)
919
TypeError:\uuuu init\uuuu()至少接受2个参数(给定1个)
我理解错误信息:我的构造函数的定义与astropy的预期不符
如何将外部矩阵传输到实例?您不需要或不想覆盖框架类上的
\uuuu init\uuuu
以将转换矩阵作为参数包含在内。相反,由于框架类中定义的特定框架依赖于此矩阵,因此应将其定义为FrameAttribute
,如文档中的示例所示:
通过查看这些文档,我可以看到定义框架属性的目的并没有那么清楚。但简而言之,仅仅添加一个\uuuuu init\uuuuu
参数并不能告诉坐标机器该参数/属性的用途——它并不以任何方式表明这是此类帧中帧的定义参数。这是框架需要了解和跟踪的信息
当您在类中将matrix
定义为框架属性时,它将自动为该属性设置访问器(即self.matrix
),并将该矩阵作为框架初始值设定项的参数接受
我不确定它是否立即支持一个
FrameAttribute
,它是初始化帧所必需的(通常每个属性都有一个默认值)。这可以通过围绕基本\uuuu init\uuuu
的简单包装来实现,尽管这对于功能请求来说也不是一个坏主意 使用m=fr.MyFrame(矩阵)
。这就是您定义MyFrame
类的方式:查看参数\uuuu init\uuuu
takes.maksymo我对您的问题进行了编辑,使其更易于理解。请确认我没有改变你说的任何话的意思。