座標系の使用と設計

はい。 astropy.coordinates 例えば、 概要 astropy.coordinates 概念 、の子類 BaseCoordinateFrame (“フレームクラス”)特定の座標フレームを定義する.彼らはできる(でもできない) have )実座標データを格納する表示オブジェクトを含む.実際の座標変換は,フレームワーククラス間で表現法を変換する関数として定義される.この方法は、高度なユーザ機能を分離するために使用される(参照 SkyCoord高級クラスを使用して )および座標の実際の記憶方式の詳細(参照) 使用と設計座標表現法 )フレームの定義およびそれらがどのように変換されるかから。

フレームワークオブジェクトの使用

データのないフレーム

Frameオブジェクトには2つの異なる(ただし関連する)用途がある.1つ目は、フレームを一意に定義するために必要な情報(例えば、春分、観測時間)を格納することである。この情報は、最初にオブジェクトを作成する際に設定されたPython属性としてFrameオブジェクトに格納されます:

>>> from astropy.coordinates import ICRS, FK5
>>> FK5(equinox='J1975')
<FK5 Frame (equinox=J1975.000)>
>>> ICRS()  # has no attributes
<ICRS Frame>
>>> FK5()  # uses default equinox
<FK5 Frame (equinox=J2000.000)>

特定のフレームに利用可能な特定の属性名(およびそのデフォルト値)をクラス方法として使用することができる get_frame_attr_names **

>>> FK5.get_frame_attr_names()
{'equinox': <Time object: scale='tt' format='jyear_str' value=J2000.000>}

標準的なPython属性アクセスを使用して、フレームワーク上の任意の属性にアクセスすることができます。このような場合には equinox これらは時間入力であり,明確な時間文字列が入力されると変換される. Time 対象(参照) 入力形式を推定する ):

>>> f = FK5(equinox='J1975')
>>> f.equinox
<Time object: scale='tt' format='jyear_str' value=J1975.000>
>>> f = FK5(equinox='2011-05-15T12:13:14')
>>> f.equinox
<Time object: scale='utc' format='isot' value=2011-05-15T12:13:14.000>

データ付きフレーム

Frameオブジェクトの第2の用途は、上述したフレームの実際に実装された座標データを格納することである。この使い方では SkyCoord クラス実際には SkyCoord クラスは内部でFrameクラスを用いて実現する.しかし,Frame類の“利便性”機能は少なく,Frame類の実現を簡略化している.これらの作成方法は SkyCoord 物体です。1つの提案方法は、フレームに適したキーワードと共に使用することである(例えば、 ra そして dec 赤道系では):

>>> from astropy import units as u
>>> ICRS(ra=1.1*u.deg, dec=2.2*u.deg)  
<ICRS Coordinate: (ra, dec) in deg
    (1.1, 2.2)>
>>> FK5(ra=1.1*u.deg, dec=2.2*u.deg, equinox='J1975')  
<FK5 Coordinate (equinox=J1975.000): (ra, dec) in deg
    (1.1, 2.2)>

これらの属性は、以下に示すように、ブロック内のデータにアクセスするために使用することができる Angle 対象(または Angle サブクラス)::

>>> coo = ICRS(ra=1.1*u.deg, dec=2.2*u.deg)
>>> coo.ra  
<Longitude 1.1 deg>
>>> coo.ra.value  
1.1
>>> coo.ra.to(u.hourangle)  
<Longitude 0.07333333 hourangle>

ご利用いただけます representation_type 属性と representation_component_names 属性は,特定のクラスオブジェクトがどのキーワードを受け取るかを決定する.前者は、システムの表示クラス(例えば、赤道フレームに対して球形)を表し、後者は、そのフレームの名前をクラス上の属性名を表す辞書にマッピングする。

>>> import astropy.units as u
>>> icrs = ICRS(1*u.deg, 2*u.deg)
>>> icrs.representation_type
<class 'astropy.coordinates.representation.SphericalRepresentation'>
>>> icrs.representation_component_names
{'ra': 'lon', 'dec': 'lat', 'distance': 'distance'}

必要に応じて、異なる表現形式のデータを取得することができます:

>>> icrs.represent_as('cartesian')  
<CartesianRepresentation (x, y, z) [dimensionless]
     (0.99923861, 0.01744177, 0.0348995)>

注釈

Astropyの初期バージョンでは,現在Frameクラスと名付けられたFrame属性とパラメータ representation_type かつては簡単だった representation それがそうです。この属性/パラメータの名前は表現を指すため混同される クラス 下位フレームデータを含むオブジェクトではなく(Frame属性でアクセスする. .data )である。明確にするために私たちは名前を変えました representation 至る representation_type それがそうです。このバージョン3.0では,文書中のこの属性への参照のみを変更した.次の主なバージョンで、私たちは廃棄警告を発表するつもりだ。2つの主なバージョンでは削除します .representation 属性と representation= 論争する。

座標オブジェクトの表示は,以下のように直接変更することも可能である.これは…。 何でもない 座標値を記憶するオブジェクト内部データには、2つの方法でデータの外部ビューを変更する:(1)オブジェクトは、新しい表現に応じて自身を印刷し、(2)新しい表現の属性に一致するように属性を変更することができる(例えば、から。 ra, dec, distance 至る x, y, z )である。設ける representation_type そこで変わったのは 財産性. オブジェクトの外観)は、3 D空間内の点を表す固有のオブジェクト自体を変更することなく。

>>> from astropy.coordinates import CartesianRepresentation
>>> icrs.representation_type = CartesianRepresentation
>>> icrs  
<ICRS Coordinate: (x, y, z) [dimensionless]
    (0.99923861, 0.01744177, 0.0348995)>
>>> icrs.x  
<Quantity 0.99923861>

この表現は、座標を作成する際に設定され、座標データを提供するためのキーワードセットに影響を与えることもできる。例えば、デカルトデータを用いて座標を作成するには、以下の動作を実行してください。

>>> ICRS(x=1*u.kpc, y=2*u.kpc, z=3*u.kpc, representation_type='cartesian')  
<ICRS Coordinate: (x, y, z) in kpc
    (1., 2., 3.)>

座標にマッピング表現を用いたより多くの情報については、参照されたい 表示法 部分的には,表示自体の詳細については,参照されたい 使用と設計座標表現法 それがそうです。

座標を用いてフレームクラスを作成するもう2つの方法がある.表現クラスは、作成時に直接入力することができ、必要な任意のフレーム属性:

>>> from astropy.coordinates import SphericalRepresentation
>>> rep = SphericalRepresentation(lon=1.1*u.deg, lat=2.2*u.deg, distance=3.3*u.kpc)
>>> FK5(rep, equinox='J1975')  
<FK5 Coordinate (equinox=J1975.000): (ra, dec, distance) in (deg, deg, kpc)
    (1.1, 2.2, 3.3)>

最後の方法は realize_frame 方法です。これは、同じ属性を有するフレームを生成するが、新しいデータを生成する:

>>> f1 = FK5(equinox='J1975')
>>> f1
<FK5 Frame (equinox=J1975.000)>
>>> rep = SphericalRepresentation(lon=1.1*u.deg, lat=2.2*u.deg, distance=3.3*u.kpc)
>>> f1.realize_frame(rep)  
<FK5 Coordinate (equinox=J1975.000): (ra, dec, distance) in (deg, deg, kpc)
    (1.1, 2.2, 3.3)>

属性はFrameオブジェクトにデータがあるかどうかを調べる. has_data 属性は,その属性が存在すれば, data 属性::

>>> ICRS().has_data
False
>>> cooi = ICRS(ra=1.1*u.deg, dec=2.2*u.deg)
>>> cooi.has_data
True
>>> cooi.data  
<UnitSphericalRepresentation (lon, lat) in deg
    (1.1, 2.2)>

上記のすべての方法は、配列データ(クラス:`~Asterpy.units.Quantity`または他のPythonシーケンスの形態で)を受け入れて座標配列を作成することもできる。

>>> ICRS(ra=[1.5, 2.5]*u.deg, dec=[3.5, 4.5]*u.deg)  
<ICRS Coordinate: (ra, dec) in deg
    [(1.5, 3.5), (2.5, 4.5)]>

ミックス配列およびスカラが着信した場合、配列は、それに応じてスカラ上でブロードキャストされる:

>>> ICRS(ra=[1.5, 2.5]*u.deg, dec=[3.5, 4.5]*u.deg, distance=5*u.kpc)  
<ICRS Coordinate: (ra, dec, distance) in (deg, deg, kpc)
    [(1.5, 3.5, 5.), (2.5, 4.5, 5.)]>

別のフレームに変換される場合、同様のブロードキャストが発生する。例えば:

>>> import numpy as np
>>> from astropy.coordinates import EarthLocation, AltAz
>>> coo = ICRS(ra=180.*u.deg, dec=51.477811*u.deg)
>>> lf = AltAz(location=EarthLocation.of_site('greenwich'),
...            obstime=['2012-03-21T00:00:00', '2012-06-21T00:00:00'])
>>> lcoo = coo.transform_to(lf)  # this can load finals2000A.all 
>>> lcoo  
<AltAz Coordinate (obstime=['2012-03-21T00:00:00.000' '2012-06-21T00:00:00.000'], location=(3980608.9024681724, -102.47522910648239, 4966861.273100675) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0.0, obswl=1.0 micron): (az, alt) in deg
    [( 94.71264993, 89.21424259), (307.69488825, 37.98077772)]>

上の形は- () 上の coo そして (2,) 上の lf -互いに放送されている座標のセットの位置を決定するためには、以下の動作を実行することができるように形状を保証する必要がある。

>>> coo2 = ICRS(ra=[180., 225., 270.]*u.deg, dec=[51.5, 0., 51.5]*u.deg)
>>> coo2.transform_to(lf)
Traceback (most recent call last):
...
ValueError: operands could not be broadcast together...
>>> coo2.shape
(3,)
>>> lf.shape
(2,)
>>> lf2 = lf[:, np.newaxis]
>>> lf2.shape
(2, 1)
>>> coo2.transform_to(lf2)  
<AltAz Coordinate (obstime=[['2012-03-21T00:00:00.000' '2012-03-21T00:00:00.000'
  '2012-03-21T00:00:00.000']
 ['2012-06-21T00:00:00.000' '2012-06-21T00:00:00.000'
  '2012-06-21T00:00:00.000']], location=(3980608.90246817, -102.47522911, 4966861.27310068) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0.0, obswl=1.0 micron): (az, alt) in deg
    [[( 93.09845183, 89.21613128), (126.85789664, 25.4660055 ),
      ( 51.37993234, 37.18532527)],
     [(307.71713698, 37.99437658), (231.3740787 , 26.36768329),
      ( 85.42187236, 89.69297998)]]>

注釈

データのないフレームは shape これは,それらのフレーム属性によって決定される.データを含むフレームでは shape 常にデータの属性であり、任意の非スカラ属性は、一致する形状を有するようにブロードキャストされる(図に示すように obstime 上の最後の行にあります)。

配列値Frameオブジェクト中の座標値を定位置で修正することができる(Asterpy 4.1に加える).これは、実際の座標データ値を除くすべての点で等価である別のフレームオブジェクトから新しい値を設定することを要求する。このように、フレーム変換を必要とせず、プロジェクト設定動作は非常にロバストである。

座標配列を修正するには,Numpy配列と同じ文法を用いてください:

>>> coo1 = ICRS([1, 2] * u.deg, [3, 4] * u.deg)
>>> coo2 = ICRS(10 * u.deg, 20 * u.deg)
>>> coo1[0] = coo2
>>> coo1
<ICRS Coordinate: (ra, dec) in deg
    [(10., 20.), ( 2.,  4.)]>

この方法は、既存のFrameオブジェクトから設定する必要があり、動作が有効であることを保証するために広範な検証を実行するために比較的遅い。いくつかのアプリケーションの場合、部分的に説明したように、異なるより低いレベルの方法をとる必要がある場合がある 座標の高速定位置修正 それがそうです。

警告

Frameオブジェクトをその場で修正するために、例えば、コンポーネント属性を直接更新するための明らかな方法を試みることができるかもしれません。 coo1.ra[1] = 40 * u.deg それがそうです。しかしこれは 現れる 正しい結果を与えるために,実際には下位表現データを修正しない.これは,現在実現されている性能ベースのキャッシュに関連している.現在のキャッシュ実現でも,表示の定位置変更を扱うことはできない. (.data )やフレーム属性など .obstime それがそうです。

フレーム間の変換

データを含むFrameオブジェクトを別のフレームに変換するには、ご利用ください transform_to 方法は、変換されるべきフレームを提供する。このフレームワークはフレームオブジェクト(座標データを持つか持たないか)であるべきである.すべてのデフォルトフレーム属性を使用したい場合、パラメータ(すなわち、空括弧)を持たないFrameクラスをインスタンス化することができる:

