From 57ac9c203ad38d4084422a4189b8ab97f22d51c2 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Wed, 1 May 2024 16:31:25 +0100 Subject: [PATCH] feat: add GetMeanAnomaly(datetime time.Time) to sun module in @observerly/sidera. feat: add GetMeanAnomaly(datetime time.Time) to sun module in @observerly/sidera. --- pkg/solar/sun.go | 49 +++++++++++++++++++++++++++++++++++++++++++ pkg/solar/sun_test.go | 33 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 pkg/solar/sun.go create mode 100644 pkg/solar/sun_test.go diff --git a/pkg/solar/sun.go b/pkg/solar/sun.go new file mode 100644 index 0000000..fa14cd2 --- /dev/null +++ b/pkg/solar/sun.go @@ -0,0 +1,49 @@ +/*****************************************************************************************************************/ + +// @author Michael Roberts +// @package @observerly/sidera +// @license Copyright © 2021-2024 observerly + +/*****************************************************************************************************************/ + +package sun + +/*****************************************************************************************************************/ + +import ( + "math" + "time" + + "github.com/observerly/sidera/pkg/epoch" +) + +/*****************************************************************************************************************/ + +/* +the Mean Anomaly of the Sun for a given datetime + +The Solar Mean Anomaly is the angle between the perihelion of the Earth's orbit and the current position +of the Earth along its orbit around the Sun. It is measured in degrees and increases uniformly with time. + +The Solar Mean Anomaly is an important concept in solar astronomy, as it is used to calculate the position +of the Sun in the sky at any given time. By knowing the Solar Mean Anomaly, an observer can determine the +Sun's position relative to the vernal equinox and calculate the time of sunrise, sunset, and other solar events. +*/ +func GetMeanAnomaly(datetime time.Time) float64 { + // get the Julian Date for the current epoch: + JD := epoch.GetJulianDate(datetime) + + // calculate the number of centuries since J2000.0: + T := (JD - 2451545.0) / 36525 + + // get the Sun's mean anomaly at the current epoch relative to J2000: + M := (357.52911 + 35999.05029*T - 0.0001537*math.Pow(T, 2)) + + if M < 0 { + M += 360 + } + + return math.Mod(M, 360) +} + +/*****************************************************************************************************************/ diff --git a/pkg/solar/sun_test.go b/pkg/solar/sun_test.go new file mode 100644 index 0000000..e4f77ea --- /dev/null +++ b/pkg/solar/sun_test.go @@ -0,0 +1,33 @@ +/*****************************************************************************************************************/ + +// @author Michael Roberts +// @package @observerly/sidera +// @license Copyright © 2021-2024 observerly + +/*****************************************************************************************************************/ + +package sun + +/*****************************************************************************************************************/ + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +/*****************************************************************************************************************/ + +// We define a datetime as some arbitrary date and time for testing purposes: +var datetime time.Time = time.Date(2021, 5, 14, 0, 0, 0, 0, time.UTC) + +/*****************************************************************************************************************/ + +func TestGetSolarMeanAnomaly(t *testing.T) { + var got float64 = GetMeanAnomaly(datetime) + + assert.Equal(t, got, 128.66090142411576) +} + +/*****************************************************************************************************************/