feat: 扩展天文计算能力
- 新增日食、月食、本地可见性、中心线、半影区域、SVG 图示与沙罗周期信息 - 新增行星冲合、留、方照、物理星历、视直径、相位、亮肢角、轨道节点等计算 - 新增木星伽利略卫星位置、现象与接触事件计算 - 新增恒星星表、星座判定、自行修正与观测辅助能力 - 新增 coord、formula、orbit、sundial、lite/sun、lite/moon 等扩展包 - 完善农历年号、月相英文别名、视差角、大气质量、折射、日晷与双星计算 - 增加 NASA、JPL Horizons、IMCCE 等回归测试数据与基线测试 - 重构基础算法文件组织,补充大量公开 API 注释和语义回归测试 - 更新中文和英文 README,补充示例、精度说明、SVG 配图
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// ApsisInfo 轨道极值事件 / orbital distance extremum event.
|
||||
type ApsisInfo struct {
|
||||
// Time 事件时刻,UTC / event time in UTC.
|
||||
Time time.Time
|
||||
// Distance 极值距离,单位 km / extremum distance in km.
|
||||
Distance float64
|
||||
}
|
||||
|
||||
// PerigeesInMonth 指定年月内的所有月球近地点 / all lunar perigees in the given Gregorian month.
|
||||
func PerigeesInMonth(year int, month time.Month) []ApsisInfo {
|
||||
return convertMoonApsisInfos(basic.MoonPerigees(year, month))
|
||||
}
|
||||
|
||||
// ApogeesInMonth 指定年月内的所有月球远地点 / all lunar apogees in the given Gregorian month.
|
||||
func ApogeesInMonth(year int, month time.Month) []ApsisInfo {
|
||||
return convertMoonApsisInfos(basic.MoonApogees(year, month))
|
||||
}
|
||||
|
||||
func convertMoonApsisInfos(events []basic.ApsisEvent) []ApsisInfo {
|
||||
result := make([]ApsisInfo, 0, len(events))
|
||||
for _, event := range events {
|
||||
result = append(result, ApsisInfo{
|
||||
Time: basic.JDE2DateByZone(event.JDE, time.UTC, false),
|
||||
Distance: event.Distance,
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestApsisWrappersMatchBasic(t *testing.T) {
|
||||
perigees := basic.MoonPerigees(2026, time.January)
|
||||
perigeesWrapped := PerigeesInMonth(2026, time.January)
|
||||
if len(perigeesWrapped) != len(perigees) {
|
||||
t.Fatalf("perigee count mismatch: got %d want %d", len(perigeesWrapped), len(perigees))
|
||||
}
|
||||
for i, event := range perigees {
|
||||
wantTime := basic.JDE2DateByZone(event.JDE, time.UTC, false)
|
||||
if !perigeesWrapped[i].Time.Equal(wantTime) {
|
||||
t.Fatalf("perigee #%d time mismatch: got %s want %s", i+1, perigeesWrapped[i].Time.Format(time.RFC3339Nano), wantTime.Format(time.RFC3339Nano))
|
||||
}
|
||||
if math.Float64bits(perigeesWrapped[i].Distance) != math.Float64bits(event.Distance) {
|
||||
t.Fatalf("perigee #%d distance mismatch: got %.6f want %.6f", i+1, perigeesWrapped[i].Distance, event.Distance)
|
||||
}
|
||||
}
|
||||
|
||||
apogees := basic.MoonApogees(2026, time.June)
|
||||
apogeesWrapped := ApogeesInMonth(2026, time.June)
|
||||
if len(apogeesWrapped) != len(apogees) {
|
||||
t.Fatalf("apogee count mismatch: got %d want %d", len(apogeesWrapped), len(apogees))
|
||||
}
|
||||
for i, event := range apogees {
|
||||
wantTime := basic.JDE2DateByZone(event.JDE, time.UTC, false)
|
||||
if !apogeesWrapped[i].Time.Equal(wantTime) {
|
||||
t.Fatalf("apogee #%d time mismatch: got %s want %s", i+1, apogeesWrapped[i].Time.Format(time.RFC3339Nano), wantTime.Format(time.RFC3339Nano))
|
||||
}
|
||||
if math.Float64bits(apogeesWrapped[i].Distance) != math.Float64bits(event.Distance) {
|
||||
t.Fatalf("apogee #%d distance mismatch: got %.6f want %.6f", i+1, apogeesWrapped[i].Distance, event.Distance)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// Semidiameter 月亮视半径,单位角秒 / apparent lunar semidiameter in arcseconds.
|
||||
func Semidiameter(date time.Time) float64 {
|
||||
return SemidiameterN(date, -1)
|
||||
}
|
||||
|
||||
// SemidiameterN 月亮视半径(截断版),单位角秒 / truncated apparent lunar semidiameter in arcseconds.
|
||||
func SemidiameterN(date time.Time, n int) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.MoonSemidiameterN(basic.TD2UT(jde, true), n)
|
||||
}
|
||||
|
||||
// Diameter 月亮视直径,单位角秒 / apparent lunar diameter in arcseconds.
|
||||
func Diameter(date time.Time) float64 {
|
||||
return DiameterN(date, -1)
|
||||
}
|
||||
|
||||
// DiameterN 月亮视直径(截断版),单位角秒 / truncated apparent lunar diameter in arcseconds.
|
||||
func DiameterN(date time.Time, n int) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.MoonDiameterN(basic.TD2UT(jde, true), n)
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// MaximumDeclinationInfo 月球最大赤纬事件 / maximum lunar declination event.
|
||||
type MaximumDeclinationInfo struct {
|
||||
// Time 事件时刻,UTC / event time in UTC.
|
||||
Time time.Time
|
||||
// Declination 该时刻的地心赤纬,单位度 / geocentric declination at the event, in degrees.
|
||||
Declination float64
|
||||
}
|
||||
|
||||
// MaximumNorthDeclinationsInMonth 指定年月内的所有月球最大北赤纬事件 / all maximum northern lunar declination events in the given Gregorian month.
|
||||
func MaximumNorthDeclinationsInMonth(year int, month time.Month) []MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfos(basic.MoonMaximumNorthDeclinations(year, month))
|
||||
}
|
||||
|
||||
// MaximumSouthDeclinationsInMonth 指定年月内的所有月球最大南赤纬事件 / all maximum southern lunar declination events in the given Gregorian month.
|
||||
func MaximumSouthDeclinationsInMonth(year int, month time.Month) []MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfos(basic.MoonMaximumSouthDeclinations(year, month))
|
||||
}
|
||||
|
||||
// LastMaximumNorthDeclination 指定时刻之前最近一次月球最大北赤纬 / last maximum northern lunar declination at or before date.
|
||||
func LastMaximumNorthDeclination(date time.Time) MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfo(date, basic.LastMoonMaximumNorthDeclination(timeToUTJDE(date)))
|
||||
}
|
||||
|
||||
// NextMaximumNorthDeclination 指定时刻之后最近一次月球最大北赤纬 / next maximum northern lunar declination after date.
|
||||
func NextMaximumNorthDeclination(date time.Time) MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfo(date, basic.NextMoonMaximumNorthDeclination(timeToUTJDE(date)))
|
||||
}
|
||||
|
||||
// ClosestMaximumNorthDeclination 离指定时刻最近一次月球最大北赤纬 / closest maximum northern lunar declination to date.
|
||||
func ClosestMaximumNorthDeclination(date time.Time) MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfo(date, basic.ClosestMoonMaximumNorthDeclination(timeToUTJDE(date)))
|
||||
}
|
||||
|
||||
// LastMaximumSouthDeclination 指定时刻之前最近一次月球最大南赤纬 / last maximum southern lunar declination at or before date.
|
||||
func LastMaximumSouthDeclination(date time.Time) MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfo(date, basic.LastMoonMaximumSouthDeclination(timeToUTJDE(date)))
|
||||
}
|
||||
|
||||
// NextMaximumSouthDeclination 指定时刻之后最近一次月球最大南赤纬 / next maximum southern lunar declination after date.
|
||||
func NextMaximumSouthDeclination(date time.Time) MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfo(date, basic.NextMoonMaximumSouthDeclination(timeToUTJDE(date)))
|
||||
}
|
||||
|
||||
// ClosestMaximumSouthDeclination 离指定时刻最近一次月球最大南赤纬 / closest maximum southern lunar declination to date.
|
||||
func ClosestMaximumSouthDeclination(date time.Time) MaximumDeclinationInfo {
|
||||
return convertMaximumDeclinationInfo(date, basic.ClosestMoonMaximumSouthDeclination(timeToUTJDE(date)))
|
||||
}
|
||||
|
||||
func convertMaximumDeclinationInfos(events []basic.DeclinationEvent) []MaximumDeclinationInfo {
|
||||
result := make([]MaximumDeclinationInfo, 0, len(events))
|
||||
for _, event := range events {
|
||||
result = append(result, convertMaximumDeclinationInfo(time.Time{}, event))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func convertMaximumDeclinationInfo(date time.Time, event basic.DeclinationEvent) MaximumDeclinationInfo {
|
||||
location := time.UTC
|
||||
if date.Location() != nil {
|
||||
location = date.Location()
|
||||
}
|
||||
return MaximumDeclinationInfo{
|
||||
Time: basic.JDE2DateByZone(event.JDE, location, false),
|
||||
Declination: event.Declination,
|
||||
}
|
||||
}
|
||||
|
||||
func timeToUTJDE(date time.Time) float64 {
|
||||
return basic.Date2JDE(date.UTC())
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestMaximumDeclinationWrappersMatchBasic(t *testing.T) {
|
||||
north := basic.MoonMaximumNorthDeclinations(2026, time.January)
|
||||
northWrapped := MaximumNorthDeclinationsInMonth(2026, time.January)
|
||||
if len(northWrapped) != len(north) {
|
||||
t.Fatalf("north count mismatch: got %d want %d", len(northWrapped), len(north))
|
||||
}
|
||||
for i, event := range north {
|
||||
wantTime := basic.JDE2DateByZone(event.JDE, time.UTC, false)
|
||||
if !northWrapped[i].Time.Equal(wantTime) {
|
||||
t.Fatalf("north #%d time mismatch: got %s want %s", i+1, northWrapped[i].Time.Format(time.RFC3339Nano), wantTime.Format(time.RFC3339Nano))
|
||||
}
|
||||
if math.Float64bits(northWrapped[i].Declination) != math.Float64bits(event.Declination) {
|
||||
t.Fatalf("north #%d declination mismatch: got %.8f want %.8f", i+1, northWrapped[i].Declination, event.Declination)
|
||||
}
|
||||
}
|
||||
|
||||
south := basic.MoonMaximumSouthDeclinations(2026, time.June)
|
||||
southWrapped := MaximumSouthDeclinationsInMonth(2026, time.June)
|
||||
if len(southWrapped) != len(south) {
|
||||
t.Fatalf("south count mismatch: got %d want %d", len(southWrapped), len(south))
|
||||
}
|
||||
for i, event := range south {
|
||||
wantTime := basic.JDE2DateByZone(event.JDE, time.UTC, false)
|
||||
if !southWrapped[i].Time.Equal(wantTime) {
|
||||
t.Fatalf("south #%d time mismatch: got %s want %s", i+1, southWrapped[i].Time.Format(time.RFC3339Nano), wantTime.Format(time.RFC3339Nano))
|
||||
}
|
||||
if math.Float64bits(southWrapped[i].Declination) != math.Float64bits(event.Declination) {
|
||||
t.Fatalf("south #%d declination mismatch: got %.8f want %.8f", i+1, southWrapped[i].Declination, event.Declination)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaximumDeclinationSearchWrappersMatchBasic(t *testing.T) {
|
||||
loc := time.FixedZone("CST", 8*3600)
|
||||
query := time.Date(2026, time.January, 10, 18, 30, 0, 0, loc)
|
||||
queryJDE := basic.Date2JDE(query.UTC())
|
||||
|
||||
assertMaximumDeclinationInfoMatchesBasic(t, "last north", LastMaximumNorthDeclination(query), basic.LastMoonMaximumNorthDeclination(queryJDE), loc)
|
||||
assertMaximumDeclinationInfoMatchesBasic(t, "next north", NextMaximumNorthDeclination(query), basic.NextMoonMaximumNorthDeclination(queryJDE), loc)
|
||||
assertMaximumDeclinationInfoMatchesBasic(t, "closest north", ClosestMaximumNorthDeclination(query), basic.ClosestMoonMaximumNorthDeclination(queryJDE), loc)
|
||||
|
||||
assertMaximumDeclinationInfoMatchesBasic(t, "last south", LastMaximumSouthDeclination(query), basic.LastMoonMaximumSouthDeclination(queryJDE), loc)
|
||||
assertMaximumDeclinationInfoMatchesBasic(t, "next south", NextMaximumSouthDeclination(query), basic.NextMoonMaximumSouthDeclination(queryJDE), loc)
|
||||
assertMaximumDeclinationInfoMatchesBasic(t, "closest south", ClosestMaximumSouthDeclination(query), basic.ClosestMoonMaximumSouthDeclination(queryJDE), loc)
|
||||
}
|
||||
|
||||
func assertMaximumDeclinationInfoMatchesBasic(t *testing.T, name string, got MaximumDeclinationInfo, want basic.DeclinationEvent, loc *time.Location) {
|
||||
t.Helper()
|
||||
wantTime := basic.JDE2DateByZone(want.JDE, loc, false)
|
||||
if got.Time.Location() != loc {
|
||||
t.Fatalf("%s location mismatch: got %q want %q", name, got.Time.Location().String(), loc.String())
|
||||
}
|
||||
if !got.Time.Equal(wantTime) {
|
||||
t.Fatalf("%s time mismatch: got %s want %s", name, got.Time.Format(time.RFC3339Nano), wantTime.Format(time.RFC3339Nano))
|
||||
}
|
||||
if math.Float64bits(got.Declination) != math.Float64bits(want.Declination) {
|
||||
t.Fatalf("%s declination mismatch: got %.8f want %.8f", name, got.Declination, want.Declination)
|
||||
}
|
||||
}
|
||||
+270
-105
@@ -17,120 +17,166 @@ var (
|
||||
ERR_NOT_TODAY = errors.New("ERROR:月亮已在(昨日/明日)(升起/降下)")
|
||||
)
|
||||
|
||||
// TrueLo 月亮真黄经
|
||||
func riseSetResult(date time.Time, jde float64, err error) (time.Time, error) {
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, basic.ErrNotOnThisDate):
|
||||
return time.Time{}, ERR_NOT_TODAY
|
||||
case errors.Is(err, basic.ErrNeverRise):
|
||||
return time.Time{}, ERR_MOON_NEVER_RISE
|
||||
case errors.Is(err, basic.ErrNeverSet):
|
||||
return time.Time{}, ERR_MOON_NEVER_SET
|
||||
default:
|
||||
return time.Time{}, err
|
||||
}
|
||||
}
|
||||
return basic.JDE2DateByZone(jde, date.Location(), true), nil
|
||||
}
|
||||
|
||||
// TrueLo 月亮真黄经 / true ecliptic longitude.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的地心真黄经,单位度。
|
||||
// Returns the Moon's geocentric true ecliptic longitude at the instant represented by date, in degrees.
|
||||
func TrueLo(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueLo(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// TrueBo 月亮真黄纬
|
||||
// TrueLoN 截断项月亮真黄经 / truncated true ecliptic longitude.
|
||||
//
|
||||
// 参数与 TrueLo 相同;n<0 使用当前仓库内嵌的全部 ELP 项,其余值用于截断月球级数。
|
||||
// Uses the same inputs as TrueLo. n<0 keeps all embedded ELP terms in this repository; other values truncate the lunar series.
|
||||
func TrueLoN(date time.Time, n int) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueLoN(basic.TD2UT(jde, true), n)
|
||||
}
|
||||
|
||||
// TrueBo 月亮真黄纬 / true ecliptic latitude.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的地心真黄纬,单位度。
|
||||
// Returns the Moon's geocentric true ecliptic latitude at the instant represented by date, in degrees.
|
||||
func TrueBo(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueBo(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// ApparentLo 月亮视黄经(地心)
|
||||
// 传入UTC对应的儒略日时间
|
||||
// TrueBoN 截断项月亮真黄纬 / truncated true ecliptic latitude.
|
||||
//
|
||||
// 参数与 TrueBo 相同;n<0 使用当前仓库内嵌的全部 ELP 项,其余值用于截断月球级数。
|
||||
// Uses the same inputs as TrueBo. n<0 keeps all embedded ELP terms in this repository; other values truncate the lunar series.
|
||||
func TrueBoN(date time.Time, n int) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueBoN(basic.TD2UT(jde, true), n)
|
||||
}
|
||||
|
||||
// ApparentLo 月亮地心视黄经 / apparent geocentric ecliptic longitude.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的地心视黄经,单位度。
|
||||
// Returns the Moon's apparent geocentric ecliptic longitude at the instant represented by date, in degrees.
|
||||
func ApparentLo(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonApparentLo(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// TrueRa 月亮视赤经(地心)
|
||||
// date, 时间
|
||||
// 返回地心坐标
|
||||
// TrueRa 月亮地心真赤经 / true geocentric right ascension.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的地心真赤经,单位度。
|
||||
// Returns the Moon's geocentric true right ascension at the instant represented by date, in degrees.
|
||||
func TrueRa(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueRa(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// TrueDec 月亮视赤纬(地心)
|
||||
// date, 时间
|
||||
// 返回地心坐标
|
||||
// TrueDec 月亮地心真赤纬 / true geocentric declination.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的地心真赤纬,单位度。
|
||||
// Returns the Moon's geocentric true declination at the instant represented by date, in degrees.
|
||||
func TrueDec(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueDec(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// TrueRaDec 月亮视赤纬赤纬(地心)
|
||||
// date, 时间
|
||||
// 返回地心坐标
|
||||
// TrueRaDec 月亮地心真赤经、真赤纬 / true geocentric right ascension and declination.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的地心真赤经与真赤纬,单位度。
|
||||
// Returns the Moon's geocentric true right ascension and declination at the instant represented by date, in degrees.
|
||||
func TrueRaDec(date time.Time) (float64, float64) {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.HMoonTrueRaDec(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// ApparentRa 月亮视赤经(站心)
|
||||
// date, 时间
|
||||
// lon, 经度
|
||||
// lat, 纬度
|
||||
// 返回站心坐标
|
||||
// ApparentRa 月亮站心视赤经 / apparent topocentric right ascension.
|
||||
//
|
||||
// date 为观测时刻,会读取其时区参与地方时计算;lon/lat 为观测者经纬度,东正西负、北正南负;返回值单位度。
|
||||
// date is the observing instant and its zone offset participates in local-time calculations. lon/lat are east-positive and north-positive; the result is in degrees.
|
||||
func ApparentRa(date time.Time, lon, lat float64) float64 {
|
||||
jde := basic.Date2JDE(date)
|
||||
_, loc := date.Zone()
|
||||
return basic.HMoonApparentRa(jde, lon, lat, float64(loc)/3600.0)
|
||||
}
|
||||
|
||||
// ApparentDec 月亮视赤纬(站心)
|
||||
// date, 时间
|
||||
// lon, 经度
|
||||
// lat, 纬度
|
||||
// 返回站心坐标
|
||||
// ApparentDec 月亮站心视赤纬 / apparent topocentric declination.
|
||||
//
|
||||
// 参数与 ApparentRa 相同,返回月亮站心视赤纬,单位度。
|
||||
// Uses the same inputs as ApparentRa and returns the Moon's apparent topocentric declination in degrees.
|
||||
func ApparentDec(date time.Time, lon, lat float64) float64 {
|
||||
jde := basic.Date2JDE(date)
|
||||
_, loc := date.Zone()
|
||||
return basic.HMoonApparentDec(jde, lon, lat, float64(loc)/3600.0)
|
||||
}
|
||||
|
||||
// ApparentRaDec 月亮视赤纬(站心)
|
||||
// date, 本地时间
|
||||
// lon, 经度
|
||||
// lat, 纬度
|
||||
// 返回站心坐标
|
||||
// ApparentRaDec 月亮站心视赤经、视赤纬 / apparent topocentric right ascension and declination.
|
||||
//
|
||||
// 参数与 ApparentRa 相同,返回月亮站心视赤经与视赤纬,单位度。
|
||||
// Uses the same inputs as ApparentRa and returns the Moon's apparent topocentric right ascension and declination in degrees.
|
||||
func ApparentRaDec(date time.Time, lon, lat float64) (float64, float64) {
|
||||
jde := basic.Date2JDE(date)
|
||||
_, loc := date.Zone()
|
||||
return basic.HMoonApparentRaDec(jde, lon, lat, float64(loc)/3600.0)
|
||||
}
|
||||
|
||||
// HourAngle 月亮时角
|
||||
// HourAngle 月亮时角 / hour angle.
|
||||
//
|
||||
// date, 世界时(忽略此处时区)
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
// date 为观测时刻,会读取其时区参与地方时计算;lon/lat 为观测者经纬度,东正西负、北正南负;返回值单位度。
|
||||
// date is the observing instant and its zone offset participates in local-time calculations. lon/lat are east-positive and north-positive; the result is in degrees.
|
||||
func HourAngle(date time.Time, lon, lat float64) float64 {
|
||||
jde := basic.Date2JDE(date)
|
||||
_, loc := date.Zone()
|
||||
return basic.MoonTimeAngle(jde, lon, lat, float64(loc)/3600.0)
|
||||
}
|
||||
|
||||
// Azimuth 月亮方位角
|
||||
// Azimuth 月亮方位角 / azimuth.
|
||||
//
|
||||
// date, 世界时(忽略此处时区)
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
// date 为观测时刻,会读取其时区参与地方时计算;lon/lat 为观测者经纬度,东正西负、北正南负;返回值按正北为 0°、向东增加。
|
||||
// date is the observing instant and its zone offset participates in local-time calculations. lon/lat are east-positive and north-positive; azimuth is measured from north toward east.
|
||||
func Azimuth(date time.Time, lon, lat float64) float64 {
|
||||
jde := basic.Date2JDE(date)
|
||||
_, loc := date.Zone()
|
||||
return basic.HMoonAngle(jde, lon, lat, float64(loc)/3600.0)
|
||||
return basic.HMoonAzimuth(jde, lon, lat, float64(loc)/3600.0)
|
||||
}
|
||||
|
||||
// Zenith 月亮高度角
|
||||
// Altitude 月亮高度角 / lunar altitude.
|
||||
//
|
||||
// date, 世界时(忽略此处时区)
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
func Zenith(date time.Time, lon, lat float64) float64 {
|
||||
// date 为观测时刻,会读取其时区参与地方时计算;lon/lat 为观测者经纬度,东正西负、北正南负;返回值单位度。
|
||||
// date is the observing instant and its zone offset participates in local-time calculations. lon/lat are east-positive and north-positive; the result is in degrees.
|
||||
func Altitude(date time.Time, lon, lat float64) float64 {
|
||||
jde := basic.Date2JDE(date)
|
||||
_, loc := date.Zone()
|
||||
return basic.HMoonHeight(jde, lon, lat, float64(loc)/3600.0)
|
||||
}
|
||||
|
||||
// CulminationTime 月亮中天时间
|
||||
// Zenith 月亮天顶距 / lunar zenith distance.
|
||||
//
|
||||
// date, 世界时(忽略此处时区)
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
// 参数与 Altitude 相同,返回值为对应时刻的天顶距,单位度。
|
||||
// Uses the same inputs as Altitude and returns the zenith distance in degrees.
|
||||
func Zenith(date time.Time, lon, lat float64) float64 {
|
||||
return 90 - Altitude(date, lon, lat)
|
||||
}
|
||||
|
||||
// CulminationTime 月亮中天时刻 / culmination time.
|
||||
//
|
||||
// date 取其所在时区的当地日期,返回值保持相同时区;lon/lat 为观测者经纬度,东正西负、北正南负。
|
||||
// date is interpreted on its local civil day and the result keeps the same time zone. lon/lat are east-positive and north-positive.
|
||||
func CulminationTime(date time.Time, lon, lat float64) time.Time {
|
||||
if date.Hour() > 12 {
|
||||
date = date.Add(time.Hour * -12)
|
||||
@@ -140,15 +186,13 @@ func CulminationTime(date time.Time, lon, lat float64) time.Time {
|
||||
return basic.JDE2DateByZone(basic.MoonCulminationTime(jde, lon, lat, float64(loc)/3600.0), date.Location(), true)
|
||||
}
|
||||
|
||||
// RiseTime 月亮升起时间
|
||||
// RiseTime 月出时刻 / moonrise time.
|
||||
//
|
||||
// date, 世界时(忽略此处时区)
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
// height,高度
|
||||
// aero,是否进行大气修正
|
||||
// date 取其所在时区的当地日期,返回值保持相同时区;lon/lat 为观测者经纬度,东正西负、北正南负;
|
||||
// height 为海拔高度,单位米;aero 为 true 时加入标准大气折射。
|
||||
// date is interpreted on its local civil day and the result keeps the same time zone. lon/lat are east-positive and north-positive;
|
||||
// height is observer elevation in meters, and aero enables standard atmospheric refraction.
|
||||
func RiseTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
|
||||
var err error
|
||||
if date.Hour() > 12 {
|
||||
date = date.Add(time.Hour * -12)
|
||||
}
|
||||
@@ -159,39 +203,25 @@ func RiseTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, e
|
||||
if aero {
|
||||
aeroFloat = 1
|
||||
}
|
||||
riseJde := basic.GetMoonRiseTime(jde, lon, lat, timezone, aeroFloat, height)
|
||||
if riseJde == -3 {
|
||||
err = ERR_NOT_TODAY
|
||||
}
|
||||
if riseJde == -2 {
|
||||
err = ERR_MOON_NEVER_RISE
|
||||
}
|
||||
if riseJde == -1 {
|
||||
err = ERR_MOON_NEVER_SET
|
||||
}
|
||||
return basic.JDE2DateByZone(riseJde, date.Location(), true), err
|
||||
riseJde, err := basic.GetMoonRiseTime(jde, lon, lat, timezone, aeroFloat, height)
|
||||
return riseSetResult(date, riseJde, err)
|
||||
}
|
||||
|
||||
// deprecated: -- use SetTime instead
|
||||
// DownTime 落下时间
|
||||
// date,取日期,时区忽略
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
// height,高度
|
||||
// aero,true时进行大气修正
|
||||
// DownTime 月落时刻别名 / deprecated moonset alias.
|
||||
//
|
||||
// Deprecated: use SetTime instead.
|
||||
//
|
||||
// 参数与 SetTime 相同,仅为兼容旧接口保留。
|
||||
// Same as SetTime and kept only for backward compatibility.
|
||||
func DownTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
|
||||
return SetTime(date, lon, lat, height, aero)
|
||||
}
|
||||
|
||||
// SetTime 月亮降下时间
|
||||
// SetTime 月落时刻 / moonset time.
|
||||
//
|
||||
// date, 世界时(忽略此处时区)
|
||||
// lon,经度,东正西负
|
||||
// lat,纬度,北正南负
|
||||
// height,高度
|
||||
// aero,大气修正
|
||||
// 参数与 RiseTime 相同,返回给定当地日期内的月落时刻。
|
||||
// Uses the same inputs as RiseTime and returns the moonset time on the corresponding local civil day.
|
||||
func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
|
||||
var err error
|
||||
if date.Hour() > 12 {
|
||||
date = date.Add(time.Hour * -12)
|
||||
}
|
||||
@@ -202,21 +232,14 @@ func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, er
|
||||
if aero {
|
||||
aeroFloat = 1
|
||||
}
|
||||
downJde := basic.GetMoonSetTime(jde, lon, lat, timezone, aeroFloat, height)
|
||||
if downJde == -3 {
|
||||
err = ERR_NOT_TODAY
|
||||
}
|
||||
if downJde == -2 {
|
||||
err = ERR_MOON_NEVER_RISE
|
||||
}
|
||||
if downJde == -1 {
|
||||
err = ERR_MOON_NEVER_SET
|
||||
}
|
||||
return basic.JDE2DateByZone(downJde, date.Location(), true), err
|
||||
downJde, err := basic.GetMoonSetTime(jde, lon, lat, timezone, aeroFloat, height)
|
||||
return riseSetResult(date, downJde, err)
|
||||
}
|
||||
|
||||
// SunMoonLoDiff 日月黄经差,新月时为0,满月时为180
|
||||
// 取值范围[0,360)
|
||||
// SunMoonLoDiff 日月黄经差 / Moon-Sun longitude difference.
|
||||
//
|
||||
// 返回月亮视黄经减去太阳视黄经的结果,单位度,取值范围 [0, 360);新月附近接近 0°,满月附近接近 180°。
|
||||
// Returns apparent lunar longitude minus apparent solar longitude in degrees, normalized to [0, 360). It is near 0° at new moon and near 180° at full moon.
|
||||
func SunMoonLoDiff(date time.Time) float64 {
|
||||
jde := basic.TD2UT(basic.Date2JDE(date.UTC()), true)
|
||||
sunLo := basic.HSunApparentLo(jde)
|
||||
@@ -224,9 +247,10 @@ func SunMoonLoDiff(date time.Time) float64 {
|
||||
return tools.Limit360(moonLo - sunLo)
|
||||
}
|
||||
|
||||
// PhaseDesc 月相描述
|
||||
// 返回Date对应UTC世界时的月相描述
|
||||
// 取值范围:新月,上峨眉月,上弦月,盈凸月,满月,亏凸月,下弦月,下峨眉月,残月
|
||||
// PhaseDesc 月相文字描述 / textual lunar phase description.
|
||||
//
|
||||
// 基于 SunMoonLoDiff 的分段结果返回中文月相名称。
|
||||
// Returns a Chinese phase name derived from the segmented Moon-Sun longitude difference.
|
||||
func PhaseDesc(date time.Time) string {
|
||||
moonSunLoDiff := SunMoonLoDiff(date)
|
||||
if moonSunLoDiff >= 0 && moonSunLoDiff <= 30 {
|
||||
@@ -250,34 +274,68 @@ func PhaseDesc(date time.Time) string {
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 月相
|
||||
// 返回Date对应UTC世界时的月相大小
|
||||
// Phase 月面受照比例 / illuminated fraction.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻的受照比例,范围 [0, 1]。
|
||||
// Returns the Moon's illuminated fraction at the instant represented by date, in the range [0, 1].
|
||||
func Phase(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
return basic.MoonPhase(basic.TD2UT(jde, true))
|
||||
}
|
||||
|
||||
// ShuoYue 朔月
|
||||
// 返回Date对应UTC世界时的月相大小
|
||||
// ShuoYue 朔月锚点解 / new-moon solution near a decimal year anchor.
|
||||
//
|
||||
// year 为公历小数年锚点,例如 2025.0 或 2025.5;返回以该锚点求得的一次朔月时刻,结果为 UTC。
|
||||
// year is a decimal Gregorian-year anchor such as 2025.0 or 2025.5. The returned time is one new moon solved near that anchor, in UTC.
|
||||
func ShuoYue(year float64) time.Time {
|
||||
jde := basic.TD2UT(basic.CalcMoonSH(year, 0), false)
|
||||
return basic.JDE2DateByZone(jde, time.UTC, false)
|
||||
}
|
||||
|
||||
// NextShuoYue 下次朔月时间
|
||||
// 返回date之后的下一个朔月时间(UTC时间)
|
||||
// NextShuoYue 下一次朔月 / next new moon.
|
||||
//
|
||||
// 返回 date 之后最近一次朔月时刻,结果保持 date 的时区。
|
||||
// Returns the next new moon after date, keeping date's time zone.
|
||||
func NextShuoYue(date time.Time) time.Time {
|
||||
return nextMoonPhase(date, 0)
|
||||
}
|
||||
|
||||
// LastShuoYue 上一次朔月 / previous new moon.
|
||||
//
|
||||
// 返回 date 之前最近一次朔月时刻,结果保持 date 的时区。
|
||||
// Returns the previous new moon before date, keeping date's time zone.
|
||||
func LastShuoYue(date time.Time) time.Time {
|
||||
return lastMoonPhase(date, 0)
|
||||
}
|
||||
|
||||
// ClosestShuoYue 最近朔月 / closest new moon.
|
||||
//
|
||||
// 返回离 date 最近的朔月时刻,结果保持 date 的时区。
|
||||
// Returns the new moon nearest to date, keeping date's time zone.
|
||||
func ClosestShuoYue(date time.Time) time.Time {
|
||||
return closestMoonPhase(date, 0)
|
||||
}
|
||||
|
||||
// NewMoon 朔月英文别名 / English alias for ShuoYue.
|
||||
func NewMoon(year float64) time.Time {
|
||||
return ShuoYue(year)
|
||||
}
|
||||
|
||||
// NextNewMoon 下一次朔月英文别名 / English alias for NextShuoYue.
|
||||
func NextNewMoon(date time.Time) time.Time {
|
||||
return NextShuoYue(date)
|
||||
}
|
||||
|
||||
// LastNewMoon 上一次朔月英文别名 / English alias for LastShuoYue.
|
||||
func LastNewMoon(date time.Time) time.Time {
|
||||
return LastShuoYue(date)
|
||||
}
|
||||
|
||||
// ClosestNewMoon 最近朔月英文别名 / English alias for ClosestShuoYue.
|
||||
func ClosestNewMoon(date time.Time) time.Time {
|
||||
return ClosestShuoYue(date)
|
||||
}
|
||||
|
||||
func closestMoonPhase(date time.Time, typed int) time.Time {
|
||||
//0=shuo 1=wang 2=shangxian 3=xiaxian
|
||||
jde := basic.TD2UT(basic.Date2JDE(date.UTC()), true)
|
||||
@@ -343,62 +401,169 @@ func lastMoonPhase(date time.Time, typed int) time.Time {
|
||||
return basic.JDE2DateByZone(basic.TD2UT(basic.CalcMoonXHByJDE(jde, typed-2), false), date.Location(), false)
|
||||
}
|
||||
|
||||
// WangYue 望月
|
||||
// WangYue 望月锚点解 / full-moon solution near a decimal year anchor.
|
||||
//
|
||||
// year 为公历小数年锚点,例如 2025.0 或 2025.5;返回以该锚点求得的一次望月时刻,结果为 UTC。
|
||||
// year is a decimal Gregorian-year anchor such as 2025.0 or 2025.5. The returned time is one full moon solved near that anchor, in UTC.
|
||||
func WangYue(year float64) time.Time {
|
||||
jde := basic.TD2UT(basic.CalcMoonSH(year, 1), false)
|
||||
return basic.JDE2DateByZone(jde, time.UTC, false)
|
||||
}
|
||||
|
||||
// NextWangYue 下一次望月 / next full moon.
|
||||
//
|
||||
// 返回 date 之后最近一次望月时刻,结果保持 date 的时区。
|
||||
// Returns the next full moon after date, keeping date's time zone.
|
||||
func NextWangYue(date time.Time) time.Time {
|
||||
return nextMoonPhase(date, 1)
|
||||
}
|
||||
|
||||
// LastWangYue 上一次望月 / previous full moon.
|
||||
//
|
||||
// 返回 date 之前最近一次望月时刻,结果保持 date 的时区。
|
||||
// Returns the previous full moon before date, keeping date's time zone.
|
||||
func LastWangYue(date time.Time) time.Time {
|
||||
return lastMoonPhase(date, 1)
|
||||
}
|
||||
|
||||
// ClosestWangYue 最近望月 / closest full moon.
|
||||
//
|
||||
// 返回离 date 最近的望月时刻,结果保持 date 的时区。
|
||||
// Returns the full moon nearest to date, keeping date's time zone.
|
||||
func ClosestWangYue(date time.Time) time.Time {
|
||||
return closestMoonPhase(date, 1)
|
||||
}
|
||||
|
||||
// ShangXianYue 上弦月
|
||||
// FullMoon 望月英文别名 / English alias for WangYue.
|
||||
func FullMoon(year float64) time.Time {
|
||||
return WangYue(year)
|
||||
}
|
||||
|
||||
// NextFullMoon 下一次望月英文别名 / English alias for NextWangYue.
|
||||
func NextFullMoon(date time.Time) time.Time {
|
||||
return NextWangYue(date)
|
||||
}
|
||||
|
||||
// LastFullMoon 上一次望月英文别名 / English alias for LastWangYue.
|
||||
func LastFullMoon(date time.Time) time.Time {
|
||||
return LastWangYue(date)
|
||||
}
|
||||
|
||||
// ClosestFullMoon 最近望月英文别名 / English alias for ClosestWangYue.
|
||||
func ClosestFullMoon(date time.Time) time.Time {
|
||||
return ClosestWangYue(date)
|
||||
}
|
||||
|
||||
// ShangXianYue 上弦锚点解 / first-quarter solution near a decimal year anchor.
|
||||
//
|
||||
// year 为公历小数年锚点,例如 2025.0 或 2025.5;返回以该锚点求得的一次上弦时刻,结果为 UTC。
|
||||
// year is a decimal Gregorian-year anchor such as 2025.0 or 2025.5. The returned time is one first-quarter solution near that anchor, in UTC.
|
||||
func ShangXianYue(year float64) time.Time {
|
||||
jde := basic.TD2UT(basic.CalcMoonXH(year, 0), false)
|
||||
return basic.JDE2DateByZone(jde, time.UTC, false)
|
||||
}
|
||||
|
||||
// NextShangXianYue 下一次上弦 / next first quarter.
|
||||
//
|
||||
// 返回 date 之后最近一次上弦时刻,结果保持 date 的时区。
|
||||
// Returns the next first quarter after date, keeping date's time zone.
|
||||
func NextShangXianYue(date time.Time) time.Time {
|
||||
return nextMoonPhase(date, 2)
|
||||
}
|
||||
|
||||
// LastShangXianYue 上一次上弦 / previous first quarter.
|
||||
//
|
||||
// 返回 date 之前最近一次上弦时刻,结果保持 date 的时区。
|
||||
// Returns the previous first quarter before date, keeping date's time zone.
|
||||
func LastShangXianYue(date time.Time) time.Time {
|
||||
return lastMoonPhase(date, 2)
|
||||
}
|
||||
|
||||
// ClosestShangXianYue 最近上弦 / closest first quarter.
|
||||
//
|
||||
// 返回离 date 最近的上弦时刻,结果保持 date 的时区。
|
||||
// Returns the first quarter nearest to date, keeping date's time zone.
|
||||
func ClosestShangXianYue(date time.Time) time.Time {
|
||||
return closestMoonPhase(date, 2)
|
||||
}
|
||||
|
||||
// XiaXianYue 下弦月
|
||||
// FirstQuarter 上弦英文别名 / English alias for ShangXianYue.
|
||||
func FirstQuarter(year float64) time.Time {
|
||||
return ShangXianYue(year)
|
||||
}
|
||||
|
||||
// NextFirstQuarter 下一次上弦英文别名 / English alias for NextShangXianYue.
|
||||
func NextFirstQuarter(date time.Time) time.Time {
|
||||
return NextShangXianYue(date)
|
||||
}
|
||||
|
||||
// LastFirstQuarter 上一次上弦英文别名 / English alias for LastShangXianYue.
|
||||
func LastFirstQuarter(date time.Time) time.Time {
|
||||
return LastShangXianYue(date)
|
||||
}
|
||||
|
||||
// ClosestFirstQuarter 最近上弦英文别名 / English alias for ClosestShangXianYue.
|
||||
func ClosestFirstQuarter(date time.Time) time.Time {
|
||||
return ClosestShangXianYue(date)
|
||||
}
|
||||
|
||||
// XiaXianYue 下弦锚点解 / last-quarter solution near a decimal year anchor.
|
||||
//
|
||||
// year 为公历小数年锚点,例如 2025.0 或 2025.5;返回以该锚点求得的一次下弦时刻,结果为 UTC。
|
||||
// year is a decimal Gregorian-year anchor such as 2025.0 or 2025.5. The returned time is one last-quarter solution near that anchor, in UTC.
|
||||
func XiaXianYue(year float64) time.Time {
|
||||
jde := basic.TD2UT(basic.CalcMoonXH(year, 1), false)
|
||||
return basic.JDE2DateByZone(jde, time.UTC, false)
|
||||
}
|
||||
|
||||
// NextXiaXianYue 下一次下弦 / next last quarter.
|
||||
//
|
||||
// 返回 date 之后最近一次下弦时刻,结果保持 date 的时区。
|
||||
// Returns the next last quarter after date, keeping date's time zone.
|
||||
func NextXiaXianYue(date time.Time) time.Time {
|
||||
return nextMoonPhase(date, 3)
|
||||
}
|
||||
|
||||
// LastXiaXianYue 上一次下弦 / previous last quarter.
|
||||
//
|
||||
// 返回 date 之前最近一次下弦时刻,结果保持 date 的时区。
|
||||
// Returns the previous last quarter before date, keeping date's time zone.
|
||||
func LastXiaXianYue(date time.Time) time.Time {
|
||||
return lastMoonPhase(date, 3)
|
||||
}
|
||||
|
||||
// ClosestXiaXianYue 最近下弦 / closest last quarter.
|
||||
//
|
||||
// 返回离 date 最近的下弦时刻,结果保持 date 的时区。
|
||||
// Returns the last quarter nearest to date, keeping date's time zone.
|
||||
func ClosestXiaXianYue(date time.Time) time.Time {
|
||||
return closestMoonPhase(date, 3)
|
||||
}
|
||||
|
||||
// EarthDistance 日地距离
|
||||
// 返回date对应UTC世界时日地距离
|
||||
// LastQuarter 下弦英文别名 / English alias for XiaXianYue.
|
||||
func LastQuarter(year float64) time.Time {
|
||||
return XiaXianYue(year)
|
||||
}
|
||||
|
||||
// NextLastQuarter 下一次下弦英文别名 / English alias for NextXiaXianYue.
|
||||
func NextLastQuarter(date time.Time) time.Time {
|
||||
return NextXiaXianYue(date)
|
||||
}
|
||||
|
||||
// LastLastQuarter 上一次下弦英文别名 / English alias for LastXiaXianYue.
|
||||
func LastLastQuarter(date time.Time) time.Time {
|
||||
return LastXiaXianYue(date)
|
||||
}
|
||||
|
||||
// ClosestLastQuarter 最近下弦英文别名 / English alias for ClosestXiaXianYue.
|
||||
func ClosestLastQuarter(date time.Time) time.Time {
|
||||
return ClosestXiaXianYue(date)
|
||||
}
|
||||
|
||||
// EarthDistance 地月距离 / Earth-Moon distance.
|
||||
//
|
||||
// 返回月亮在 date 对应绝对时刻到地球质心的距离,单位千米。
|
||||
// Returns the distance from the Moon to Earth's center at the instant represented by date, in kilometers.
|
||||
func EarthDistance(date time.Time) float64 {
|
||||
jde := basic.Date2JDE(date)
|
||||
jde = basic.TD2UT(jde, true)
|
||||
|
||||
+47
-30
@@ -1,54 +1,71 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_MoonPhaseDate(t *testing.T) {
|
||||
assertUnixClose := func(name string, got time.Time, want int64) {
|
||||
t.Helper()
|
||||
if math.Abs(float64(got.Unix()-want)) > 5 {
|
||||
t.Fatalf("%s = %d, want %d", name, got.Unix(), want)
|
||||
}
|
||||
}
|
||||
|
||||
//指定北京时间2022年1月20日
|
||||
tz := time.FixedZone("CST", 8*3600)
|
||||
date := time.Date(2022, 01, 20, 00, 00, 00, 00, tz)
|
||||
//指定日期后的下一个朔月
|
||||
moonPhase01 := NextShuoYue(date)
|
||||
fmt.Println("下一朔月", moonPhase01)
|
||||
if moonPhase01.Unix() != 1643694356 {
|
||||
t.Fatal(moonPhase01.Unix())
|
||||
}
|
||||
assertUnixClose("NextShuoYue", moonPhase01, 1643694356)
|
||||
//指定日期后的上一个朔月
|
||||
moonPhase01 = LastShuoYue(date)
|
||||
fmt.Println("上一朔月", moonPhase01)
|
||||
if moonPhase01.Unix() != 1641148406 {
|
||||
t.Fatal(moonPhase01.Unix())
|
||||
}
|
||||
assertUnixClose("LastShuoYue", moonPhase01, 1641148406)
|
||||
//离指定日期最近的朔月
|
||||
moonPhase01 = ClosestShuoYue(date)
|
||||
fmt.Println("最近朔月", moonPhase01)
|
||||
if moonPhase01.Unix() != 1643694356 {
|
||||
t.Fatal(moonPhase01.Unix())
|
||||
}
|
||||
assertUnixClose("ClosestShuoYue", moonPhase01, 1643694356)
|
||||
//离指定日期最近的望月时间
|
||||
moonPhase01 = ClosestWangYue(date)
|
||||
fmt.Println("最近望月", moonPhase01)
|
||||
if moonPhase01.Unix() != 1642463301 {
|
||||
t.Fatal(moonPhase01.Unix())
|
||||
}
|
||||
assertUnixClose("ClosestWangYue", moonPhase01, 1642463301)
|
||||
//离指定日期最近的上弦月时间
|
||||
moonPhase01 = ClosestShangXianYue(date)
|
||||
fmt.Println("最近上弦月", moonPhase01)
|
||||
if moonPhase01.Unix() != 1641751871 {
|
||||
t.Fatal(moonPhase01.Unix())
|
||||
}
|
||||
assertUnixClose("ClosestShangXianYue", moonPhase01, 1641751871)
|
||||
//离指定日期最近的下弦月时间
|
||||
moonPhase01 = ClosestXiaXianYue(date)
|
||||
fmt.Println("最近下弦月", moonPhase01)
|
||||
if moonPhase01.Unix() != 1643118050 {
|
||||
t.Fatal(moonPhase01.Unix())
|
||||
}
|
||||
//-------------------
|
||||
for i := 0; i < 26; i++ {
|
||||
moonPhase01 = LastShuoYue(moonPhase01)
|
||||
fmt.Println("上一朔月", moonPhase01)
|
||||
}
|
||||
assertUnixClose("ClosestXiaXianYue", moonPhase01, 1643118050)
|
||||
}
|
||||
|
||||
func TestMoonPhaseEnglishAliases(t *testing.T) {
|
||||
tz := time.FixedZone("CST", 8*3600)
|
||||
date := time.Date(2022, 1, 20, 0, 0, 0, 0, tz)
|
||||
year := 2022.25
|
||||
|
||||
assertSameTime := func(name string, got, want time.Time) {
|
||||
t.Helper()
|
||||
if !got.Equal(want) {
|
||||
t.Fatalf("%s = %s, want %s", name, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
assertSameTime("NewMoon", NewMoon(year), ShuoYue(year))
|
||||
assertSameTime("NextNewMoon", NextNewMoon(date), NextShuoYue(date))
|
||||
assertSameTime("LastNewMoon", LastNewMoon(date), LastShuoYue(date))
|
||||
assertSameTime("ClosestNewMoon", ClosestNewMoon(date), ClosestShuoYue(date))
|
||||
|
||||
assertSameTime("FullMoon", FullMoon(year), WangYue(year))
|
||||
assertSameTime("NextFullMoon", NextFullMoon(date), NextWangYue(date))
|
||||
assertSameTime("LastFullMoon", LastFullMoon(date), LastWangYue(date))
|
||||
assertSameTime("ClosestFullMoon", ClosestFullMoon(date), ClosestWangYue(date))
|
||||
|
||||
assertSameTime("FirstQuarter", FirstQuarter(year), ShangXianYue(year))
|
||||
assertSameTime("NextFirstQuarter", NextFirstQuarter(date), NextShangXianYue(date))
|
||||
assertSameTime("LastFirstQuarter", LastFirstQuarter(date), LastShangXianYue(date))
|
||||
assertSameTime("ClosestFirstQuarter", ClosestFirstQuarter(date), ClosestShangXianYue(date))
|
||||
|
||||
assertSameTime("LastQuarter", LastQuarter(year), XiaXianYue(year))
|
||||
assertSameTime("NextLastQuarter", NextLastQuarter(date), NextXiaXianYue(date))
|
||||
assertSameTime("LastLastQuarter", LastLastQuarter(date), LastXiaXianYue(date))
|
||||
assertSameTime("ClosestLastQuarter", ClosestLastQuarter(date), ClosestXiaXianYue(date))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// AscendingNode 月球升交点黄经 / ascending node longitude of the Moon.
|
||||
func AscendingNode(date time.Time) float64 {
|
||||
return AscendingNodeN(date, -1)
|
||||
}
|
||||
|
||||
// AscendingNodeN 月球升交点黄经(截断版) / truncated ascending node longitude of the Moon.
|
||||
func AscendingNodeN(date time.Time, n int) float64 {
|
||||
jde := basic.TD2UT(basic.Date2JDE(date.UTC()), true)
|
||||
return basic.MoonAscendingNodeN(jde, n)
|
||||
}
|
||||
|
||||
// DescendingNode 月球降交点黄经 / descending node longitude of the Moon.
|
||||
func DescendingNode(date time.Time) float64 {
|
||||
return DescendingNodeN(date, -1)
|
||||
}
|
||||
|
||||
// DescendingNodeN 月球降交点黄经(截断版) / truncated descending node longitude of the Moon.
|
||||
func DescendingNodeN(date time.Time, n int) float64 {
|
||||
jde := basic.TD2UT(basic.Date2JDE(date.UTC()), true)
|
||||
return basic.MoonDescendingNodeN(jde, n)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// ParallacticAngle 月亮视差角(天顶方向角) / lunar parallactic angle.
|
||||
//
|
||||
// 对月亮使用现有站心视时角和站心视赤纬链路,因此会显式依赖观测者经纬度。
|
||||
func ParallacticAngle(date time.Time, lon, lat float64) float64 {
|
||||
return basic.ParallacticAngleByHourAngle(HourAngle(date, lon, lat), ApparentDec(date, lon, lat), lat)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestParallacticAngleMatchesHourAngleForm(t *testing.T) {
|
||||
date := time.Date(2026, 4, 29, 21, 15, 0, 0, time.FixedZone("CST", 8*3600))
|
||||
lon := 116.391
|
||||
lat := 39.907
|
||||
|
||||
got := ParallacticAngle(date, lon, lat)
|
||||
want := basic.ParallacticAngleByHourAngle(HourAngle(date, lon, lat), ApparentDec(date, lon, lat), lat)
|
||||
if math.Abs(got-want) > 1e-12 {
|
||||
t.Fatalf("parallactic angle mismatch: got %.15f want %.15f", got, want)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// BrightLimbPositionAngle 月亮明亮边缘位置角,单位度 / position angle of the Moon's bright limb in degrees.
|
||||
func BrightLimbPositionAngle(date time.Time) float64 {
|
||||
return BrightLimbPositionAngleN(date, -1)
|
||||
}
|
||||
|
||||
// BrightLimbPositionAngleN 月亮明亮边缘位置角(截断版),单位度 / truncated position angle of the Moon's bright limb in degrees.
|
||||
func BrightLimbPositionAngleN(date time.Time, n int) float64 {
|
||||
return basic.MoonBrightLimbPositionAngleN(observationTT(date), n)
|
||||
}
|
||||
|
||||
// TopocentricBrightLimbPositionAngle 月亮站心明亮边缘位置角,单位度 / topocentric position angle of the Moon's bright limb in degrees.
|
||||
//
|
||||
// date 为观测时刻;observerLon/observerLat 为观测者经纬度,东正西负、北正南负;height 为海拔高度,单位米。
|
||||
// date is the observing instant; observerLon/observerLat are east-positive and north-positive; height is observer elevation in meters.
|
||||
func TopocentricBrightLimbPositionAngle(date time.Time, observerLon, observerLat, height float64) float64 {
|
||||
return TopocentricBrightLimbPositionAngleN(date, observerLon, observerLat, height, -1)
|
||||
}
|
||||
|
||||
// TopocentricBrightLimbPositionAngleN 月亮站心明亮边缘位置角(截断版),单位度 / truncated topocentric position angle of the Moon's bright limb in degrees.
|
||||
func TopocentricBrightLimbPositionAngleN(date time.Time, observerLon, observerLat, height float64, n int) float64 {
|
||||
return basic.MoonTopocentricBrightLimbPositionAngleN(observationTT(date), observerLon, observerLat, height, n)
|
||||
}
|
||||
|
||||
func observationTT(date time.Time) float64 {
|
||||
return basic.TD2UT(basic.Date2JDE(date.UTC()), true)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestBrightLimbPositionAngleWrapperMatchesBasic(t *testing.T) {
|
||||
date := time.Date(2026, 4, 28, 9, 30, 45, 0, time.UTC)
|
||||
jd := observationTT(date)
|
||||
|
||||
got := BrightLimbPositionAngle(date)
|
||||
want := basic.MoonBrightLimbPositionAngleN(jd, -1)
|
||||
if math.Float64bits(got) != math.Float64bits(want) {
|
||||
t.Fatalf("BrightLimbPositionAngle mismatch: got %.18f want %.18f", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTopocentricBrightLimbPositionAngleWrapperMatchesBasic(t *testing.T) {
|
||||
date := time.Date(2026, 4, 28, 9, 30, 45, 0, time.UTC)
|
||||
jd := observationTT(date)
|
||||
observerLon := 121.4737
|
||||
observerLat := 31.2304
|
||||
height := 4.0
|
||||
|
||||
got := TopocentricBrightLimbPositionAngle(date, observerLon, observerLat, height)
|
||||
want := basic.MoonTopocentricBrightLimbPositionAngleN(jd, observerLon, observerLat, height, -1)
|
||||
if math.Float64bits(got) != math.Float64bits(want) {
|
||||
t.Fatalf("TopocentricBrightLimbPositionAngle mismatch: got %.18f want %.18f", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTopocentricBrightLimbPositionAnglePreservesInstantAcrossTimezones(t *testing.T) {
|
||||
utc := time.Date(2026, 4, 28, 9, 30, 45, 123000000, time.UTC)
|
||||
shanghai := utc.In(time.FixedZone("UTC+8", 8*3600))
|
||||
observerLon := 121.4737
|
||||
observerLat := 31.2304
|
||||
height := 4.0
|
||||
|
||||
got := TopocentricBrightLimbPositionAngle(shanghai, observerLon, observerLat, height)
|
||||
want := TopocentricBrightLimbPositionAngle(utc, observerLon, observerLat, height)
|
||||
if math.Float64bits(got) != math.Float64bits(want) {
|
||||
t.Fatalf("timezone instant mismatch: got %.18f want %.18f", got, want)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// PhysicalInfo 月球物理观测参数 / physical observing parameters of the Moon.
|
||||
type PhysicalInfo struct {
|
||||
// OpticalLongitude 光学经度天平动,单位度 / optical libration in longitude, degrees.
|
||||
OpticalLongitude float64
|
||||
// OpticalLatitude 光学纬度天平动,单位度 / optical libration in latitude, degrees.
|
||||
OpticalLatitude float64
|
||||
// PhysicalLongitude 物理经度天平动,单位度 / physical libration in longitude, degrees.
|
||||
PhysicalLongitude float64
|
||||
// PhysicalLatitude 物理纬度天平动,单位度 / physical libration in latitude, degrees.
|
||||
PhysicalLatitude float64
|
||||
// LibrationLongitude 总经度天平动,单位度 / total libration in longitude, degrees.
|
||||
LibrationLongitude float64
|
||||
// LibrationLatitude 总纬度天平动,单位度 / total libration in latitude, degrees.
|
||||
LibrationLatitude float64
|
||||
// PositionAngle 月球自转轴位置角,单位度 / position angle of the lunar rotation axis, degrees.
|
||||
PositionAngle float64
|
||||
}
|
||||
|
||||
// Physical 月球物理观测参数 / physical observing parameters of the Moon.
|
||||
func Physical(date time.Time) PhysicalInfo {
|
||||
return PhysicalN(date, -1)
|
||||
}
|
||||
|
||||
// PhysicalN 月球物理观测参数(截断版) / truncated physical observing parameters of the Moon.
|
||||
func PhysicalN(date time.Time, n int) PhysicalInfo {
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
info := basic.MoonPhysicalN(basic.TD2UT(jde, true), n)
|
||||
return PhysicalInfo{
|
||||
OpticalLongitude: info.OpticalLongitude,
|
||||
OpticalLatitude: info.OpticalLatitude,
|
||||
PhysicalLongitude: info.PhysicalLongitude,
|
||||
PhysicalLatitude: info.PhysicalLatitude,
|
||||
LibrationLongitude: info.LibrationLongitude,
|
||||
LibrationLatitude: info.LibrationLatitude,
|
||||
PositionAngle: info.PositionAngle,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestPhysicalWrapperMatchesBasic(t *testing.T) {
|
||||
date := time.Date(2026, 4, 28, 9, 30, 45, 0, time.UTC)
|
||||
jde := basic.Date2JDE(date.UTC())
|
||||
|
||||
got := Physical(date)
|
||||
want := basic.MoonPhysicalN(basic.TD2UT(jde, true), -1)
|
||||
|
||||
assertMoonPhysicalSameFloat(t, "OpticalLongitude", got.OpticalLongitude, want.OpticalLongitude)
|
||||
assertMoonPhysicalSameFloat(t, "OpticalLatitude", got.OpticalLatitude, want.OpticalLatitude)
|
||||
assertMoonPhysicalSameFloat(t, "PhysicalLongitude", got.PhysicalLongitude, want.PhysicalLongitude)
|
||||
assertMoonPhysicalSameFloat(t, "PhysicalLatitude", got.PhysicalLatitude, want.PhysicalLatitude)
|
||||
assertMoonPhysicalSameFloat(t, "LibrationLongitude", got.LibrationLongitude, want.LibrationLongitude)
|
||||
assertMoonPhysicalSameFloat(t, "LibrationLatitude", got.LibrationLatitude, want.LibrationLatitude)
|
||||
assertMoonPhysicalSameFloat(t, "PositionAngle", got.PositionAngle, want.PositionAngle)
|
||||
}
|
||||
|
||||
func assertMoonPhysicalSameFloat(t *testing.T, name string, got, want float64) {
|
||||
t.Helper()
|
||||
if math.Float64bits(got) != math.Float64bits(want) {
|
||||
t.Fatalf("%s mismatch: got %.18f want %.18f", name, got, want)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPhysicalPreservesInstantAcrossTimezones(t *testing.T) {
|
||||
utc := time.Date(2026, 4, 28, 9, 30, 45, 123000000, time.UTC)
|
||||
shanghai := utc.In(time.FixedZone("UTC+8", 8*3600))
|
||||
got := Physical(shanghai)
|
||||
want := Physical(utc)
|
||||
valuesGot := []float64{got.OpticalLongitude, got.OpticalLatitude, got.PhysicalLongitude, got.PhysicalLatitude, got.LibrationLongitude, got.LibrationLatitude, got.PositionAngle}
|
||||
valuesWant := []float64{want.OpticalLongitude, want.OpticalLatitude, want.PhysicalLongitude, want.PhysicalLatitude, want.LibrationLongitude, want.LibrationLatitude, want.PositionAngle}
|
||||
for i := range valuesGot {
|
||||
if math.Float64bits(valuesGot[i]) != math.Float64bits(valuesWant[i]) {
|
||||
t.Fatalf("timezone instant mismatch at index %d: got %.18f want %.18f", i, valuesGot[i], valuesWant[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// TopocentricPhysical 月球站心物理观测参数 / topocentric physical observing parameters of the Moon.
|
||||
//
|
||||
// date 为观测时刻;observerLon/observerLat 为观测者经纬度,东正西负、北正南负;height 为海拔高度,单位米。
|
||||
// date is the observing instant; observerLon/observerLat are east-positive and north-positive; height is observer elevation in meters.
|
||||
func TopocentricPhysical(date time.Time, observerLon, observerLat, height float64) PhysicalInfo {
|
||||
return TopocentricPhysicalN(date, observerLon, observerLat, height, -1)
|
||||
}
|
||||
|
||||
// TopocentricPhysicalN 月球站心物理观测参数(截断版) / truncated topocentric physical observing parameters of the Moon.
|
||||
func TopocentricPhysicalN(date time.Time, observerLon, observerLat, height float64, n int) PhysicalInfo {
|
||||
info := basic.MoonTopocentricPhysicalN(observationTT(date), observerLon, observerLat, height, n)
|
||||
return PhysicalInfo{
|
||||
OpticalLongitude: info.OpticalLongitude,
|
||||
OpticalLatitude: info.OpticalLatitude,
|
||||
PhysicalLongitude: info.PhysicalLongitude,
|
||||
PhysicalLatitude: info.PhysicalLatitude,
|
||||
LibrationLongitude: info.LibrationLongitude,
|
||||
LibrationLatitude: info.LibrationLatitude,
|
||||
PositionAngle: info.PositionAngle,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestTopocentricPhysicalWrapperMatchesBasic(t *testing.T) {
|
||||
date := time.Date(2026, 4, 28, 9, 30, 45, 0, time.UTC)
|
||||
jd := observationTT(date)
|
||||
observerLon := 121.4737
|
||||
observerLat := 31.2304
|
||||
height := 4.0
|
||||
|
||||
got := TopocentricPhysical(date, observerLon, observerLat, height)
|
||||
want := basic.MoonTopocentricPhysicalN(jd, observerLon, observerLat, height, -1)
|
||||
|
||||
assertMoonPhysicalSameFloat(t, "OpticalLongitude", got.OpticalLongitude, want.OpticalLongitude)
|
||||
assertMoonPhysicalSameFloat(t, "OpticalLatitude", got.OpticalLatitude, want.OpticalLatitude)
|
||||
assertMoonPhysicalSameFloat(t, "PhysicalLongitude", got.PhysicalLongitude, want.PhysicalLongitude)
|
||||
assertMoonPhysicalSameFloat(t, "PhysicalLatitude", got.PhysicalLatitude, want.PhysicalLatitude)
|
||||
assertMoonPhysicalSameFloat(t, "LibrationLongitude", got.LibrationLongitude, want.LibrationLongitude)
|
||||
assertMoonPhysicalSameFloat(t, "LibrationLatitude", got.LibrationLatitude, want.LibrationLatitude)
|
||||
assertMoonPhysicalSameFloat(t, "PositionAngle", got.PositionAngle, want.PositionAngle)
|
||||
}
|
||||
|
||||
func TestTopocentricPhysicalPreservesInstantAcrossTimezones(t *testing.T) {
|
||||
utc := time.Date(2026, 4, 28, 9, 30, 45, 123000000, time.UTC)
|
||||
shanghai := utc.In(time.FixedZone("UTC+8", 8*3600))
|
||||
observerLon := 121.4737
|
||||
observerLat := 31.2304
|
||||
height := 4.0
|
||||
|
||||
got := TopocentricPhysical(shanghai, observerLon, observerLat, height)
|
||||
want := TopocentricPhysical(utc, observerLon, observerLat, height)
|
||||
valuesGot := []float64{got.OpticalLongitude, got.OpticalLatitude, got.PhysicalLongitude, got.PhysicalLatitude, got.LibrationLongitude, got.LibrationLatitude, got.PositionAngle}
|
||||
valuesWant := []float64{want.OpticalLongitude, want.OpticalLatitude, want.PhysicalLongitude, want.PhysicalLatitude, want.LibrationLongitude, want.LibrationLatitude, want.PositionAngle}
|
||||
for i := range valuesGot {
|
||||
if math.Float64bits(valuesGot[i]) != math.Float64bits(valuesWant[i]) {
|
||||
t.Fatalf("timezone instant mismatch at index %d: got %.18f want %.18f", i, valuesGot[i], valuesWant[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
// ApparentAltitude 月亮视高度角 / apparent lunar altitude.
|
||||
func ApparentAltitude(date time.Time, lon, lat, pressureHPa, temperatureC float64) float64 {
|
||||
return basic.ApparentAltitude(Altitude(date, lon, lat), pressureHPa, temperatureC)
|
||||
}
|
||||
|
||||
// ApparentZenith 月亮视天顶距 / apparent lunar zenith distance.
|
||||
func ApparentZenith(date time.Time, lon, lat, pressureHPa, temperatureC float64) float64 {
|
||||
return 90 - ApparentAltitude(date, lon, lat, pressureHPa, temperatureC)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"b612.me/astro/basic"
|
||||
)
|
||||
|
||||
func TestApparentAltitudeWrappers(t *testing.T) {
|
||||
date := time.Date(2026, 4, 28, 9, 30, 45, 0, time.UTC)
|
||||
pressureHPa := 1010.0
|
||||
temperatureC := 10.0
|
||||
|
||||
trueAltitude := Altitude(date, 115, 40)
|
||||
assertMoonRefractionClose(t, "ApparentAltitude", ApparentAltitude(date, 115, 40, pressureHPa, temperatureC), basic.ApparentAltitude(trueAltitude, pressureHPa, temperatureC), 1e-12)
|
||||
assertMoonRefractionClose(t, "ApparentZenith", ApparentZenith(date, 115, 40, pressureHPa, temperatureC), 90-ApparentAltitude(date, 115, 40, pressureHPa, temperatureC), 1e-12)
|
||||
}
|
||||
|
||||
func assertMoonRefractionClose(t *testing.T, name string, got, want, tolerance float64) {
|
||||
t.Helper()
|
||||
if math.Abs(got-want) > tolerance {
|
||||
t.Fatalf("%s mismatch: got %.18f want %.18f", name, got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user