Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added getBodyTransit() to transit module in @observerly/astrome… #76

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion src/transit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {
} from './common'
import { convertEquatorialToHorizontal } from './coordinates'

import { getNormalizedInclinationDegree, convertDegreesToRadians as radians } from './utilities'
import {
getNormalizedInclinationDegree,
convertDegreesToRadians as radians,
convertRadiansToDegrees as degrees
} from './utilities'

/*****************************************************************************************************************/

Expand Down Expand Up @@ -211,3 +215,63 @@ export const doesBodyRiseOrSet = (
}

/*****************************************************************************************************************/

/**
*
* getBodyTransit()
*
* Determines the local sidereal time and azimuthal angle of rise and set for an object.
*
* @param observer - The geographic coordinate of the observer.
* @param target - The equatorial or horizontal coordinate of the observed object.
* @returns the transit for the body, or undefined if the body never rises or sets for the observer.
*
*/
export const getBodyTransit = (
observer: GeographicCoordinate,
target: EquatorialCoordinate
): Transit | undefined => {
// Convert the right ascension to hours:
const ra = target.ra / 15

// Get the transit parameters:
const body = doesBodyRiseOrSet(observer, target)

if (!body) {
return undefined
}

// Extract the transit parameters from the body:
const { H1, Ar } = body

const H2 = degrees(Math.acos(-H1)) / 15

// Get the azimuthal angle of rise:
const R = degrees(Math.acos(Ar))

// Get the azimuthal angle of set:
const S = 360 - R

// The local sidereal time of rise:
let LSTr = 24 + ra - H2

if (LSTr > 24) {
LSTr -= 24
}

// The local sidereal time of set:
let LSTs = ra + H2

if (LSTs > 24) {
LSTs -= 24
}

return {
LSTr,
LSTs,
R,
S
}
}

/*****************************************************************************************************************/
32 changes: 28 additions & 4 deletions tests/transit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
isBodyCircumpolar,
isBodyVisible,
isBodyAboveHorizon,
doesBodyRiseOrSet
doesBodyRiseOrSet,
getBodyTransit
} from '../src'

/*****************************************************************************************************************/
Expand All @@ -34,7 +35,7 @@ export const longitude = -155.468094
const polaris: EquatorialCoordinate = { ra: 37.95456, dec: 89.264108 }

// For testing
const betelgeuse: EquatorialCoordinate = { ra: 5.919529, dec: 7.407064 }
const betelgeuse: EquatorialCoordinate = { ra: 88.7929583, dec: 7.4070639 }

// For testings
const sigmaOctantis: EquatorialCoordinate = { ra: 21.07875, dec: -88.9569444 }
Expand Down Expand Up @@ -266,8 +267,8 @@ describe('doesBodyRiseOrSet', () => {
betelgeuse
)
).toEqual({
Ar: 0.13703603027752978,
H1: 0.04685668461549029
Ar: 0.13703602843777568,
H1: 0.04685668397579211
})
})

Expand All @@ -285,3 +286,26 @@ describe('doesBodyRiseOrSet', () => {
})

/*****************************************************************************************************************/

describe('getBodyTransit', () => {
it('should be defined', () => {
expect(getBodyTransit).toBeDefined()
})

it('should return transit parameters for a northerm hemisphere object for a postive latitude', () => {
const { LSTr, LSTs, R, S } = getBodyTransit(
{
latitude,
longitude
},
betelgeuse
)

expect(LSTr).toBe(23.740485646638913)
expect(LSTs).toBe(12.098575460027751)
expect(R).toBeCloseTo(82.12362992591511)
expect(S).toBeCloseTo(277.8763700740849)
})
})

/*****************************************************************************************************************/
Loading