Skip to content

Commit

Permalink
Delay planet load until GPS lock
Browse files Browse the repository at this point in the history
  • Loading branch information
brickbots committed Jan 21, 2024
1 parent ab63d2c commit 7e9fb50
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
5 changes: 3 additions & 2 deletions python/PiFinder/calc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
load_constellation_map,
)
from skyfield.magnitudelib import planetary_magnitude
from skyfield import almanac
import PiFinder.utils as utils
import json
import hashlib
Expand Down Expand Up @@ -200,14 +201,14 @@ def radec_to_constellation(self, ra, dec):
sky_pos = position_of_radec(Angle(degrees=ra)._hours, dec)
return self.constellation_map(sky_pos)

def calc_planets(self):
def calc_planets(self, dt):
"""Returns dictionary with all planet positions:
{'SUN': {'radec': (279.05819685702846, -23.176809282384962),
'radec_pretty': ((18.0, 36.0, 14), (-23, 10, 36.51)),
'altaz': (1.667930045300066, 228.61434416619613)},
}
"""
t = self.ts.now()
t = self.ts.from_datetime(dt)
observer = self.observer_loc.at(t)
planet_dict = {}
for name, planet in zip(self.planet_names, self.planets):
Expand Down
19 changes: 11 additions & 8 deletions python/PiFinder/catalogs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import time
import datetime
from typing import List, Dict, DefaultDict, Optional
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -301,11 +302,14 @@ def __iter__(self):
class PlanetCatalog(Catalog):
"""Creates a catalog of planets"""

def __init__(self):
super().__init__("PL", 11, "The planets")
planet_dict = sf_utils.calc_planets()
for sequence, name in enumerate(sf_utils.planet_names):
self.add_planet(sequence, name, planet_dict[name])
def __init__(self, dt: datetime.datetime):
super().__init__("PL", 10, "The planets")
planet_dict = sf_utils.calc_planets(dt)
sequence = 0
for name in sf_utils.planet_names:
if name.lower() != "sun":
self.add_planet(sequence, name, planet_dict[name])
sequence += 1

def add_planet(self, sequence: int, name: str, planet: Dict[str, Dict[str, float]]):
ra, dec = planet["radec"]
Expand All @@ -320,9 +324,10 @@ def add_planet(self, sequence: int, name: str, planet: Dict[str, Dict[str, float
"const": constellation,
"size": "",
"mag": planet["mag"],
"names": [name.capitalize()],
"catalog_code": "PL",
"sequence": sequence + 1,
"description": f"{name.capitalize()}, alt={planet['altaz'][0]:.1f}°",
"description": f"",
}
)
self.add_object(obj)
Expand Down Expand Up @@ -351,8 +356,6 @@ def build(self) -> Catalogs:
self.catalog_dicts = {}
logging.debug(f"Loaded {len(composite_objects)} objects from database")
all_catalogs: Catalogs = self._get_catalogs(composite_objects, catalogs_info)
planet_catalog: Catalog = PlanetCatalog()
all_catalogs.add(planet_catalog)
return all_catalogs

def _build_composite(
Expand Down
1 change: 1 addition & 0 deletions python/PiFinder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def main(script_name=None, show_fps=False):
f'GPS: Location {location["lat"]} {location["lon"]} {location["altitude"]}'
)
location["gps_lock"] = True

shared_state.set_location(location)
if gps_msg == "time":
logging.debug(f"GPS time msg: {gps_content}")
Expand Down
21 changes: 20 additions & 1 deletion python/PiFinder/ui/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import logging

from PiFinder.db.observations_db import ObservationsDatabase
from PiFinder.catalogs import CompositeObject, CatalogBuilder, Catalogs
from PiFinder.catalogs import CompositeObject, CatalogBuilder, Catalogs, PlanetCatalog


# Constants for display modes
Expand Down Expand Up @@ -130,6 +130,18 @@ def __init__(self, *args):

self.catalog_tracker.filter()
self.update_object_info()
self._planets_loaded = False

def add_planets(self, dt):
"""
Since we can't calc planet positions until we know the date/time
this is called once we have a GPS lock to add on the planets catalog
"""
self.catalogs.add(PlanetCatalog(dt))
self.catalog_tracker = CatalogTracker(
self.catalogs, self.shared_state, self._config_options
)
self._planets_loaded = True

def _layout_designator(self):
"""
Expand Down Expand Up @@ -329,6 +341,13 @@ def update_object_info(self):
def active(self):
# trigger refilter
super().active()

# check for planet add
if not self._planets_loaded:
dt = self.shared_state.datetime()
if dt:
self.add_planets(dt)

self.catalog_tracker.filter()
target = self.ui_state.target()
if target:
Expand Down

0 comments on commit 7e9fb50

Please sign in to comment.