.. _astropy-timeseries: **************************************************** Time series (`astropy_timeseries`) **************************************************** .. |Time| replace:: :class:`~astropy.time.Time` .. |Table| replace:: :class:`~astropy.table.Table` .. |QTable| replace:: :class:`~astropy.table.QTable` .. |Quantity| replace:: :class:`~astropy.units.Quantity` .. |TimeSeries| replace:: :class:`~astropy_timeseries.TimeSeries` .. |BinnedTimeSeries| replace:: :class:`~astropy_timeseries.BinnedTimeSeries` Introduction ============ Many different areas of astrophysics have to deal with 1D time series data, either sampling a continuous variable at fixed times or counting some events binned into time windows. The `astropy_timeseries` package therefore provides classes to represent and manipulate time series The time series classes presented below are |QTable| sub-classes that have special columns to represent times using the |Time| class. Therefore, much of the functionality described in :ref:`astropy-table` applies here. Getting Started =============== In this section, we take a quick look at how to read in a time series, access the data, and carry out some basic analysis. For more details about creating and using time series, see the full documentation in :ref:`using-timeseries`. The simplest time series class is |TimeSeries| - it represents a time series as a collection of values at specific points in time. If you are interested in representing time series as measurements in discrete time bins, you will likely be interested in the |BinnedTimeSeries| sub-class which we show in :ref:`using-timeseries`). To start off, we retrieve a FITS file containing a Kepler light curve for a source:: >>> from astropy.utils.data import get_pkg_data_filename >>> filename = get_pkg_data_filename('timeseries/kplr010666592-2009131110544_slc.fits') # doctest: +REMOTE_DATA We can then use the |TimeSeries| class to read in this file:: >>> from astropy_timeseries import TimeSeries >>> ts = TimeSeries.read(filename, format='kepler.fits') # doctest: +REMOTE_DATA Time series are specialized kinds of |Table| objects:: >>> ts # doctest: +REMOTE_DATA time timecorr ... pos_corr1 pos_corr2 d ... pixels pixels object float32 ... float32 float32 ----------------------- ------------- ... -------------- -------------- 2009-05-02T00:41:40.338 6.630610e-04 ... 1.5822421e-03 -1.4463664e-03 2009-05-02T00:42:39.187 6.630857e-04 ... 1.5743829e-03 -1.4540013e-03 2009-05-02T00:43:38.045 6.631103e-04 ... 1.5665225e-03 -1.4616371e-03 ... ... ... ... ... 2009-05-11T18:05:14.479 1.014664e-03 ... 3.5986886e-03 3.1407392e-03 2009-05-11T18:06:13.328 1.014689e-03 ... 3.5967610e-03 3.1329831e-03 2009-05-11T18:07:12.186 1.014713e-03 ... 3.5948332e-03 3.1252259e-03 In the same way as for |Table|, the various columns and rows can be accessed and sliced using index notation:: >>> ts['sap_flux'] # doctest: +REMOTE_DATA >>> ts['time', 'sap_flux'] # doctest: +REMOTE_DATA time sap_flux electron / s object float32 ----------------------- -------------- 2009-05-02T00:41:40.338 1.0270451e+06 2009-05-02T00:42:39.187 1.0271844e+06 2009-05-02T00:43:38.045 1.0270762e+06 ... ... 2009-05-11T18:05:14.479 1.0254516e+06 2009-05-11T18:06:13.328 1.0254685e+06 2009-05-11T18:07:12.186 1.0259309e+06 >>> ts[0:4] # doctest: +REMOTE_DATA time timecorr ... pos_corr1 pos_corr2 d ... pixels pixels object float32 ... float32 float32 ----------------------- ------------- ... -------------- -------------- 2009-05-02T00:41:40.338 6.630610e-04 ... 1.5822421e-03 -1.4463664e-03 2009-05-02T00:42:39.187 6.630857e-04 ... 1.5743829e-03 -1.4540013e-03 2009-05-02T00:43:38.045 6.631103e-04 ... 1.5665225e-03 -1.4616371e-03 2009-05-02T00:44:36.894 6.631350e-04 ... 1.5586632e-03 -1.4692718e-03 As seen in the example above, |TimeSeries| objects have a ``time`` column, which is always the first column. This column can also be accessed using the ``.time`` attribute:: >>> ts.time # doctest: +REMOTE_DATA