Skip to content
Draft
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
Binary file modified astro_data/pifinder_objects.db
Binary file not shown.
29 changes: 15 additions & 14 deletions python/PiFinder/catalog_imports/harris_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,29 @@ def read_harris_catalog(file_path: Path) -> npt.NDArray:
(206, 210), # Half-mass radius (Rh) (F4.2 arcmin)
]

# Define dtype for structured array
# Define dtype for structured array. The floats are float64, so a value
# such as 6.47 stays 6.47 and not 6.46999979019165.
dtype = [
("ID", "U10"), # Cluster ID
("Name", "U12"), # Common name
("RAh", "i4"), # RA hours
("RAm", "i4"), # RA minutes
("RAs", "f4"), # RA seconds
("RAs", "f8"), # RA seconds
("DE_sign", "U1"), # Dec sign
("DEd", "i4"), # Dec degrees
("DEm", "i4"), # Dec minutes
("DEs", "i4"), # Dec seconds
("GLON", "f4"), # Galactic longitude
("GLAT", "f4"), # Galactic latitude
("Rsun", "f4"), # Distance from Sun
("Rgc", "f4"), # Distance from Galactic center
("X", "f4"), # X component
("Y", "f4"), # Y component
("Z", "f4"), # Z component
("Vt", "f4"), # Integrated V magnitude
("MVt", "f4"), # Absolute magnitude
("Rc", "f4"), # Core radius (arcmin)
("Rh", "f4"), # Half-mass radius (arcmin)
("GLON", "f8"), # Galactic longitude
("GLAT", "f8"), # Galactic latitude
("Rsun", "f8"), # Distance from Sun
("Rgc", "f8"), # Distance from Galactic center
("X", "f8"), # X component
("Y", "f8"), # Y component
("Z", "f8"), # Z component
("Vt", "f8"), # Integrated V magnitude
("MVt", "f8"), # Absolute magnitude
("Rc", "f8"), # Core radius (arcmin)
("Rh", "f8"), # Half-mass radius (arcmin)
]

def parse_line(line: str) -> tuple:
Expand All @@ -117,7 +118,7 @@ def parse_field(value: str, field_dtype: str) -> Any:
return value
elif field_dtype == "i4":
return int(value) if value and value != "." else 0
elif field_dtype == "f4":
elif field_dtype == "f8":
try:
return float(value) if value and value != "." else np.nan
except ValueError:
Expand Down
30 changes: 15 additions & 15 deletions python/PiFinder/catalog_imports/lynga_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,33 @@ def read_lynga_catalog(file_path: Path) -> npt.NDArray:
("ClSeq", "i4"), # Cluster Sequence code
("ClNum", "i4"), # Number inside sequence
("RA2000h", "i4"), # RA 2000 hours
("RA2000m", "f4"), # RA 2000 minutes
("RA2000m", "f8"), # RA 2000 minutes
("DE2000s", "U1"), # Dec 2000 sign
("DE2000d", "i4"), # Dec 2000 degrees
("DE2000m", "i4"), # Dec 2000 minutes
("Diam", "f4"), # Angular diameter (arcmin)
("Diam", "f8"), # Angular diameter (arcmin)
("Dist", "i4"), # Distance (pc)
("logAge", "f4"), # log(age) years
("FeH", "f4"), # Metallicity [Fe/H]
("EBV", "f4"), # Reddening E(B-V)
("logAge", "f8"), # log(age) years
("FeH", "f8"), # Metallicity [Fe/H]
("EBV", "f8"), # Reddening E(B-V)
("ClTyp", "U2"), # Doubtful cluster flag
("TrConc", "i4"), # Trumpler concentration class
("TrRange", "i4"), # Trumpler range class
("TrRich", "U2"), # Trumpler richness class
("TrNeb", "U1"), # Trumpler nebulosity
("maxBr50", "f4"), # Brightest star magnitude (ref.50)
("totMag50", "f4"), # Total magnitude (ref.50)
("totMag422", "f4"), # Total magnitude (Skiff ref.422)
("iBV422", "f4"), # Integrated B-V (Skiff)
("maxBr50", "f8"), # Brightest star magnitude (ref.50)
("totMag50", "f8"), # Total magnitude (ref.50)
("totMag422", "f8"), # Total magnitude (Skiff ref.422)
("iBV422", "f8"), # Integrated B-V (Skiff)
("N422", "i4"), # Number of stars (Skiff)
("wRVel", "f4"), # Radial velocity weight
("wRVel", "f8"), # Radial velocity weight
("RVel", "i4"), # Radial velocity (km/s)
("Cname", "U9"), # "C" designation
("DistJDL", "i4"), # jdl distance (pc)
("turnJDL", "f4"), # jdl turn-off colour
("AgeJDL", "f4"), # jdl age (Myr)
("EBVJDL", "f4"), # jdl reddening
("FeHJDL", "f4"), # jdl abundance
("turnJDL", "f8"), # jdl turn-off colour
("AgeJDL", "f8"), # jdl age (Myr)
("EBVJDL", "f8"), # jdl reddening
("FeHJDL", "f8"), # jdl abundance
]