>>> cooi = ICRS(1.5*u.deg, 2.5*u.deg)
>>> cooi.transform_to(FK5())  
<FK5 Coordinate (equinox=J2000.000): (ra, dec) in deg
    (1.50000661, 2.50000238)>
>>> cooi.transform_to(FK5(equinox='J1975'))  
<FK5 Coordinate (equinox=J1975.000): (ra, dec) in deg
    (1.17960348, 2.36085321)>

♪the 参照/API 中に内蔵されているすべてのフレームのリスト。 astropy.coordinates そして,それらの間で定義された変換である.有効な経路を持つ変換は,他のフレームを通過しても変換可能である.プログラミング方式で動作変換をチェックまたはチェックする場合は、参照されたい TransformGraph 書類です。

新しい枠組みを定義する

接続を実現する astropy.coordinates インフラはサブクラス化によって行うことができる BaseCoordinateFrame それがそうです。以下にいくつかのガイダンスおよび例を示すが、文書文字列には、新しいフレームワークを作成するための詳細な説明が示されている。 BaseCoordinateFrame それがそうです。

全ての枠は少なくとも定義することで default_representation Class属性(参照) 使用と設計座標表現法 支持されている Representation 対象)。

実例.

デフォルトで球面座標でその座標データを受信したい新しいフレームを作成するために、以下に示すようにサブクラスを作成します。

>>> from astropy.coordinates import BaseCoordinateFrame
>>> import astropy.coordinates.representation as r
>>> class MyFrame1(BaseCoordinateFrame):
...     # Specify how coordinate values are represented when outputted
...     default_representation = r.SphericalRepresentation

これは効果的なフレームワーククラスです

>>> fr = MyFrame1(1*u.deg, 2*u.deg)
>>> fr 
<MyFrame1 Coordinate: (lon, lat) in deg
    (1., 2.)>
>>> fr.lon 
<Longitude 1. deg>

However, as we have defined it above, (1) the coordinate component names will be the same as used in the specified default_representation (in this case, lon, lat, and distance for longitude, latitude, and distance, respectively), (2) this frame does not have any additional attributes or metadata, (3) this frame does not support transformations to any other coordinate frame, and (4) this frame does not support velocity data. We can address each of these points by seeing some other ways of customizing frame subclasses.

カスタムフレームワークコンポーネント名

第一に、(1)点で述べたように above ,あるFrameクラスはそのコンポーネントに対して特殊な名前を持つ.例えば ICRS 赤道フレームや他の赤道フレーム類は,経度の代わりに“右昇”や“RA”を用い,経度の代わりに“赤緯”または“12月”を用いるのが一般的である。緯度ではありませんこれらのコンポーネント名を書き換えると、フレームワーク·コンポーネント名のデフォルト値が変更され、これらのデフォルト名が取られます。 Representation クラスは、グループを指定することで RepresentationMapping インスタンス(各コンポーネント1つ)は、Frameクラス上で付加クラス属性を定義する一部として: frame_specific_representation_info それがそうです。この属性は辞書でなければならず、キーは Representation あるいは…。 Differential クラス(カスタム速度コンポーネントの振舞いに関する議論は,以下を参照されたい,これは通過する. Differential 類)。上記で実装された例示的なフレームワークを使用して、“lon”および“lat”ではなく、名前“R”および“D”を使用するようにカスタマイズすることができる:

>>> from astropy.coordinates import RepresentationMapping
>>> class MyFrame2(BaseCoordinateFrame):
...     # Specify how coordinate values are represented when outputted
...     default_representation = r.SphericalRepresentation
...
...     # Override component names (e.g., "ra" instead of "lon")
...     frame_specific_representation_info = {
...         r.SphericalRepresentation: [RepresentationMapping('lon', 'R'),
...                                     RepresentationMapping('lat', 'D')]
...     }

この枠組みを使って、私たちは今名前を使うことができます R そして D フレームデータにアクセスするには、以下の動作を実行してください。

>>> fr = MyFrame2(3*u.deg, 4*u.deg)
>>> fr 
<MyFrame2 Coordinate: (R, D) in deg
    (3., 4.)>
>>> fr.R 
<Longitude 3. deg>

