Skip to content

Instantly share code, notes, and snippets.

@paulphys
Last active July 25, 2020 14:30
Show Gist options
  • Save paulphys/360b9164da87ee63e30762603626e803 to your computer and use it in GitHub Desktop.
Save paulphys/360b9164da87ee63e30762603626e803 to your computer and use it in GitHub Desktop.
pipeline for time series analysis on TESS light curves
import os
from astropy.timeseries import TimeSeries
from astropy.io import fits
class Lightcurve:
def __init__(self,path,telescope,instrument,date_obs_start,date_obs_end,creator,object,tessid,sector,camera,ccd,radesys,ra_obj,dec_obj,equinox,
pxtable,tessmag,radius,ticver,crmitten,crblksz,crspoc,checksum,time,timecorr,cadenceno,sap_flux,sap_flux_err,sap_bkg,sap_bkg_err,
pdcsap_flux,pdcsap_flux_err):
self.path = path
self.telescope = telescope
self.instrument = instrument
self.date_obs_start = date_obs_start
self.date_obs_end = date_obs_end
self.creator = creator
self.object = object
self.tessid = tessid
self.sector = sector
self.camera = camera
self.cdd = ccd
self.radesys = radesys
self.ra_obj = ra_obj
self.de_obj = dec_obj
self.equinox = equinox
self.pxtable = pxtable
self.tessmag = tessmag
self.radius = radius
self.ticver = ticver
self.crmitten = crmitten
self.crblksz = crblksz
self.crspoc = crspoc
self.checksum = checksum
self.time = time
self.timecorr = timecorr
self.cadenceno = cadenceno
self.sap_flux = sap_flux
self.sap_flux_err = sap_flux_err
self.sap_bkg = sap_bkg
self.sap_bkg_err = sap_bkg_err
self.pdcsap_flux = pdcsap_flux
self.pdcsap_flux_err = pdcsap_flux_err
directory = "/"
lightcurves=[]
with os.scandir(directory) as files:
if files.endswith(".fits"):
for file in files:
hdulist = fits.open(file.name)
ts = TimeSeries.read(file.name, format='tess.fits')
hdu = hdulist[0]
element = Lightcurve(directory+file.name, hdu.header['telescop'], hdu.header['instrume'], hdu.header['date-obs'],
hdu.header['date-end'],
hdu.header['creator'], hdu.header['object'], hdu.header['ticid'], hdu.header['sector'],
hdu.header['camera'], hdu.header['ccd'], hdu.header['radesys'], hdu.header['ra_obj'],
hdu.header['de_obj'], hdu.header['equinox'], hdu.header['pxtable'],
hdu.header['tessmag'],
hdu.header['radius'], hdu.header['ticver'], hdu.header['crmitten'],
hdu.header['crspoc'],
hdu.header['checksum'], ts['sap_flux'], ts['sap_flux_err'], ts['sap_bkg'],
ts['sap_bkg_err'],
ts['pdcsap_flux'], ts['pdcsap_flux_err'])
lightcurves.append(element)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment