Skip to content

Commit

Permalink
Merge pull request #34 from observerly/feature/refraction/GetAirmass
Browse files Browse the repository at this point in the history
feat: add GetAirmass() to refraction module in @observerly/sidera
  • Loading branch information
michealroberts authored Oct 22, 2024
2 parents 02d6a45 + bf81d32 commit 1fd4ebb
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/refraction/refraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,27 @@ func GetRefraction(
}

/*****************************************************************************************************************/

func GetAirmass(target common.HorizontalCoordinate) float64 {
alt := target.Altitude

if alt < 0 {
return math.Inf(1)
}

// Convert the altitude to radians:
z := common.Radians(target.Altitude)

// Get the tangent of the altitude:
tanZ := math.Tan(z)

// Airmass approaches infinity as the altitude approaches 0 degrees (horizon):
if tanZ == 0 {
return math.Inf(1)
}

// Get the airmass using the Ciddor (1996) equation of state for air:
return 1 / (math.Sin(z) + 0.0001184*(1/tanZ) + 0.003188*(1/tanZ*tanZ))
}

/*****************************************************************************************************************/
47 changes: 47 additions & 0 deletions pkg/refraction/refraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,50 @@ func TestRefractionAtTargetWithPressureAndTemperature(t *testing.T) {
}

/*****************************************************************************************************************/

func TestAirmassAtTargetBelowHorizon(t *testing.T) {
// Test the airmass at a target below the horizon:
Z := GetAirmass(common.HorizontalCoordinate{
Altitude: -10.0,
Azimuth: 180.0,
})

if Z != math.Inf(1) {
t.Errorf("Expected airmass to be infinite, got %f", Z)
}
}

/*****************************************************************************************************************/

func TestAirmassAtTargetAboveHorizon(t *testing.T) {
// Test the airmass at a target above the horizon:
Z := GetAirmass(target)

if Z == math.Inf(1) {
t.Errorf("Expected airmass to be finite, got %f", Z)
}

if Z <= 0 {
t.Errorf("Expected airmass to be positive, got %f", Z)
}

if Z > 1.5 {
t.Errorf("Expected airmass to be less than 1.5, got %f", Z)
}
}

/*****************************************************************************************************************/

func TestAirmassAtTargetAtHorizon(t *testing.T) {
// Test the airmass at a target below the horizon:
Z := GetAirmass(common.HorizontalCoordinate{
Altitude: 0.0,
Azimuth: 180.0,
})

if Z != math.Inf(1) {
t.Errorf("Expected airmass to be infinite, got %f", Z)
}
}

/*****************************************************************************************************************/

0 comments on commit 1fd4ebb

Please sign in to comment.