Skip to content

Commit

Permalink
Merge pull request #74 from michealroberts/feature/astrometry/get_ang…
Browse files Browse the repository at this point in the history
…ular_separation

feat: Added get_angular_separation to celerity/astrometry module.
  • Loading branch information
michealroberts authored May 18, 2023
2 parents 0fdf78e + c1eb375 commit 653e78b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/celerity/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,46 @@
# *****************************************************************************************************************

from datetime import datetime
from math import atan2, cos, degrees, pow, radians, sin, tan
from math import acos, atan2, cos, degrees, pow, radians, sin, tan

from .common import EquatorialCoordinate, GeographicCoordinate
from .temporal import get_julian_date, get_local_sidereal_time

# *****************************************************************************************************************


def get_angular_separation(A: EquatorialCoordinate, B: EquatorialCoordinate) -> float:
"""
The angular separation between two objects in the sky is the angle between the two objects
as seen by an observer on Earth.
:param A: The equatorial coordinate of the observed object.
:param B: The equatorial coordinate of the observed object.
:return The angular separation in degrees between target A and target B.
"""
# Calculate the angular separation between A and B (in degrees):
θ = (
degrees(
acos(
sin(radians(A["dec"])) * sin(radians(B["dec"]))
+ cos(radians(A["dec"]))
* cos(radians(B["dec"]))
* cos(radians(A["ra"] - B["ra"]))
)
)
% 360
)

# Correct for negative angles:
if θ < 0:
θ += 360

return θ


# *****************************************************************************************************************


def get_hour_angle(date: datetime, ra: float, longitude: float) -> float:
"""
Gets the hour angle for a particular object for a particular observer at a given datetime
Expand Down
10 changes: 10 additions & 0 deletions tests/test_astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TypedDict

from src.celerity.astrometry import (
get_angular_separation,
get_hour_angle,
get_obliquity_of_the_ecliptic,
get_parallactic_angle,
Expand All @@ -20,9 +21,18 @@

betelgeuse: EquatorialCoordinate = {"ra": 88.7929583, "dec": 7.4070639}

arcturus: EquatorialCoordinate = {"ra": 213.9153, "dec": 19.182409}

spica: EquatorialCoordinate = {"ra": 201.2983, "dec": -11.1614}

observer: GeographicCoordinate = {"lat": latitude, "lon": longitude}


def test_get_angular_separation():
θ = get_angular_separation(arcturus, spica)
assert θ == 32.79290589269233


def test_get_hour_angle():
ha = get_hour_angle(date, betelgeuse["ra"], longitude)
assert ha == 347.6988036852858
Expand Down

0 comments on commit 653e78b

Please sign in to comment.