备注
Go to the end 下载完整的示例代码
为MARS创建新的坐标框类#
此示例介绍如何为可由大地表示或形心表示描述的行星体子类化和定义自定义坐标系,如中所述 定义新框架 和 创建您自己的大地测量表示和身体中心表示 。
请注意,我们在这里使用框架仅用于存储坐标。要使用它来确定,例如,将望远镜指向地球上的哪个位置来观测奥林匹斯山,需要将该帧添加到传递图中,这超出了本例的范围。
为此,我们首先需要定义 BaseGeodeticRepresentation
和 BaseBodycentricRepresentation
,然后是的子类 BaseCoordinateFrame
使用前面定义的表示法。
By: Chiara Marmo, Marten van Kerkwijk
许可证:BSD
设置NumPy、matplotlib并使用一组更好的绘图参数:
import matplotlib.pyplot as plt
import numpy as np
from astropy.visualization import astropy_mpl_style, quantity_support
plt.style.use(astropy_mpl_style)
quantity_support()
<astropy.visualization.units.quantity_support.<locals>.MplQuantityConverter object at 0x7f4f9f74d1d0>
导入坐标所需的包
import astropy.units as u
from astropy.coordinates.baseframe import BaseCoordinateFrame
from astropy.coordinates.representation import CartesianRepresentation
from astropy.coordinates.representation.geodetic import (
BaseBodycentricRepresentation,
BaseGeodeticRepresentation,
)
第一步是创建一个新类,并使其成为 BaseGeodeticRepresentation
。使用大地纬度,经度从东经0度到360度正表示火星椭球体与火星大地水准面(区域)的最佳匹配:
class MarsBestFitAeroid(BaseGeodeticRepresentation):
"""
A Spheroidal representation of Mars that minimized deviations with respect to the
areoid following
Ardalan A. A, R. Karimi, and E. W. Grafarend (2010)
https://doi.org/10.1007/s11038-009-9342-7
"""
_equatorial_radius = 3395.4280 * u.km
_flattening = 0.5227617843759314 * u.percent
现在,让我们定义一个从MarsBestFitAeroid获得但由星心纬度描述的新大地测量表示法。
class MarsBestFitOcentricAeroid(BaseBodycentricRepresentation):
"""
A Spheroidal planetocentric representation of Mars that minimized deviations with
respect to the areoid following
Ardalan A. A, R. Karimi, and E. W. Grafarend (2010)
https://doi.org/10.1007/s11038-009-9342-7
"""
_equatorial_radius = 3395.4280 * u.km
_flattening = 0.5227617843759314 * u.percent
作为比较,我们定义了一个新的球面框架表示法,我们可以将其作为基础 BaseBodycentricRepresentation
也是。
class MarsSphere(BaseGeodeticRepresentation):
"""
A Spherical representation of Mars
"""
_equatorial_radius = 3395.4280 * u.km
_flattening = 0.0 * u.percent
新的行星体固定参考系将使用先前定义的表示法来描述。
class MarsCoordinateFrame(BaseCoordinateFrame):
"""
A reference system for Mars.
"""
name = "Mars"
现在,假设物体表面上的点,绘制笛卡尔表示相对于球面模型的每个分量之间的差异 (height = 0
)
mars_sphere = MarsCoordinateFrame(
lon=np.linspace(0, 360, 128) * u.deg,
lat=np.linspace(-90, 90, 128) * u.deg,
representation_type=MarsSphere,
)
mars = MarsCoordinateFrame(
lon=np.linspace(0, 360, 128) * u.deg,
lat=np.linspace(-90, 90, 128) * u.deg,
representation_type=MarsBestFitAeroid,
)
mars_ocentric = MarsCoordinateFrame(
lon=np.linspace(0, 360, 128) * u.deg,
lat=np.linspace(-90, 90, 128) * u.deg,
representation_type=MarsBestFitOcentricAeroid,
)
xyz_sphere = mars_sphere.represent_as(CartesianRepresentation)
xyz = mars.represent_as(CartesianRepresentation)
xyz_ocentric = mars_ocentric.represent_as(CartesianRepresentation)
fig, ax = plt.subplots(2, subplot_kw={"projection": "3d"})
ax[0].scatter(*((xyz - xyz_sphere).xyz << u.km))
ax[0].tick_params(labelsize=8)
ax[0].set(xlabel="x [km]", ylabel="y [km]", zlabel="z [km]")
ax[0].set_title("Mars-odetic spheroid difference from sphere")
ax[1].scatter(*((xyz_ocentric - xyz_sphere).xyz << u.km))
ax[1].tick_params(labelsize=8)
ax[1].set(xlabel="x [km]", ylabel="y [km]", zlabel="z [km]")
ax[1].set_title("Mars-ocentric spheroid difference from sphere")
plt.show()
Total running time of the script: (0分0.127秒)