私たちは何のためにも Representation 中のクラス astropy.coordinates デフォルトコンポーネント名を変更する場合は、以下の操作を実行してください。例えば Galactic Frameはaとともに使用する際に標準経度と緯度名“l”と“b”を用いる. SphericalRepresentation ただし、表示形式をさらに“x”、“y”、“z”に変更する際には、コンポーネント名“x”、“y”、“z”が使用される。 CartesianRepresentation それがそうです。上記の例では、デフォルトの“x”、“y”および“z”ではなく、デカルトコンポーネント名“a”、“b”、および“c”をカバーするための追加のマッピングのセットを追加することができる。

>>> class MyFrame3(BaseCoordinateFrame):
...     # Specify how coordinate values are represented when outputted
...     default_representation = r.SphericalRepresentation
...
...     # Override component names (e.g., "ra" instead of "lon")
...     frame_specific_representation_info = {
...         r.SphericalRepresentation: [RepresentationMapping('lon', 'R'),
...                                     RepresentationMapping('lat', 'D')],
...         r.CartesianRepresentation: [RepresentationMapping('x', 'a'),
...                                     RepresentationMapping('y', 'b'),
...                                     RepresentationMapping('z', 'c')]
...     }

はい、何でも。 RepresentationMapping 属性は、コンポーネントのデフォルト単位を指定することもできます。 defaultunit キーワードパラメータ。

フレームワーク属性を定義する

第2に,図中の点(2)に示す. introduction above 座標フレームの場合、所与のフレームといくつかの他のフレームとの間の変換を完全に指定するために、追加のデータまたはパラメータを指定することができるフレーム“属性”を指定することが一般的に有用である。例えば FK5 frame allows specifying an equinox that helps define the transformation between FK5 and the ICRS frame. Frame attributes are defined by creating class attributes that are instances of Attribute or its subclasses (e.g., TimeAttribute, QuantityAttribute, etc.). If attributes are defined using these classes, there is often no need to define an ``_ _init__≡`関数は,中の初期値設定項として BaseCoordinateFrame あなたが望むように行動するかもしれません。では、上のおもちゃフレームクラス実装を修正して、2つのフレーム属性を追加しましょう。

>>> from astropy.coordinates import TimeAttribute, QuantityAttribute
>>> class MyFrame4(BaseCoordinateFrame):
...     # Specify how coordinate values are represented when outputted
...     default_representation = r.SphericalRepresentation
...
...     # Override component names (e.g., "ra" instead of "lon")
...     frame_specific_representation_info = {
...         r.SphericalRepresentation: [RepresentationMapping('lon', 'R'),
...                                     RepresentationMapping('lat', 'D')],
...         r.CartesianRepresentation: [RepresentationMapping('x', 'a'),
...                                     RepresentationMapping('y', 'b'),
...                                     RepresentationMapping('z', 'c')]
...     }
...
...     # Specify frame attributes required to fully specify the frame
...     time = TimeAttribute(default='B1950')
...     orientation = QuantityAttribute(default=42*u.deg)

初期値設定項を指定しない場合には,これらの属性を定義すると通知される. BaseCoordinateFrame サブクラスの初期値設定項に渡すパラメータ付加では何が発生するか.例えば,我々のサブクラスを用いてFrameインスタンスを定義する場合,我々は現在,以下の属性指定値として選択することができる.

>>> fr = MyFrame4(R=1*u.deg, D=2*u.deg, orientation=21*u.deg)
>>> fr 
<MyFrame4 Coordinate (time=B1950.000, orientation=21.0 deg): (R, D) in deg
    (1., 2.)>

デフォルト値を使用して2つのフレーム属性を指定しているので、フレーム初期化器の選択可能なパラメータであることに留意されたい。なお,フレーム属性は現在表示されている. repr 上のフレームワークインスタンスの。追加的な報酬としてほとんどの場合 Attribute サブクラスは,初期値設定項が定義されていなくても,パラメータとして指定された属性を検証する.例えば入力されたパラメータは QuantityAttribute 属性が期待属性単位と有効かつ互換性のある単位を持つかどうかを調べる.上のフレームワークの例を使って orientation 角度単位を使用した場合、入力時間はエラーを引き起こす:

>>> MyFrame4(R=1*u.deg, D=2*u.deg, orientation=55*u.microyear) 
Traceback (most recent call last):
...
UnitConversionError: 'uyr' (time) and 'deg' (angle) are not convertible

フレーム属性を定義する際には,つねにデフォルト値を指定する必要はない. Attribute サブクラスは入力を検証することができる.例えば上のフレームについては orientation デフォルト値は必要ありませんが、角度単位を強制したいです。

orientation = QuantityAttribute(unit=u.deg)

上記の場合、もし orientation 新しいフレームワーク·インスタンスを作成する際に指定されていない場合、その値は None :フレームワーククラスと変換関数によってどのように処理するかを定義することに注意されたい. None 価値がある。ほとんどの場合 None “この値に対して異なるフレーム属性を使用する”や同様の場合のような特殊な場合を表すべきである.

カスタム属性の表示

デフォルト設定は repr for coordinate frames is suitable for most cases, you may want to customize how frame attributes are displayed in certain cases. To do this you can define a method named ``_ Astpy_Repr_in_Frame゚`。この方法はFrame属性自体に設定されたオブジェクト上で定義されるべきである. not ♪the Attribute 記述子。

