Skip to content

Commit

Permalink
fixed ranges of cam-display so they correspond to fixed toymodel sims (
Browse files Browse the repository at this point in the history
…#808)

also added hillas params
  • Loading branch information
kosack authored Oct 23, 2018
1 parent 31f9397 commit a9ff9a6
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions ctapipe/tools/camdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from matplotlib.animation import FuncAnimation

from ctapipe.core import Tool, traits
from ctapipe.image import toymodel, tailcuts_clean, dilate
from ctapipe.image import toymodel, tailcuts_clean, dilate, \
hillas_parameters, HillasParameterizationError
from ctapipe.instrument import TelescopeDescription, CameraGeometry, \
OpticsDescription
from ctapipe.visualization import CameraDisplay
Expand All @@ -22,7 +23,7 @@ class CameraDemo(Tool):
description = "Display fake events in a demo camera"

delay = traits.Int(50, help="Frame delay in ms", min=20).tag(config=True)
cleanframes = traits.Int(100, help="Number of frames between turning on "
cleanframes = traits.Int(20, help="Number of frames between turning on "
"cleaning", min=0).tag(config=True)
autoscale = traits.Bool(False, help='scale each frame to max if '
'True').tag(config=True)
Expand Down Expand Up @@ -77,10 +78,14 @@ def _display_camera_animation(self):

# poor-man's coordinate transform from telscope to camera frame (it's
# better to use ctapipe.coordiantes when they are stable)
scale = tel.optics.equivalent_focal_length.to(geom.pix_x.unit).value
foclen = tel.optics.equivalent_focal_length.to(geom.pix_x.unit).value
fov = np.deg2rad(4.0)
maxwid = np.deg2rad(0.01)
maxlen = np.deg2rad(0.03)
scale = foclen
minwid = np.deg2rad(0.1)
maxwid = np.deg2rad(0.3)
maxlen = np.deg2rad(0.5)

self.log.debug("scale={} m, wid=({}-{})".format(scale, minwid, maxwid))

disp = CameraDisplay(
geom, ax=ax, autoupdate=True,
Expand All @@ -90,20 +95,27 @@ def _display_camera_animation(self):

def update(frame):

self.log.debug("Frame=", frame)

centroid = np.random.uniform(-fov, fov, size=2) * scale
width = np.random.uniform(0, maxwid) * scale
width = np.random.uniform(0, maxwid-minwid) * scale + minwid
length = np.random.uniform(0, maxlen) * scale + width
angle = np.random.uniform(0, 360)
intens = np.random.exponential(2) * 50
intens = np.random.exponential(2) * 500
model = toymodel.generate_2d_shower_model(centroid=centroid,
width=width,
length=length,
psi=angle * u.deg)
image, sig, bg = toymodel.make_toymodel_shower_image(geom,
model.pdf,
intensity=intens,
nsb_level_pe=5000)
self.log.debug(
"Frame=%d width=%03f length=%03f intens=%03d",
frame, width, length, intens
)

image, sig, bg = toymodel.make_toymodel_shower_image(
geom,
model.pdf,
intensity=intens,
nsb_level_pe=3,
)

# alternate between cleaned and raw images
if self._counter == self.cleanframes:
Expand All @@ -113,21 +125,32 @@ def update(frame):
plt.suptitle("Image Cleaning OFF")
self.imclean = False
self._counter = 0
disp.clear_overlays()

if self.imclean:
cleanmask = tailcuts_clean(geom, image / 80.0)
for ii in range(3):
cleanmask = tailcuts_clean(geom, image,
picture_thresh=10.0,
boundary_thresh=5.0)
for ii in range(2):
dilate(geom, cleanmask)
image[cleanmask == 0] = 0 # zero noise pixels

self.log.debug("count = {}, image sum={} max={}"
.format(self._counter, image.sum(), image.max()))
try:
hillas = hillas_parameters(geom, image)
disp.overlay_moments(hillas, with_label=False,
color='red', alpha=0.7,
linewidth=2, linestyle='dashed')
except HillasParameterizationError:
disp.clear_overlays()
pass

self.log.debug("Frame=%d image_sum=%.3f max=%.3f",
self._counter, image.sum(), image.max())
disp.image = image

if self.autoscale:
disp.set_limits_percent(95)
else:
disp.set_limits_minmax(-100, 4000)
disp.set_limits_minmax(-5, 200)

disp.axes.figure.canvas.draw()
self._counter += 1
Expand Down

0 comments on commit a9ff9a6

Please sign in to comment.