Skip to content

Commit

Permalink
Merge pull request #130 from observerly/feature/dusk/BelowObserversHo…
Browse files Browse the repository at this point in the history
…rizon

feat: Added checks for BelowObserversHorizon() to altitude related utilities.
  • Loading branch information
michealroberts authored Jun 21, 2022
2 parents e24b372 + 1a4a7e1 commit 6270d45
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 61 deletions.
80 changes: 43 additions & 37 deletions coverage.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
mode: atomic
github.com/observerly/dusk/pkg/dusk/astrometry.go:14.52,18.12 2 16490
github.com/observerly/dusk/pkg/dusk/astrometry.go:22.2,22.11 1 16490
github.com/observerly/dusk/pkg/dusk/astrometry.go:18.12,20.3 1 3388
github.com/observerly/dusk/pkg/dusk/astrometry.go:34.73,42.2 4 4
github.com/observerly/dusk/pkg/dusk/coordinates.go:101.108,124.2 10 12982
github.com/observerly/dusk/pkg/dusk/coordinates.go:136.149,151.2 6 16488
github.com/observerly/dusk/pkg/dusk/lawrence.go:15.59,24.12 3 3
Expand Down Expand Up @@ -85,36 +81,10 @@ github.com/observerly/dusk/pkg/dusk/trigonometry.go:26.31,28.2 1 42489
github.com/observerly/dusk/pkg/dusk/trigonometry.go:30.31,32.2 1 16543
github.com/observerly/dusk/pkg/dusk/trigonometry.go:34.31,36.2 1 1
github.com/observerly/dusk/pkg/dusk/trigonometry.go:38.36,40.2 1 25976
github.com/observerly/dusk/pkg/dusk/epoch.go:31.56,33.2 1 26
github.com/observerly/dusk/pkg/dusk/epoch.go:41.48,46.2 2 124040
github.com/observerly/dusk/pkg/dusk/epoch.go:53.45,55.2 1 79
github.com/observerly/dusk/pkg/dusk/epoch.go:63.60,93.13 15 16493
github.com/observerly/dusk/pkg/dusk/epoch.go:97.2,97.12 1 16493
github.com/observerly/dusk/pkg/dusk/epoch.go:93.13,95.3 1 5505
github.com/observerly/dusk/pkg/dusk/epoch.go:106.74,114.11 4 16491
github.com/observerly/dusk/pkg/dusk/epoch.go:118.2,118.17 1 16491
github.com/observerly/dusk/pkg/dusk/epoch.go:114.11,116.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:127.65,138.2 4 36
github.com/observerly/dusk/pkg/dusk/epoch.go:146.76,154.2 3 77943
github.com/observerly/dusk/pkg/dusk/epoch.go:162.73,170.2 3 13017
github.com/observerly/dusk/pkg/dusk/epoch.go:179.62,190.2 3 6
github.com/observerly/dusk/pkg/dusk/epoch.go:198.73,213.12 6 4
github.com/observerly/dusk/pkg/dusk/epoch.go:217.2,217.11 1 4
github.com/observerly/dusk/pkg/dusk/epoch.go:213.12,215.3 1 4
github.com/observerly/dusk/pkg/dusk/epoch.go:226.77,248.12 10 3
github.com/observerly/dusk/pkg/dusk/epoch.go:252.2,252.11 1 3
github.com/observerly/dusk/pkg/dusk/epoch.go:248.12,250.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:262.70,267.2 2 34
github.com/observerly/dusk/pkg/dusk/epoch.go:276.95,280.13 2 25
github.com/observerly/dusk/pkg/dusk/epoch.go:284.2,284.12 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:280.13,282.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:294.92,312.12 9 25
github.com/observerly/dusk/pkg/dusk/epoch.go:317.2,317.13 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:321.2,324.11 2 25
github.com/observerly/dusk/pkg/dusk/epoch.go:328.2,328.21 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:312.12,314.3 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:317.13,319.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:324.11,326.3 1 1
github.com/observerly/dusk/pkg/dusk/astrometry.go:14.52,18.12 2 16490
github.com/observerly/dusk/pkg/dusk/astrometry.go:22.2,22.11 1 16490
github.com/observerly/dusk/pkg/dusk/astrometry.go:18.12,20.3 1 3388
github.com/observerly/dusk/pkg/dusk/astrometry.go:34.73,42.2 4 4
github.com/observerly/dusk/pkg/dusk/lunar.go:32.47,37.11 2 13006
github.com/observerly/dusk/pkg/dusk/lunar.go:41.2,41.10 1 13006
github.com/observerly/dusk/pkg/dusk/lunar.go:37.11,39.3 1 16
Expand Down Expand Up @@ -206,6 +176,42 @@ github.com/observerly/dusk/pkg/dusk/utils.go:31.12,33.3 1 0
github.com/observerly/dusk/pkg/dusk/utils.go:47.84,49.2 1 4
github.com/observerly/dusk/pkg/dusk/utils.go:60.84,62.2 1 12986
github.com/observerly/dusk/pkg/dusk/utils.go:72.85,74.2 1 25
github.com/observerly/dusk/pkg/dusk/utils.go:83.57,85.2 1 2
github.com/observerly/dusk/pkg/dusk/utils.go:93.51,95.2 1 3
github.com/observerly/dusk/pkg/dusk/utils.go:103.52,106.2 2 1
github.com/observerly/dusk/pkg/dusk/utils.go:83.58,84.18 1 3
github.com/observerly/dusk/pkg/dusk/utils.go:88.2,90.11 2 2
github.com/observerly/dusk/pkg/dusk/utils.go:84.18,86.3 1 1
github.com/observerly/dusk/pkg/dusk/utils.go:99.52,100.18 1 4
github.com/observerly/dusk/pkg/dusk/utils.go:104.2,106.11 2 3
github.com/observerly/dusk/pkg/dusk/utils.go:100.18,102.3 1 1
github.com/observerly/dusk/pkg/dusk/utils.go:115.53,116.18 1 2
github.com/observerly/dusk/pkg/dusk/utils.go:120.2,124.13 3 1
github.com/observerly/dusk/pkg/dusk/utils.go:116.18,118.3 1 1
github.com/observerly/dusk/pkg/dusk/epoch.go:31.56,33.2 1 26
github.com/observerly/dusk/pkg/dusk/epoch.go:41.48,46.2 2 124040
github.com/observerly/dusk/pkg/dusk/epoch.go:53.45,55.2 1 79
github.com/observerly/dusk/pkg/dusk/epoch.go:63.60,93.13 15 16493
github.com/observerly/dusk/pkg/dusk/epoch.go:97.2,97.12 1 16493
github.com/observerly/dusk/pkg/dusk/epoch.go:93.13,95.3 1 5505
github.com/observerly/dusk/pkg/dusk/epoch.go:106.74,114.11 4 16491
github.com/observerly/dusk/pkg/dusk/epoch.go:118.2,118.17 1 16491
github.com/observerly/dusk/pkg/dusk/epoch.go:114.11,116.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:127.65,138.2 4 36
github.com/observerly/dusk/pkg/dusk/epoch.go:146.76,154.2 3 77943
github.com/observerly/dusk/pkg/dusk/epoch.go:162.73,170.2 3 13017
github.com/observerly/dusk/pkg/dusk/epoch.go:179.62,190.2 3 6
github.com/observerly/dusk/pkg/dusk/epoch.go:198.73,213.12 6 4
github.com/observerly/dusk/pkg/dusk/epoch.go:217.2,217.11 1 4
github.com/observerly/dusk/pkg/dusk/epoch.go:213.12,215.3 1 4
github.com/observerly/dusk/pkg/dusk/epoch.go:226.77,248.12 10 3
github.com/observerly/dusk/pkg/dusk/epoch.go:252.2,252.11 1 3
github.com/observerly/dusk/pkg/dusk/epoch.go:248.12,250.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:262.70,267.2 2 34
github.com/observerly/dusk/pkg/dusk/epoch.go:276.95,280.13 2 25
github.com/observerly/dusk/pkg/dusk/epoch.go:284.2,284.12 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:280.13,282.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:294.92,312.12 9 25
github.com/observerly/dusk/pkg/dusk/epoch.go:317.2,317.13 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:321.2,324.11 2 25
github.com/observerly/dusk/pkg/dusk/epoch.go:328.2,328.21 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:312.12,314.3 1 25
github.com/observerly/dusk/pkg/dusk/epoch.go:317.13,319.3 1 0
github.com/observerly/dusk/pkg/dusk/epoch.go:324.11,326.3 1 1
31 changes: 25 additions & 6 deletions pkg/dusk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ func GetArgumentOfLocalSiderealTimeForTransit(latitude float64, δ float64) floa
@returns the atmospheric refraction in degrees for all angles from 0° - 90°
@see p.106 of Meeus, Jean. 1991. Astronomical algorithms. Richmond, Va: Willmann-Bell.
*/
func GetAtmosphericRefraction(altitude float64) float64 {
return (1.02 / tanx(altitude+(10.3/(altitude+5.11)))) / 60
func GetAtmosphericRefraction(altitude float64) *float64 {
if altitude < 0 {
return nil
}

R := (1.02 / tanx(altitude+(10.3/(altitude+5.11)))) / 60

return &R
}

/*
Expand All @@ -90,8 +96,14 @@ func GetAtmosphericRefraction(altitude float64) float64 {
@param altitude - is the altitude of the object in degrees
@returns the relative air mass, the ratio of absolute air masses (as defined above) at oblique incidence relative to that at zenith.
*/
func GetRelativeAirMass(altitude float64) float64 {
return 1 / sinx(altitude+(244/(165+47*math.Pow(altitude, 1.1))))
func GetRelativeAirMass(altitude float64) *float64 {
if altitude < 0 {
return nil
}

X := 1 / sinx(altitude+(244/(165+47*math.Pow(altitude, 1.1))))

return &X
}

/*
Expand All @@ -100,7 +112,14 @@ func GetRelativeAirMass(altitude float64) float64 {
@param altitude - is the altitude of the object in degrees
@returns the apparent altitude in degrees
*/
func GetApparentAltitude(altitude float64) float64 {
func GetApparentAltitude(altitude float64) *float64 {
if altitude < 0 {
return nil
}

R := GetAtmosphericRefraction(altitude)
return altitude + R

app := altitude + *R

return &app
}
60 changes: 42 additions & 18 deletions pkg/dusk/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,69 +99,93 @@ func TestGetArgumentOfLocalSiderealTime(t *testing.T) {
func TestGetAtmosphericRefraction(t *testing.T) {
var hz HorizontalCoordinate = ConvertEquatorialCoordinateToHorizontal(datetime, longitude, latitude, EquatorialCoordinate{RightAscension: 88.7929583, Declination: 7.4070639})

var got float64 = GetAtmosphericRefraction(hz.Altitude)
got := GetAtmosphericRefraction(hz.Altitude)

var want float64 = 0.005219

if math.Abs(got-want) > 0.00001 {
t.Errorf("got %f, wanted %f", got, want)
if math.Abs(*got-want) > 0.00001 {
t.Errorf("got %f, wanted %f", *got, want)
}

if got < 0 || got > 1.0 {
if *got < 0 || *got > 1.0 {
t.Errorf("The atmospheric refraction must be between 0.0 and 0.5")
}
}

func TestGetAtmosphericRefractionBelowHorizon(t *testing.T) {
got := GetAtmosphericRefraction(-45)

if got != nil {
t.Errorf("The atmospheric refraction must be nil below the observer's horizon")
}
}

func TestGetRelativeAirMass(t *testing.T) {
var hz HorizontalCoordinate = ConvertEquatorialCoordinateToHorizontal(datetime, longitude, latitude, EquatorialCoordinate{RightAscension: 88.7929583, Declination: 7.4070639})

var got float64 = GetRelativeAirMass(hz.Altitude)
got := GetRelativeAirMass(hz.Altitude)

var want float64 = 1.046558

if math.Abs(got-want) > 0.00001 {
t.Errorf("got %f, wanted %f", got, want)
if math.Abs(*got-want) > 0.00001 {
t.Errorf("got %f, wanted %f", *got, want)
}

if got < 1 || got > 40.0 {
if *got < 1 || *got > 40.0 {
t.Errorf("The relative air mass must be a value bewteen 1 and approx. 40 at the observer's horizon")
}
}

func TestGetRelativeAirMassAtZenith(t *testing.T) {
var got float64 = GetRelativeAirMass(90)
got := GetRelativeAirMass(90)

var want float64 = 1.0

if math.Abs(got-want) > 0.00001 {
t.Errorf("got %f, wanted %f", got, want)
if math.Abs(*got-want) > 0.00001 {
t.Errorf("got %f, wanted %f", *got, want)
}

if got < 1 || got > 40.0 {
if *got < 1 || *got > 40.0 {
t.Errorf("The relative air mass must be a value bewteen 1 and approx. 40 at the observer's horizon")
}
}

func TestGetRelativeAirMassAtHorizon(t *testing.T) {
var got float64 = GetRelativeAirMass(0)
got := GetRelativeAirMass(0)

var want float64 = 38

if math.Abs(got-want) > 2 {
if math.Abs(*got-want) > 2 {
t.Errorf("The relative air mass must be approximately ~37 - 39 at the observer's horizon")
}

if got < 1 || got > 40.0 {
if *got < 1 || *got > 40.0 {
t.Errorf("The relative air mass must be a value bewteen 1 and approx. 40 at the observer's horizon")
}
}

func TestGetRelativeAirMassBelowHorizon(t *testing.T) {
got := GetRelativeAirMass(-1)

if got != nil {
t.Errorf("The relative air mass must be nil below the observer's horizon")
}
}

func TestGetApparentAltitude(t *testing.T) {
var hz HorizontalCoordinate = ConvertEquatorialCoordinateToHorizontal(datetime, longitude, latitude, EquatorialCoordinate{RightAscension: 88.7929583, Declination: 7.4070639})

var got float64 = GetApparentAltitude(hz.Altitude)
got := GetApparentAltitude(hz.Altitude)

if math.Abs(*got-hz.Altitude) > 0.0053 {
t.Errorf("got %f, wanted %f", *got, hz.Altitude)
}
}

func TestGetApparentAltitudeBelowHorizon(t *testing.T) {
got := GetApparentAltitude(-45)

if math.Abs(got-hz.Altitude) > 0.0053 {
t.Errorf("got %f, wanted %f", got, hz.Altitude)
if got != nil {
t.Errorf("The apparent altitude must have no adjustment below the observer's horizon")
}
}

0 comments on commit 6270d45

Please sign in to comment.