例を引く

方法の一例として _astropy_repr_in_frame 物体があるとしましょう Spam この属性はフレームワークの属性として:

>>> class Spam:
...     def _astropy_repr_in_frame(self):
...         return "<A can of Spam>"

フレームワークがこれを属性とする場合:

>>> from astropy.coordinates import Attribute
>>> class Egg(BaseCoordinateFrame):
...     can = Attribute(default=Spam())

フレームに表示されると _astropy_repr_in_frame **

>>> Egg()
<Egg Frame (can=<A can of Spam>)>

フレーム間の変換を定義する.

図中の点(3)に示す. introduction above また,フレームワーククラスと他の座標フレームクラスとの変換を定義する前に,フレームワーククラス自体はあまり有用ではない可能性がある.変換の重要な概念を定義する astropy.coordinates “フレーム変換図”(“図論”の意味では、“描画”ではなく)であり、内蔵フレーム間のすべての変換を格納し、合成変換によって任意のフレームから任意の他のフレームに変換するために、この図を介して最短経路を探すための手段である。この概念の背後にある強力な機能は、ユーザが作成したフレームワークにも適用可能であり、これは、あなたのフレームからグラフのいずれかのフレームへの変換が定義されると、フレームワークで定義された座標が変換されることを意味します。 any グラフ中の他のフレーム。コードには以下のように“フレーム変換図”が提供されている. astropy.coordinates.frame_transform_graph これは TransformGraph 級友たち。

変換自体は CoordinateTransform 対象またはそのサブクラス。変換された有用なサブクラス/タイプは、:

  • FunctionTransform

    1つのFrameクラスのFrameオブジェクトを受け取り,別のクラスのオブジェクトを返す関数の変換として定義する.

  • AffineTransform

    線形行列演算およびシフト(ベクトルオフセット)の変換を含む。これらの変換は,3 x 3行列とオフセットの3ベクトル(デカルト表現形式で与えられる)で定義される.この変換は、1フレームのデカルト表現に適用され、目標フレームのデカルト表現に変換される。

  • StaticMatrixTransform

  • DynamicMatrixTransform

    行列変換は AffineTransform 平行移動(すなわち回転のみ)を持たない変換.静的バージョンは、行列がフレーム属性とは独立している場合に適用される(例えば、ICRS−>FK 5変換は、ICRSにはフレーム属性がないので)。動的な場合は、変換行列がToまたはFromフレームのフレーム属性に依存する変換に適用される。

通常,これらのクラスを直接使用する必要はない.代わりに使うのは frame_transform_graph 機能装飾符として使うことができます。実際の変換を行う関数を定義する(では FunctionTransform )、または変換のために必要な変換行列を計算する。次いで、これらの変換をフレーム変換マップを使用して登録するために関数を装飾する:

from astropy.coordinates import frame_transform_graph

@frame_transform_graph.transform(DynamicMatrixTransform, ICRS, FK5)
def icrs_to_fk5(icrscoord, fk5frame):
    ...

@frame_transform_graph.transform(DynamicMatrixTransform, FK5, ICRS)
def fk5_to_icrs(fk5coord, icrsframe):
    ...

関心のある座標枠の変換が行列演算で表すことができない場合には、1つの関数を指定して実際の変換を実行してもよい。 FunctionTransform クラス設定変換グラフィックス修飾器::

@frame_transform_graph.transform(FunctionTransform, FK4NoETerms, FK4)
def fk4_no_e_to_fk4(fk4noecoord, fk4frame):
    ...

また、 frame_transform_graph 1つのフレームから別のフレームに転送しようと最初に試みた後、変換速度を高速化するためにいくつかのキャッシュおよび最適化が実行され、関連するステップにおいてショートカットが設定される(例えば、複数の静的行列変換が1つの行列に統合される)。したがって,一般に,最適化やキャッシュ変換を心配してプロセスを高速化するのではなく,ユーザ定義のフレームワークのために最も自然な変換を定義することが望ましい.

変換速度成分にも利用可能な変換関数をどのように定義するかについては,参照されたい. 速度変換フレームを使う それがそうです。

フレーム内の速度データをサポート

本文書の第(4)点が示唆しているように introduction above 以上で見た例は,主に位置情報のカスタムフレームワークアクションを扱う.(中で速度をどのように扱うかに関するいくつかの文脈 astropy.coordinates 要約を読むのは役立つかもしれません 速度データを用いたフレームワークオブジェクトの作成 ()

When defining a frame class, it is also possible to set a default_differential (analogous to default_representation), and to customize how velocity data components are named. Expanding on our custom frame example above, we can use RepresentationMapping to override Differential component names. The default Differential components are typically named after the corresponding Representation component, preceded by d_. So, for example, the longitude Differential component is, by default, d_lon. However, there are some defaults to be aware of. Here, if we set the default Differential class to also be Spherical, it will implement a set of default "nicer" names for the velocity components, mapping pm_R to d_lon, pm_D to d_lat, and radial_velocity to d_distance (taking the previously overridden longitude and latitude component names):

>>> class MyFrame4WithVelocity(BaseCoordinateFrame):
...     # Specify how coordinate values are represented when outputted
...     default_representation = r.SphericalRepresentation
...     default_differential = r.SphericalDifferential
...
...     # Override component names (e.g., "ra" instead of "lon")
...     frame_specific_representation_info = {
...         r.SphericalRepresentation: [RepresentationMapping('lon', 'R'),
...                                     RepresentationMapping('lat', 'D')],
...         r.CartesianRepresentation: [RepresentationMapping('x', 'a'),
...                                     RepresentationMapping('y', 'b'),
...                                     RepresentationMapping('z', 'c')]
...     }
>>> fr = MyFrame4WithVelocity(R=1*u.deg, D=2*u.deg,
...                           pm_R=3*u.mas/u.yr, pm_D=4*u.mas/u.yr)
>>> fr 
<MyFrame4WithVelocity Coordinate: (R, D) in deg
    (1., 2.)
(pm_R, pm_D) in mas / yr
    (3., 4.)>

デフォルトの“より良い”という名前を上書きするには、 frame_specific_representation_info どのようなものでも Differential クラス、例えば:

>>> class MyFrame4WithVelocity2(BaseCoordinateFrame):
...     # Specify how coordinate values are represented when outputted
...     default_representation = r.SphericalRepresentation
...     default_differential = r.SphericalDifferential
...
...     # Override component names (e.g., "ra" instead of "lon")
...     frame_specific_representation_info = {
...         r.SphericalRepresentation: [RepresentationMapping('lon', 'R'),
...                                     RepresentationMapping('lat', 'D')],
...         r.CartesianRepresentation: [RepresentationMapping('x', 'a'),
...                                     RepresentationMapping('y', 'b'),
...                                     RepresentationMapping('z', 'c')],
...         r.SphericalDifferential: [RepresentationMapping('d_lon', 'pm1'),
...                                   RepresentationMapping('d_lat', 'pm2'),
...                                   RepresentationMapping('d_distance', 'rv')]
...     }
>>> fr = MyFrame4WithVelocity2(R=1*u.deg, D=2*u.deg,
...                           pm1=3*u.mas/u.yr, pm2=4*u.mas/u.yr)
>>> fr 
<MyFrame4WithVelocity2 Coordinate: (R, D) in deg
    (1., 2.)
(pm1, pm2) in mas / yr
    (3., 4.)>

おわりに

また、フレームワークがこのフレームワーク固有の追加機能を有することを望む任意の方法を定義することができます。これらの方法は SkyCoord これは,ユーザ定義のフレームワークを用いて作成される.

フレームクラスを定義する例については,まず,含まれるフレームのソースコードを見る. astropy (いられる) astropy.coordinates.builtin_frames )である。これらは、特殊なサイズではなく、ユーザが作成したフレームワークを使用して利用可能なすべての同じAPIおよび機能である。

例えば:

また見られる. 新しい座標類(射手座用)を作成する 新しい座標フレームを定義するより多くの注釈例については、参照されたい。