# 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:

[1]:

from astropy.timeseries import TimeSeries
from astropy.utils.data import get_pkg_data_filename
filename = get_pkg_data_filename('timeseries/kplr010666592-2009131110544_slc.fits')


As we’ve seen before, we can make a basic figure with:

[2]:

import numpy as np
from astropy.time import Time
from aas_timeseries import InteractiveTimeSeriesFigure

[3]:

fig = InteractiveTimeSeriesFigure()
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:

[4]:

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 icon):

For now, if you click on Custom View, nothing should change since we haven’t customized anything in the view yet.

[5]:

fig.preview_interactive()


## Custom limits¶

Views can have different default limits than the base figure - to change the limits on a view, you can use the xlim and ylim properties:

[6]:

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

[7]:

fig.preview_interactive()


## 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:

[8]:

view1.hide(baseline)


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):

[9]:

fig.preview_interactive()


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 include example:

[10]:

view2 = fig.add_view('Data only', include=[markers])

[11]:

fig.preview_interactive()


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.

## View-specific layers¶

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:

[12]:

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