Skip to content

Commit

Permalink
Merge pull request #437 from kosack/improve_examples
Browse files Browse the repository at this point in the history
Improve examples
  • Loading branch information
kosack authored Jun 16, 2017
2 parents abc3553 + 8b2b5fd commit 8836d67
Showing 1 changed file with 40 additions and 44 deletions.
84 changes: 40 additions & 44 deletions examples/display_events_single_tel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,72 +11,65 @@
is not a fast operation)
"""

import argparse
import logging

import numpy as np
from ctapipe.instrument import CameraGeometry
from ctapipe.io.hessio import hessio_event_source
from ctapipe.utils import get_dataset
from ctapipe.visualization import CameraDisplay
from ctapipe.calib import CameraCalibrator
from ctapipe.image import tailcuts_clean, hillas_parameters
from matplotlib import pyplot as plt
from matplotlib.patches import Ellipse
from ctapipe.core import Tool, ToolConfigurationError
from ctapipe.core.traits import *
from ctapipe.io.eventfilereader import EventFileReaderFactory
from tqdm import tqdm

logging.basicConfig(level=logging.DEBUG)
from ctapipe.calib import CameraCalibrator
from ctapipe.core import Tool
from ctapipe.core.traits import *
from ctapipe.image import (tailcuts_clean, hillas_parameters,
HillasParameterizationError)
from ctapipe.instrument import CameraGeometry
from ctapipe.io.eventfilereader import EventFileReaderFactory
from ctapipe.visualization import CameraDisplay


class SingleTelEventDisplay(Tool):
name="ctapipe-display-single-tel"
description=Unicode(__doc__)
name = "ctapipe-display-single-tel"
description = Unicode(__doc__)

infile = Unicode(help="input file to read", default='').tag(config=True)
tel = Int(help='Telescope ID to display', default=0).tag(config=True)
channel = Integer(help="channel number to display", min=0, max=1).tag(config=True)
channel = Integer(help="channel number to display", min=0, max=1).tag(
config=True)
write = Bool(help="Write out images to PNG files", default=False).tag(
config=True)
clean = Bool(help="Apply image cleaning", default=False).tag(config=True)
hillas = Bool(help="Apply and display Hillas parametrization",
hillas = Bool(help="Apply and display Hillas parametrization",
default=False).tag(config=True)
samples =Bool(help="Show each sample", default=False).tag(config=True)
samples = Bool(help="Show each sample", default=False).tag(config=True)
display = Bool(help="Display results in interactive window",
default_value=True).tag(config=True)
delay = Float(help='delay between events in s', default_value=0.01,
min=0.001).tag(config=True)

aliases = Dict({'infile': 'EventFileReaderFactory.input_path',
'tel':'SingleTelEventDisplay.tel',
'tel': 'SingleTelEventDisplay.tel',
'max-events': 'EventFileReaderFactory.max_events',
'channel' : 'SingleTelEventDisplay.channel',
'write' : 'SingleTelEventDisplay.write',
'clean' : 'SingleTelEventDisplay.clean',
'hillas' : 'SingleTelEventDisplay.hillas',
'samples' : 'SingleTelEventDisplay.samples',
'display' : 'SingleTelEventDisplay.display',
'delay' : 'SingleTelEventDisplay.delay'
'channel': 'SingleTelEventDisplay.channel',
'write': 'SingleTelEventDisplay.write',
'clean': 'SingleTelEventDisplay.clean',
'hillas': 'SingleTelEventDisplay.hillas',
'samples': 'SingleTelEventDisplay.samples',
'display': 'SingleTelEventDisplay.display',
'delay': 'SingleTelEventDisplay.delay'
})

classes = List([EventFileReaderFactory, CameraCalibrator])
classes = List([EventFileReaderFactory, CameraCalibrator])

def setup(self):

reader_factory = EventFileReaderFactory(None, self)
reader_class = reader_factory.get_class()
self.reader = reader_class(None,self)
self.reader = reader_class(None, self)

self.calibrator = CameraCalibrator(config=None, tool=self,
origin=self.reader.origin)
self.source = self.reader.read(allowed_tels=[self.tel, ])

self.log.info('SELECTING EVENTS FROM TELESCOPE {}'.format(self.tel))



def start(self):

disp = None
Expand All @@ -102,7 +95,7 @@ def start(self):
plt.show(block=False)

# display the event
disp.axes.set_title('CT{:03d} ({}), event {:010d}'.format(
disp.axes.set_title('CT{:03d} ({}), event {:06d}'.format(
self.tel, geom.cam_id, event.r0.event_id)
)

Expand All @@ -116,7 +109,7 @@ def start(self):
if self.display:
plt.pause(self.delay)
if self.write:
plt.savefig('CT{:03d}_EV{:010d}_S{:02d}.png'
plt.savefig('CT{:03d}_EV{:10d}_S{:02d}.png'
.format(self.tel, event.r0.event_id, ii))
else:
# display integrated event:
Expand All @@ -130,13 +123,17 @@ def start(self):
disp.image = im

if self.hillas:
params = hillas_parameters(pix_x=geom.pix_x,
pix_y=geom.pix_y, image=im)
ellipses = disp.axes.findobj(Ellipse)
if len(ellipses) > 0:
ellipses[0].remove()
disp.overlay_moments(params, color='pink', lw=3,
with_label=False)
try:
ellipses = disp.axes.findobj(Ellipse)
if len(ellipses) > 0:
ellipses[0].remove()

params = hillas_parameters(pix_x=geom.pix_x,
pix_y=geom.pix_y, image=im)
disp.overlay_moments(params, color='pink', lw=3,
with_label=False)
except HillasParameterizationError:
pass

if self.display:
plt.pause(self.delay)
Expand All @@ -156,6 +153,5 @@ def start(self):


if __name__ == '__main__':

tool = SingleTelEventDisplay()
tool.run()

0 comments on commit 8836d67

Please sign in to comment.