Skip to content

Commit

Permalink
Adjust Catalog Selection Logic, Add Filter by Constellation, Fix mino…
Browse files Browse the repository at this point in the history
…r catalog defects (#236)

Catalog filter refactor, add constellation, fix catalog data defects
  • Loading branch information
brickbots authored Jan 21, 2025
1 parent a5e218f commit 084f876
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 25 deletions.
Binary file modified astro_data/pifinder_objects.db
Binary file not shown.
109 changes: 108 additions & 1 deletion default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,121 @@
"chart_reticle": 128,
"chart_constellations": 64,
"solve_pixel": [256, 256],
"active_catalogs": [
"filter.selected_catalogs": [
"NGC",
"M",
"H",
"Str",
"PL",
"RDS"
],
"filter.object_types": [
"Gx",
"OC",
"Gb",
"Nb",
"DN",
"PN",
"C+N",
"Ast",
"Kt",
"***",
"D*",
"*",
"?",
"Pla",
"CM"
],
"filter.constellations": [
"And",
"Ant",
"Aps",
"Aql",
"Aqr",
"Ara",
"Ari",
"Aur",
"Boo",
"CMa",
"CMi",
"CVn",
"Cae",
"Cam",
"Cap",
"Car",
"Cas",
"Cen",
"Cep",
"Cet",
"Cha",
"Cir",
"Cnc",
"Col",
"Com",
"CrA",
"CrB",
"Crt",
"Cru",
"Crv",
"Cyg",
"Del",
"Dor",
"Dra",
"Equ",
"Eri",
"For",
"Gem",
"Gru",
"Her",
"Hor",
"Hya",
"Hyi",
"Ind",
"LMi",
"Lac",
"Leo",
"Lep",
"Lib",
"Lup",
"Lyn",
"Lyr",
"Men",
"Mic",
"Mon",
"Mus",
"Nor",
"Oct",
"Oph",
"Ori",
"Pav",
"Peg",
"Per",
"Phe",
"Pic",
"PsA",
"Psc",
"Pup",
"Pyx",
"Ret",
"Scl",
"Sco",
"Sct",
"Ser",
"Sex",
"Sge",
"Sgr",
"Tau",
"Tel",
"TrA",
"Tri",
"Tuc",
"UMa",
"UMi",
"Vel",
"Vir",
"Vol",
"Vul"
],
"equipment": {
"telescopes": [
{
Expand Down
49 changes: 48 additions & 1 deletion python/PiFinder/catalog_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This module holds various utils
and importers used during setup
and importers used during catalog setup
"""

Expand Down Expand Up @@ -1442,6 +1442,49 @@ def load_ngc_catalog():
insert_catalog_max_sequence("M")


def fix_object_types():
"""
Runs some global queries to normalize object types from various catalogs
"""
logging.info("FIX: Object Types")
conn, db_c = objects_db.get_conn_cursor()

type_mappings = {
"Dark Nebula": "DN",
"* ": "*",
"*?": "?",
"-": "?",
"": "?",
"Bright Nebula": "Nb",
"D*?": "D*",
"Open Cluster": "OC",
"Pl": "PN",
"PD": "PN",
"Supernova Remnant": "Nb",
}

for k, v in type_mappings.items():
db_c.execute(f"update objects set obj_type = '{v}' where obj_type='{k}'")

conn.commit()


def fix_m45():
"""
m45 coordinates are wrong in our NGC source
"""
logging.info("FIX: m45 location")
conn, db_c = objects_db.get_conn_cursor()

db_c.execute(
"update objects set ra=56.85, dec=24.1167 where "
"id = (select object_id from catalog_objects "
"where catalog_code='M' and sequence=45)"
)

conn.commit()


if __name__ == "__main__":
logging.info("starting main")
logger = logging.getLogger()
Expand Down Expand Up @@ -1505,6 +1548,10 @@ def load_ngc_catalog():
load_arp()
load_tlk_90_vars()

# Fix data issues
fix_object_types()
fix_m45()

# Populate the images table
logging.info("Resolving object images...")
resolve_object_images()
Expand Down
40 changes: 39 additions & 1 deletion python/PiFinder/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from PiFinder.composite_object import CompositeObject, MagnitudeObject
import PiFinder.comets as comets
from PiFinder.utils import Timer, comet_file
from PiFinder.config import Config

logger = logging.getLogger("Catalog")

Expand Down Expand Up @@ -94,6 +95,7 @@ def __init__(
object_types: Union[list[str], None] = None,
altitude: int = -1,
observed: str = "Any",
constellations: list[str] = [],
selected_catalogs: list[str] = [],
):
self.shared_state = shared_state
Expand All @@ -104,9 +106,22 @@ def __init__(
self._object_types = object_types
self._altitude = altitude
self._observed = observed
self._constellations = constellations
self._selected_catalogs = set(selected_catalogs)
self.last_filtered_time = 0

def load_from_config(self, config_object: Config):
"""
Loads filter values from configuration object
"""
self._magnitude = config_object.get_option("filter.magnitude")
self._object_types = config_object.get_option("filter.object_types", [])
self._altitude = config_object.get_option("filter.altitude", -1)
self._observed = config_object.get_option("filter.observed", "Any")
self._constellations = config_object.get_option("filter.constellations", [])
self._selected_catalogs = config_object.get_option("filter.selected_catalogs")
self.last_filtered_time = 0

@property
def magnitude(self):
return self._magnitude
Expand Down Expand Up @@ -143,6 +158,15 @@ def observed(self, observed: str):
self._observed = observed
self.dirty_time = time.time()

@property
def constellations(self):
return self._constellations

@constellations.setter
def constellations(self, constellations: list[str]):
self._constellations = constellations
self.dirty_time = time.time()

@property
def selected_catalogs(self):
return self._selected_catalogs
Expand Down Expand Up @@ -183,6 +207,16 @@ def apply_filter(self, obj: CompositeObject):

obj.last_filtered_time = time.time()
self.last_filtered_time = time.time()

# check constellation
if self._constellations:
if obj.const not in self._constellations:
obj.last_filtered_result = False
return False
else:
obj.last_filtered_result = False
return False

# check altitude
if self._altitude != -1 and self.fast_aa:
obj_altitude, _ = self.fast_aa.radec_to_altaz(
Expand All @@ -202,7 +236,11 @@ def apply_filter(self, obj: CompositeObject):
return False

# check type
if self._object_types is not None and obj.obj_type not in self._object_types:
if self._object_types:
if obj.obj_type not in self._object_types:
obj.last_filtered_result = False
return False
else:
obj.last_filtered_result = False
return False

Expand Down
13 changes: 3 additions & 10 deletions python/PiFinder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,9 @@ def main(
catalogs: Catalogs = CatalogBuilder().build(shared_state)

# Establish the common catalog filter object
catalogs.set_catalog_filter(
CatalogFilter(
shared_state=shared_state,
magnitude=cfg.get_option("filter.magnitude"),
object_types=cfg.get_option("filter.object_types"),
altitude=cfg.get_option("filter.altitude", -1),
observed=cfg.get_option("filter.observed", "Any"),
selected_catalogs=cfg.get_option("active_catalogs"),
)
)
_new_filter = CatalogFilter(shared_state=shared_state)
_new_filter.load_from_config(cfg)
catalogs.set_catalog_filter(_new_filter)
console.write(" Menus")
console.update()

Expand Down
9 changes: 5 additions & 4 deletions python/PiFinder/obj_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"OC": "Open Cluster",
"Gb": "Globular",
"Nb": "Nebula",
"Pl": "Planetary",
"DN": "Dark Nebula",
"PN": "Planetary",
"C+N": "Cluster + Neb",
"Ast": "Asterism",
"Kt": "Knot",
"***": "Triple star",
"D*": "Double star",
"* ": "Star",
"? ": "Unkn",
"*": "Star",
"?": "Unkn",
"Pla": "Planet",
"CM": "Comet",
}
Expand All @@ -20,7 +21,7 @@
"OC": "oc",
"Gb": "gc",
"Nb": "neb",
"Pl": "pneb",
"PN": "pneb",
"D*": "dstar",
"***": "dstar",
"Ast": "ast",
Expand Down
8 changes: 5 additions & 3 deletions python/PiFinder/ui/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def reset_filters(ui_module: UIModule) -> None:
"""
Reset all filters to default
"""
ui_module.catalogs.set_catalog_filter(
CatalogFilter(shared_state=ui_module.shared_state)
)
ui_module.config_object.reset_filters()

new_filter = CatalogFilter(shared_state=ui_module.shared_state)
new_filter.load_from_config(ui_module.config_object)

ui_module.catalogs.set_catalog_filter(new_filter)
ui_module.catalogs.filter_catalogs()
ui_module.message("Filters Reset")
ui_module.remove_from_stack()
Expand Down
Loading

0 comments on commit 084f876

Please sign in to comment.