Skip to content

debias() raises KeyError on blank/unknown star-catalog codes (crashes fits on real obs80 data) #401

Description

@matthewholman

Summary

debias() in src/layup/utilities/debiasing.py raises KeyError when an observation's star-catalog code is blank, None, or otherwise not a key in MPC_CATALOGS. Because debiasing runs inside the per-object fit loop, this aborts the entire fit for any object that contains such an observation — which is common in real MPC data (pre-CCD / uncatalogued astrometry, and any obs where the catalog column is absent so catalog=None is passed).

Root cause

def debias(ra, dec, epoch_jd_tdb, catalog, bias_dict, nside=256):
    catalog_key = MPC_CATALOGS[catalog]        # line 79: unguarded -> KeyError
    if catalog_key not in bias_dict.keys():    # line 80: guard is AFTER the lookup
        return ra, dec

The guard on line 80 only handles a mapped catalog that is missing from bias_dict; it never protects the MPC_CATALOGS[catalog] lookup itself. A blank code '', None (passed by orbitfit._orbitfit when no astCat column is present, orbit_fit.py ~L913-919), or any unrecognized single-char code therefore crashes.

Reproduction

KeyError: np.str_('')
  File ".../layup/utilities/debiasing.py", line 79, in debias
    catalog_key = MPC_CATALOGS[catalog]

Fit any real obs80 dataset containing observations with a blank star-catalog code with orbitfit(..., debias=True). (Hit while fitting historical astrometry — e.g. 1930s NEO obs — in the MPC full-catalog demo.)

Proposed fix

Treat an unknown/blank/None catalog as "no debias correction available" and return the astrometry unchanged, guarding before the lookup:

def debias(ra, dec, epoch_jd_tdb, catalog, bias_dict, nside=256):
    catalog_key = MPC_CATALOGS.get(catalog)
    if catalog_key is None or catalog_key not in bias_dict:
        return ra, dec  # no reference-catalog bias model -> leave astrometry as-is
    ...

This matches the intended semantics (bias correction is only defined for observations tied to a known reference catalog) and makes debias=True robust on real, catalog-scale data.

Impact

Blocks debias=True on essentially any historical or full-catalog dataset. Low-risk fix (behavior only changes for the currently-crashing cases, which become no-ops).

Found during Phase 0a of the MPC full-catalog fitting demo.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions