Skip to content

Commit 0f21f26

Browse files
Merge pull request #397 from observerly/feature/refraction/getRefraction
feat: add getRefraction() to refraction module in @observerly/astrometry
2 parents 66cd625 + 20d5d92 commit 0f21f26

File tree

2 files changed

+69
-9
lines changed

2 files changed

+69
-9
lines changed

src/refraction.ts

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@ import { convertDegreesToRadians as radians } from './utilities'
1414

1515
/**
1616
*
17-
* getCorrectionToHorizontalForRefraction()
17+
* getRefraction()
1818
*
19-
* The correct to the HorizontalCoordinate for refraction is an adjustment to the observed
20-
* HorizontalCoordinate based on pressure and temperature effects.
19+
* The refraction correction to the observed object is an adjustment to the observed object
20+
* based on pressure and temperature effects.
21+
*
22+
* N.B. There is no correction for the azimuthal angle.
2123
*
2224
* @param target - The horizontal coordinate of the observed object.
2325
* @param temperature - The temperature in Kelvin.
2426
* @param pressure - The pressure in Pascals.
25-
* @returns The horizontal coordinate of the observed object corrected for atmospheric refraction.
27+
* @returns The refraction correction to the observed object (in degrees).
2628
*
2729
*/
28-
export const getCorrectionToHorizontalForRefraction = (
30+
export const getRefraction = (
2931
target: HorizontalCoordinate,
3032
temperature: number = 283.15,
3133
pressure: number = 101325
32-
): HorizontalCoordinate => {
33-
const { alt, az } = target
34+
): number => {
35+
const { alt } = target
3436

3537
if (alt < 0) {
36-
return target
38+
return Number.POSITIVE_INFINITY
3739
}
3840

3941
// The pressure, in Pascals:
@@ -45,6 +47,38 @@ export const getCorrectionToHorizontalForRefraction = (
4547
// Get the atmospheric refraction in degrees, corrected for temperature and pressure:
4648
const R = (1.02 / Math.tan(radians(alt + 10.3 / (alt + 5.11))) / 60) * (P / 101325) * (283.15 / T)
4749

50+
return R
51+
}
52+
53+
/*****************************************************************************************************************/
54+
55+
/**
56+
*
57+
* getCorrectionToHorizontalForRefraction()
58+
*
59+
* The correction to the HorizontalCoordinate for refraction is an adjustment to the observed
60+
* HorizontalCoordinate based on pressure and temperature effects.
61+
*
62+
* @param target - The horizontal coordinate of the observed object.
63+
* @param temperature - The temperature in Kelvin.
64+
* @param pressure - The pressure in Pascals.
65+
* @returns The horizontal coordinate of the observed object corrected for atmospheric refraction.
66+
*
67+
*/
68+
export const getCorrectionToHorizontalForRefraction = (
69+
target: HorizontalCoordinate,
70+
temperature: number = 283.15,
71+
pressure: number = 101325
72+
): HorizontalCoordinate => {
73+
const { alt, az } = target
74+
75+
if (alt < 0) {
76+
return target
77+
}
78+
79+
// Get the atmospheric refraction in degrees, corrected for temperature and pressure:
80+
const R = getRefraction(target, temperature, pressure)
81+
4882
return {
4983
alt: alt + R,
5084
az: az

tests/refraction.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { describe, expect, it } from 'vitest'
1313
import {
1414
type EquatorialCoordinate,
1515
convertEquatorialToHorizontal,
16-
getCorrectionToHorizontalForRefraction
16+
getCorrectionToHorizontalForRefraction,
17+
getRefraction
1718
} from '../src'
1819

1920
/*****************************************************************************************************************/
@@ -33,6 +34,31 @@ const betelgeuse: EquatorialCoordinate = { ra: 88.7929583, dec: 7.4070639 }
3334

3435
/*****************************************************************************************************************/
3536

37+
describe('getRefraction', () => {
38+
it('should be defined', () => {
39+
expect(getRefraction).toBeDefined()
40+
})
41+
42+
it('should return the refraction correction to the observed object', () => {
43+
const target = convertEquatorialToHorizontal(
44+
datetime,
45+
{
46+
latitude,
47+
longitude
48+
},
49+
betelgeuse
50+
)
51+
52+
expect(target.az).toBe(134.44877920325155)
53+
expect(target.alt).toBe(72.78539444063765)
54+
55+
const R = getRefraction(target, 283.15, 101325)
56+
expect(R).toBe(0.005224159687428409)
57+
})
58+
})
59+
60+
/*****************************************************************************************************************/
61+
3662
describe('getCorrectionToHorizontalForRefractione', () => {
3763
it('should be defined', () => {
3864
expect(getCorrectionToHorizontalForRefraction).toBeDefined()

0 commit comments

Comments
 (0)