Browse Source

Minor changes to _search_earth_season_change

pull/24/head
Tung Lam Nguyen Le 3 years ago
committed by Jérôme Deuchnord
parent
commit
6f79a6c90c
2 changed files with 21 additions and 15 deletions
  1. +6
    -4
      kosmorrolib/enum.py
  2. +15
    -11
      kosmorrolib/events.py

+ 6
- 4
kosmorrolib/enum.py View File

@@ -15,6 +15,11 @@ class MoonPhaseType(Enum):
LAST_QUARTER = 7
WANING_CRESCENT = 8

class SeasonType(Enum):
MARCH_EQUINOX = 0
JUNE_SOLSTICE = 1
SEPTEMBER_EQUINOX = 2
DECEMBER_SOLSTICE = 3

class EventType(Enum):
"""An enumeration for the supported event types."""
@@ -25,10 +30,7 @@ class EventType(Enum):
MAXIMAL_ELONGATION = 4
MOON_PERIGEE = 5
MOON_APOGEE = 6
VERNAL_EQUINOX = 7
SUMMER_SOLSTICE = 8
AUTUMNAL_EQUINOX = 9
WINTER_SOLSTICE = 10


class ObjectType(Enum):
"""An enumeration of object types"""


+ 15
- 11
kosmorrolib/events.py View File

@@ -11,7 +11,7 @@ from skyfield import api

from .model import Event, Star, Planet, ASTERS
from .dateutil import translate_to_timezone
from .enum import EventType, ObjectIdentifier
from .enum import EventType, ObjectIdentifier, SeasonType
from .exceptions import OutOfRangeDateError
from .core import get_timescale, get_skf_objects, flatten_list

@@ -254,7 +254,7 @@ def _search_earth_season_change(start_time: Time, end_time: Time, timezone: int)

Will return Summer Solstice and Autumnal Equinox on respectively 2020-06-20 and 2020-09-21:

>>> season_change = _search_earth_season_change(get_timescale().utc(2020, 5, 13), get_timescale().utc(2020, 10, 14), 0)
>>> season_change = _search_earth_season_change(get_timescale().utc(2020, 6, 20), get_timescale().utc(2020, 6, 21), 0)
>>> len(season_change)
2
>>> oppositions[0].objects[0]
@@ -265,15 +265,19 @@ def _search_earth_season_change(start_time: Time, end_time: Time, timezone: int)
>>> _search_oppositions(get_timescale().utc(2021, 3, 20), get_timescale().utc(2021, 3, 21), 0)
[]
"""
eph = api.load('de421.bsp')
event = []
t, y = almanac.find_discrete(start_time,end_time,almanac.seasons(eph))
for yi, ti in zip(y,t):
event.append(Event(
EventType[f'{almanac.SEASON_EVENTS[yi].upper().replace(" ","_")}'],
[almanac.SEASON_EVENTS[yi]],
ti.utc_iso(' ')))
return event
events = []
t, y = almanac.find_discrete(start_time,end_time,almanac.seasons(get_skf_objects()))
if len(t) == 0:
return []
else:
events.append(Event(
SeasonType(y[0]),
[],
translate_to_timezone(t.utc_datetime()[0], timezone)))
return events



def get_events(for_date: date = date.today(), timezone: int = 0) -> [Event]:
"""Calculate and return a list of events for the given date, adjusted to the given timezone if any.


Loading…
Cancel
Save