astrobase.astrotess module

Contains various tools for analyzing TESS light curves.

astrobase.astrotess.normalized_flux_to_mag(lcdict, columns=('sap.sap_flux', 'sap.sap_flux_err', 'sap.sap_bkg', 'sap.sap_bkg_err', 'pdc.pdcsap_flux', 'pdc.pdcsap_flux_err'))[source]

This converts the normalized fluxes in the TESS lcdicts to TESS mags.

Uses the object’s TESS mag stored in lcdict[‘objectinfo’][‘tessmag’]:

mag - object_tess_mag = -2.5 log (flux/median_flux)
Parameters:
  • lcdict (lcdict) – An lcdict produced by read_tess_fitslc or consolidate_tess_fitslc. This must have normalized fluxes in its measurement columns (use the normalize kwarg for these functions).
  • columns (sequence of str) – The column keys of the normalized flux and background measurements in the lcdict to operate on and convert to magnitudes in TESS band (T).
Returns:

The returned lcdict will contain extra columns corresponding to magnitudes for each input normalized flux/background column.

Return type:

lcdict

astrobase.astrotess.read_tess_fitslc(lcfits, headerkeys=['EXPOSURE', 'TIMEREF', 'TASSIGN', 'TIMESYS', 'BJDREFI', 'BJDREFF', 'TELAPSE', 'LIVETIME', 'INT_TIME', 'NUM_FRM', 'TIMEDEL', 'BACKAPP', 'DEADAPP', 'VIGNAPP', 'GAINA', 'GAINB', 'GAINC', 'GAIND', 'READNOIA', 'READNOIB', 'READNOIC', 'READNOID', 'CDPP0_5', 'CDPP1_0', 'CDPP2_0', 'PDCVAR', 'PDCMETHD', 'CROWDSAP', 'FLFRCSAP', 'NSPSDDET', 'NSPSDCOR'], datakeys=['TIME', 'TIMECORR', 'CADENCENO', 'QUALITY', 'PSF_CENTR1', 'PSF_CENTR1_ERR', 'PSF_CENTR2', 'PSF_CENTR2_ERR', 'MOM_CENTR1', 'MOM_CENTR1_ERR', 'MOM_CENTR2', 'MOM_CENTR2_ERR', 'POS_CORR1', 'POS_CORR2'], sapkeys=['SAP_FLUX', 'SAP_FLUX_ERR', 'SAP_BKG', 'SAP_BKG_ERR'], pdckeys=['PDCSAP_FLUX', 'PDCSAP_FLUX_ERR'], topkeys=['DATE-OBS', 'DATE-END', 'PROCVER', 'ORIGIN', 'DATA_REL', 'TIMVERSN', 'OBJECT', 'TICID', 'SECTOR', 'CAMERA', 'CCD', 'PXTABLE', 'RADESYS', 'RA_OBJ', 'DEC_OBJ', 'EQUINOX', 'PMRA', 'PMDEC', 'PMTOTAL', 'TESSMAG', 'TEFF', 'LOGG', 'MH', 'RADIUS', 'TICVER', 'CRMITEN', 'CRBLKSZ', 'CRSPOC'], apkeys=['NPIXSAP', 'NPIXMISS', 'CDELT1', 'CDELT2'], normalize=False, appendto=None, filterqualityflags=False, nanfilter=None, timestoignore=None)[source]

This extracts the light curve from a single TESS .lc.fits file.

This works on the light curves available at MAST.

TODO: look at:

https://archive.stsci.edu/missions/tess/doc/EXP-TESS-ARC-ICD-TM-0014.pdf

for details on the column descriptions and to fill in any other info we need.

