feat: 引入可切换星历模型并扩展天象观测链路

- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算
- 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询
- 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出
- 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解
- 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤
- 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持
- 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理
- 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
This commit is contained in:
2026-10-15 23:54:15 +08:00
parent 16c62a97d5
commit 044f2f4381
674 changed files with 62983 additions and 8396 deletions
+82
View File
@@ -0,0 +1,82 @@
package formula
import "math"
const arcsecToRadian = math.Pi / 180 / 3600
// TIOLocatorArcsec 地球自转原点定位角 s′,单位角秒 / TIO locator s′ in arcseconds.
//
// jdeTT 为 TT 儒略日。采用 IERS 2010 的线性近似 s′ = −47 µas·t,t 为 J2000 起的儒略世纪数。
// jdeTT is a TT Julian date. Uses the IERS 2010 linear model s′ = −47 µas·t,
// with t in Julian centuries since J2000.
func TIOLocatorArcsec(jdeTT float64) float64 {
if !isFinitePhotometry(jdeTT) {
return math.NaN()
}
return -47e-6 * (jdeTT - 2451545.0) / 36525
}
// PolarMotionMatrix 极移矩阵 W,把地球中间参考系 (TIRS) 矢量转到 ITRS / polar-motion matrix from TIRS to ITRS.
//
// xp、yp 为 IERS 公布的极坐标,sPrime 为 TIOLocatorArcsec 的结果,单位都是角秒。
// 返回 W = R1(−yp)·R2(−xp)·R3(s′),按 v_ITRS = W·v_TIRS 使用。
// xp and yp are IERS pole coordinates and sPrime is the TIO locator, all in
// arcseconds. Returns W = R1(−yp)·R2(−xp)·R3(s′) for v_ITRS = W·v_TIRS.
func PolarMotionMatrix(xp, yp, sPrime float64) [3][3]float64 {
if !isFinitePhotometry(xp) || !isFinitePhotometry(yp) || !isFinitePhotometry(sPrime) {
return nanMatrix()
}
return multiplyMatrix(rotationX(-yp*arcsecToRadian),
multiplyMatrix(rotationY(-xp*arcsecToRadian), rotationZ(sPrime*arcsecToRadian)))
}
// CelestialPoleOffsetMatrix 天球极偏差修正矩阵 / celestial pole offset correction matrix.
//
// dX、dY 为 IERS 公布的 CIP 坐标改正,单位毫角秒。返回一阶小角矩阵 Δ,
// 左乘模型给出的 GCRS→CIRS(或 GCRS→真赤道)矩阵即得改正后的矩阵:C′ = Δ·C。
// dX and dY are IERS CIP corrections in milliarcseconds. Returns the
// first-order matrix Δ; left-multiply a model GCRS→CIRS (or GCRS→true-equator)
// matrix to apply the offsets: C′ = Δ·C.
func CelestialPoleOffsetMatrix(dX, dY float64) [3][3]float64 {
if !isFinitePhotometry(dX) || !isFinitePhotometry(dY) {
return nanMatrix()
}
x := dX * arcsecToRadian / 1000
y := dY * arcsecToRadian / 1000
return [3][3]float64{
{1, 0, -x},
{0, 1, -y},
{x, y, 1},
}
}
// rotationX 等为被动旋转:把矢量所在坐标轴绕 x/y/z 轴转 angle 弧度。
func rotationX(angle float64) [3][3]float64 {
s, c := math.Sincos(angle)
return [3][3]float64{{1, 0, 0}, {0, c, s}, {0, -s, c}}
}
func rotationY(angle float64) [3][3]float64 {
s, c := math.Sincos(angle)
return [3][3]float64{{c, 0, -s}, {0, 1, 0}, {s, 0, c}}
}
func rotationZ(angle float64) [3][3]float64 {
s, c := math.Sincos(angle)
return [3][3]float64{{c, s, 0}, {-s, c, 0}, {0, 0, 1}}
}
func multiplyMatrix(a, b [3][3]float64) [3][3]float64 {
var out [3][3]float64
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
out[i][j] = a[i][0]*b[0][j] + a[i][1]*b[1][j] + a[i][2]*b[2][j]
}
}
return out
}
func nanMatrix() [3][3]float64 {
n := math.NaN()
return [3][3]float64{{n, n, n}, {n, n, n}, {n, n, n}}
}
+44
View File
@@ -0,0 +1,44 @@
package formula
import (
"math"
"testing"
)
func TestTIOLocator(t *testing.T) {
// 2002-09-29 0h TT(MJD 52541):s′ = −6.216698469981019e-12 rad。
got := TIOLocatorArcsec(2452541.5) * arcsecToRadian
assertFormulaClose(t, "TIOLocator", got, -0.6216698469981019309e-11, 1e-24)
if !math.IsNaN(TIOLocatorArcsec(math.NaN())) {
t.Fatal("expected NaN")
}
}
func TestPolarMotionMatrix(t *testing.T) {
const r2as = 1 / arcsecToRadian
w := PolarMotionMatrix(2.55060238e-7*r2as, 1.860359247e-6*r2as, -0.1367174580728891460e-10*r2as)
want := [3][3]float64{
{0.9999999999999674721, -0.1367174580728846989e-10, 0.2550602379999972345e-6},
{0.1414624947957029801e-10, 0.9999999999982695317, -0.1860359246998866389e-5},
{-0.2550602379741215021e-6, 0.1860359247002414021e-5, 0.9999999999982370039},
}
for i := range want {
for j := range want[i] {
assertFormulaClose(t, "PolarMotionMatrix", w[i][j], want[i][j], 1e-16)
}
}
}
func TestCelestialPoleOffsetMatrix(t *testing.T) {
// 改正后的极方向必须被映射到 z 轴:Δ·(dX, dY, 1) ≈ (0, 0, 1)。
d := CelestialPoleOffsetMatrix(0.3, -0.2)
x, y := 0.3*arcsecToRadian/1000, -0.2*arcsecToRadian/1000
p := [3]float64{x, y, 1}
for i, want := range [3]float64{0, 0, 1} {
got := d[i][0]*p[0] + d[i][1]*p[1] + d[i][2]*p[2]
assertFormulaClose(t, "CelestialPoleOffsetMatrix", got, want, 1e-20)
}
if !math.IsNaN(CelestialPoleOffsetMatrix(math.Inf(1), 0)[0][0]) {
t.Fatal("expected NaN matrix")
}
}
+47
View File
@@ -0,0 +1,47 @@
package formula
import "math"
// ExtinctionComponents V 波段天顶消光系数分量,单位星等/大气质量 / V-band zenith extinction components in magnitudes per airmass.
type ExtinctionComponents struct {
Rayleigh float64 // 分子散射 / molecular scattering
Aerosol float64 // 气溶胶 / aerosol
Ozone float64 // 臭氧 / ozone
Water float64 // 水汽 / water vapour
Total float64 // 四项之和 / sum of the four terms
}
// ExtinctionSchaefer 按 Schaefer 经验模型由气象条件合成 V 波段天顶消光系数 / V-band zenith extinction from weather by Schaefer's empirical model.
//
// heightM 为测站海拔(米),temperatureC 为气温(°C),relativeHumidity 为相对湿度(百分比,
// 须在 (0, 100) 内),latitude 为测站纬度(度),sunRA 为太阳赤经(度,用于季节项)。
// Total 可直接作为 basic.HeliacalOptions.ExtinctionCoefficient;输入越界时各分量为 NaN。
// heightM is site elevation in metres, temperatureC is air temperature,
// relativeHumidity is a percentage in (0, 100), latitude is the site latitude,
// and sunRA is the Sun's right ascension in degrees for the seasonal terms.
// Total can be used as basic.HeliacalOptions.ExtinctionCoefficient. Out-of-range
// inputs yield NaN components.
func ExtinctionSchaefer(heightM, temperatureC, relativeHumidity, latitude, sunRA float64) ExtinctionComponents {
if !isFinitePhotometry(heightM) || !isFinitePhotometry(temperatureC) || !isFinitePhotometry(relativeHumidity) ||
!isFinitePhotometry(latitude) || !isFinitePhotometry(sunRA) ||
relativeHumidity <= 0 || relativeHumidity >= 100 || latitude < -90 || latitude > 90 {
n := math.NaN()
return ExtinctionComponents{n, n, n, n, n}
}
lat := latitude * math.Pi / 180
ra := sunRA * math.Pi / 180
hemisphere := 1.0
if latitude < 0 {
hemisphere = -1
}
// 标高:分子与水汽 8200 m,气溶胶 1500 m;臭氧层在高空,不随测站海拔变化。
components := ExtinctionComponents{
Rayleigh: 0.1066 * math.Exp(-heightM/8200),
Aerosol: 0.1 * math.Exp(-heightM/1500) * math.Pow(1-0.32/math.Log(relativeHumidity/100), 1.33) *
(1 + 0.33*hemisphere*math.Sin(ra)),
Ozone: 0.031 * (3 + 0.4*(lat*math.Cos(ra)-math.Cos(3*lat))) / 3,
Water: 0.031 * 0.94 * (relativeHumidity / 100) * math.Exp(temperatureC/15) * math.Exp(-heightM/8200),
}
components.Total = components.Rayleigh + components.Aerosol + components.Ozone + components.Water
return components
}
+38
View File
@@ -0,0 +1,38 @@
package formula
import (
"math"
"testing"
)
func TestExtinctionSchaefer(t *testing.T) {
// 海平面、20 °C、湿度 50%、北纬 30°、春分点:逐项手算。
got := ExtinctionSchaefer(0, 20, 50, 30, 0)
aerosol := 0.1 * math.Pow(1-0.32/math.Log(0.5), 1.33)
lat := math.Pi / 6
ozone := 0.031 * (3 + 0.4*(lat-math.Cos(3*lat))) / 3
water := 0.031 * 0.94 * 0.5 * math.Exp(20.0/15)
assertFormulaClose(t, "Rayleigh", got.Rayleigh, 0.1066, 1e-15)
assertFormulaClose(t, "Aerosol", got.Aerosol, aerosol, 1e-15)
assertFormulaClose(t, "Ozone", got.Ozone, ozone, 1e-15)
assertFormulaClose(t, "Water", got.Water, water, 1e-15)
assertFormulaClose(t, "Total", got.Total, 0.1066+aerosol+ozone+water, 1e-15)
if got.Total < 0.2 || got.Total > 0.5 {
t.Fatalf("sea-level humid extinction out of typical range: %.3f", got.Total)
}
// 高山干燥站点消光明显更小。
high := ExtinctionSchaefer(2500, 0, 20, 30, 0)
if high.Total >= got.Total*0.6 {
t.Fatalf("high dry site %.3f should be well below sea level %.3f", high.Total, got.Total)
}
for _, rh := range []float64{0, 100, -1, math.NaN()} {
if !math.IsNaN(ExtinctionSchaefer(0, 20, rh, 30, 0).Total) {
t.Fatalf("humidity %v should be rejected", rh)
}
}
if !math.IsNaN(ExtinctionSchaefer(0, 20, 50, 91, 0).Total) {
t.Fatal("latitude out of range should be rejected")
}
}
+29
View File
@@ -0,0 +1,29 @@
package formula
import "b612.me/astro/internal/refraction"
// RefractionStandardPressureHPa 与 RefractionStandardTemperatureC 是折射公式的标准气压与气温 / standard pressure and temperature of the refraction formula.
const (
RefractionStandardPressureHPa = refraction.StandardPressureHPa
RefractionStandardTemperatureC = refraction.StandardTemperatureC
)
// RefractionFromApparentAltitude 由视高度角求折射量(度,视高度减去它得真高度),无逆解时为 NaN / refraction from apparent altitude.
func RefractionFromApparentAltitude(apparentAltitude, pressureHPa, temperatureC float64) float64 {
return refraction.RefractionFromApparentAltitude(apparentAltitude, pressureHPa, temperatureC)
}
// TrueAltitude 视高度角转真高度角(度),无逆解时为 NaN / true altitude from apparent altitude.
func TrueAltitude(apparentAltitude, pressureHPa, temperatureC float64) float64 {
return refraction.TrueAltitude(apparentAltitude, pressureHPa, temperatureC)
}
// ApparentAltitude 真高度角转视高度角(度) / apparent altitude from true altitude.
func ApparentAltitude(trueAltitude, pressureHPa, temperatureC float64) float64 {
return refraction.ApparentAltitude(trueAltitude, pressureHPa, temperatureC)
}
// RefractionFromTrueAltitude 由真高度角求折射量(度,加到真高度上得视高度) / refraction from true altitude.
func RefractionFromTrueAltitude(trueAltitude, pressureHPa, temperatureC float64) float64 {
return refraction.RefractionFromTrueAltitude(trueAltitude, pressureHPa, temperatureC)
}
+21
View File
@@ -0,0 +1,21 @@
package formula
import (
"math"
"testing"
)
func TestRefractionRoundTrip(t *testing.T) {
for _, alt := range []float64{-1, 0, 0.5, 5, 30, 80} {
apparent := ApparentAltitude(alt, RefractionStandardPressureHPa, RefractionStandardTemperatureC)
if back := TrueAltitude(apparent, RefractionStandardPressureHPa, RefractionStandardTemperatureC); math.Abs(back-alt) > 1e-9 {
t.Errorf("alt %v: round trip %v", alt, back)
}
}
if r := RefractionFromTrueAltitude(0, 1010, 10) * 60; r < 28 || r > 36 {
t.Errorf("horizon refraction %.2f arcmin", r)
}
if !math.IsNaN(RefractionFromTrueAltitude(0, 0, 10)) {
t.Error("zero pressure must be NaN")
}
}