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
12 changes: 0 additions & 12 deletions .gitpod.yml

This file was deleted.

89 changes: 45 additions & 44 deletions kosmorrolib/ephemerides.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
get_skf_objects,
get_timescale,
get_iau2000b,
deprecated,
alert_deprecation,
)
from .enum import MoonPhaseType
Expand All @@ -39,48 +38,6 @@
RISEN_ANGLE = -0.8333


def _get_skyfield_to_moon_phase(
times: [Time], vals: [int], now: Time, utc_offset: Union[int, float]
) -> Union[MoonPhase, None]:
tomorrow = get_timescale().utc(
now.utc_datetime().year, now.utc_datetime().month, now.utc_datetime().day + 1
)

next_phase_time = None
i = 0

# Find the current moon phase:
for i, time in enumerate(times):
if now.utc_datetime() <= time.utc_datetime():
if time.utc_datetime() >= tomorrow.utc_datetime():
i -= 1
break

current_phase = MoonPhaseType(vals[i])

if current_phase in [
MoonPhaseType.NEW_MOON,
MoonPhaseType.FIRST_QUARTER,
MoonPhaseType.FULL_MOON,
MoonPhaseType.LAST_QUARTER,
]:
current_phase_time = translate_to_utc_offset(
times[i].utc_datetime(), utc_offset
)
else:
current_phase_time = None

# Find the next moon phase
for j in range(i + 1, len(times)):
if vals[j] in [0, 2, 4, 6]:
next_phase_time = translate_to_utc_offset(
times[j].utc_datetime(), utc_offset
)
break

return MoonPhase(current_phase, current_phase_time, next_phase_time)


def get_moon_phase(
for_date: date = date.today(), utc_offset: Union[int, float] = 0, **argv
) -> MoonPhase:
Expand Down Expand Up @@ -116,6 +73,49 @@ def get_moon_phase(
kosmorrolib.exceptions.OutOfRangeDateError: The date must be between 1899-08-09 and 2053-09-26
"""

def _get_skyfield_to_moon_phase(
times: [Time], vals: [int], now: Time, utc_offset: Union[int, float]
):
tomorrow = get_timescale().utc(
now.utc_datetime().year,
now.utc_datetime().month,
now.utc_datetime().day + 1,
)

next_phase_time = None
i = 0

# Find the current moon phase:
for i, time in enumerate(times):
if now.utc_datetime() <= time.utc_datetime():
if time.utc_datetime() >= tomorrow.utc_datetime():
i -= 1
break

current_phase = MoonPhaseType(vals[i])

if current_phase in [
MoonPhaseType.NEW_MOON,
MoonPhaseType.FIRST_QUARTER,
MoonPhaseType.FULL_MOON,
MoonPhaseType.LAST_QUARTER,
]:
current_phase_time = translate_to_utc_offset(
times[i].utc_datetime(), utc_offset
)
else:
current_phase_time = None

# Find the next moon phase
for j in range(i + 1, len(times)):
if vals[j] in [0, 2, 4, 6]:
next_phase_time = translate_to_utc_offset(
times[j].utc_datetime(), utc_offset
)
break

return MoonPhase(current_phase, current_phase_time, next_phase_time)

if argv.get("timezone") is not None:
alert_deprecation(
"'timezone' argument of the get_moon_phase() function is deprecated. Use utc_offset instead."
Expand Down Expand Up @@ -275,7 +275,8 @@ def get_ephemerides(
alert_deprecation(
"'timezone' argument of the get_ephemerides() function is deprecated. Use utc_offset instead."
)
utc_offset = argv.get("timezone")

return get_ephemerides(position, for_date, argv.get("timezone"))

def get_angle(for_aster: Object):
def fun(time: Time) -> float:
Expand Down
Loading