Reading flag columns

LSST-DM writes boolean flag columns using what I believe is a convention that we invented, so other FITS readers don’t have immediate access to the flags by symbolic name, as we do when using lsst.afw.table. In at least some circumstances, this has led to scientists writing code assuming a particular layout of the flags (e.g., bad =["flags"][:, 42]), which is dangerous because the layout is subject to change between pipeline releases, and even within a release when the pipeline configuration changes.

In case someone finds it useful, I recently put together some simple code that reads the flags and makes them available by symbolic name:


class LsstTable:
    def __init__(self, filename):
        fits =
        self.phu = fits[0].header
        self.header = fits[1].header = fits[1].data
        self.flags = {}
        ii = 1
        while ("TFLAG%d" % ii) in self.header:
            self.flags[self.header["TFLAG%d" % ii]] =["flags"][:, ii - 1]
            ii += 1

Then you can do:

table = LsstTable(filename)
bad = table.flags["base_PsfFlux_flag"]
import numpy as np
mag = - 2.5*np.log10(["base_PsfFlux_flux"])
print("Good values:", mag[~bad])
1 Like