Skip to content

Commit

Permalink
chore: ensure typeshed compatible mypy types are exported
Browse files Browse the repository at this point in the history
chore: ensure typeshed compatible mypy types are exported
  • Loading branch information
michealroberts committed Mar 16, 2024
1 parent bd17a45 commit aed5cf3
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 204 deletions.
39 changes: 14 additions & 25 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
{
"editor.formatOnSave": true,
"python.formatting.provider": "none",
"python.formatting.blackArgs": [
"--line-length=88"
],
"python.linting.enabled": true,
"python.linting.flake8Enabled": false,
"python.linting.pylintEnabled": false,
"python.linting.flake8Args": [
"--max-line-length=88"
],
"python.linting.mypyEnabled": true,
"isort.args": [
"--profile",
"black"
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnPaste": false,
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.semanticHighlighting.enabled": true
},
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///Users/michael/Developer/observerly/perseus/.github/workflows/deploy.yml"
}
}
"editor.cursorBlinking": "smooth",
"editor.cursorSmoothCaretAnimation": "on",
"editor.cursorStyle": "line",
"editor.formatOnSave": true,
"editor.rulers": [88],
"explorer.compactFolders": true,
"explorer.confirmDelete": true,
}
61 changes: 55 additions & 6 deletions src/celerity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
# *****************************************************************************************************************
# **************************************************************************************

# @author Michael Roberts <[email protected]>
# @package @observerly/celerity
# @license Copyright © 2021-2023 observerly

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

"""Celerity is a lightweight, zero-dependency and type-safe Python library for astronomical calculations."""
"""
Celerity is a lightweight, zero-dependency and type-safe
Python library for astronomical calculations.
"""

__version__ = "0.1.0"

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

from .temporal import Time
from celerity import (
aberration,
astrometry,
common,
constants,
coordinates,
earth,
equinox,
humanize,
moon,
night,
nutation,
parallax,
precession,
refraction,
seeing,
solstice,
sun,
temporal,
transit,
utilities,
)

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

__all__ = [
"aberration",
"astrometry",
"common",
"constants",
"coordinates",
"earth",
"equinox",
"humanize",
"moon",
"night",
"nutation",
"parallax",
"precession",
"refraction",
"seeing",
"solstice",
"sun",
"temporal",
"transit",
"utilities",
]

# **************************************************************************************
14 changes: 9 additions & 5 deletions src/celerity/aberration.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# *****************************************************************************************************************
# **************************************************************************************

# @author Michael Roberts <[email protected]>
# @package @observerly/celerity
# @license Copyright © 2021-2023 observerly

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

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

from .astrometry import get_obliquity_of_the_ecliptic
from .common import EquatorialCoordinate
Expand All @@ -20,7 +20,7 @@
from .sun import get_true_geometric_longitude as get_solar_true_geometric_longitude
from .temporal import get_julian_date

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


