Setting up pre-defined views¶
While interactive figures allows readers to explore data in a very flexible way, it can be useful to set up pre-defined views of the data that might interest a reader - for example zooming in to a particular feature, and/or showing only a subset of the data or a different model on top of the data.
Let’s use the same time series as in the Getting Started guide:
from astropy.timeseries import TimeSeries from astropy.utils.data import get_pkg_data_filename filename = get_pkg_data_filename('timeseries/kplr010666592-2009131110544_slc.fits') ts = TimeSeries.read(filename, format='kepler.fits')['time', 'sap_flux']
As we’ve seen before, we can make a basic figure with:
import numpy as np from astropy.time import Time from aas_timeseries import InteractiveTimeSeriesFigure
fig = InteractiveTimeSeriesFigure() markers = fig.add_markers(time_series=ts, column='sap_flux', label='Flux') baseline = fig.add_horizontal_line(np.nanmedian(ts['sap_flux']), label='Baseline level', color='blue') fig.preview_interactive()
Let’s say we want to create a pre-defined view of one of the transits - we can make a new view with:
view1 = fig.add_view('Custom View')
At this point,
view1 is a View object which by default will contain the same layers as the original figure. We now look at the different ways in which views can be customized compared to the main figure. Note that in all cases below, the default figure that appears when we preview it is the base figure - to see the available views and switch to them, use the menu in the top right to access the views tab (indicated by the ABCD
For now, if you click on Custom View, nothing should change since we haven’t customized anything in the view yet.
Views can have different default limits than the base figure - to change the limits on a view, you can use the
from astropy import units as u view1.xlim = '2009-05-02T10:00:00Z', '2009-05-03T08:00:00Z' view1.ylim = 1014000. * u.electron / u.s, 1040000. * u.electron / u.s
Custom subset of layers visible/available¶
Views can customize which data is present in the figure (i.e. listed in the legend) and which data are visible by default (visibility can be controlled by clicking on layers in the layer list). To hide layers by default in the view, use the hide method:
If we now preview the figure and go to the custom view, then to the list of layers, the horizontal line should be hidden by default (but can be shown again by clicking on it in the legend):
Layers can be made visible again by using the corresponding show method.
It is also possible to completely remove layers from a given view in a way that it can’t be toggled back. This is controled when the view is created. There are several ways to filter the layers to include. You can for example list the layers to include explicitly using:
fig.add_view('View name', include=[markers])
Or you can instead specify the layers to exclude:
fig.add_view('View name', exclude=[baseline])
Finally, you can also create an empty view using:
fig.add_view('View name', empty=True)
Let’s try the
view2 = fig.add_view('Data only', include=[markers])
If you go to the new view, select it, then go to the list of layers, you will see that only the markers are available in the legend, and there is no way to add the baseline back.
Once views are created, it is also possible to add layers to them, e.g. specific lines/areas that only make sense in the context of the view. View objects have all the same
add_* methods as the base figure object (see the Adding and modifying layers notebook). For example, we can create a view in which a vertical range is added:
view3 = fig.add_view('Transit') view3.xlim = '2009-05-02T10:00:00Z', '2009-05-03T08:00:00Z' view3.ylim = 1014000. * u.electron / u.s, 1040000. * u.electron / u.s view3.add_vertical_range('2009-05-02T18:35:00Z', '2009-05-02T22:30:00Z', color='red') fig.preview_interactive()
This range will only be visible in the Transit view, and not in the base figure or any other view.