Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions pkg/refraction/refraction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/sidera
// @license Copyright © 2021-2024 observerly

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

package refraction

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

import (
"math"

"github.com/observerly/sidera/pkg/common"
)

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

func GetRefraction(
target common.HorizontalCoordinate,
pressure float64,
temperature float64,
) float64 {
alt := target.Altitude

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

// The pressure, in Pascals:
P := pressure

// The temperature, in Kelvin:
T := temperature

// Get the atmospheric refraction in degrees, corrected for temperature and pressure:
R := (1.02 / math.Tan(common.Radians(alt+10.3/(alt+5.11))) / 60) * (P / 101325) * (283.15 / T)

return R
}

/*****************************************************************************************************************/
133 changes: 133 additions & 0 deletions pkg/refraction/refraction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/sidera
// @license Copyright © 2021-2024 observerly

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

package refraction

import (
"math"
"testing"

"github.com/observerly/sidera/pkg/common"
)

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

var target = common.HorizontalCoordinate{
Altitude: 50.0,
Azimuth: 180.0, // For diffraction tests, the azimuthal angle does not matter.
}

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

func TestRefractionAtTargetBelowHorizon(t *testing.T) {
// Test the refraction at a target below the horizon:
R := GetRefraction(common.HorizontalCoordinate{
Altitude: -10.0,
Azimuth: 180.0,
}, 101325, 283.15)

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

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

func TestRefractionAtTargetAboveHorizon(t *testing.T) {
// Test the refraction at a target above the horizon:
R := GetRefraction(target, 101325, 283.15)

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

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

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

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

func TestRefractionAtTargetAtHorizon(t *testing.T) {
// Test the refraction at a target below the horizon:
R := GetRefraction(common.HorizontalCoordinate{
Altitude: 0.0,
Azimuth: 180.0,
}, 101325, 283.15)

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

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

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

func TestRefractionAtTargetWithPressure(t *testing.T) {
// Test the refraction at a target above the horizon:
R := GetRefraction(target, 102325, 283.15)

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

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

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

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

func TestRefractionAtTargetWithTemperature(t *testing.T) {
// Test the refraction at a target above the horizon:
R := GetRefraction(target, 101325, 286.15)

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

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

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

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

func TestRefractionAtTargetWithPressureAndTemperature(t *testing.T) {
// Test the refraction at a target above the horizon:
R := GetRefraction(target, 103325, 288.15)

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

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

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

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