From 862fb20b42b6031d736e3f834611fa7f4ce99063 Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 9 Nov 2026 17:08:03 -0700 Subject: [PATCH 1/2] feat(catalog-import): a Named Stars catalog of every IAU-named Hipparcos star One listing per HIP number the IAU Catalog of Star Names (WGSN) gives, 578 stars, numbered by that number (Vega is Nam 91262) so the numbers stay put as the WGSN adopts names. Position and V from Hipparcos (V the star's own, else its system's combined light); no names of its own: add_wgsn_names names each. The star-identity stage identifies a HIP-numbered listing by its number alone: it takes no part in the cross-match or the rules, so no other match changes, and the merge joins it to the star they identify. 363 listings join an existing star, 215 become new sky objects (137 of them naked-eye). The catalog is in both Stars... menus beside Bright Named, which stays. The object list's jump-to-number takes as many digits as the list's largest sequence (6 for Nam and WDS, was 4). Refs #670 Co-Authored-By: Claude Opus 5.5 (1M context) --- astro_data/named_stars.desc | 1 + docs/ax/catalog.md | 27 +- docs/ax/catalog/CONTEXT.md | 2 +- docs/source/catalogs.rst | 16 +- docs/source/menu_map.rst | 5 +- python/PiFinder/catalog_imports/main.py | 3 + .../catalog_imports/named_stars_loader.py | 90 +++++ .../PiFinder/catalog_imports/star_identity.py | 63 ++- python/PiFinder/ui/menu_structure.py | 10 + python/PiFinder/ui/object_list.py | 7 +- python/tests/test_catalog_named_stars.py | 359 ++++++++++++++++++ python/tests/test_object_list_jump.py | 59 +++ 12 files changed, 627 insertions(+), 15 deletions(-) create mode 100644 astro_data/named_stars.desc create mode 100644 python/PiFinder/catalog_imports/named_stars_loader.py create mode 100644 python/tests/test_catalog_named_stars.py create mode 100644 python/tests/test_object_list_jump.py diff --git a/astro_data/named_stars.desc b/astro_data/named_stars.desc new file mode 100644 index 000000000..5c968171b --- /dev/null +++ b/astro_data/named_stars.desc @@ -0,0 +1 @@ +Every star the IAU has named, from the IAU Catalog of Star Names kept by its Working Group on Star Names (WGSN). Each star is listed by its Hipparcos number: Vega is Nam 91262. 578 stars carry 579 names. The 73 names of objects without a Hipparcos number, mostly faint planet-host stars, are left out. Epsilon Bootis (Nam 72105) has two IAU names, Izar and Pulcherrima, and the IAU does not say which star of the pair each one names, so neither is shown as its name. diff --git a/docs/ax/catalog.md b/docs/ax/catalog.md index 4b5c38538..96e0b648d 100644 --- a/docs/ax/catalog.md +++ b/docs/ax/catalog.md @@ -471,7 +471,11 @@ before the next build. Each stage has the last word over the stages before it. Loader order matters: a loader can only join sky objects that earlier loaders created -(so Sharpless loads before Caldwell, whose C 9 is Sh2 155). +(so Sharpless loads before Caldwell, whose C 9 is Sh2 155). The Named +Stars loader (`Nam`) loads last: its listings join no sky object at +insert, and the star-identity stage joins each to its star by HIP number, +where the lowest id survives, so a star another catalog lists keeps that +catalog's sky object. When a loader joins a sky object an earlier loader created, it may only fill what is empty — never replace — with two named exceptions: @@ -590,6 +594,22 @@ and would give a listing another star's values, while a miss costs one line in a corrections file. A listing with no match stays its own sky object. +- **A HIP-numbered listing is its star.** The Named Stars catalog (`Nam`) + lists each star the IAU Catalog of Star Names gives a HIP number, and its + sequence is that number (Vega is Nam 91262), so the number stays the + star's as the WGSN adopts names (`HIP_NUMBERED_CATALOGS`). Such a listing + is identified by its number alone, with the rule "HIP number": it is not + cross-matched, takes no part in the rules below, and takes no `hip` + correction. It changes no other listing's match, and joins whatever the + rules and corrections identify as its HIP number in the merge. Where they + miss a star another catalog lists, the Named Stars listing is a sky object + of its own beside it, until a `hip` correction identifies the missed + listing; position never joins them. The listing's position and V are + Hipparcos's: V is the star's own where Hipparcos says so (9.4), and + otherwise its system's combined light, which is what a finder shows of + a star listed alone. A star with no other listing keeps that V, and + without one it would drop out of every magnitude filter. + - **The match** is the one Hipparcos star within the listing's radius whose V lies within 1 mag of the listing's first magnitude, the primary's; for a variable listed by its range (TLK's [max, min]), @@ -775,7 +795,10 @@ star-identity stage identified by that number, and nothing else: - A name with no HIP number, one whose star PiFinder doesn't hold or didn't identify, and the two names of HIP 72105 (Izar and Pulcherrima, with no component to choose between them) are skipped; the import logs - how many, and the names other sky objects carry too. + how many, and the names other sky objects carry too. Since the Named + Stars catalog lists every HIP number the WGSN names (9.3), every name + with a HIP number has its star: Nam 72105 is ε Boo, the pair, with + neither IAU name, as before. Steinicke's Bmag is never used as a fallback V on its own: for non-galaxies it is often NGC 2000.0's photographic figure, and for M 43 diff --git a/docs/ax/catalog/CONTEXT.md b/docs/ax/catalog/CONTEXT.md index 05c6491d8..42af5b5bf 100644 --- a/docs/ax/catalog/CONTEXT.md +++ b/docs/ax/catalog/CONTEXT.md @@ -17,7 +17,7 @@ The readable, human-facing label for a catalog as a whole — `"Collinder"`, `"C _Avoid_: catalog name (prefer the full term), catalog title, long name. **Sequence**: -Integer position of an object inside one catalog (e.g. `13` for M 13). Must be unique within a catalog (enforced by `CatalogBase.check_sequences()`). +Integer position of an object inside one catalog (e.g. `13` for M 13). Must be unique within a catalog (enforced by `CatalogBase.check_sequences()`). In the Named Stars catalog (`Nam`) it is the star's Hipparcos (HIP) number, so it stays the star's as names are added: Vega is Nam 91262. _Avoid_: number, index, ordinal. **Object ID** (`object_id`): diff --git a/docs/source/catalogs.rst b/docs/source/catalogs.rst index 4777972e0..211ea1bb1 100644 --- a/docs/source/catalogs.rst +++ b/docs/source/catalogs.rst @@ -74,6 +74,19 @@ M ---------- Messier catalog +Nam +---- +Named Stars: every star with a name from the IAU Catalog of Star Names, 578 in +all, from Vega and Miaplacidus down to faint stars named for the planets they +host. Each star is listed by its Hipparcos number, so Vega is Nam 91262. Type a +name in **Name Search** to find the star, or sort by **Nearest**. The 73 IAU names +of objects without a Hipparcos number are not included. See +`IAU Catalog of Star Names `_. + +The IAU name is the name the PiFinder shows for each of these stars, in every +catalog that lists it. A name with accents, such as Mönch, can also be found +by typing it without them. + NGC ---------- NGC 2000.0, The Complete New General Catalogue and Index Catalogue of Nebulae and Star Clusters by J.L.E. Dreyer (edited by R.W. Sinnott). @@ -110,7 +123,8 @@ Sh2 Str ---- -Named bright stars. Especially useful for aligning GoTo telescopes. +Named bright stars. Especially useful for aligning GoTo telescopes. For every +star the IAU has named, see Nam. Ta2 ---------- diff --git a/docs/source/menu_map.rst b/docs/source/menu_map.rst index 5ec1fb297..c50a2e26a 100644 --- a/docs/source/menu_map.rst +++ b/docs/source/menu_map.rst @@ -133,8 +133,9 @@ By Catalog extragalactic globulars, Harris globulars, Herschel 400, IC, Lyngå open clusters, Messier, NGC, Sharpless emission nebulae, and the TAAS 200 list. Stars... - Star catalogs: bright named stars, the SAC double, asterism and red-star - lists, RASC and WDS doubles, and TLK's hand-picked variable stars. + Star catalogs: bright named stars, every IAU-named star, the SAC double, + asterism and red-star lists, RASC and WDS doubles, and TLK's hand-picked + variable stars. Recent The objects you've viewed this session, most recent first. It starts empty each session. diff --git a/python/PiFinder/catalog_imports/main.py b/python/PiFinder/catalog_imports/main.py index edaa7e1a1..063798077 100644 --- a/python/PiFinder/catalog_imports/main.py +++ b/python/PiFinder/catalog_imports/main.py @@ -43,6 +43,9 @@ ("wds_loader", "load_wds"), ("harris_loader", "load_harris"), ("lynga_loader", "load_lynga"), + # Last, so each star another catalog lists keeps its sky object when the + # star-identity stage joins the Named Stars listing to it by HIP number. + ("named_stars_loader", "load_named_stars"), ] POST_PROCESSING_FUNCTIONS = [ diff --git a/python/PiFinder/catalog_imports/named_stars_loader.py b/python/PiFinder/catalog_imports/named_stars_loader.py new file mode 100644 index 000000000..c5dca9d5a --- /dev/null +++ b/python/PiFinder/catalog_imports/named_stars_loader.py @@ -0,0 +1,90 @@ +""" +Named Stars catalog loader for PiFinder. + +One listing for each star the IAU Catalog of Star Names (the WGSN's) gives a +Hipparcos number for, numbered by that number: Vega is Nam 91262. The number +stays the star's as the WGSN adopts new names, and it identifies the star: +the star-identity stage joins the listing to the star other catalogs list by +that number, never by position (docs/ax/catalog.md §9.3). + +The listing carries no names of its own. The WGSN supplementary source +(add_wgsn_names) gives each identified star its IAU name, so a star never +gets its name twice. +""" + +import logging +import math +from pathlib import Path +from typing import List, Optional + +import PiFinder.utils as utils +from PiFinder.composite_object import MagnitudeObject, SizeObject +from .catalog_import_utils import ( + NewCatalogObject, + delete_catalog_from_database, + insert_catalog, + insert_catalog_max_sequence, +) +from .database import objects_db +from .star_identity import HIP_NUMBERED_CATALOGS, Hipparcos, load_hipparcos +from .supplementary_sources import WGSN_PATH, read_wgsn + +CATALOG_CODE = "Nam" +assert CATALOG_CODE in HIP_NUMBERED_CATALOGS +DESCRIPTION_PATH = Path(utils.astro_data_dir, "named_stars.desc") + + +def named_star_listings( + hipparcos: Hipparcos, path: Path = WGSN_PATH +) -> List[NewCatalogObject]: + """One listing per HIP number the WGSN names, in HIP order. + + The position is Hipparcos's, carried to J2000 by its proper motion. The V + is Hipparcos's: the star's own where Hipparcos says so (Hipparcos.own_vmag), + otherwise the light of the whole system it measured, which is what a + finder shows of a star its catalog lists alone. A name without a HIP + number has no listing. + """ + hips = sorted({name.hip for name in read_wgsn(path) if name.hip is not None}) + listings = [] + for hip in hips: + index = hipparcos.index_of(hip) + if index is None: + raise ValueError(f"WGSN names HIP {hip}, which Hipparcos lacks") + vmag = float(hipparcos.vmag[index]) + listings.append( + NewCatalogObject( + object_type="*", + catalog_code=CATALOG_CODE, + sequence=hip, + ra=float(hipparcos.ra[index]), + dec=float(hipparcos.dec[index]), + mag=MagnitudeObject([] if math.isnan(vmag) else [vmag]), + size=SizeObject([]), + ) + ) + return listings + + +def load_named_stars( + hipparcos: Optional[Hipparcos] = None, path: Path = WGSN_PATH +) -> None: + """Load the Named Stars catalog: every IAU-named Hipparcos star.""" + logging.info("Loading Named Stars") + assert objects_db is not None, "init_shared_database() runs first" + hipparcos = hipparcos if hipparcos is not None else load_hipparcos() + conn, _ = objects_db.get_conn_cursor() + delete_catalog_from_database(CATALOG_CODE) + insert_catalog(CATALOG_CODE, DESCRIPTION_PATH) + listings = named_star_listings(hipparcos, path) + objects_db.bulk_mode = True + try: + for listing in listings: + # The listing names nothing to join: the star-identity stage joins + # it to its star by HIP number. + listing.insert(find_object_id=False) + conn.commit() + finally: + objects_db.bulk_mode = False + insert_catalog_max_sequence(CATALOG_CODE) + logging.info("Named Stars: %d stars", len(listings)) diff --git a/python/PiFinder/catalog_imports/star_identity.py b/python/PiFinder/catalog_imports/star_identity.py index a710590d3..e6bb995df 100644 --- a/python/PiFinder/catalog_imports/star_identity.py +++ b/python/PiFinder/catalog_imports/star_identity.py @@ -1,7 +1,7 @@ """ Star identity: a star is identified by its Hipparcos number. -The star catalogs (Str, SaM, SaR, TLK, RDS, WDS) list many of the same stars, +The star catalogs (Str, SaM, SaR, TLK, RDS, WDS, Nam) list many of the same stars, and few of their listings carry a designation the loaders' lookup resolves, so each loader leaves a star a sky object of its own: Mizar was SaM's and Str's. This stage cross-matches each star sky object to hip_main.dat and merges the @@ -41,7 +41,12 @@ from .corrections import CorrectionError, parse_designator, resolve_listing # The catalogs whose listings are stars, in loader order. -STAR_CATALOGS = ("SaM", "SaR", "Str", "RDS", "TLK", "WDS") +STAR_CATALOGS = ("SaM", "SaR", "Str", "RDS", "TLK", "WDS", "Nam") + +# The catalogs whose sequence is the star's HIP number (Named Stars, Nam 91262 +# is Vega). Such a listing is identified by its number alone: it is not +# cross-matched, and no rule or `hip` correction applies to it. +HIP_NUMBERED_CATALOGS = frozenset({"Nam"}) # A match is made only where it is reliably right, at the cost of missing # some stars; those are matched by `hip` corrections (catalog.md §9.3). The @@ -98,7 +103,7 @@ # Prefixes that are catalog numbers, not double-star discoverers. _NOT_DISCOVERERS = frozenset( {"HD", "HR", "SAO", "HIP", "BD", "CD", "CPD", "COD", "NGC", "IC", "M", "ADS"} - | {code.upper() for code in ("SaM", "SaR", "Str", "RDS", "TLK", "WDS", "H")} + | {code.upper() for code in ("SaM", "SaR", "Str", "RDS", "TLK", "WDS", "Nam", "H")} ) _DESIGNATION_RE = re.compile(r"([A-Za-z]{1,8})\s*(\d+)") _HD_RE = re.compile(r"HD\s*(\d+)") @@ -298,6 +303,8 @@ class StarObject: # its position stands in for its star's (STAND_IN_POSITIONS). precise: bool = False stand_in: bool = False + # The HIP number of a listing of a HIP-numbered catalog: its sequence. + hip_number: Optional[int] = None listings: List[str] = field(default_factory=list) names: List[str] = field(default_factory=list) # The DM number its source gives outside its names (WDS's), and for a SAC @@ -365,6 +372,8 @@ def read_star_objects( dm=dm_numbers.get(listing), system_first=systems.get(listing), ) + if row["catalog_code"] in HIP_NUMBERED_CATALOGS and star.hip_number is None: + star.hip_number = row["sequence"] star.listings.append(f"{row['catalog_code']} {row['sequence']}") for row in cursor.execute( "SELECT object_id, common_name FROM names WHERE object_id IN" @@ -385,8 +394,8 @@ class Match: separation_arcmin: Optional[float] = None # Why there is no match: "no V", "V gate", "ambiguous", or a veto. reason: Optional[str] = None - # The rule that made it: "position", "catalog number", "WDS designation" - # or "SAC system". + # The rule that made it: "position", "catalog number", "WDS designation", + # "SAC system", or "HIP number" for a HIP-numbered catalog's listing. rule: Optional[str] = None # A SAC continuation row joins its system's first row's sky object, # with that row's HIP, or none. @@ -753,6 +762,12 @@ def apply_hip_identifications( if code not in STAR_CATALOGS or object_id not in stars: problems.append(f"{label}: {designator} is no star catalog's listing") continue + if stars[object_id].hip_number is not None: + problems.append( + f"{label}: {designator} is numbered by its HIP; it takes no" + " hip correction" + ) + continue if hipparcos.index_of(hip) is None: problems.append(f"{label}: Hipparcos has no HIP {hip}") continue @@ -774,6 +789,33 @@ def apply_hip_identifications( raise CorrectionError(problems) +def hip_numbered_matches( + stars: Mapping[int, StarObject], hipparcos: Hipparcos +) -> Dict[int, Match]: + """The matches of the HIP-numbered catalogs' listings: each its number. + + Fails on a number Hipparcos lacks, and on a sky object that holds a + HIP-numbered listing and is not that listing's alone (a loader joined + another listing to it): its number would identify the other too. + """ + matches: Dict[int, Match] = {} + for object_id, star in sorted(stars.items()): + hip = star.hip_number + if hip is None: + continue + if hipparcos.index_of(hip) is None: + raise ValueError(f"{star.listings[0]}: Hipparcos has no HIP {hip}") + if len(star.listings) > 1: + raise ValueError( + f"HIP {hip}'s listing shares its sky object with other" + f" listings: {', '.join(star.listings)}" + ) + matches[object_id] = Match( + object_id, hip=hip, separation_arcmin=0.0, rule="HIP number" + ) + return matches + + def d_star_type(members: Sequence[StarObject]) -> str: """The D* rule for a star: D* if any listing's catalog types it D*. @@ -817,9 +859,14 @@ def identify_stars( conn = db.conn cursor = conn.cursor() stars = read_star_objects(cursor) - matches = cross_match(stars, hipparcos) - apply_vetoes(stars, matches, hipparcos) - apply_identifier_rules(stars, matches, hipparcos) + # A HIP-numbered listing is its star: it takes no part in the rules, so + # it changes no other listing's match, and it joins the stars they match + # to its number in the merge below. + listed = {oid: star for oid, star in stars.items() if star.hip_number is None} + matches = cross_match(listed, hipparcos) + apply_vetoes(listed, matches, hipparcos) + apply_identifier_rules(listed, matches, hipparcos) + matches.update(hip_numbered_matches(stars, hipparcos)) apply_hip_identifications(cursor, stars, matches, hip_identifications, hipparcos) # A joined continuation row follows its system's first row, which a hip # correction may have identified since. diff --git a/python/PiFinder/ui/menu_structure.py b/python/PiFinder/ui/menu_structure.py index a24202bee..f2db368ab 100644 --- a/python/PiFinder/ui/menu_structure.py +++ b/python/PiFinder/ui/menu_structure.py @@ -216,6 +216,12 @@ def _(key: str) -> Any: "objects": "catalog", "value": "Str", }, + { + "name": _("Named Stars"), + "class": UIObjectList, + "objects": "catalog", + "value": "Nam", + }, { "name": _("SAC Doubles"), "class": UIObjectList, @@ -389,6 +395,10 @@ def _(key: str) -> Any: "name": _("Bright Named"), "value": "Str", }, + { + "name": _("Named Stars"), + "value": "Nam", + }, { "name": _("SAC Doubles"), "value": "SaM", diff --git a/python/PiFinder/ui/object_list.py b/python/PiFinder/ui/object_list.py index b87ac0f2b..a773c2b66 100644 --- a/python/PiFinder/ui/object_list.py +++ b/python/PiFinder/ui/object_list.py @@ -915,8 +915,13 @@ def key_right(self): self.show_object_details(self._current_item_index) def key_number(self, number): + if not self.jump_input_display: + # As many digits as the list's largest number: a Named Stars HIP + # number or a WDS sequence has six. + largest = max((obj.sequence for obj in self._menu_items_sorted), default=0) + self.jump_to_number.width = max(4, len(str(largest))) self.jump_to_number.append_number(number) - if str(self.jump_to_number) == "----": + if not self.jump_to_number.has_number(): self.jump_input_display = False return diff --git a/python/tests/test_catalog_named_stars.py b/python/tests/test_catalog_named_stars.py new file mode 100644 index 000000000..a774c5655 --- /dev/null +++ b/python/tests/test_catalog_named_stars.py @@ -0,0 +1,359 @@ +"""Tests for the Named Stars catalog: every IAU-named Hipparcos star (#670). + +The loader reads the WGSN's table and Hipparcos, and the star-identity stage +joins each listing to its star by its HIP number, never by position +(docs/ax/catalog.md §9.3). The sky objects are built in a small objects DB +here, never the committed one. +""" + +import math +import re + +import numpy as np +import pytest + +import PiFinder.catalog_imports.catalog_import_utils as ciu +import PiFinder.catalog_imports.named_stars_loader as named_stars_loader +from PiFinder.catalog_imports.corrections import CorrectionError +from PiFinder.catalog_imports.named_stars_loader import ( + CATALOG_CODE, + DESCRIPTION_PATH, + load_named_stars, + named_star_listings, +) +from PiFinder.catalog_imports.star_identity import ( + Hipparcos, + identify_stars, + load_hipparcos, +) +from PiFinder.catalog_imports.supplementary_sources import ( + WGSN_PATH, + add_wgsn_names, + read_wgsn, +) +from PiFinder.catalogs import Catalogs +from PiFinder.composite_object import MagnitudeObject, SizeObject +from PiFinder.db.objects_db import ObjectsDatabase + +pytestmark = pytest.mark.unit + +ARCMIN = 1 / 60 + +VEGA, MIZAR, IZAR, LONE, NO_V = 91262, 65378, 72105, 1, 2 +HIPPARCOS = Hipparcos( + hip=np.array([LONE, NO_V, MIZAR, IZAR, VEGA]), + ra=np.array([10.0, 20.0, 200.98, 221.2467, 279.2347]), + dec=np.array([-10.0, -20.0, 54.925, 27.0742, 38.7837]), + vmag=np.array([5.0, np.nan, 2.27, 2.35, 0.03]), + var_flag=np.zeros(5, dtype=int), + # Mizar's and Izar's V are their pairs' combined light. + own_vmag=np.array([True, True, False, False, True]), +) + + +def write_wgsn(tmp_path, *rows): + """A WGSN table of (name, HIP or None) rows, as extract.py writes it.""" + path = tmp_path / "iau_csn.tsv" + lines = ["name\twgsn_id\tdesignation\thip\tbayer_id\tconstellation\tadopted"] + for name, hip in rows: + lines.append(f"{name}\t1\tHR 1\t{hip or ''}\t\tLyr\t2016/06/30") + path.write_text("\n".join(lines) + "\n", encoding="utf-8") + return path + + +@pytest.fixture +def db(tmp_path, monkeypatch): + """An empty objects DB, set as the import's objects_db.""" + ciu.STAND_IN_POSITIONS.clear() + ciu.SAC_SYSTEMS.clear() + ciu.SOURCE_DM_NUMBERS.clear() + ciu.STAR_HIPS.clear() + db = ObjectsDatabase(tmp_path / "objects.db") + db.create_tables() + monkeypatch.setattr(ciu, "objects_db", db) + monkeypatch.setattr(named_stars_loader, "objects_db", db) + for code in ("SaM", "Str", "WDS"): + db.insert_catalog(code, 100000, code) + yield db + db.conn.close() + ciu.STAR_HIPS.clear() + + +def add(db, code, sequence, obj_type, ra, dec, mag=(), names=()): + """A sky object of one listing, named as the loaders name it.""" + object_id = db.insert_object( + obj_type, + ra, + dec, + "UMa", + SizeObject([]).to_json(), + MagnitudeObject(list(mag)).to_json(), + ) + db.insert_catalog_object(object_id, code, sequence, "") + db.insert_name(object_id, f"{code} {sequence}", code) + for name in names: + db.insert_name(object_id, name, code) + return object_id + + +def object_of(db, code, sequence): + row = db.conn.execute( + "SELECT object_id FROM catalog_objects WHERE catalog_code = ? AND sequence = ?", + (code, sequence), + ).fetchone() + return row["object_id"] + + +def names_of(db, object_id): + return [ + row["common_name"] + for row in db.conn.execute( + "SELECT common_name FROM names WHERE object_id = ? ORDER BY id", + (object_id,), + ) + ] + + +def sky_object(db, object_id): + return db.conn.execute( + "SELECT * FROM objects WHERE id = ?", (object_id,) + ).fetchone() + + +# --- The loader ------------------------------------------------------------------ + + +def test_one_listing_per_hip_number_numbered_by_it(tmp_path): + path = write_wgsn( + tmp_path, + ("Vega", VEGA), + ("Izar", IZAR), + ("Pulcherrima", IZAR), + ("WASP-1", None), + ("Mizar", MIZAR), + ) + listings = named_star_listings(HIPPARCOS, path) + assert [listing.sequence for listing in listings] == [MIZAR, IZAR, VEGA] + assert {listing.catalog_code for listing in listings} == {CATALOG_CODE} + assert {listing.object_type for listing in listings} == {"*"} + # The listing carries no names: the WGSN source gives them. + assert all(listing.aka_names == [] for listing in listings) + + +def test_a_listing_lies_at_its_hipparcos_position_at_j2000(tmp_path): + (vega,) = named_star_listings(HIPPARCOS, write_wgsn(tmp_path, ("Vega", VEGA))) + assert (vega.ra, vega.dec) == (279.2347, 38.7837) + + +def test_the_real_listings_lie_at_hipparcos_j2000(): + hipparcos = load_hipparcos() + listings = {listing.sequence: listing for listing in named_star_listings(hipparcos)} + # Arcturus in hip_main.dat: 213.91811403 +19.18726997 at J1991.25, moving + # -1093.45 and -1999.40 mas/yr; 8.75 years carry it about 20". + years, mas = 8.75, 3.6e6 + dec = 19.18726997 - 1999.40 * years / mas + ra = 213.91811403 - 1093.45 * years / mas / math.cos(math.radians(19.18726997)) + assert (listings[69673].ra, listings[69673].dec) == pytest.approx((ra, dec)) + index = hipparcos.index_of(VEGA) + assert (listings[VEGA].ra, listings[VEGA].dec) == ( + hipparcos.ra[index], + hipparcos.dec[index], + ) + + +def test_v_is_the_stars_own_or_its_systems_combined_light(tmp_path): + path = write_wgsn(tmp_path, ("Vega", VEGA), ("Mizar", MIZAR), ("None", NO_V)) + mags = { + listing.sequence: listing.mag.mags + for listing in named_star_listings(HIPPARCOS, path) + } + # Mizar's 2.27 is the pair's light: what a finder shows of a star listed + # alone. A star Hipparcos gives no V for has none. + assert mags == {VEGA: [0.03], MIZAR: [2.27], NO_V: []} + + +def test_a_hip_number_hipparcos_lacks_fails(tmp_path): + with pytest.raises(ValueError, match="HIP 999999"): + named_star_listings(HIPPARCOS, write_wgsn(tmp_path, ("Nobody", 999999))) + + +def test_the_catalog_description_counts_the_wgsn_table(): + names = read_wgsn() + hips = {name.hip for name in names if name.hip is not None} + text = DESCRIPTION_PATH.read_text() + with_hip = sum(name.hip is not None for name in names) + without = len(names) - with_hip + assert re.search(rf"\b{len(hips)} stars carry {with_hip} names\b", text) + assert re.search(rf"\b{without} names of objects without", text) + + +# --- Identity: a listing is its HIP number --------------------------------------- + + +def load(db, tmp_path, *rows): + db.insert_catalog(CATALOG_CODE, 0, "") + load_named_stars(HIPPARCOS, write_wgsn(tmp_path, *rows)) + + +def test_a_listing_joins_the_star_other_catalogs_list(db, tmp_path): + # Mizar's listings in Str, SAC and WDS are one star, and the Named Stars + # listing joins it: the first loader's sky object survives. + str_mizar = add(db, "Str", 56, "*", 200.975, 54.925, mag=[2.2], names=["Mizar"]) + sam = add(db, "SaM", 2054, "D*", 200.975, 54.9333, mag=[2.3, 4.0]) + wds = add(db, "WDS", 70779, "D*", 200.98, 54.925, mag=[2.2, 3.9]) + load(db, tmp_path, ("Mizar", MIZAR)) + named = object_of(db, CATALOG_CODE, MIZAR) + result = identify_stars(db, {}, hipparcos=HIPPARCOS) + assert result.matches[named].rule == "HIP number" + assert result.merged_into == {sam: str_mizar, wds: str_mizar, named: str_mizar} + assert result.hips == {str_mizar: MIZAR} + assert object_of(db, CATALOG_CODE, MIZAR) == str_mizar + # Typed by the D* rule; the survivor's V stands. + assert sky_object(db, str_mizar)["obj_type"] == "D*" + assert MagnitudeObject.from_json(sky_object(db, str_mizar)["mag"]).mags == [2.2] + + +def test_a_star_no_catalog_lists_is_a_sky_object_of_its_own(db, tmp_path): + load(db, tmp_path, ("Lone", LONE)) + named = object_of(db, CATALOG_CODE, LONE) + result = identify_stars(db, {}, hipparcos=HIPPARCOS) + assert result.merged_into == {} + assert result.hips == {named: LONE} + + +def test_a_listing_never_joins_by_position(db, tmp_path): + # A Str listing on the star whose V fails the gate is not identified, so + # the Named Stars listing does not join it: a miss is a `hip` correction. + off = add(db, "Str", 1, "*", 10.0, -10.0, mag=[8.0]) + load(db, tmp_path, ("Lone", LONE)) + named = object_of(db, CATALOG_CODE, LONE) + result = identify_stars(db, {}, hipparcos=HIPPARCOS) + assert result.matches[off].hip is None + assert result.merged_into == {} + assert result.hips == {named: LONE} + + +def test_a_hip_correction_joins_a_missed_listing_to_it(db, tmp_path): + off = add(db, "Str", 1, "*", 10.0, -10.0, mag=[8.0]) + load(db, tmp_path, ("Lone", LONE)) + named = object_of(db, CATALOG_CODE, LONE) + result = identify_stars(db, {"Str 1": LONE}, hipparcos=HIPPARCOS) + assert result.merged_into == {named: off} + + +def test_a_listing_takes_no_hip_correction(db, tmp_path): + load(db, tmp_path, ("Lone", LONE)) + with pytest.raises(CorrectionError, match="numbered by its HIP"): + identify_stars(db, {f"{CATALOG_CODE} {LONE}": VEGA}, hipparcos=HIPPARCOS) + + +def test_the_listings_change_no_other_match(db, tmp_path): + def stars(database): + add(database, "Str", 56, "*", 200.975, 54.925, mag=[2.2]) + add(database, "SaM", 1, "D*", 200.975, 54.925 + 2 * ARCMIN, mag=[2.3]) + add(database, "Str", 1, "*", 10.0, -10.0, mag=[8.0]) + + def other_matches(database): + result = identify_stars(database, {}, hipparcos=HIPPARCOS) + return { + oid: (match.hip, match.rule, match.reason) + for oid, match in result.matches.items() + if not result.stars[oid].listings[0].startswith(CATALOG_CODE) + } + + without = ObjectsDatabase(tmp_path / "without.db") + without.create_tables() + for code in ("SaM", "Str", "WDS"): + without.insert_catalog(code, 100000, code) + stars(without) + stars(db) + load(db, tmp_path, ("Mizar", MIZAR), ("Lone", LONE)) + assert other_matches(db) == other_matches(without) + without.conn.close() + + +def test_a_listing_that_shares_its_sky_object_fails(db, tmp_path): + load(db, tmp_path, ("Lone", LONE)) + db.insert_catalog_object(object_of(db, CATALOG_CODE, LONE), "Str", 9, "") + with pytest.raises(ValueError, match="shares its sky object"): + identify_stars(db, {}, hipparcos=HIPPARCOS) + + +# --- Names ----------------------------------------------------------------------- + + +def test_a_star_gets_its_iau_name_once(db, tmp_path): + vega = add(db, "Str", 77, "*", 279.2347, 38.7837, mag=[0.0], names=["Vega"]) + path = write_wgsn(tmp_path, ("Vega", VEGA), ("Lone", LONE)) + db.insert_catalog(CATALOG_CODE, 0, "") + load_named_stars(HIPPARCOS, path) + lone = object_of(db, CATALOG_CODE, LONE) + identify_stars(db, {}, hipparcos=HIPPARCOS) + add_wgsn_names(db, path=path) + assert names_of(db, vega) == ["Vega", "Str 77", f"{CATALOG_CODE} {VEGA}"] + assert names_of(db, lone) == ["Lone", f"{CATALOG_CODE} {LONE}"] + + +def test_izar_keeps_its_names_and_gets_neither_iau_name(db, tmp_path): + # HIP 72105 carries two IAU names, with no component to choose between + # them: its listing is the pair's, and the older Izar stays. + izar = add(db, "Str", 45, "*", 221.2467, 27.0742, mag=[2.4], names=["Izar"]) + path = write_wgsn(tmp_path, ("Izar", IZAR), ("Pulcherrima", IZAR)) + db.insert_catalog(CATALOG_CODE, 0, "") + load_named_stars(HIPPARCOS, path) + identify_stars(db, {}, hipparcos=HIPPARCOS) + result = add_wgsn_names(db, path=path) + assert names_of(db, izar) == ["Str 45", "Izar", f"{CATALOG_CODE} {IZAR}"] + assert result.shared_hip == ["Izar", "Pulcherrima"] + + +# --- The real catalog ------------------------------------------------------------ + + +class _Catalog: + def __init__(self, objects): + self.catalog_code = CATALOG_CODE + self._objects = objects + + def is_selected(self): + return True + + def get_objects(self): + return self._objects + + +class _Object: + def __init__(self, sequence, names): + self.catalog_code = CATALOG_CODE + self.sequence = sequence + self.names = names + + +def test_search_finds_the_stars_no_other_catalog_lists(db): + # The real table and Hipparcos, with no other catalog loaded: Miaplacidus, + # Naos and Pherkad were in none. + db.insert_catalog(CATALOG_CODE, 0, "") + hipparcos = load_hipparcos() + load_named_stars(hipparcos) + identify_stars(db, {}, hipparcos=hipparcos) + add_wgsn_names(db, path=WGSN_PATH) + objects = [ + _Object(row["sequence"], names_of(db, row["object_id"])) + for row in db.conn.execute( + "SELECT sequence, object_id FROM catalog_objects WHERE catalog_code = ?", + (CATALOG_CODE,), + ) + ] + catalogs = Catalogs([_Catalog(objects)]) + by_hip = {obj.sequence: obj for obj in objects} + for name, hip in (("Miaplacidus", 45238), ("Naos", 39429), ("Pherkad", 75097)): + assert hip in [obj.sequence for obj in catalogs.search_by_text(name)] + assert by_hip[hip].names[0] == name + # "Pherkad" also finds Pherkad Minor. + assert {obj.sequence for obj in catalogs.search_by_text("Pherkad")} == { + 75097, + 74793, + } + # The keypad's text search finds an accented name by its ASCII form. + assert [obj.sequence for obj in catalogs.search_by_text("Monch")] == [72339] + assert len(objects) == len({n.hip for n in read_wgsn() if n.hip is not None}) diff --git a/python/tests/test_object_list_jump.py b/python/tests/test_object_list_jump.py new file mode 100644 index 000000000..1a27434e1 --- /dev/null +++ b/python/tests/test_object_list_jump.py @@ -0,0 +1,59 @@ +"""Tests for the object list's jump to a number typed on the keypad. + +The number takes as many digits as the list's largest: a Named Stars HIP +number (Nam 118322) or a WDS sequence has six, Messier's four at least. +""" + +import types + +import pytest + +from PiFinder.composite_object import CompositeObject +from PiFinder.ui.object_list import CatalogSequence, UIObjectList + + +def _list(*sequences): + """Just enough of a UIObjectList for key_number.""" + jumped = [] + return types.SimpleNamespace( + jump_input_display=False, + jump_to_number=CatalogSequence(), + _menu_items_sorted=[ + CompositeObject(object_id=s, catalog_code="Nam", sequence=s) + for s in sequences + ], + scroll_to_sequence=jumped.append, + update=lambda: None, + jumped=jumped, + ) + + +def _type(object_list, digits): + for digit in digits: + UIObjectList.key_number(object_list, int(digit)) + + +@pytest.mark.unit +def test_a_six_digit_number_is_typed_whole(): + object_list = _list(677, 91262, 118322) + _type(object_list, "118322") + assert object_list.jumped[-1] == 118322 + assert str(object_list.jump_to_number) == "118322" + + +@pytest.mark.unit +def test_a_short_catalog_keeps_four_digits(): + object_list = _list(1, 31, 110) + _type(object_list, "31") + assert str(object_list.jump_to_number) == "--31" + _type(object_list, "042") + # The oldest digit drops off past four. + assert object_list.jump_to_number.object_number == 1042 + + +@pytest.mark.unit +def test_a_leading_zero_opens_no_input(): + object_list = _list(91262) + _type(object_list, "0") + assert not object_list.jump_input_display + assert object_list.jumped == [] From 72b5e9ee63edd9875b23a5d9ec47be23c3cfe8ac Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 9 Nov 2026 21:19:55 -0700 Subject: [PATCH 2/2] feat(obslist): read "Nam 91262" as a Named Stars designation An observing list saves a Named Stars listing as "Nam 91262", and reads it back to the same listing. No source names a star "Nam ", so no import join changes. Refs #670 Co-Authored-By: Claude Opus 5.5 (1M context) --- python/PiFinder/designations.py | 1 + python/tests/test_obslist_designations.py | 1 + 2 files changed, 2 insertions(+) diff --git a/python/PiFinder/designations.py b/python/PiFinder/designations.py index b5e422ecb..13eae30fa 100644 --- a/python/PiFinder/designations.py +++ b/python/PiFinder/designations.py @@ -42,6 +42,7 @@ "lyn": "Lyn", "m": "M", "messier": "M", + "nam": "Nam", "ngc": "NGC", "rds": "RDS", "saa": "SaA", diff --git a/python/tests/test_obslist_designations.py b/python/tests/test_obslist_designations.py index bb02a9da2..c662fad2d 100644 --- a/python/tests/test_obslist_designations.py +++ b/python/tests/test_obslist_designations.py @@ -237,6 +237,7 @@ def test_designations_is_runtime_safe(): ("Sh2", 155, "Sh2 155"), ("H", 24, "Herschel 24"), ("B", 33, "Barnard 33"), + ("Nam", 91262, "Nam 91262"), ("WDS", 50812, None), ], )