Absolute times, relative times, and phases¶
Types of time axes¶
So far, the examples we’ve looked at all involve time series with absolute time on the x axis. However, it is also possible to show relative times, or even phases. To take a look at this, we will use a dataset that consists of radial velocities as a function of time:
[1]:
from astropy.timeseries import TimeSeries
[2]:
ts = TimeSeries.read('https://aperiosoftware.github.io/timeseries.js/examples/data/phase.csv', format='ascii.csv')
[3]:
ts
[3]:
time | relative | phase | flux | error | flux_lo | flux_hi |
---|---|---|---|---|---|---|
object | int64 | float64 | float64 | float64 | float64 | float64 |
2016-03-22T12:30:28.000 | 0 | 0.0 | 0.98 | 0.15 | 0.97 | 1.0 |
2016-03-22T12:30:38.000 | 10 | 0.1 | 1.02 | 0.15 | 1.0 | 1.03 |
2016-03-22T12:30:48.000 | 20 | 0.2 | 1.01 | 0.15 | 1.0 | 1.02 |
2016-03-22T12:30:58.000 | 30 | 0.3 | 0.87 | 0.15 | 0.85 | 0.89 |
2016-03-22T12:31:08.000 | 40 | 0.4 | 0.75 | 0.15 | 0.72 | 0.76 |
2016-03-22T12:31:18.000 | 50 | 0.5 | 0.7 | 0.15 | 0.69 | 0.71 |
2016-03-22T12:31:28.000 | 60 | 0.6 | 0.71 | 0.15 | 0.7 | 0.72 |
2016-03-22T12:31:38.000 | 70 | 0.7 | 0.82 | 0.15 | 0.805 | 0.835 |
2016-03-22T12:31:48.000 | 80 | 0.8 | 0.97 | 0.15 | 0.96 | 0.985 |
2016-03-22T12:31:58.000 | 90 | 0.9 | 1.02 | 0.15 | 1.01 | 1.04 |
... | ... | ... | ... | ... | ... | ... |
2016-03-22T12:33:08.000 | 160 | 0.6 | 0.69 | 0.15 | 0.65 | 0.75 |
2016-03-22T12:33:18.000 | 170 | 0.7 | 0.73 | 0.15 | 0.68 | 0.78 |
2016-03-22T12:33:28.000 | 180 | 0.8 | 0.86 | 0.15 | 0.8 | 0.91 |
2016-03-22T12:33:38.000 | 190 | 0.9 | 1.0 | 0.15 | 0.98 | 1.02 |
2016-03-22T12:33:48.000 | 200 | 1.0 | 0.99 | 0.15 | 0.97 | 1.02 |
2016-03-22T12:33:58.000 | 210 | 0.1 | 1.01 | 0.15 | 1.0 | 1.02 |
2016-03-22T12:34:00.000 | 212 | 0.12 | 1.007 | 0.15 | 1.0 | 1.024 |
2016-03-22T12:34:05.000 | 217 | 0.17 | 1.011 | 0.15 | 0.995 | 1.025 |
2016-03-22T12:34:16.000 | 228 | 0.28 | 0.94 | 0.15 | 0.89 | 1.01 |
2016-03-22T12:34:20.000 | 232 | 0.32 | 0.84 | 0.15 | 0.78 | 0.9 |
This time series contains an absolute time column, but it also contains a relative time (since the start of the observations) and a pre-computed phase for a given period and epoch. You could also for example compute these on-the-fly and add them to an existing TimeSeries object.
Before we proceed, we need to update the TimeSeries object to include information about the units for the relative time column - we can do this using:
[4]:
from astropy import units as u
relative = ts['relative']
ts.remove_column('relative')
ts['relative'] = relative * u.s
We can now create a figure that shows relative time instead of absolute time by specifing time_mode
when creating a figure:
[5]:
from aas_timeseries import InteractiveTimeSeriesFigure
fig = InteractiveTimeSeriesFigure(title='Radial Velocity Curve', time_mode='relative')
fig.add_markers(time_series=ts, time_column='relative', column='flux', color='orange', size=50)
fig.ylabel='Radial Velocity (km/s)'
fig.preview_interactive()
Similarly, we can create a figure showing the velocities as a function of phase using:
[6]:
fig = InteractiveTimeSeriesFigure(title='Radial Velocity Curve', time_mode='phase')
fig.add_markers(time_series=ts, time_column='phase', column='flux', color='orange', size=50)
fig.ylabel='Radial Velocity (km/s)'
fig.preview_interactive()
The time_mode
can also be passed when creating views, so we can make a figure that shows absolute time by default, and have a view with the relative time and the phase axes:
[7]:
fig = InteractiveTimeSeriesFigure(title='Radial Velocity Curve', time_mode='absolute')
fig.ylabel='Radial Velocity (km/s)'
fig.add_markers(time_series=ts, time_column='time', column='flux', color='orange', size=50)
view1 = fig.add_view(title='By phase', empty=True, time_mode='phase')
view1.add_markers(time_series=ts, time_column='phase', column='flux', color='orange', size=50)
view2 = fig.add_view(title='By relative time', empty=True, time_mode='relative')
view2.add_markers(time_series=ts, time_column='relative', column='flux', color='orange', size=50)
fig.preview_interactive()
Formatting of time axes¶
For each of the different types of time axes, it is possible to customize the format of the axes, by using the time_format
setting. For a figure/view with absolute time, time_format
can be set to 'jd'
, 'mjd'
, 'unix'
, 'iso'
, or 'auto'
:
[8]:
fig = InteractiveTimeSeriesFigure(title='Radial Velocity Curve', time_mode='absolute')
fig.add_markers(time_series=ts, time_column='time', column='flux', color='orange', size=50)
fig.time_format = 'jd'
fig.preview_interactive()
For figures/views with relative times, the time_format
can be set to 'seconds'
, 'hours'
, 'days'
, or 'years'
:
[9]:
fig = InteractiveTimeSeriesFigure(title='Radial Velocity Curve', time_mode='relative')
fig.add_markers(time_series=ts, time_column='relative', column='flux', color='orange', size=50)
fig.time_format = 'hours'
fig.preview_interactive()
And finally, for phases, this can be set to 'unity'
, 'radians'
, or 'degrees'
:
[10]:
fig = InteractiveTimeSeriesFigure(title='Radial Velocity Curve', time_mode='phase')
fig.add_markers(time_series=ts, time_column='phase', column='flux', color='orange', size=50)
fig.time_format = 'radians'
fig.preview_interactive()