diff --git a/src/refraction.ts b/src/refraction.ts index b976ded..1539abe 100644 --- a/src/refraction.ts +++ b/src/refraction.ts @@ -14,26 +14,28 @@ import { convertDegreesToRadians as radians } from './utilities' /** * - * getCorrectionToHorizontalForRefraction() + * getRefraction() * - * The correct to the HorizontalCoordinate for refraction is an adjustment to the observed - * HorizontalCoordinate based on pressure and temperature effects. + * The refraction correction to the observed object is an adjustment to the observed object + * based on pressure and temperature effects. + * + * N.B. There is no correction for the azimuthal angle. * * @param target - The horizontal coordinate of the observed object. * @param temperature - The temperature in Kelvin. * @param pressure - The pressure in Pascals. - * @returns The horizontal coordinate of the observed object corrected for atmospheric refraction. + * @returns The refraction correction to the observed object (in degrees). * */ -export const getCorrectionToHorizontalForRefraction = ( +export const getRefraction = ( target: HorizontalCoordinate, temperature: number = 283.15, pressure: number = 101325 -): HorizontalCoordinate => { - const { alt, az } = target +): number => { + const { alt } = target if (alt < 0) { - return target + return Number.POSITIVE_INFINITY } // The pressure, in Pascals: @@ -45,6 +47,38 @@ export const getCorrectionToHorizontalForRefraction = ( // Get the atmospheric refraction in degrees, corrected for temperature and pressure: const R = (1.02 / Math.tan(radians(alt + 10.3 / (alt + 5.11))) / 60) * (P / 101325) * (283.15 / T) + return R +} + +/*****************************************************************************************************************/ + +/** + * + * getCorrectionToHorizontalForRefraction() + * + * The correction to the HorizontalCoordinate for refraction is an adjustment to the observed + * HorizontalCoordinate based on pressure and temperature effects. + * + * @param target - The horizontal coordinate of the observed object. + * @param temperature - The temperature in Kelvin. + * @param pressure - The pressure in Pascals. + * @returns The horizontal coordinate of the observed object corrected for atmospheric refraction. + * + */ +export const getCorrectionToHorizontalForRefraction = ( + target: HorizontalCoordinate, + temperature: number = 283.15, + pressure: number = 101325 +): HorizontalCoordinate => { + const { alt, az } = target + + if (alt < 0) { + return target + } + + // Get the atmospheric refraction in degrees, corrected for temperature and pressure: + const R = getRefraction(target, temperature, pressure) + return { alt: alt + R, az: az diff --git a/tests/refraction.spec.ts b/tests/refraction.spec.ts index 81ecb9a..ad24dc8 100644 --- a/tests/refraction.spec.ts +++ b/tests/refraction.spec.ts @@ -13,7 +13,8 @@ import { describe, expect, it } from 'vitest' import { type EquatorialCoordinate, convertEquatorialToHorizontal, - getCorrectionToHorizontalForRefraction + getCorrectionToHorizontalForRefraction, + getRefraction } from '../src' /*****************************************************************************************************************/ @@ -33,6 +34,31 @@ const betelgeuse: EquatorialCoordinate = { ra: 88.7929583, dec: 7.4070639 } /*****************************************************************************************************************/ +describe('getRefraction', () => { + it('should be defined', () => { + expect(getRefraction).toBeDefined() + }) + + it('should return the refraction correction to the observed object', () => { + const target = convertEquatorialToHorizontal( + datetime, + { + latitude, + longitude + }, + betelgeuse + ) + + expect(target.az).toBe(134.44877920325155) + expect(target.alt).toBe(72.78539444063765) + + const R = getRefraction(target, 283.15, 101325) + expect(R).toBe(0.005224159687428409) + }) +}) + +/*****************************************************************************************************************/ + describe('getCorrectionToHorizontalForRefractione', () => { it('should be defined', () => { expect(getCorrectionToHorizontalForRefraction).toBeDefined()