Skip to content

Commit

Permalink
Merge pull request #397 from observerly/feature/refraction/getRefraction
Browse files Browse the repository at this point in the history
feat: add getRefraction() to refraction module in @observerly/astrometry
  • Loading branch information
michealroberts authored Oct 22, 2024
2 parents 66cd625 + 20d5d92 commit 0f21f26
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
50 changes: 42 additions & 8 deletions src/refraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
28 changes: 27 additions & 1 deletion tests/refraction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { describe, expect, it } from 'vitest'
import {
type EquatorialCoordinate,
convertEquatorialToHorizontal,
getCorrectionToHorizontalForRefraction
getCorrectionToHorizontalForRefraction,
getRefraction
} from '../src'

/*****************************************************************************************************************/
Expand All @@ -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()
Expand Down

0 comments on commit 0f21f26

Please sign in to comment.