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
+2 -4
View File
@@ -5,8 +5,6 @@ import (
"math"
. "b612.me/astro/tools"
"b612.me/astro/basic"
)
const (
@@ -40,7 +38,7 @@ func EclipticToEquatorial(jde, lo, bo float64) (float64, float64) {
}
func HorizontalCoordinates(ra, dec, jd, lon, lat float64) (float64, float64, float64) {
lst := Limit360(MeanSiderealTime(basic.UTC2UT1(jd)) + lon)
lst := Limit360(MeanSiderealTime(UTC2UT1(jd)) + lon)
hourAngle := Limit360(lst - ra)
altitude := ArcSin(clampUnit(Sin(lat)*Sin(dec) + Cos(lat)*Cos(dec)*Cos(hourAngle)))
@@ -65,7 +63,7 @@ func TopocentricRaDec(ra, dec, observerLat, observerLon, jd, distanceEarthRadii,
rhoCos := math.Cos(u) + heightMeters/6378140.0*Cos(observerLat)
parallax := math.Asin(1.0 / distanceEarthRadii)
hourAngle := (Limit360(MeanSiderealTime(basic.UTC2UT1(jd)) + observerLon - ra)) * math.Pi / 180.0
hourAngle := (Limit360(MeanSiderealTime(UTC2UT1(jd)) + observerLon - ra)) * math.Pi / 180.0
decRad := dec * math.Pi / 180.0
numerator := -rhoCos * math.Sin(parallax) * math.Sin(hourAngle)
+28
View File
@@ -0,0 +1,28 @@
package internal
import "math"
const (
earthEquatorialRadius = 6378137.0
earthPolarRadius = 6356752.3
)
// HeightDegreeByLat 高度对应地平线下角 / horizon dip at latitude.
func HeightDegreeByLat(height, lat float64) float64 {
radius := geocentricRadius(lat)
return math.Acos(radius/(radius+height)) * 180 / math.Pi
}
func geocentricRadius(lat float64) float64 {
cosLat := math.Cos(lat * math.Pi / 180)
sinLat := math.Sin(lat * math.Pi / 180)
a := earthEquatorialRadius * earthEquatorialRadius * cosLat
a *= a
b := earthPolarRadius * earthPolarRadius * sinLat
b *= b
c := earthEquatorialRadius * cosLat
c *= c
d := earthPolarRadius * sinLat
d *= d
return math.Sqrt((a + b) / (c + d))
}
+18
View File
@@ -0,0 +1,18 @@
package internal
import (
"math"
"testing"
"b612.me/astro/basic"
)
func TestHeightDegreeByLatTakesDegrees(t *testing.T) {
for _, lat := range []float64{0, 30, 60, -45, 89} {
got := HeightDegreeByLat(10000, lat)
want := basic.HeightDegreeByLat(10000, lat)
if math.Abs(got-want) > 1e-9 {
t.Fatalf("lat %v: lite %.9f, basic %.9f", lat, got, want)
}
}
}
+25
View File
@@ -0,0 +1,25 @@
package internal
import "math"
const (
refractionStandardPressureHPa = 1010.0
refractionStandardTemperatureK = 283.15
refractionAbsoluteZeroC = -273.15
refractionLowerLimitAltitude = -5.0
refractionUpperLimitAltitude = 90.0
)
// RefractionFromTrueAltitude 真高度到视高度的折射修正 / true-to-apparent altitude refraction.
func RefractionFromTrueAltitude(trueAltitude, pressureHPa, temperatureC float64) float64 {
if !validRefractionInputs(trueAltitude, pressureHPa, temperatureC) || trueAltitude <= refractionLowerLimitAltitude || trueAltitude >= refractionUpperLimitAltitude {
return 0
}
angle := (trueAltitude + 10.3/(trueAltitude+5.11)) * math.Pi / 180
scale := pressureHPa / refractionStandardPressureHPa * refractionStandardTemperatureK / (temperatureC - refractionAbsoluteZeroC)
return scale * (1.02 / math.Tan(angle)) / 60
}
func validRefractionInputs(altitude, pressureHPa, temperatureC float64) bool {
return !(math.IsNaN(altitude) || math.IsInf(altitude, 0) || math.IsNaN(pressureHPa) || math.IsInf(pressureHPa, 0) || pressureHPa <= 0 || math.IsNaN(temperatureC) || math.IsInf(temperatureC, 0) || temperatureC <= refractionAbsoluteZeroC)
}
+114
View File
@@ -0,0 +1,114 @@
package internal
import (
"errors"
"math"
"time"
)
// ErrInvalidCivilDate 日期非法 / invalid civil date.
var ErrInvalidCivilDate = errors.New("invalid civil date")
// Date2JD 日期转儒略日 / Julian day from a civil time.
func Date2JD(date time.Time) float64 {
day := float64(date.Day()) + float64(date.Hour())/24.0 + float64(date.Minute())/1440.0 + float64(date.Second())/86400.0 + float64(date.Nanosecond())/86400000000000.0
return JDCalc(date.Year(), int(date.Month()), day)
}
// JDCalc 由公历年月日计算儒略日 / Julian day from a civil date.
func JDCalc(year, month int, day float64) float64 {
if !validCivilDate(year, month, day) {
return math.NaN()
}
effectiveYear, effectiveMonth, effectiveDay := year, month, int(math.Floor(day))
if month == 1 || month == 2 {
year--
month += 12
}
correction := 0
if effectiveYear > 1582 || (effectiveYear == 1582 && (effectiveMonth > 10 || (effectiveMonth == 10 && effectiveDay >= 15))) {
century := int(year / 100)
correction = 2 - century + int(century/4)
}
return math.Floor(365.25*(float64(year)+4716.0)) + math.Floor(30.6001*float64(month+1)) + day + float64(correction) - 1524.5
}
func validCivilDate(year, month int, day float64) bool {
if math.IsNaN(day) || math.IsInf(day, 0) || month < 1 || month > 12 || day < 1 {
return false
}
dayInt := int(math.Floor(day))
if dayInt > daysInCivilMonth(year, month) {
return false
}
return !(year == 1582 && month == 10 && day >= 5 && day < 15)
}
func daysInCivilMonth(year, month int) int {
switch month {
case 1, 3, 5, 7, 8, 10, 12:
return 31
case 4, 6, 9, 11:
return 30
case 2:
if isCivilLeapYear(year, month, 1) {
return 29
}
return 28
default:
return 0
}
}
func isCivilLeapYear(year, month int, day float64) bool {
if year < 1582 || (year == 1582 && (month < 10 || (month == 10 && day <= 4))) {
return year%4 == 0
}
if year%400 == 0 {
return true
}
if year%100 == 0 {
return false
}
return year%4 == 0
}
// JD2DateByZone 儒略日转目标时区日期 / convert a Julian day to a target timezone.
func JD2DateByZone(jd float64, tz *time.Location, byZone bool) time.Time {
jd += 0.5
z := float64(int(jd))
fraction := jd - z
a := z
if z >= 2299161.0 {
alpha := math.Floor((z - 1867216.25) / 36524.25)
a = z + 1 + alpha - math.Floor(alpha/4)
}
b := a + 1524
c := math.Floor((b - 122.1) / 365.25)
d := math.Floor(365.25 * c)
e := math.Floor((b - d) / 30.6001)
days := b - d - math.Floor(30.6001*e) + fraction
month := e - 1
if e >= 14 {
month = e - 13
}
year := c - 4716
if month <= 2 {
year = c - 4715
}
seconds := (days - math.Floor(days)) * 86400
day := math.Floor(days)
date := time.Date(int(year), time.Month(int(month)), int(day), 0, 0, 0, 0, time.UTC).
Add(time.Duration(int64(1000000000 * seconds)))
if !byZone {
return date.In(tz)
}
y, m, dayInt := date.Date()
h, minute, second := date.Clock()
return time.Date(y, m, dayInt, h, minute, second, date.Nanosecond(), tz)
}
// UTC2UT1 轻量民用时转世界时,忽略 DUT1(|UT1−UTC| < 0.9 s) / lightweight UTC to UT1, DUT1 ignored.
func UTC2UT1(jd float64) float64 {
return jd
}
+39
View File
@@ -0,0 +1,39 @@
package internal
import (
"math"
"testing"
"time"
)
func TestDateJulianRoundTrip(t *testing.T) {
cases := []struct {
date time.Time
jd float64
}{
{time.Date(2026, 10, 6, 8, 30, 15, 123000000, time.UTC), 2461319.8543417014},
{time.Date(1582, 10, 4, 0, 0, 0, 0, time.UTC), 2299159.5},
{time.Date(1582, 10, 15, 0, 0, 0, 0, time.UTC), 2299160.5},
}
for _, tc := range cases {
if got := Date2JD(tc.date); math.Abs(got-tc.jd) > 1e-9 {
t.Fatalf("Date2JD(%s) = %.12f, want %.12f", tc.date, got, tc.jd)
}
}
}
func TestJD2DateByZone(t *testing.T) {
zone := time.FixedZone("CST", 8*3600)
got := JD2DateByZone(2461320.5, zone, false)
want := time.Date(2026, 10, 7, 8, 0, 0, 0, zone)
if !got.Equal(want) {
t.Fatalf("JD2DateByZone = %s, want %s", got, want)
}
}
func TestUTC2UT1IgnoresDUT1(t *testing.T) {
jd := 2461320.5
if got := UTC2UT1(jd); got != jd {
t.Fatalf("UTC2UT1 = %.12f, want %.12f", got, jd)
}
}
+14 -15
View File
@@ -6,7 +6,6 @@ import (
"math"
"time"
"b612.me/astro/basic"
lite "b612.me/astro/lite/internal"
. "b612.me/astro/tools"
)
@@ -19,50 +18,50 @@ var (
// TrueLo 轻量真黄经 / lightweight true ecliptic longitude.
func TrueLo(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).Longitude
return lite.MoonGeocentric(lite.Date2JD(date.UTC())).Longitude
}
// TrueBo 轻量真黄纬 / lightweight true ecliptic latitude.
func TrueBo(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).Latitude
return lite.MoonGeocentric(lite.Date2JD(date.UTC())).Latitude
}
// TrueRa 轻量真赤经 / lightweight true right ascension.
func TrueRa(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).RightAscension
return lite.MoonGeocentric(lite.Date2JD(date.UTC())).RightAscension
}
// TrueDec 轻量真赤纬 / lightweight true declination.
func TrueDec(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).Declination
return lite.MoonGeocentric(lite.Date2JD(date.UTC())).Declination
}
// TrueRaDec 轻量真赤经、真赤纬 / lightweight true right ascension and declination.
func TrueRaDec(date time.Time) (float64, float64) {
state := lite.MoonGeocentric(basic.Date2JD(date.UTC()))
state := lite.MoonGeocentric(lite.Date2JD(date.UTC()))
return state.RightAscension, state.Declination
}
// ApparentRa 轻量站心视赤经 / lightweight topocentric apparent right ascension.
func ApparentRa(date time.Time, lon, lat float64) float64 {
state := lite.MoonTopocentric(basic.Date2JD(date.UTC()), lon, lat, 0)
state := lite.MoonTopocentric(lite.Date2JD(date.UTC()), lon, lat, 0)
return state.RightAscension
}
// ApparentDec 轻量站心视赤纬 / lightweight topocentric apparent declination.
func ApparentDec(date time.Time, lon, lat float64) float64 {
state := lite.MoonTopocentric(basic.Date2JD(date.UTC()), lon, lat, 0)
state := lite.MoonTopocentric(lite.Date2JD(date.UTC()), lon, lat, 0)
return state.Declination
}
// ApparentRaDec 轻量站心视赤经、视赤纬 / lightweight topocentric apparent right ascension and declination.
func ApparentRaDec(date time.Time, lon, lat float64) (float64, float64) {
state := lite.MoonTopocentric(basic.Date2JD(date.UTC()), lon, lat, 0)
state := lite.MoonTopocentric(lite.Date2JD(date.UTC()), lon, lat, 0)
return state.RightAscension, state.Declination
}
func topocentricHorizontal(date time.Time, lon, lat float64) (altitude, azimuth, hourAngle float64) {
jd := basic.Date2JD(date.UTC())
jd := lite.Date2JD(date.UTC())
state := lite.MoonTopocentric(jd, lon, lat, 0)
return lite.HorizontalCoordinates(state.RightAscension, state.Declination, jd, lon, lat)
}
@@ -93,7 +92,7 @@ func Zenith(date time.Time, lon, lat float64) float64 {
// SunMoonLoDiff 轻量日月黄经差 / lightweight Moon-Sun ecliptic-longitude difference.
func SunMoonLoDiff(date time.Time) float64 {
jdUTC := basic.Date2JD(date.UTC())
jdUTC := lite.Date2JD(date.UTC())
return Limit360(lite.MoonGeocentric(jdUTC).Longitude - lite.SunApparentLo(jdUTC))
}
@@ -129,11 +128,11 @@ func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, er
func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (time.Time, error) {
localMidnight := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
localJD := basic.Date2JD(localMidnight)
localJD := lite.Date2JD(localMidnight)
_, offset := localMidnight.Zone()
timezone := float64(offset) / 3600.0
horizonDip := basic.HeightDegreeByLat(height, lat)
horizonDip := lite.HeightDegreeByLat(height, lat)
altitudeFn := func(localJD float64) float64 {
utcJD := localJD - timezone/24.0
@@ -141,7 +140,7 @@ func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (t
altitude, _, _ := lite.HorizontalCoordinates(state.RightAscension, state.Declination, utcJD, lon, lat)
residual := altitude + horizonDip
if aero {
residual += basic.RefractionFromTrueAltitude(altitude, 1010, 10)
residual += lite.RefractionFromTrueAltitude(altitude, 1010, 10)
residual += liteMoonSemidiameterDegrees(state.DistanceEarthRadii)
}
return residual
@@ -160,7 +159,7 @@ func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (t
return time.Time{}, err
}
}
return basic.JD2DateByZone(eventJD-timezone/24, date.Location(), false), nil
return lite.JD2DateByZone(eventJD-timezone/24, date.Location(), false), nil
}
func liteMoonSemidiameterDegrees(distanceEarthRadii float64) float64 {
+18 -19
View File
@@ -6,7 +6,6 @@ import (
"math"
"time"
"b612.me/astro/basic"
lite "b612.me/astro/lite/internal"
)
@@ -17,68 +16,68 @@ var (
// TrueLo 轻量真黄经 / lightweight true ecliptic longitude.
func TrueLo(date time.Time) float64 {
return lite.SunTrueLo(basic.Date2JD(date.UTC()))
return lite.SunTrueLo(lite.Date2JD(date.UTC()))
}
// ApparentLo 轻量视黄经 / lightweight apparent ecliptic longitude.
func ApparentLo(date time.Time) float64 {
return lite.SunApparentLo(basic.Date2JD(date.UTC()))
return lite.SunApparentLo(lite.Date2JD(date.UTC()))
}
// Distance 轻量日地距离 / lightweight Sun-Earth distance in AU.
func Distance(date time.Time) float64 {
return lite.SunDistanceAU(basic.Date2JD(date.UTC()))
return lite.SunDistanceAU(lite.Date2JD(date.UTC()))
}
// TrueRa 轻量真赤经 / lightweight true right ascension.
func TrueRa(date time.Time) float64 {
ra, _ := lite.SunTrueRaDec(basic.Date2JD(date.UTC()))
ra, _ := lite.SunTrueRaDec(lite.Date2JD(date.UTC()))
return ra
}
// TrueDec 轻量真赤纬 / lightweight true declination.
func TrueDec(date time.Time) float64 {
_, dec := lite.SunTrueRaDec(basic.Date2JD(date.UTC()))
_, dec := lite.SunTrueRaDec(lite.Date2JD(date.UTC()))
return dec
}
// TrueRaDec 轻量真赤经、真赤纬 / lightweight true right ascension and declination.
func TrueRaDec(date time.Time) (float64, float64) {
return lite.SunTrueRaDec(basic.Date2JD(date.UTC()))
return lite.SunTrueRaDec(lite.Date2JD(date.UTC()))
}
// ApparentRa 轻量视赤经 / lightweight apparent right ascension.
func ApparentRa(date time.Time) float64 {
ra, _ := lite.SunApparentRaDec(basic.Date2JD(date.UTC()))
ra, _ := lite.SunApparentRaDec(lite.Date2JD(date.UTC()))
return ra
}
// ApparentDec 轻量视赤纬 / lightweight apparent declination.
func ApparentDec(date time.Time) float64 {
_, dec := lite.SunApparentRaDec(basic.Date2JD(date.UTC()))
_, dec := lite.SunApparentRaDec(lite.Date2JD(date.UTC()))
return dec
}
// ApparentRaDec 轻量视赤经、视赤纬 / lightweight apparent right ascension and declination.
func ApparentRaDec(date time.Time) (float64, float64) {
return lite.SunApparentRaDec(basic.Date2JD(date.UTC()))
return lite.SunApparentRaDec(lite.Date2JD(date.UTC()))
}
// HourAngle 轻量时角 / lightweight hour angle.
func HourAngle(date time.Time, lon, lat float64) float64 {
_, _, hourAngle := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JD(date.UTC()), lon, lat)
_, _, hourAngle := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), lite.Date2JD(date.UTC()), lon, lat)
return hourAngle
}
// Azimuth 轻量方位角 / lightweight azimuth.
func Azimuth(date time.Time, lon, lat float64) float64 {
_, azimuth, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JD(date.UTC()), lon, lat)
_, azimuth, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), lite.Date2JD(date.UTC()), lon, lat)
return azimuth
}
// Altitude 轻量高度角 / lightweight altitude.
func Altitude(date time.Time, lon, lat float64) float64 {
altitude, _, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JD(date.UTC()), lon, lat)
altitude, _, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), lite.Date2JD(date.UTC()), lon, lat)
return altitude
}
@@ -89,7 +88,7 @@ func Zenith(date time.Time, lon, lat float64) float64 {
// RiseTime 轻量日出时刻 / lightweight sunrise time.
func RiseTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
if result, err, handled := civiltime.Event(date, basic.ErrNotOnThisDate, func(d time.Time) (time.Time, error) {
if result, err, handled := civiltime.Event(date, lite.ErrNotOnThisDate, func(d time.Time) (time.Time, error) {
return RiseTime(d, lon, lat, height, aero)
}); handled {
return result, err
@@ -99,7 +98,7 @@ func RiseTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, e
// SetTime 轻量日落时刻 / lightweight sunset time.
func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
if result, err, handled := civiltime.Event(date, basic.ErrNotOnThisDate, func(d time.Time) (time.Time, error) {
if result, err, handled := civiltime.Event(date, lite.ErrNotOnThisDate, func(d time.Time) (time.Time, error) {
return SetTime(d, lon, lat, height, aero)
}); handled {
return result, err
@@ -109,11 +108,11 @@ func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, er
func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (time.Time, error) {
localMidnight := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
localJD := basic.Date2JD(localMidnight)
localJD := lite.Date2JD(localMidnight)
_, offset := localMidnight.Zone()
timezone := float64(offset) / 3600.0
horizonDip := basic.HeightDegreeByLat(height, lat)
horizonDip := lite.HeightDegreeByLat(height, lat)
altitudeFn := func(localJD float64) float64 {
utcJD := localJD - timezone/24.0
@@ -121,7 +120,7 @@ func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (t
altitude, _, _ := lite.HorizontalCoordinates(ra, dec, utcJD, lon, lat)
residual := altitude + horizonDip
if aero {
residual += basic.RefractionFromTrueAltitude(altitude, 1010, 10)
residual += lite.RefractionFromTrueAltitude(altitude, 1010, 10)
residual += liteSunSemidiameterDegrees(lite.SunDistanceAU(utcJD))
}
return residual
@@ -138,7 +137,7 @@ func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (t
return time.Time{}, err
}
}
return basic.JD2DateByZone(eventJD-timezone/24, date.Location(), false), nil
return lite.JD2DateByZone(eventJD-timezone/24, date.Location(), false), nil
}
func liteSunSemidiameterDegrees(distanceAU float64) float64 {