Skip to content

Instantly share code, notes, and snippets.

@barentsen
Last active February 15, 2019 21:42
Show Gist options
  • Save barentsen/9b5a7b51f48e026e3af5 to your computer and use it in GitHub Desktop.
Save barentsen/9b5a7b51f48e026e3af5 to your computer and use it in GitHub Desktop.
Convert the 'QUALITY' column in Kepler/K2 target pixel and light curve files into a list of human-readable flag strings.
"""
Example function to convert the 'QUALITY' column in Kepler/K2 target pixel
and lightcurve files into a list of meaningful strings.
"""
# The meaning of the various flags are described in the Kepler Archive Manual
KEPLER_QUALITY_FLAGS = {
"1": "Attitude tweak",
"2": "Safe mode",
"4": "Coarse point",
"8": "Earth point",
"16": "Zero crossing",
"32": "Desaturation event",
"64": "Argabrightening",
"128": "Cosmic ray",
"256": "Manual exclude",
"1024": "Sudden sensitivity dropout",
"2048": "Impulsive outlier",
"4096": "Argabrightening",
"8192": "Cosmic ray",
"16384": "Detector anomaly",
"32768": "No fine point",
"65536": "No data",
"131072": "Rolling band",
"262144": "Rolling band",
"524288": "Possible thruster firing",
"1048576": "Thruster firing"
}
def quality_flags(quality):
"""Converts a Kepler/K2 QUALITY integer into human-readable flags.
This function takes the QUALITY bitstring that can be found for each
cadence in Kepler/K2's pixel and light curve files and converts into
a list of human-readable strings explaining the flags raised (if any).
Parameters
----------
quality : int
Value from the 'QUALITY' column of a Kepler/K2 pixel or lightcurve file.
Returns
-------
flags : list of str
List of human-readable strings giving a short description of the
quality flags raised. Returns an empty list if no flags raised.
"""
flags = []
for flag in KEPLER_QUALITY_FLAGS.keys():
if quality & int(flag) > 0:
flags.append(KEPLER_QUALITY_FLAGS[flag])
return flags
if __name__ == '__main__':
example_quality = 1089568
print(quality_flags(example_quality))
@stephtdouglas
Copy link

Hey Geert - I found a QUALITY flag of 1048576 (so bit=20) in my data, which isn't listed here -- this says that's a possible thruster firing. I also have points flagged as 524288 (bit=19), which I can't find anywhere obvious on the website. Are they both possible thruster firings?
Thanks,
Stephanie

@barentsen
Copy link
Author

You are right. I verified with the archive scientist that the correct value for "Thruster firing" is 1048576. I revised the gist accordingly.

@rrpastro
Copy link

Hey Geert - I found new QUALITY Flags of 393216 and 401408 in Campaign 16 but they are not listed above. Would you please let me know what those flags are for.
~Rishi

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