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
17 changes: 12 additions & 5 deletions src/layup/utilities/debiasing.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ def generate_bias_dict(cache_dir=None):

def debias(ra, dec, epoch_jd_tdb, catalog, bias_dict, nside=256):

# A blank, None, or unrecognized star-catalog code has no bias model (common
# in historical / uncatalogued astrometry, or when no astCat column is
# present). Leave the astrometry unchanged rather than raising KeyError, which
# would otherwise abort the whole object's fit (issue #401).
catalog_key = MPC_CATALOGS.get(catalog)
# ``catalog`` may be a catalog NAME (an MPC_CATALOGS key, e.g. "UCAC4", as
# ADES provides) or the single-char CODE that obs80 supplies (an MPC_CATALOGS
# value, e.g. "q"). bias_dict is keyed by the code, so map a name to its code
# and let a code pass through -- otherwise debiasing silently no-ops on all
# obs80 input (issue #409).
#
# A blank, None, or unrecognized catalog has no bias model (common in
# historical / uncatalogued astrometry, or when no astCat column is present);
# it falls through the ``not in bias_dict`` guard and the astrometry is left
# unchanged rather than raising KeyError, which would abort the whole object's
# fit (issue #401).
catalog_key = MPC_CATALOGS.get(catalog, catalog)
if catalog_key is None or catalog_key not in bias_dict:
return ra, dec

Expand Down
19 changes: 19 additions & 0 deletions tests/layup/test_debias.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,22 @@ def test_debias_known_catalog_absent_from_bias_dict_returns_unchanged():
returns the astrometry unchanged (the pre-existing second guard)."""
ra, dec = 50.0, 10.0
assert debias(ra, dec, 2451545.0, "PPM", bias_dict={}) == (ra, dec)


def test_debias_accepts_catalog_code_like_a_name():
"""obs80 supplies the single-char catalog CODE (an MPC_CATALOGS value, e.g.
``"p"``), while ADES supplies the NAME (a key, e.g. ``"PPM"``). Both must apply
the same bias correction -- otherwise debiasing silently no-ops on all obs80
input (issue #409)."""
cache_dir = pooch.os_cache("layup")
bias_dict = generate_bias_dict(cache_dir=cache_dir)
ra, dec, epoch = 10.0, 20.0, 2451545.0

name, code = "PPM", MPC_CATALOGS["PPM"] # "PPM" -> "p"
ra_name, dec_name = debias(ra, dec, epoch, name, bias_dict)
ra_code, dec_code = debias(ra, dec, epoch, code, bias_dict)

# The code must resolve to the same correction as its name...
assert (ra_code, dec_code) == (ra_name, dec_name)
# ...and actually apply one (not silently return the input unchanged).
assert (ra_code, dec_code) != (ra, dec)
Loading