Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions python/PiFinder/catalog_imports/harris_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
delete_catalog_from_database,
insert_catalog,
insert_catalog_max_sequence,
listing_named,
NewCatalogObject,
trim_string,
)
Expand Down Expand Up @@ -168,29 +169,38 @@ 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
"<catalog code> <sequence>", 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]:
"""
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
Expand All @@ -216,7 +226,6 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]:
"B",
"Sh2",
"Abl",
"Arp",
"TLK",
"WDS",
}
Expand All @@ -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

Expand Down Expand Up @@ -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}"
Expand Down
18 changes: 15 additions & 3 deletions python/PiFinder/catalog_imports/lynga_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
delete_catalog_from_database,
insert_catalog,
insert_catalog_max_sequence,
listing_named,
NewCatalogObject,
trim_string,
)
Expand Down Expand Up @@ -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
Expand All @@ -323,6 +331,7 @@ def identify_catalog_type(name: str) -> Tuple[bool, str]:
"M",
"C",
"Col",
"Collinder",
"Ta2",
"H",
"SaA",
Expand All @@ -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

Expand Down
112 changes: 109 additions & 3 deletions python/tests/test_catalog_matching.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"]
Loading