def get_correction_to_equatorial_for_aberration(
Expand All @@ -40,7 +40,8 @@ def get_correction_to_equatorial_for_aberration(
# Get the Julian date:
JD = get_julian_date(date)

# Get the difference in fractional Julian centuries between the target date and J2000.0
# Get the difference in fractional Julian centuries between the target
# date and J2000.0
T = (JD - 2451545.0) / 36525

# Get the ecliptic longitude of the ascending node of the mode (in degrees):
Expand Down Expand Up @@ -90,3 +91,6 @@ def get_correction_to_equatorial_for_aberration(
)

return {"ra": Δra, "dec": Δdec}


# **************************************************************************************
30 changes: 16 additions & 14 deletions src/celerity/astrometry.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# *****************************************************************************************************************
# **************************************************************************************

# @author Michael Roberts <[email protected]>
# @package @observerly/celerity
# @license Copyright © 2021-2023 observerly

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

from datetime import datetime
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.
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.
Expand All @@ -44,15 +44,16 @@ def get_angular_separation(A: EquatorialCoordinate, B: EquatorialCoordinate) ->
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
Gets the hour angle for a particular object for a particular observer
at a given datetime
:param date: The datetime object to convert.
:param ra: The right ascension of the observed object's equatorial coordinate in degrees.
:param ra: The right ascension of the observed object's equatorial coordinate.
:param longitude: The longitude of the observer in degrees.
:return The hour angle in degrees.
"""
Expand All @@ -67,15 +68,15 @@ def get_hour_angle(date: datetime, ra: float, longitude: float) -> float:
return ha


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


def get_obliquity_of_the_ecliptic(date: datetime) -> float:
"""
Gets the obliquity of the ecliptic for a particular datetime
The obliquity of the ecliptic is the angle between the ecliptic and the celestial equator, and is used to
convert between ecliptic and equatorial coordinates.
The obliquity of the ecliptic is the angle between the ecliptic and the celestial
equator, and is used to convert between ecliptic and equatorial coordinates.
:param date: The datetime object to convert.
:return The obliquity of the ecliptic in degrees.
Expand All @@ -90,7 +91,7 @@ def get_obliquity_of_the_ecliptic(date: datetime) -> float:
return 23.439292 - (46.845 * T + 0.00059 * pow(T, 2) + 0.001813 * pow(T, 3)) / 3600


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


def get_parallactic_angle(
Expand All @@ -99,7 +100,8 @@ def get_parallactic_angle(
target: EquatorialCoordinate,
) -> float:
"""
Gets the parallactic angle for a particular object for a particular observer at a given datetime
Gets the parallactic angle for a particular object for a particular observer
at a given datetime
:param date: The datetime object to convert.
:param observer: The geographic coordinate of the observer.
Expand All @@ -122,4 +124,4 @@ def get_parallactic_angle(
)


# *****************************************************************************************************************
# **************************************************************************************
28 changes: 14 additions & 14 deletions src/celerity/common.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# *****************************************************************************************************************
# **************************************************************************************

# @author Michael Roberts <[email protected]>
# @package @observerly/celerity
# @license Copyright © 2021-2023 observerly

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

from math import cos, pow, radians
from typing import Any, TypedDict

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


class Age(TypedDict):
a: float
A: float


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


class Angle(TypedDict):
Expand All @@ -26,7 +26,7 @@ class Angle(TypedDict):
sec: float


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


class HourAngle(TypedDict):
Expand All @@ -35,35 +35,35 @@ class HourAngle(TypedDict):
sec: float


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


class EquatorialCoordinate(TypedDict):
ra: float
dec: float


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


class GeographicCoordinate(TypedDict):
lat: float
lon: float


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


class HorizontalCoordinate(TypedDict):
alt: float
az: float


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


def is_equatorial_coordinate(coordinate: Any) -> EquatorialCoordinate | None:
if type(coordinate) is not dict:
if isinstance(coordinate, dict):
return None

return (
Expand All @@ -73,11 +73,11 @@ def is_equatorial_coordinate(coordinate: Any) -> EquatorialCoordinate | None:
)


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


def is_horizontal_coordinate(coordinate: Any) -> HorizontalCoordinate | None:
if type(coordinate) is not dict:
if isinstance(coordinate, dict):
return None

return (
Expand All @@ -87,11 +87,11 @@ def is_horizontal_coordinate(coordinate: Any) -> HorizontalCoordinate | None:
)


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


def get_F_orbital_parameter(ν: float, e: float) -> float:
return (1 + (e * cos(radians(ν)))) / (1 - pow(e, 2))


# *****************************************************************************************************************
# **************************************************************************************
10 changes: 5 additions & 5 deletions src/celerity/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# *****************************************************************************************************************
# **************************************************************************************

# @author Michael Roberts <[email protected]>
# @package @observerly/celerity
# @license Copyright © 2021-2023 observerly

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

"""
The previous standard epoch "J1900" was defined by international
Expand All @@ -15,7 +15,7 @@
"""
J1900: float = 2415020.0

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

"""
The standard epoch "J1970" is defined by international agreement to be
Expand All @@ -31,7 +31,7 @@
"""
J1970: float = 2440587.5

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

"""
The currently-used standard epoch "J2000" is defined by international
Expand All @@ -42,4 +42,4 @@
"""
J2000: float = 2451545.0

# *****************************************************************************************************************
# **************************************************************************************
Loading

0 comments on commit aed5cf3

Please sign in to comment.