-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from observerly/feature/transit/isBodyCircumpolar
feat: Added isBodyCircumpolar() to transit module in @observerly/astr…
- Loading branch information
Showing
2 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,44 @@ | ||
/*****************************************************************************************************************/ | ||
|
||
// @author Michael Roberts <michael@observerly.com> | ||
// @package @observerly/astrometry/transits | ||
// @package @observerly/astrometry/transit | ||
// @license Copyright © 2021-2023 observerly | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
export {} | ||
import { type EquatorialCoordinate, type GeographicCoordinate } from './common' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
/** | ||
* | ||
* isBodyCircumpolar() | ||
* | ||
* An object is considered circumpolar if it is always above the observer's horizon | ||
* and never sets. This is true when the object's declination is greater than 90 | ||
* degrees minus the observer's latitude. | ||
* | ||
* @param observer - The geographic coordinate of the observer. | ||
* @param target - The equatorial coordinate of the observed object. | ||
* @param horizon - The observer's horizon (in degrees). | ||
* @returns a boolean indicating whether the target is circumpolar. | ||
*/ | ||
export const isBodyCircumpolar = ( | ||
observer: GeographicCoordinate, | ||
target: EquatorialCoordinate, | ||
horizon: number = 0 | ||
): boolean => { | ||
// We only need to consider the latitude of the observer: | ||
const { latitude } = observer | ||
|
||
// We only need to consider the declination of the target object: | ||
const { dec } = target | ||
|
||
const extrema = 90 - Math.abs(latitude) - horizon | ||
|
||
// If the object's declination is greater than 90 degrees minus the observer's latitude, | ||
// then the object is circumpolar (always above the observer's horizon and never sets). | ||
return latitude >= 0 ? dec > extrema : dec < extrema | ||
} | ||
|
||
/*****************************************************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/*****************************************************************************************************************/ | ||
|
||
// @author Michael Roberts <michael@observerly.com> | ||
// @package @observerly/astrometry/epoch | ||
// @license Copyright © 2021-2023 observerly | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import { describe, expect, it } from 'vitest' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import { type EquatorialCoordinate, isBodyCircumpolar } from '../src' | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
// For testing we need to specify a date because most calculations are | ||
// differential w.r.t a time component. We set it to the author's birthday: | ||
export const datetime = new Date('2021-05-14T00:00:00.000+00:00') | ||
|
||
// For testing we will fix the latitude to be Manua Kea, Hawaii, US | ||
export const latitude = 19.820611 | ||
|
||
// For testing we will fix the longitude to be Manua Kea, Hawaii, US: | ||
export const longitude = -155.468094 | ||
|
||
// For testing | ||
const polaris: EquatorialCoordinate = { ra: 37.95456, dec: 89.264108 } | ||
|
||
// For testing | ||
const betelgeuse: EquatorialCoordinate = { ra: 5.919529, dec: 7.407064 } | ||
|
||
// For testings | ||
const sigmaOctantis: EquatorialCoordinate = { ra: 21.07875, dec: -88.9569444 } | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
describe('isBodyCircumpolar', () => { | ||
it('should be defined', () => { | ||
expect(isBodyCircumpolar).toBeDefined() | ||
}) | ||
|
||
it('should return true for northerm hemisphere circumpolar objects', () => { | ||
expect( | ||
isBodyCircumpolar( | ||
{ | ||
latitude, | ||
longitude | ||
}, | ||
polaris, | ||
0 | ||
) | ||
).toBe(true) | ||
}) | ||
|
||
it('should return false for northerm hemisphere non-circumpolar objects', () => { | ||
expect( | ||
isBodyCircumpolar( | ||
{ | ||
latitude, | ||
longitude | ||
}, | ||
sigmaOctantis, | ||
0 | ||
) | ||
).toBe(false) | ||
}) | ||
|
||
it('should return true for southern hemisphere circumpolar objects', () => { | ||
expect( | ||
isBodyCircumpolar( | ||
{ | ||
latitude: -latitude, | ||
longitude | ||
}, | ||
sigmaOctantis, | ||
0 | ||
) | ||
).toBe(true) | ||
}) | ||
|
||
it('should return false for southern hemisphere non-circumpolar objects', () => { | ||
expect( | ||
isBodyCircumpolar( | ||
{ | ||
latitude: -latitude, | ||
longitude | ||
}, | ||
polaris, | ||
0 | ||
) | ||
).toBe(false) | ||
}) | ||
|
||
it('should return false for an object that does set below the horizon', () => { | ||
expect( | ||
isBodyCircumpolar( | ||
{ | ||
latitude, | ||
longitude | ||
}, | ||
betelgeuse, | ||
0 | ||
) | ||
).toBe(false) | ||
}) | ||
|
||
it('should return true for an object that does not set below the horizon', () => { | ||
expect( | ||
isBodyCircumpolar( | ||
{ | ||
latitude: -latitude, | ||
longitude | ||
}, | ||
betelgeuse, | ||
0 | ||
) | ||
).toBe(true) | ||
}) | ||
}) |