From 82682aa5dc67c8e3c0988d0a6b416c7ef0d6288c Mon Sep 17 00:00:00 2001 From: michealroberts Date: Wed, 22 Jan 2025 17:11:34 +0000 Subject: [PATCH] feat: add getCorrectionToEquatorialForAberration to aberration module in @observerly/astrometry feat: add getCorrectionToEquatorialForAberration to aberration module in @observerly/astrometry --- src/aberration.ts | 31 +++++++++++++++++++++++++++++++ tests/aberration.spec.ts | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/aberration.ts b/src/aberration.ts index c9e0f48..c960e88 100644 --- a/src/aberration.ts +++ b/src/aberration.ts @@ -153,3 +153,34 @@ export const getCorrectionToEquatorialForDiurnalAberration = ( } /*****************************************************************************************************************/ + +/** + * + * getCorrectionToEquatorialForAberration() + * + * Corrects the equatorial coordinate of a target for aberration in + * longitude and obliquity due to the apparent motion of the Earth. + * + * @param date - The date to correct the equatorial coordinate for. + * @param target - The equatorial J2000 coordinate of the target. + * @returns The corrected equatorial coordinate of the target. + * + */ +export const getCorrectionToEquatorialForAberration = ( + datetime: Date, + observer: GeographicCoordinate, + target: EquatorialCoordinate +): EquatorialCoordinate => { + // Get the annual aberration correction: + const annual = getCorrectionToEquatorialForAnnualAberration(datetime, target) + + // Get the diurnal aberration correction: + const diurnal = getCorrectionToEquatorialForDiurnalAberration(datetime, observer, target) + + return { + ra: annual.ra + diurnal.ra, + dec: annual.dec + diurnal.dec + } +} + +/*****************************************************************************************************************/ diff --git a/tests/aberration.spec.ts b/tests/aberration.spec.ts index 5e1cc6f..d9cffe9 100644 --- a/tests/aberration.spec.ts +++ b/tests/aberration.spec.ts @@ -10,7 +10,12 @@ import { describe, expect, it } from 'vitest' /*****************************************************************************************************************/ -import { type EquatorialCoordinate, getCorrectionToEquatorialForAnnualAberration, getCorrectionToEquatorialForDiurnalAberration } from '../src' +import { + type EquatorialCoordinate, + getCorrectionToEquatorialForAberration, + getCorrectionToEquatorialForAnnualAberration, + getCorrectionToEquatorialForDiurnalAberration, +} from '../src' /*****************************************************************************************************************/ @@ -80,4 +85,34 @@ describe('getCorrectionToEquatorialForDiurnalAberration', () => { }) }) +/*****************************************************************************************************************/ + +describe('getCorrectionToEquatorialForAberration', () => { + it('should be defined', () => { + expect(getCorrectionToEquatorialForAberration).toBeDefined() + }) + + it('should return the correct aberration correction for the J2000 default epoch', () => { + const { ra, dec } = getCorrectionToEquatorialForAberration( + new Date('2000-01-01T00:00:00+00:00'), + { + latitude, + longitude + }, + betelgeuse + ) + expect(ra + betelgeuse.ra).toBe(88.79875665605677) + expect(dec + betelgeuse.dec).toBe(7.406836962857944) + }) + + it('should return the correct aberration correction for the designated epoch', () => { + const { ra, dec } = getCorrectionToEquatorialForAberration(datetime, { + latitude, + longitude + }, betelgeuse) + expect(ra + betelgeuse.ra).toBe(88.78844263611573) + expect(dec + betelgeuse.dec).toBe(7.4061425995174766) + }) +}) + /*****************************************************************************************************************/ \ No newline at end of file