Reading/writing time series¶
Build-in readers¶
Since TimeSeries
and BinnedTimeSeries
are sub-classes of Table
,
they have read()
and
write()
methods that can be used to read time series
from files. We include a few readers for well-defined formats in astropy_timeseries
-
for example we have readers for light curves in FITS format from the
Kepler and
TESS missions.
Here is an example of using Kepler FITS time series - we start off by fetching an example file:
from astropy.utils.data import get_pkg_data_filename
example_data = get_pkg_data_filename('timeseries/kplr010666592-2009131110544_slc.fits')
This will set example_data
to the filename of the downloaded file (so you can
replace this by the filename for the file you want to read in). We can then read in
the time series using:
from astropy_timeseries import TimeSeries
kepler = TimeSeries.read(example_data, format='kepler.fits')
Let’s check that the time series has been read in correctly:
import matplotlib.pyplot as plt
plt.plot(kepler.time.jd, kepler['sap_flux'], 'k.', markersize=1)
plt.xlabel('Barycentric Julian Date')
plt.ylabel('SAP Flux (e-/s)')
Reading other formats¶
At the moment only a few formats are defined in astropy itself, in part because
there are not many well documented formats for storing time series. So in many cases,
you will likely have to first read in your files using the more generic Table
class (see Reading and writing Table objects), and then construct the time series object as
described in Creating time series.
If you have written a reader/writer for a commonly used format, and it is well documented, please feel free to contribute it to astropy!