使用和设计坐标表示法#
三维矢量空间中的点可以用不同的方式表示,如笛卡尔、球面极轴、圆柱等。这些是协调数据的基础 astropy.coordinates 表示,如中所述 概述 astropy.coordinates 概念 . 下面,我们将介绍如何单独使用它们作为在不同表示(包括非内置表示)之间进行转换的方法,以及如何进行简单的向量运算。
内置表示类包括:
CartesianRepresentation:笛卡尔坐标x,y和z.SphericalRepresentation:以经度表示的球面极坐标 (lon),一个纬度 (lat),还有一段距离 (distance). 纬度是-90到90度之间的值。UnitSphericalRepresentation:单位球体上的球面极坐标,用经度表示 (lon)和纬度 (lat)PhysicsSphericalRepresentation:球面极坐标,用倾角表示 (theta)和方位角 (phi),和半径r. 倾角从0度到180度,与纬度有关SphericalRepresentation通过theta = 90 deg - lat.CylindricalRepresentation:圆柱极坐标,用圆柱半径表示 (rho),方位角 (phi),和高度 (z)
Astropy还提供了一个 BaseGeodeticRepresentation 以及一个 BaseBodycentricRepresentation 对于在球体上创建特定表示非常有用。
BaseGeodeticRepresentation 是椭球体(赤道半径相等的椭球体)表面上的坐标表示,用经度表示 (lon 大地纬度 (lat )和高度 (height )在地表以上。大地纬度是由椭球体上某一特定点的垂线与其在赤道平面上的投影之间的夹角来定义的。纬度是一个从-90度到90度的值,经度是从0度到360度,高度是椭球体曲面上方的高程(垂直于曲面测量)。
BaseBodycentricRepresentation is the coordinate representation recommended by the Cartographic Coordinates & Rotational Elements Working Group (see for example its 2019 report) :人体重心的纬度和经度是相对于身体重心的球状纬度和经度,高度是到球体表面的距离(径向测量)。纬度是-90到90度之间的值,经度是0到360度之间的值。
BaseGeodeticRepresentation is used internally for the standard
Earth ellipsoids used in
EarthLocation
(WGS84GeodeticRepresentation,
WGS72GeodeticRepresentation, and
GRS80GeodeticRepresentation).
BaseGeodeticRepresentation and
BaseBodycentricRepresentation
can be customized as described in 创建您自己的大地测量表示和身体中心表示.
实例化和转换#
表示类实例化为 Quantity 物体::
>>> from astropy import units as u
>>> from astropy.coordinates.representation import CartesianRepresentation
>>> car = CartesianRepresentation(3 * u.kpc, 5 * u.kpc, 4 * u.kpc)
>>> car
<CartesianRepresentation (x, y, z) in kpc
(3., 5., 4.)>
数组 Quantity 对象也可以传递给表示。它们将具有预期的形状,可以使用与 ndarray ,如 reshape , ravel 等::
>>> x = u.Quantity([[1., 0., 0.], [3., 5., 3.]], u.m)
>>> y = u.Quantity([[0., 2., 0.], [4., 0., -4.]], u.m)
>>> z = u.Quantity([[0., 0., 3.], [0., 12., -12.]], u.m)
>>> car_array = CartesianRepresentation(x, y, z)
>>> car_array
<CartesianRepresentation (x, y, z) in m
[[(1., 0., 0.), (0., 2., 0.), (0., 0., 3.)],
[(3., 4., 0.), (5., 0., 12.), (3., -4., -12.)]]>
>>> car_array.shape
(2, 3)
>>> car_array.ravel()
<CartesianRepresentation (x, y, z) in m
[(1., 0., 0.), (0., 2., 0.), (0., 0., 3.), (3., 4., 0.),
(5., 0., 12.), (3., -4., -12.)]>
可以使用 represent_as 方法:
>>> from astropy.coordinates.representation import SphericalRepresentation, CylindricalRepresentation
>>> sph = car.represent_as(SphericalRepresentation)
>>> sph
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(1.03037683, 0.60126422, 7.07106781)>
>>> cyl = car.represent_as(CylindricalRepresentation)
>>> cyl
<CylindricalRepresentation (rho, phi, z) in (kpc, rad, kpc)
(5.83095189, 1.03037683, 4.)>
所有表示可以相互转换而不丢失信息,除了 UnitSphericalRepresentation . 此类用于存储点的经度和纬度,但不包含到这些点的任何距离,并假定它们位于一个单位和无量纲球体上:
>>> from astropy.coordinates.representation import UnitSphericalRepresentation
>>> sph_unit = car.represent_as(UnitSphericalRepresentation)
>>> sph_unit
<UnitSphericalRepresentation (lon, lat) in rad
(1.03037683, 0.60126422)>
转换回笛卡尔坐标后,绝对缩放信息已被删除,点仍位于单位球体上:
>>> sph_unit = car.represent_as(UnitSphericalRepresentation)
>>> sph_unit.represent_as(CartesianRepresentation)
<CartesianRepresentation (x, y, z) [dimensionless]
(0.42426407, 0.70710678, 0.56568542)>
数组值和NumPy数组方法类比#
数组 Quantity 还可以将对象传递给表示,并且可以使用与可用的方法相同的方法对这些表示进行切片、重塑等 ndarray 。相应的函数,以及影响形状的其他函数,例如 atleast_1d 和 rollaxis ,如预期般工作。
例子#
传递数组 Quantity 对象到表示:
>>> import numpy as np
>>> x = np.linspace(0., 5., 6)
>>> y = np.linspace(10., 15., 6)
>>> z = np.linspace(20., 25., 6)
>>> car_array = CartesianRepresentation(x * u.m, y * u.m, z * u.m)
>>> car_array
<CartesianRepresentation (x, y, z) in m
[(0., 10., 20.), (1., 11., 21.), (2., 12., 22.),
(3., 13., 23.), (4., 14., 24.), (5., 15., 25.)]>
使用方法和 numpy 功能::
>>> car_array.reshape(3, 2)
<CartesianRepresentation (x, y, z) in m
[[(0., 10., 20.), (1., 11., 21.)],
[(2., 12., 22.), (3., 13., 23.)],
[(4., 14., 24.), (5., 15., 25.)]]>
>>> car_array[2]
<CartesianRepresentation (x, y, z) in m
(2., 12., 22.)>
>>> car_array[2] = car_array[1]
>>> car_array[:3]
<CartesianRepresentation (x, y, z) in m
[(0., 10., 20.), (1., 11., 21.), (1., 11., 21.)]>
>>> np.roll(car_array, 1)
<CartesianRepresentation (x, y, z) in m
[(5., 15., 25.), (0., 10., 20.), (1., 11., 21.), (1., 11., 21.),
(3., 13., 23.), (4., 14., 24.)]>
以及使用其他表示类来设置元素(只要它们的单位和维数兼容):
>>> car_array[2] = SphericalRepresentation(0*u.deg, 0*u.deg, 99*u.m)
>>> car_array[:3]
<CartesianRepresentation (x, y, z) in m
[(0., 10., 20.), (1., 11., 21.), (99., 0., 0.)]>
>>> car_array[0] = UnitSphericalRepresentation(0*u.deg, 0*u.deg)
Traceback (most recent call last):
...
ValueError: value must be representable as CartesianRepresentation without loss of information.
矢量算法#
表示法支持基本的向量运算,如取范数、乘和除以量、取点积和叉积,以及表示的加、减、和和和取平均值,以及与矩阵相乘。
备注
除了矩阵乘法之外,所有的算法也适用于非笛卡尔表示。对于取范数、乘法和除法,它只使用非角度分量,而对于其他运算,表示在运算完成之前在内部转换为笛卡尔坐标,结果转换回原始表示。因此,为了获得最佳速度,最好使用笛卡尔表示法。
实例#
要了解向量算术运算如何处理表示对象,请考虑以下示例:
>>> car_array = CartesianRepresentation([[1., 0., 0.], [3., 5., 3.]] * u.m,
... [[0., 2., 0.], [4., 0., -4.]] * u.m,
... [[0., 0., 3.], [0.,12.,-12.]] * u.m)
>>> car_array
<CartesianRepresentation (x, y, z) in m
[[(1., 0., 0.), (0., 2., 0.), (0., 0., 3.)],
[(3., 4., 0.), (5., 0., 12.), (3., -4., -12.)]]>
>>> car_array.norm()
<Quantity [[ 1., 2., 3.],
[ 5., 13., 13.]] m>
>>> car_array / car_array.norm()
<CartesianRepresentation (x, y, z) [dimensionless]
[[(1. , 0. , 0. ),
(0. , 1. , 0. ),
(0. , 0. , 1. )],
[(0.6 , 0.8 , 0. ),
(0.38461538, 0. , 0.92307692),
(0.23076923, -0.30769231, -0.92307692)]]>
>>> (car_array[1] - car_array[0]) / (10. * u.s)
<CartesianRepresentation (x, y, z) in m / s
[(0.2, 0.4, 0. ), (0.5, -0.2, 1.2), (0.3, -0.4, -1.5)]>
>>> car_array.sum()
<CartesianRepresentation (x, y, z) in m
(12., 2., 3.)>
>>> car_array.mean(axis=0)
<CartesianRepresentation (x, y, z) in m
[(2. , 2., 0. ), (2.5, 1., 6. ), (1.5, -2., -4.5)]>
>>> unit_x = UnitSphericalRepresentation(0.*u.deg, 0.*u.deg)
>>> unit_y = UnitSphericalRepresentation(90.*u.deg, 0.*u.deg)
>>> unit_z = UnitSphericalRepresentation(0.*u.deg, 90.*u.deg)
>>> car_array.dot(unit_x)
<Quantity [[1., 0., 0.],
[3., 5., 3.]] m>
>>> car_array.dot(unit_y)
<Quantity [[ 6.12323400e-17, 2.00000000e+00, 0.00000000e+00],
[ 4.00000000e+00, 3.06161700e-16, -4.00000000e+00]] m>
>>> car_array.dot(unit_z)
<Quantity [[ 6.12323400e-17, 0.00000000e+00, 3.00000000e+00],
[ 1.83697020e-16, 1.20000000e+01, -1.20000000e+01]] m>
>>> car_array.cross(unit_x)
<CartesianRepresentation (x, y, z) in m
[[(0., 0., 0.), (0., 0., -2.), (0., 3., 0.)],
[(0., 0., -4.), (0., 12., 0.), (0., -12., 4.)]]>
>>> from astropy.coordinates.matrix_utilities import rotation_matrix
>>> rotation = rotation_matrix(90 * u.deg, axis='z')
>>> rotation
array([[ 6.12323400e-17, 1.00000000e+00, 0.00000000e+00],
[-1.00000000e+00, 6.12323400e-17, 0.00000000e+00],
[ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]])
>>> car_array.transform(rotation)
<CartesianRepresentation (x, y, z) in m
[[( 6.12323400e-17, -1.00000000e+00, 0.),
( 2.00000000e+00, 1.22464680e-16, 0.),
( 0.00000000e+00, 0.00000000e+00, 3.)],
[( 4.00000000e+00, -3.00000000e+00, 0.),
( 3.06161700e-16, -5.00000000e+00, 12.),
(-4.00000000e+00, -3.00000000e+00, -12.)]]>
表示的微分和导数#
除此之外,还需要用坐标系来表示空间运动的微分。为了支持这一点,表示都有相应的 Differential 类,它可以根据表示类的组件保存偏移量或导数。将这样的偏移量添加到表示中意味着偏移量是在相应坐标的方向上进行的。(尽管对于除笛卡尔坐标外的任何表示,这只是相对于特定位置定义的,因为单位向量不是不变的。)
实例#
看看 Differential 表示类有效,请考虑以下几点:
>>> from astropy.coordinates import SphericalRepresentation, SphericalDifferential
>>> sph_coo = SphericalRepresentation(lon=0.*u.deg, lat=0.*u.deg,
... distance=1.*u.kpc)
>>> sph_derivative = SphericalDifferential(d_lon=1.*u.arcsec/u.yr,
... d_lat=0.*u.arcsec/u.yr,
... d_distance=0.*u.km/u.s)
>>> sph_derivative.to_cartesian(base=sph_coo)
<CartesianRepresentation (x, y, z) in arcsec kpc / (rad yr)
(0., 1., 0.)>
笛卡尔变换只能用一个音符来完成 base ,因为否则代码无法知道经度增加对应的方向。为 lon=0 ,这是在 y 方向。现在,在两次之后得到坐标:
>>> sph_coo + sph_derivative * [1., 3600*180/np.pi] * u.yr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
[(4.84813681e-06, 0., 1. ), (7.85398163e-01, 0., 1.41421356)]>
上面的例子说明了增加不是在经度本身,而是在增加经度的方向上:对于较大的偏移量,相当于一个弧度,距离也增加了(毕竟,一个震源可能不会沿着天空上的曲线移动!)。这也意味着操作顺序很重要:
>>> big_offset = SphericalDifferential(1.*u.radian, 0.*u.radian, 0.*u.kpc)
>>> sph_coo + big_offset + big_offset
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(1.57079633, 0., 2.)>
>>> sph_coo + (big_offset + big_offset)
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(1.10714872, 0., 2.23606798)>
通常,你可能只有一个固有运动或一个径向速度,但不能两者兼而有之:
>>> from astropy.coordinates import UnitSphericalDifferential, RadialDifferential
>>> radvel = RadialDifferential(1000*u.km/u.s)
>>> sph_coo + radvel * 1. * u.Myr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(0., 0., 2.02271217)>
>>> pm = UnitSphericalDifferential(1.*u.mas/u.yr, 0.*u.mas/u.yr)
>>> sph_coo + pm * 1. * u.Myr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(0.0048481, 0., 1.00001175)>
>>> pm + radvel
<SphericalDifferential (d_lon, d_lat, d_distance) in (mas / yr, mas / yr, km / s)
(1., 0., 1000.)>
>>> sph_coo + (pm + radvel) * 1. * u.Myr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(0.00239684, 0., 2.02271798)>
注意,在上面,固有运动严格定义为经度的变化(即,它不包括 cos(latitude) 期限)。有一些特殊的课程包括这个术语:
>>> from astropy.coordinates import UnitSphericalCosLatDifferential
>>> sph_lat60 = SphericalRepresentation(lon=0.*u.deg, lat=60.*u.deg,
... distance=1.*u.kpc)
>>> pm = UnitSphericalDifferential(1.*u.mas/u.yr, 0.*u.mas/u.yr)
>>> pm
<UnitSphericalDifferential (d_lon, d_lat) in mas / yr
(1., 0.)>
>>> pm_coslat = UnitSphericalCosLatDifferential(1.*u.mas/u.yr, 0.*u.mas/u.yr)
>>> pm_coslat
<UnitSphericalCosLatDifferential (d_lon_coslat, d_lat) in mas / yr
(1., 0.)>
>>> sph_lat60 + pm * 1. * u.Myr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(0.0048481, 1.04719246, 1.00000294)>
>>> sph_lat60 + pm_coslat * 1. * u.Myr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(0.00969597, 1.0471772, 1.00001175)>
仔细检查表明,这些变化确实如预期的那样。有无系统 cos(latitude) 如果您提供 base (代表)::
>>> usph_lat60 = sph_lat60.represent_as(UnitSphericalRepresentation)
>>> pm_coslat2 = pm.represent_as(UnitSphericalCosLatDifferential,
... base=usph_lat60)
>>> pm_coslat2
<UnitSphericalCosLatDifferential (d_lon_coslat, d_lat) in mas / yr
(0.5, 0.)>
>>> sph_lat60 + pm_coslat2 * 1. * u.Myr
<SphericalRepresentation (lon, lat, distance) in (rad, rad, kpc)
(0.0048481, 1.04719246, 1.00000294)>
备注
目前,微分类通常用于一阶导数,但它们不检查输入的单位来实现这一点。传递二阶导数(例如,带有加速度单位的加速度值)将成功,但通过重新表示微分而发生的任何变换都不一定是正确的。
附加 Differential 对象 Representation 物体#
Differential 对象可以附加到 Representation 对象作为将相关信息封装到单个对象中的方法。 Differential 对象可以传递到任何内置 Representation 类。
例子#
要存储具有位置的单个速度差:
>>> from astropy.coordinates import representation as r
>>> dif = r.SphericalDifferential(d_lon=1 * u.mas/u.yr,
... d_lat=2 * u.mas/u.yr,
... d_distance=3 * u.km/u.s)
>>> rep = r.SphericalRepresentation(lon=0.*u.deg, lat=0.*u.deg,
... distance=1.*u.kpc,
... differentials=dif)
>>> rep
<SphericalRepresentation (lon, lat, distance) in (deg, deg, kpc)
(0., 0., 1.)
(has differentials w.r.t.: 's')>
>>> rep.differentials
{'s': <SphericalDifferential (d_lon, d_lat, d_distance) in (mas / yr, mas / yr, km / s)
(1., 2., 3.)>}
这个 Differential 对象作为Python字典存储在 Representation 对象的键等于(字符串)单位,用它来计算微分导数(转换为SI)。
在这种情况下,关键是 's' (二)因为 Differential 单位是速度,时间导数。将单个差速器传递给 Representation 初始值设定项将自动生成所需的密钥并将其存储在差异字典中,但需要字典来指定多个差异:
>>> dif2 = r.SphericalDifferential(d_lon=4 * u.mas/u.yr**2,
... d_lat=5 * u.mas/u.yr**2,
... d_distance=6 * u.km/u.s**2)
>>> rep = r.SphericalRepresentation(lon=0.*u.deg, lat=0.*u.deg,
... distance=1.*u.kpc,
... differentials={'s': dif, 's2': dif2})
>>> rep.differentials['s']
<SphericalDifferential (d_lon, d_lat, d_distance) in (mas / yr, mas / yr, km / s)
(1., 2., 3.)>
>>> rep.differentials['s2']
<SphericalDifferential (d_lon, d_lat, d_distance) in (mas / yr2, mas / yr2, km / s2)
(4., 5., 6.)>
Differential 对象也可以附加到 Representation 创建后:
>>> rep = r.CartesianRepresentation(x=1 * u.kpc, y=2 * u.kpc, z=3 * u.kpc)
>>> dif = r.CartesianDifferential(*[1, 2, 3] * u.km/u.s)
>>> rep = rep.with_differentials(dif)
>>> rep
<CartesianRepresentation (x, y, z) in kpc
(1., 2., 3.)
(has differentials w.r.t.: 's')>
这也适用于数组数据,只要 Differential 数据与 Representation ::
>>> xyz = np.arange(12).reshape(3, 4) * u.au
>>> d_xyz = np.arange(12).reshape(3, 4) * u.km/u.s
>>> rep = r.CartesianRepresentation(*xyz)
>>> dif = r.CartesianDifferential(*d_xyz)
>>> rep = rep.with_differentials(dif)
>>> rep
<CartesianRepresentation (x, y, z) in AU
[(0., 4., 8.), (1., 5., 9.), (2., 6., 10.), (3., 7., 11.)]
(has differentials w.r.t.: 's')>
和A一样 Representation 实例,若要将位置数据转换为新表达,请使用 .represent_as() ::
>>> rep.represent_as(r.SphericalRepresentation)
<SphericalRepresentation (lon, lat, distance) in (rad, rad, AU)
[(1.57079633, 1.10714872, 8.94427191),
(1.37340077, 1.05532979, 10.34408043),
(1.24904577, 1.00685369, 11.83215957),
(1.16590454, 0.96522779, 13.37908816)]>
但是,通过传递所需的表示类,只有 Representation 变了,差分也掉了。重新代表 Representation 还有任何 Differential 对象,则必须为 Differential 也::
>>> rep2 = rep.represent_as(r.SphericalRepresentation, r.SphericalDifferential)
>>> rep2
<SphericalRepresentation (lon, lat, distance) in (rad, rad, AU)
[(1.57079633, 1.10714872, 8.94427191),
(1.37340077, 1.05532979, 10.34408043),
(1.24904577, 1.00685369, 11.83215957),
(1.16590454, 0.96522779, 13.37908816)]
(has differentials w.r.t.: 's')>
>>> rep2.differentials['s']
<SphericalDifferential (d_lon, d_lat, d_distance) in (km rad / (AU s), km rad / (AU s), km / s)
[( 6.12323400e-17, 1.11022302e-16, 8.94427191),
(-2.77555756e-17, 5.55111512e-17, 10.34408043),
( 0.00000000e+00, 0.00000000e+00, 11.83215957),
( 5.55111512e-17, 0.00000000e+00, 13.37908816)]>
形状更改操作(例如,重塑)将传播到所有 Differential 对象,因为它们保证与宿主具有相同的形状 Representation 对象:
>>> rep.shape
(4,)
>>> rep.differentials['s'].shape
(4,)
>>> new_rep = rep.reshape(2, 2)
>>> new_rep.shape
(2, 2)
>>> new_rep.differentials['s'].shape
(2, 2)
这也适用于切片:
>>> new_rep = rep[:2]
>>> new_rep.shape
(2,)
>>> new_rep.differentials['s'].shape
(2,)
对返回的表示的操作 Quantity 相对于其他物体 Representation 实例)仍然有效,但仅对位置信息进行操作,例如:
>>> rep.norm()
<Quantity [ 8.94427191, 10.34408043, 11.83215957, 13.37908816] AU>
涉及组合或缩放表示或包含差异的表示对象对的操作当前将失败,但在将来的版本中可能会添加对某些操作的支持:
>>> rep + rep
Traceback (most recent call last):
...
TypeError: Operation 'add' is not supported when differentials are attached to a CartesianRepresentation.
如果你有 Representation 附带 Differential 对象,可以检索 Representation 没有 Differential 反对并使用这个 Differential -任何算术运算的自由对象:
>>> 15 * rep.without_differentials()
<CartesianRepresentation (x, y, z) in AU
[( 0., 60., 120.), (15., 75., 135.), (30., 90., 150.),
(45., 105., 165.)]>
创建自己的表达#
要创建自己的表示类,您的类必须继承 BaseRepresentation class. This base has an _ _方法,它将把所有参数组件通过其初始值设定项放置,验证它们是否可以相互广播,并将组件存储在 ``self 作为名字的前缀。此外,通过元类,它为组件提供了默认属性,以便可以使用 <instance>.<component> . 为使机器工作,必须定义以下内容:
attr_classes类属性 (dict):定义其类的实例(以及它们应该通过的键的顺序)
Quantity或者一个子类,或者任何可以初始化它的东西)。from_cartesian类方法:采用
CartesianRepresentation对象并返回类的实例。to_cartesian方法:返回A
CartesianRepresentation对象。__init__方法(可选):如果您想要的不仅仅是基表示类提供的基本初始化和检查,或者只是一个显式签名,那么您可以定义自己的签名
__init__. 一般来说,建议保持接近基本表示假定的签名,__init__(self, comp1, comp2, comp3, copy=True)及使用super调用基表示初始值设定项。
完成此操作后,您将自动能够调用 represent_as 要将其他表示与您的表示类相互转换,请执行以下操作。您的制图表达也可用于 SkyCoord 和所有的框架类。
表示类也可以具有 _unit_representation 属性(虽然不是必需的)。此属性指向适当的“单位”表示(即无量纲表示)。这可能只对 SphericalRepresentation ,其中假定它将是 UnitSphericalRepresentation .
最后,如果希望在坐标系中也使用偏移量,则应定义另外两种方法(请参见 SphericalRepresentation 例如):
unit_vectors方法:返回A
dict用一个CartesianRepresentation在每个分量方向上的单位向量。scale_factors方法:返回A
dict用一个Quantity每一个物理单位的比例都会发生相应的变化。
而且你应该定义一个 Differential 基于 BaseDifferential . 此类只需定义:
base_representation属性:一个链接,指向此差分保存的表示形式。
在伪代码中,这意味着类看起来像:
class MyRepresentation(BaseRepresentation):
attr_classes = {
"comp1": ComponentClass1,
"comp2": ComponentClass2,
"comp3": ComponentClass3,
}
# __init__ is optional
def __init__(self, comp1, comp2, comp3, copy=True):
super().__init__(comp1, comp2, comp3, copy=copy)
...
@classmethod
def from_cartesian(self, cartesian):
...
return MyRepresentation(...)
def to_cartesian(self):
...
return CartesianRepresentation(...)
# if differential motion is needed
def unit_vectors(self):
...
return {'comp1': CartesianRepresentation(...),
'comp2': CartesianRepresentation(...),
'comp3': CartesianRepresentation(...)}
def scale_factors(self):
...
return {'comp1': ...,
'comp2': ...,
'comp3': ...}
class MyDifferential(BaseDifferential):
base_representation = MyRepresentation
创建您自己的大地测量表示和身体中心表示#
如果要在地球以外的行星体上使用大地坐标,可以定义一个继承自 BaseGeodeticRepresentation or BaseBodycentricRepresentation. The equatorial radius and flattening must be both assigned via the attributes _ 赤道半径`和 `_flattening 。
例如,描述火星的椭球体,如 1979 IAU standard 可定义为::
class IAUMARS1979GeodeticRepresentation(BaseGeodeticRepresentation):
_equatorial_radius = 3393400.0 * u.m
_flattening = 0.518650 * u.percent
以身体为中心的坐标系表示火星,如 2000 IAU standard 可以定义为:
class IAUMARS2000BodycentricRepresentation(BaseBodycentricRepresentation):
_equatorial_radius = 3396190.0 * u.m
_flattening = 0.5886008 * u.percent