Skip to content

Commit

Permalink
Merge pull request #68 from observerly/feature/transit/isBodyCircumpolar
Browse files Browse the repository at this point in the history
feat: Added isBodyCircumpolar() to transit module in @observerly/astr…
  • Loading branch information
michealroberts authored Aug 27, 2023
2 parents d2e5ab7 + 96609b3 commit 5e0c23f
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/transit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
/*****************************************************************************************************************/

// @author Michael Roberts <[email protected]>
// @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
}

/*****************************************************************************************************************/
120 changes: 120 additions & 0 deletions tests/transit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*****************************************************************************************************************/

// @author Michael Roberts <[email protected]>
// @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)
})
})

0 comments on commit 5e0c23f

Please sign in to comment.