def parse_field(value: str, field_dtype: str) -> Any:
Expand All @@ -208,7 +208,7 @@ def parse_field(value: str, field_dtype: str) -> Any:
return value
elif field_dtype == "i4":
return int(value) if value and value not in (".", "-") else 0
elif field_dtype == "f4":
elif field_dtype == "f8":
try:
return float(value) if value and value not in (".", "-") else np.nan
except ValueError:
Expand Down
5 changes: 4 additions & 1 deletion python/PiFinder/catalog_imports/specialized_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,10 @@ def expand(name):
aka_names = [row["name"]] # Start with the first name
mag = row["magnitude"]
if utils.is_number(mag):
mag = MagnitudeObject([float(mag)])
# arp.sqlite stores the magnitudes as float32 values
# (13.800000190734863), so round to the two decimals of a
# catalog magnitude.
mag = MagnitudeObject([round(float(mag), 2)])
else:
logging.warning(
f"Invalid magnitude for Arp {row['catalog_identifier']}"
Expand Down
12 changes: 7 additions & 5 deletions python/tests/test_catalog_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def test_object_counts():
"Ta2": 200,
"H": 400,
"SaA": 114,
"SaM": 2162,
"SaM": 2157, # five pairs SAC marks rejected ("STT 56 rej.") are no double star
"SaR": 333,
"Str": 78,
"EGC": 91,
"EGC": 102, # with the Magellanic Cloud globulars
"RDS": 110,
"B": 343,
"Sh2": 313,
Expand All @@ -34,11 +34,12 @@ def test_object_counts():
"TLK": 93,
"Har": 147,
"Lyn": 1151,
"Nam": 578, # every IAU-named star with a Hipparcos number
}

# catalog count
num_catalogs = len(list(db.get_catalogs()))
assert num_catalogs == 21
assert num_catalogs == 22
actual_catalogs = [row["catalog_code"] for row in db.get_catalogs()]
expected_catalogs = list(catalog_counts.keys())
missing_catalogs = set(expected_catalogs) - set(actual_catalogs)
Expand Down Expand Up @@ -291,8 +292,9 @@ def check_ic_objects():
"name": "Heart Nebula",
"ra": 38.200, # RA = 02h 32m 48s
"dec": 61.450, # Dec = +61° 27' 00"
# "obj_type": "Nb", # Emission nebula
"obj_type": "OC", # Open cluster at the heart of the nebula
# The import merges IC 1805, Sh2 190 and Lyn 77 into one object:
# the cluster with its emission nebula.
"obj_type": "C+N",
"const": "Cas", # Cassiopeia
},
{
Expand Down
13 changes: 13 additions & 0 deletions python/tests/test_catalog_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import logging
import sqlite3

from pathlib import Path

import pytest

import PiFinder.catalog_imports.caldwell_loader as caldwell_loader
Expand Down Expand Up @@ -606,6 +608,17 @@ def test_harris_keeps_the_sign_of_a_declination_just_south_of_the_equator(tmp_pa
)


def test_harris_magnitudes_keep_their_two_decimals():
from PiFinder.catalog_imports.harris_loader import read_harris_catalog

catalog = Path(__file__).parents[2] / "astro_data" / "harris" / "catalog"
entries = {str(entry["ID"]): entry for entry in read_harris_catalog(catalog)}
m2 = entries["NGC 7089"]
# The catalog gives V = 6.47; a float32 gives 6.46999979019165.
assert m2["Vt"].item() == 6.47
assert repr(m2["Vt"].item()) == "6.47"


def test_lynga_keeps_the_sign_of_a_declination_just_south_of_the_equator(tmp_path):
from PiFinder.catalog_imports.lynga_loader import (
create_cluster_object,
Expand Down
Loading