Parameters:
  • lcfits (str) – The filename of a MAST Kepler/K2 light curve FITS file.
  • headerkeys (list) – A list of FITS header keys that will be extracted from the FITS light curve file. These describe the observations. The default value for this is given in LCHEADERKEYS above.
  • datakeys (list) – A list of FITS column names that correspond to the auxiliary measurements in the light curve. The default is LCDATAKEYS above.
  • sapkeys (list) – A list of FITS column names that correspond to the SAP flux measurements in the light curve. The default is LCSAPKEYS above.
  • pdckeys (list) – A list of FITS column names that correspond to the PDC flux measurements in the light curve. The default is LCPDCKEYS above.
  • topkeys (list) – A list of FITS header keys that describe the object in the light curve. The default is LCTOPKEYS above.
  • apkeys (list) – A list of FITS header keys that describe the flux measurement apertures used by the TESS pipeline. The default is LCAPERTUREKEYS above.
  • normalize (bool) – If True, then the light curve’s SAP_FLUX and PDCSAP_FLUX measurements will be normalized to 1.0 by dividing out the median flux for the component light curve.
  • appendto (lcdict or None) – If appendto is an lcdict, will append measurements of this lcdict to that lcdict. This is used for consolidating light curves for the same object across different files (sectors/cameras/CCDs?). The appending does not care about the time order. To consolidate light curves in time order, use consolidate_tess_fitslc below.
  • filterqualityflags (bool) – If True, will remove any measurements that have non-zero quality flags present. This usually indicates an issue with the instrument or spacecraft.
  • nanfilter ({'sap','pdc','sap,pdc'} or None) – Indicates the flux measurement type(s) to apply the filtering to.
  • timestoignore (list of tuples or None) –

    This is of the form:

    [(time1_start, time1_end), (time2_start, time2_end), ...]
    

    and indicates the start and end times to mask out of the final lcdict. Use this to remove anything that wasn’t caught by the quality flags.

Returns:

Returns an lcdict (this is useable by most astrobase functions for LC processing).

Return type:

lcdict

astrobase.astrotess.consolidate_tess_fitslc(lclist, normalize=True, filterqualityflags=False, nanfilter=None, timestoignore=None, headerkeys=['EXPOSURE', 'TIMEREF', 'TASSIGN', 'TIMESYS', 'BJDREFI', 'BJDREFF', 'TELAPSE', 'LIVETIME', 'INT_TIME', 'NUM_FRM', 'TIMEDEL', 'BACKAPP', 'DEADAPP', 'VIGNAPP', 'GAINA', 'GAINB', 'GAINC', 'GAIND', 'READNOIA', 'READNOIB', 'READNOIC', 'READNOID', 'CDPP0_5', 'CDPP1_0', 'CDPP2_0', 'PDCVAR', 'PDCMETHD', 'CROWDSAP', 'FLFRCSAP', 'NSPSDDET', 'NSPSDCOR'], datakeys=['TIME', 'TIMECORR', 'CADENCENO', 'QUALITY', 'PSF_CENTR1', 'PSF_CENTR1_ERR', 'PSF_CENTR2', 'PSF_CENTR2_ERR', 'MOM_CENTR1', 'MOM_CENTR1_ERR', 'MOM_CENTR2', 'MOM_CENTR2_ERR', 'POS_CORR1', 'POS_CORR2'], sapkeys=['SAP_FLUX', 'SAP_FLUX_ERR', 'SAP_BKG', 'SAP_BKG_ERR'], pdckeys=['PDCSAP_FLUX', 'PDCSAP_FLUX_ERR'], topkeys=['DATE-OBS', 'DATE-END', 'PROCVER', 'ORIGIN', 'DATA_REL', 'TIMVERSN', 'OBJECT', 'TICID', 'SECTOR', 'CAMERA', 'CCD', 'PXTABLE', 'RADESYS', 'RA_OBJ', 'DEC_OBJ', 'EQUINOX', 'PMRA', 'PMDEC', 'PMTOTAL', 'TESSMAG', 'TEFF', 'LOGG', 'MH', 'RADIUS', 'TICVER', 'CRMITEN', 'CRBLKSZ', 'CRSPOC'], apkeys=['NPIXSAP', 'NPIXMISS', 'CDELT1', 'CDELT2'])[source]

This consolidates a list of LCs for a single TIC object.

NOTE: if light curve time arrays contain nans, these and their associated measurements will be sorted to the end of the final combined arrays.

Parameters:
  • lclist (list of str, or str) – lclist is either a list of actual light curve files or a string that is valid for glob.glob to search for and generate a light curve list based on the file glob. This is useful for consolidating LC FITS files across different TESS sectors for a single TIC ID using a glob like *<TICID>*_lc.fits.
  • normalize (bool) – If True, then the light curve’s SAP_FLUX and PDCSAP_FLUX measurements will be normalized to 1.0 by dividing out the median flux for the component light curve.
  • filterqualityflags (bool) – If True, will remove any measurements that have non-zero quality flags present. This usually indicates an issue with the instrument or spacecraft.
  • nanfilter ({'sap','pdc','sap,pdc'} or None) – Indicates the flux measurement type(s) to apply the filtering to.
  • timestoignore (list of tuples or None) –

    This is of the form:

    [(time1_start, time1_end), (time2_start, time2_end), ...]
    

    and indicates the start and end times to mask out of the final lcdict. Use this to remove anything that wasn’t caught by the quality flags.

  • headerkeys (list) – A list of FITS header keys that will be extracted from the FITS light curve file. These describe the observations. The default value for this is given in LCHEADERKEYS above.
  • datakeys (list) – A list of FITS column names that correspond to the auxiliary measurements in the light curve. The default is LCDATAKEYS above.
  • sapkeys (list) – A list of FITS column names that correspond to the SAP flux measurements in the light curve. The default is LCSAPKEYS above.
  • pdckeys (list) – A list of FITS column names that correspond to the PDC flux measurements in the light curve. The default is LCPDCKEYS above.
  • topkeys (list) – A list of FITS header keys that describe the object in the light curve. The default is LCTOPKEYS above.
  • apkeys (list) – A list of FITS header keys that describe the flux measurement apertures used by the TESS pipeline. The default is LCAPERTUREKEYS above.
Returns:

Returns an lcdict (this is useable by most astrobase functions for LC processing).

Return type:

lcdict

astrobase.astrotess.tess_lcdict_to_pkl(lcdict, outfile=None)[source]

This writes the lcdict to a Python pickle.

Parameters:
  • lcdict (lcdict) – This is the input lcdict to write to a pickle.
  • outfile (str or None) – If this is None, the object’s Kepler ID/EPIC ID will determined from the lcdict and used to form the filename of the output pickle file. If this is a str, the provided filename will be used.
Returns:

The absolute path to the written pickle file.

Return type:

str

astrobase.astrotess.read_tess_pklc(picklefile)[source]

This turns the pickled lightcurve file back into an lcdict.

Parameters:picklefile (str) – The path to a previously written Kepler LC picklefile generated by tess_lcdict_to_pkl above.
Returns:Returns an lcdict (this is useable by most astrobase functions for LC processing).
Return type:lcdict
astrobase.astrotess.filter_tess_lcdict(lcdict, filterqualityflags=True, nanfilter='sap, pdc, time', timestoignore=None, quiet=False)[source]

This filters the provided TESS lcdict, removing nans and bad observations.

By default, this function removes points in the TESS LC that have ANY quality flags set.

Parameters:
  • lcdict (lcdict) – An lcdict produced by consolidate_tess_fitslc or read_tess_fitslc.
  • filterflags (bool) – If True, will remove any measurements that have non-zero quality flags present. This usually indicates an issue with the instrument or spacecraft.
  • nanfilter ({'sap','pdc','sap,pdc'}) – Indicates the flux measurement type(s) to apply the filtering to.
  • timestoignore (list of tuples or None) –

    This is of the form:

    [(time1_start, time1_end), (time2_start, time2_end), ...]
    

    and indicates the start and end times to mask out of the final lcdict. Use this to remove anything that wasn’t caught by the quality flags.

Returns:

Returns an lcdict (this is useable by most astrobase functions for LC processing). The lcdict is filtered IN PLACE!

Return type:

lcdict