Skip to content
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
6 changes: 3 additions & 3 deletions src/celerity/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ def get_parallactic_angle(
:param target: The equatorial coordinate of the observed object.
:return The parallactic angle in degrees.
"""
lat, lon = radians(observer["lat"]), observer["lon"]
latitude, longitude = radians(observer["latitude"]), observer["longitude"]

dec = radians(target["dec"])

# Get the hour angle for the target:
ha = radians(get_hour_angle(date, target["ra"], lon))
ha = radians(get_hour_angle(date, target["ra"], longitude))

# Calculate the parallactic angle and return in degrees:
return degrees(
atan2(
sin(ha),
tan(lat) * cos(dec) - sin(dec) * cos(ha),
tan(latitude) * cos(dec) - sin(dec) * cos(ha),
)
)

Expand Down
6 changes: 3 additions & 3 deletions src/celerity/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class EquatorialCoordinate(TypedDict):


class GeographicCoordinate(TypedDict):
lat: float
lon: float
el: NotRequired[float]
latitude: float
longitude: float
elevation: NotRequired[float]


# **************************************************************************************
Expand Down
16 changes: 8 additions & 8 deletions src/celerity/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# **************************************************************************************

from datetime import datetime
from math import acos, asin, cos, degrees, radians, sin, atan2
from math import acos, asin, atan2, cos, degrees, radians, sin

from .aberration import get_correction_to_equatorial_for_aberration
from .astrometry import get_hour_angle
Expand Down Expand Up @@ -75,22 +75,22 @@ def convert_equatorial_to_horizontal(
:param target: The equatorial coordinate of the observed object.
:return The horizontal coordinate of the observed object.
"""
lat, lon = radians(observer["lat"]), observer["lon"]
latitude, longitude = radians(observer["latitude"]), observer["longitude"]

dec = radians(target["dec"])

# Divide-by-zero errors can occur when we have cos(90), and sin(0)/sin(180) etc
# cosine: multiples of π/2
# sine: 0, and multiples of π.
if cos(lat) == 0:
if cos(latitude) == 0:
return {"az": -1, "alt": -1}

# Get the hour angle for the target:
ha = radians(get_hour_angle(date, target["ra"], lon))
ha = radians(get_hour_angle(date, target["ra"], longitude))

alt = asin(sin(dec) * sin(lat) + cos(dec) * cos(lat) * cos(ha))
alt = asin(sin(dec) * sin(latitude) + cos(dec) * cos(latitude) * cos(ha))

az = acos((sin(dec) - sin(alt) * sin(lat)) / (cos(alt) * cos(lat)))
az = acos((sin(dec) - sin(alt) * sin(latitude)) / (cos(alt) * cos(latitude)))

return {
"az": 360 - degrees(az) if sin(ha) > 0 else degrees(az),
Expand Down Expand Up @@ -118,7 +118,7 @@ def convert_horizontal_to_equatorial(
:return: The equatorial coordinate (RA and Dec) of the object.
"""
# Convert the latitude to radians:
latitude = radians(observer["lat"])
latitude = radians(observer["latitude"])

# Convert the altitude to radians:
a = radians(target["alt"])
Expand All @@ -143,7 +143,7 @@ def convert_horizontal_to_equatorial(
ha = atan2(sin_H, cos_H)

# Compute Local Sidereal Time (LST) in degrees, and convert to radians:
LST = get_local_sidereal_time(date, observer["lon"])
LST = get_local_sidereal_time(date, observer["longitude"])

# Right Ascension (RA) is given by LST - the hour angle:
ra = ((LST * 15) - degrees(ha)) % 360
Expand Down
2 changes: 1 addition & 1 deletion src/celerity/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def convert_local_sidereal_time_to_greenwich_sidereal_time(
:param longitude: The longitude of the observer.
:return: The Local Sidereal Time (LST) of the given date normalised to UTC.
"""
lon = observer["lon"]
lon = observer["longitude"]

GST = LST - (lon / 15.0)

Expand Down
6 changes: 3 additions & 3 deletions src/celerity/transit.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def is_object_circumpolar(
dec = target["dec"]

# We only need the latitude of the observer:
lat = observer["lat"]
lat = observer["latitude"]

# 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).
Expand Down Expand Up @@ -129,7 +129,7 @@ def is_object_never_visible(
dec = target["dec"]

# We only need the latitude of the observer:
lat = observer["lat"]
lat = observer["latitude"]

# If the object's declination is less than the observer's latitude
# minus 90 degrees, then the object is never visible (always below the
Expand Down Expand Up @@ -188,7 +188,7 @@ def get_does_object_rise_or_set(
:param target: The equatorial coordinate of the observed object.
:return either false when the object does not rise or set or the transit parameters.
"""
lat = radians(observer["lat"])
lat = radians(observer["latitude"])

dec = radians(target["dec"])

Expand Down
2 changes: 1 addition & 1 deletion tests/test_abberation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

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


def test_get_correction_to_equatorial_for_aberration():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

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


def test_get_angular_separation():
Expand Down
6 changes: 5 additions & 1 deletion tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from math import isclose
from datetime import datetime
from math import isclose

from src.celerity.common import EquatorialCoordinate, GeographicCoordinate
from src.celerity.coordinates import (
Expand All @@ -20,7 +20,7 @@

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

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


def test_convert_equatorial_to_horizontal():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_moon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

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

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


def test_get_annual_equation_correction():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_night.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# For testing, we will fix the longitude to be the Isles of Scilly, Cornwall, UK.
longitude: float = -6.315165

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


def test_get_solar_altitude():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

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


def test_get_correction_to_equatorial_for_nutation():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_precession.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

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


def test_get_correction_to_equatorial_for_precession_of_equinoxes():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_refraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

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


def test_get_correction_to_horizontal_for_refraction():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

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


def test_get_mean_anomaly():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# For testing, we will fix the longitude to be Manua Kea, Hawaii, US
longitude: float = -155.468094

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

T = Time(date)

Expand Down
22 changes: 13 additions & 9 deletions tests/test_transit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,36 @@

LMC: EquatorialCoordinate = {"ra": 80.8941667, "dec": -69.7561111}

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


def test_get_does_object_rise_or_set():
d = get_does_object_rise_or_set(observer, betelgeuse)
assert d["Ar"] == 0.13703602843777568
assert d["H1"] == 0.04685668397579211

d = get_does_object_rise_or_set({"lat": 80, "lon": 0}, betelgeuse)
d = get_does_object_rise_or_set({"latitude": 80, "longitude": 0}, betelgeuse)
assert d["Ar"] == 0.7424083500051002
assert d["H1"] == 0.7372819131688116

d = get_does_object_rise_or_set({"lat": -85, "lon": 0}, betelgeuse)
d = get_does_object_rise_or_set({"latitude": -85, "longitude": 0}, betelgeuse)
assert d == False


def test_is_object_never_visible():
d = is_object_never_visible(observer, polaris, 0)
assert d == False

d = is_object_never_visible({"lat": -85, "lon": 0}, polaris, 0)
d = is_object_never_visible({"latitude": -85, "longitude": 0}, polaris, 0)
assert d == True

d = is_object_never_visible(observer, betelgeuse, 0)
assert d == False

d = is_object_never_visible({"lat": -50, "lon": 0}, betelgeuse, 0)
d = is_object_never_visible({"latitude": -50, "longitude": 0}, betelgeuse, 0)
assert d == True

d = is_object_never_visible({"lat": -85, "lon": 0}, betelgeuse, 0)
d = is_object_never_visible({"latitude": -85, "longitude": 0}, betelgeuse, 0)
assert d == True


Expand All @@ -65,7 +65,7 @@ def test_is_object_circumpolar():
assert p == True

so = is_object_circumpolar(
{"lat": -85, "lon": 0}, {"ra": 317.398, "dec": -88.956}, 0
{"latitude": -85, "longitude": 0}, {"ra": 317.398, "dec": -88.956}, 0
)
assert so == True

Expand Down Expand Up @@ -106,7 +106,9 @@ def test_get_next_rise():

# Test where we known the object only rises at specific times of the year:
date = datetime(2021, 1, 12, 0, 0, 0, 0)
r = get_next_rise(date, {"lat": 20.2437, "lon": observer["lon"]}, LMC, 0)
r = get_next_rise(
date, {"latitude": 20.2437, "longitude": observer["longitude"]}, LMC, 0
)
assert r["date"] == datetime(2021, 1, 12, 8, 16, 12, 950867, tzinfo=timezone.utc)
assert r["LST"] == 5.375729797576824
assert r["GST"] == 15.740269397576824
Expand All @@ -128,7 +130,9 @@ def test_get_next_set():

# Test where we known the object only rises at specific times of the year:
date = datetime(2021, 1, 12, 0, 0, 0, 0)
s = get_next_set(date, {"lat": 20.2437, "lon": observer["lon"]}, LMC, 0)
s = get_next_set(
date, {"latitude": 20.2437, "longitude": observer["longitude"]}, LMC, 0
)
assert s["date"] == datetime(2021, 1, 12, 8, 18, 16, 557970, tzinfo=timezone.utc)
assert s["LST"] == 5.410159095756511
assert s["GST"] == 15.774698695756513
Expand Down