From 3cb593520e48f40f591ac0d536c0ac3c29506939 Mon Sep 17 00:00:00 2001 From: Richard Date: Fri, 23 Oct 2026 20:19:36 -0700 Subject: [PATCH] =?UTF-8?q?fix(catalog-import):=20Lyng=C3=A5's=20"Collinde?= =?UTF-8?q?r=20nnn"=20joins=20Collinder,=20Harris's=20"Arp=202"=20is=20a?= =?UTF-8?q?=20common=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lyngå spells Collinder out, and its loader knew only "Col", so its 67 "Collinder nnn" names were common names that never reached the lookup. They are designations now: 64 of those listings join their Collinder sky object, and the match guard refuses three (Lyn 639 to Col 285, Lyn 829 to Col 394, Lyn 855 to Col 401), whose Collinder positions disagree with Lyngå's. Harris filed "Arp 2" as an Arp designation, so the names rule dropped it from Har 133: it resolves to Arp's galaxy 2. Harris's Arp 2 is the globular Arp found in the Sagittarius dwarf, so it is a common name now, and no join candidate. Both loaders write a designation the lookup reads as PiFinder writes its designators, " ": "Collinder 65" is "Col 65", Lyngå's "NGC6222" and Harris's "NGC104" and "M79" are "NGC 6222", "NGC 104" and "M 79". On a joined sky object they repeat that listing's own name, which the device drops when it loads names. Refs #670 Co-Authored-By: Claude Opus 5.5 --- .../PiFinder/catalog_imports/harris_loader.py | 30 +++-- .../PiFinder/catalog_imports/lynga_loader.py | 18 ++- python/tests/test_catalog_matching.py | 112 +++++++++++++++++- 3 files changed, 143 insertions(+), 17 deletions(-) diff --git a/python/PiFinder/catalog_imports/harris_loader.py b/python/PiFinder/catalog_imports/harris_loader.py index 42f1ed4b9..158e91def 100644 --- a/python/PiFinder/catalog_imports/harris_loader.py +++ b/python/PiFinder/catalog_imports/harris_loader.py @@ -20,6 +20,7 @@ delete_catalog_from_database, insert_catalog, insert_catalog_max_sequence, + listing_named, NewCatalogObject, trim_string, ) @@ -168,21 +169,26 @@ def is_valid_mag(mag: Any) -> bool: def normalize_catalog_name(name: str) -> str: """ - Normalize catalog designations by removing spaces between prefix and number. + Write a catalog designation as PiFinder writes its designators. - Harris catalog has names like "NGC 104", "M 79", "Arp 2" with spaces, - but the database has them as "NGC104", "M79", "Arp2" without spaces. + A designation the loaders' lookup reads (listing_named) becomes + " ", so Harris's "NGC 104" and "M 79" stay as + they are: on the sky object the listing joins, they repeat that + listing's own name. Any other has its spaces removed. Args: name: Catalog designation with potential spaces Returns: - Normalized name with spaces removed + Normalized name """ name = name.strip() - # Remove spaces between catalog prefix and number - return name.replace(" ", "") + listing = listing_named(name) + if listing is None: + return name.replace(" ", "") + catalog_code, sequence = listing + return f"{catalog_code} {sequence}" def identify_catalog_type(name: str) -> Tuple[bool, str]: @@ -190,7 +196,11 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]: Identify if a name is an official catalog designation or a common name. Official catalogs in the system: NGC, IC, M, C, Col, Ta2, H, SaA, SaM, - SaR, Str, EGC, RDS, B, Sh2, Abl, Arp, TLK, WDS + SaR, Str, EGC, RDS, B, Sh2, Abl, TLK, WDS + + Not Arp: Harris's "Arp 2" (Har 133) is the globular Arp found in the + Sagittarius dwarf, not galaxy 2 of Arp's Atlas of Peculiar Galaxies, + PiFinder's Arp catalog. It is a common name, like "Pal 1". Args: name: Name to check @@ -216,7 +226,6 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]: "B", "Sh2", "Abl", - "Arp", "TLK", "WDS", } @@ -226,7 +235,6 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]: # Check if the name starts with any official catalog prefix for catalog in official_catalogs: if name.startswith(catalog + " ") or name == catalog: - # Normalize NGC and IC by removing spaces normalized = normalize_catalog_name(name) return True, normalized @@ -334,8 +342,8 @@ def create_cluster_object(entry: npt.NDArray, seq: int) -> Dict[str, Any]: logging.debug(f" Description: {len(description_parts)} features") # Separate catalog names from common names - # Official catalogs: NGC, IC, M, C, Col, Ta2, H, SaA, SaM, SaR, Str, EGC, RDS, B, Sh2, Abl, Arp, TLK, WDS - # Everything else (Pal, AM, Terzan, etc.) becomes a common name + # Official catalogs: NGC, IC, M, C, Col, Ta2, H, SaA, SaM, SaR, Str, EGC, RDS, B, Sh2, Abl, TLK, WDS + # Everything else (Pal, AM, Terzan, Arp 2, etc.) becomes a common name result["catalog_names"] = [] # For aka_names (catalog designations) result["common_names"] = [] # For insert_name (common names) result["primary_name"] = f"Har {seq}" diff --git a/python/PiFinder/catalog_imports/lynga_loader.py b/python/PiFinder/catalog_imports/lynga_loader.py index 7542d0df3..ca196497e 100644 --- a/python/PiFinder/catalog_imports/lynga_loader.py +++ b/python/PiFinder/catalog_imports/lynga_loader.py @@ -23,6 +23,7 @@ delete_catalog_from_database, insert_catalog, insert_catalog_max_sequence, + listing_named, NewCatalogObject, trim_string, ) @@ -309,7 +310,14 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]: Identify if a name is an official catalog designation or a common name. Official catalogs in the system: NGC, IC, M, C, Col, Ta2, H, SaA, SaM, - SaR, Str, EGC, RDS, B, Sh2, Abl, Arp, TLK, WDS + SaR, Str, EGC, RDS, B, Sh2, Abl, Arp, TLK, WDS. Lyngå spells Collinder + out ("Collinder 65"), so that long form is a designation too, and the + listing joins its Collinder sky object. + + A designation the loaders' lookup reads (listing_named) is written as + PiFinder writes its designators, so "Collinder 65" is "Col 65" and + "NGC 6222" stays "NGC 6222": on the sky object the listing joins, it + repeats that listing's own name. Any other has its spaces removed. Args: name: Name to check @@ -323,6 +331,7 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]: "M", "C", "Col", + "Collinder", "Ta2", "H", "SaA", @@ -343,8 +352,11 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]: for catalog in official_catalogs: if name.startswith(catalog + " ") or name == catalog: - normalized = name.replace(" ", "") - return True, normalized + listing = listing_named(name) + if listing is None: + return True, name.replace(" ", "") + catalog_code, sequence = listing + return True, f"{catalog_code} {sequence}" return False, name diff --git a/python/tests/test_catalog_matching.py b/python/tests/test_catalog_matching.py index d26d806db..1d01a564e 100644 --- a/python/tests/test_catalog_matching.py +++ b/python/tests/test_catalog_matching.py @@ -1,9 +1,10 @@ """Tests for how a catalog listing joins a sky object (docs/ax/catalog.md §9). The match guard (§9.3), precedence when a listing joins (§9.1), which akas -are stored as names, the Arp loader's lettered components, and the Caldwell, -Barnard and Arp loaders. Everything runs against a small objects DB built -here, never the committed one. +are stored as names, the Arp loader's lettered components, the Caldwell, +Barnard and Arp loaders, and what the Lyngå and Harris loaders identify as a +designation. Everything runs against a small objects DB built here, never the +committed one. """ import importlib @@ -678,3 +679,108 @@ def test_load_caldwell_keeps_the_sign_of_minus_0(db, astro_data, monkeypatch): caldwell_loader.load_caldwell() assert sky_object(db, "C", 200)["dec"] == pytest.approx(-0.5) + + +# --- Identification: Lyngå's "Collinder nnn", Harris's "Arp 2" --------------- + + +def add_sky_object(db, code, sequence, obj_type, ra, dec, size=(), mag=()): + object_id = db.insert_object( + obj_type, + ra, + dec, + "And", + SizeObject.from_arcmin(*size).to_json(), + MagnitudeObject(list(mag)).to_json(), + ) + db.insert_catalog_object(object_id, code, sequence, "") + db.insert_name(object_id, f"{code} {sequence}", code) + + +@pytest.mark.parametrize( + "name, expected", + [ + ("Collinder 65", (True, "Col 65")), + ("NGC 6222", (True, "NGC 6222")), + ("IC 1848", (True, "IC 1848")), + # Lyngå's own clusters, Harvard's and Melotte's are no PiFinder + # catalog's: "Lynga 7" is not Lyn 7, nor "Harvard 5" Har 5. + ("Lynga 7", (False, "Lynga 7")), + ("Harvard 5", (False, "Harvard 5")), + ("Melotte 20", (False, "Melotte 20")), + ], +) +def test_lynga_identifies_pifinder_catalog_designations(name, expected): + from PiFinder.catalog_imports.lynga_loader import identify_catalog_type + + assert identify_catalog_type(name) == expected + + +@pytest.mark.parametrize( + "name, expected", + [ + ("NGC 104", (True, "NGC 104")), + ("M 79", (True, "M 79")), + ("IC 4499", (True, "IC 4499")), + # The globular Arp found in the Sagittarius dwarf, not Arp's galaxy 2. + ("Arp 2", (False, "Arp 2")), + ("Pal 1", (False, "Pal 1")), + ("Lynga 7", (False, "Lynga 7")), + ], +) +def test_harris_identifies_pifinder_catalog_designations(name, expected): + from PiFinder.catalog_imports.harris_loader import identify_catalog_type + + assert identify_catalog_type(name) == expected + + +def test_load_lynga_joins_collinder_nnn_to_its_collinder_object( + db, astro_data, monkeypatch +): + import PiFinder.catalog_imports.lynga_loader as lynga_loader + + # Col 65 and Col 401 as the Collinder loader builds them. Col 401 is at + # collinder.txt's -00 20; Lyngå (and SIMBAD) have +00 20. + add_sky_object(db, "Col", 65, "OC", 81.2708, 15.6997, [220.0], [3.0]) + add_sky_object(db, "Col", 401, "OC", 294.6, -20 / 60, [1.0], [7.0]) + lynga = astro_data / "lynga" + lynga.mkdir() + (lynga / "ReadMe").write_text("Lynga") + # Lyn 163 and Lyn 855, astro_data/lynga/catalog lines 163 and 855. + (lynga / "catalog").write_text( + " 6 65 525.9+16 5 523.0+16 3 .58 .5188.48-10.71 174 474 219. 315\n" + " 6 401 1938.4+0020 1935.8+0013 .51 1.4 38.64-10.27 898 98 1.0 315\n" + ) + monkeypatch.setattr(lynga_loader, "objects_db", db) + lynga_loader.load_lynga() + + # 25.9' apart, inside Col 65's 220'. The aka repeats Col 65's own name, + # which the device drops when it loads names. + assert object_of(db, "Lyn", 1) == object_of(db, "Col", 65) + assert names(db, "Col", 65) == ["Col 65", "Lyn 1", "Col 65"] + # 40' apart: the guard refuses it, and "Col 401" names another sky object. + assert [rejection.listing for rejection in ciu.MATCH_REJECTIONS] == ["Lyn 2"] + assert names(db, "Lyn", 2) == ["Lyn 2"] + + +def test_load_harris_keeps_arp_2_as_a_common_name(db, astro_data, monkeypatch): + import PiFinder.catalog_imports.harris_loader as harris_loader + + # Arp's galaxy 2, which a lookup of "Arp 2" would find. + add_sky_object(db, "Arp", 2, "Gx", 244.075, 47.0333) + harris = astro_data / "harris" + harris.mkdir() + (harris / "ReadMe").write_text("Harris") + # Har 133 and Har 85, the position columns of astro_data/harris/catalog. + (harris / "catalog").write_text( + " Arp 2 19 28 44.1 -30 21 14 8.55 -20.78\n" + " NGC 6401 17 38 36.9 -23 54 32 3.45 3.98\n" + ) + monkeypatch.setattr(harris_loader, "objects_db", db) + harris_loader.load_harris() + + assert object_of(db, "Har", 1) != object_of(db, "Arp", 2) + assert names(db, "Har", 1) == ["Har 1", "Arp 2"] + assert ciu.MATCH_REJECTIONS == [] + # A designation is written as PiFinder writes its designators. + assert names(db, "NGC", 6401) == ["NGC 6401", "Har 2", "NGC 6401"]