Skip to content

Commit

Permalink
Bokeh plotter (#714)
Browse files Browse the repository at this point in the history
* Created the bokeh/file_viewer tool
Also includes
- ctapipe.utils.rgbtohex
- ctapipe.visualization.bokeh
- ctapipe.plotting.bokeh_event_viewer

* Fixed formatting

* Moved run to inside function (fixes tests)

* Replaced the rgbtohex C extension with @dneise's Python solution

* Corrected references to the old num_samples Field in inst

* Further corrections to n_chan

* Improvements to setting view as suggested by @dneise

* Improved method to execute file_viewer

Used bokeh.server.server.Server to run file_viewer through `python`
instead of `bokeh serve`
Created entry_point ctapipe-event-viewer
Rearranged directory structure of tools/bokeh

* Fixed selection of extractor

* Fixed selection of pixels to work with bokeh > 1.0
Added bokeh>1.1 as a dependency to ensure compatibility

* Changed pixel shape from rectangular to circular to better display all cameras

* Corrected tests to use example_event

* Corrected bokeh version
  • Loading branch information
watsonjj authored and kosack committed Nov 9, 2018
1 parent 0558f39 commit 1efbd77
Show file tree
Hide file tree
Showing 12 changed files with 1,685 additions and 2 deletions.
445 changes: 445 additions & 0 deletions ctapipe/plotting/bokeh_event_viewer.py

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions ctapipe/plotting/tests/test_bokeh_event_viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
from ctapipe.plotting.bokeh_event_viewer import BokehEventViewer
from ctapipe.calib.camera.calibrator import CameraCalibrator
import pytest


def test_bokeh_event_viewer_creation():
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()


def test_event_setting(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event
for cam in viewer.cameras:
assert cam.event == example_event
for wf in viewer.waveforms:
assert wf.event == example_event


def test_enable_automatic_index_increment():
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.enable_automatic_index_increment()
for cam in viewer.cameras:
assert cam.automatic_index_increment


def test_change_time(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

t = 5
viewer.change_time(t)
for cam in viewer.cameras:
assert cam.time == t
for wf in viewer.waveforms:
assert wf.active_time == t

t = -11
viewer.change_time(t)
for cam in viewer.cameras:
assert cam.time == 0
for wf in viewer.waveforms:
assert wf.active_time == 0

tel = list(example_event.r0.tels_with_data)[0]
n_samples = example_event.r0.tel[tel].waveform.shape[-1]
t = 10000
viewer.change_time(t)
for cam in viewer.cameras:
assert cam.time == n_samples - 1
for wf in viewer.waveforms:
assert wf.active_time == n_samples - 1


def test_on_waveform_click(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

t = 5
viewer.waveforms[0]._on_waveform_click(t)
for cam in viewer.cameras:
assert cam.time == t
for wf in viewer.waveforms:
assert wf.active_time == t


def test_telid(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

tels = list(example_event.r0.tels_with_data)

assert viewer.telid == tels[0]
for cam in viewer.cameras:
assert cam.telid == tels[0]
for wf in viewer.waveforms:
assert wf.telid == tels[0]

viewer.telid = tels[1]
assert viewer.telid == tels[1]
for cam in viewer.cameras:
assert cam.telid == tels[1]
for wf in viewer.waveforms:
assert wf.telid == tels[1]


def test_telid_incorrect(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

with pytest.raises(KeyError):
viewer.telid = 148937242


def test_on_pixel_click(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

p1 = 5
viewer.cameras[0]._on_pixel_click(p1)
assert viewer.waveforms[viewer.cameras[0].active_index].pixel == p1


def test_channel(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

assert viewer.channel == 0
for cam in viewer.cameras:
assert cam.channel == 0
for wf in viewer.waveforms:
assert wf.channel == 0


def test_channel_incorrect(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

with pytest.raises(IndexError):
viewer.channel = 148937242


def test_view_camera(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

c = CameraCalibrator()
c.calibrate(example_event)

t = list(example_event.r0.tels_with_data)[0]

cam = viewer.cameras[0]
cam.view = 'r1'
assert (cam.image == example_event.r1.tel[t].waveform[0, :, 0]).all()

with pytest.raises(ValueError):
cam.view = 'q'


def test_view_wf(example_event):
viewer = BokehEventViewer(config=None, tool=None)
viewer.create()
viewer.event = example_event

c = CameraCalibrator()
c.calibrate(example_event)

t = list(example_event.r0.tels_with_data)[0]

wf = viewer.waveforms[0]
wf.view = 'r1'
assert (wf.waveform == example_event.r1.tel[t].waveform[0, 0, :]).all()

with pytest.raises(ValueError):
wf.view = 'q'
Empty file added ctapipe/tools/bokeh/__init__.py
Empty file.
Loading

0 comments on commit 1efbd77

Please sign in to comment.