Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
plt.suptitle("EVENT {} {:.1e} TeV @({:.1f},{:.1f})deg @{:.1f} m".format(
event.r0.event_id, event.mc.energy,
event.mc.alt, event.mc.az,
np.sqrt(pow(event.mc.core_x, 2) +
pow(event.mc.core_y, 2))))
print("\t draw cam {} (gains={})...".format(tel_id,nchan))
ax=[]
disp=[]
signals=[]
npads=0
for i in range(nchan):
npads += 1
# Display the camera charge (HG/LG)
ax.append(plt.subplot(nchan, 2, npads))
disp.append(visualization.CameraDisplay(geom, ax=ax[-1],
title="CT{} [{} ADC cts]".format(tel_id,gain_label[i])))
disp[-1].pixels.set_antialiaseds(False)
signals.append(event.r0.tel[tel_id].adc_sums[i])
disp[-1].image = signals[-1]
disp[-1].pixels.set_cmap(get_cmap(disp[-1].image))
disp[-1].add_colorbar(label=" [{} ADC cts]".format(gain_label[i]))
# Display the camera charge for significant pixels (HG/LG)
npads += 1
ax.append(plt.subplot(nchan, 2, npads))
disp.append(visualization.CameraDisplay(geom, ax=ax[-1],
title="CT{} [{} ADC cts]".format(tel_id,gain_label[i])))
disp[-1].pixels.set_antialiaseds(False)
signals.append(event.r0.tel[tel_id].adc_sums[i])
m = (get_zero_sup_mode(tel_id) & 0x001) or (get_significant(tel_id) & 0x020)
disp[-1].image = signals[-1]*(m/m.max())
from time import sleep
from ctapipe.core import Component
class ListTelsWithData(Component):
"""`ListTelsWithData` class represents a Stage for pipeline.
It receives a hessio event and return a list containing
telescope id of triggered telescopes for this event.
"""
def init(self):
self.log.info("--- ListTelsWithData init ---")
def run(self, event):
if event is not None:
res = list(event.dl0.tels_with_data)
yield((res,event))
def finish(self):
self.log.info("--- ListTelsWithData finish ---")
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# coding: utf8
import zmq
from multiprocessing import Process
from multiprocessing import Value
from pickle import loads
from ctapipe.core import Component
class ConsumerZMQ(Process, Component):
"""`ConsumerZMQ` class represents a Consumer pipeline Step.
It is derived from Process class. It receives
new input from its prev stage, thanks to its ZMQ REQ socket,
and executes its coroutine objet's run method by passing
input as parameter.
The processus is launched by calling run method.
init() method is call by run method.
The processus is stopped by setting share data stop to True
"""
def __init__(
self, coroutine, sock_consumer_port, _name=""):
"""
Parameters
----------
coroutine : Class instance that contains init, run and finish methods
sock_consumer_port: str
from ctapipe.core import Component
from ctapipe.plotting.camera import CameraPlotter
import numpy as np
from matplotlib import colors
from matplotlib import pyplot as plt
class PrepareDisplayStep(Component):
"""PrepareDisplayStep` class represents a Stage for pipeline.
it prepares Display for the next stage
This stage is time comsuming, so in multiprocess mode you should
activate several process for it i.e.("nb_process" : 4)
"""
def init(self):
self.log.debug("--- PrepareDisplayStep init ---")
self.fig = plt.figure(figsize=(16, 7))
return True
def run(self, inputs):
self.log.debug("--- PrepareDisplayStep RUN ---")
calibrated_event, geom_dict = inputs
for tel_id in calibrated_event.dl0.tels_with_data:
self.fig.clear()
from ctapipe.utils.datasets import get_path
import ctapipe.instrument.InstrumentDescription as ID
from ctapipe.core import Component
from traitlets import Unicode
from time import sleep
class LSTDump(Component):
"""LSTDump` class represents a Stage for pipeline.
it dumps RawCameraData contents to a string
"""
def init(self):
self.log.info("--- LSTDump init ---")
return True
def run(self, raw_camera_data):
if raw_camera_data != None:
self.log.debug("LSTDump receive {}".format(raw_camera_data))
return('LSTDump START-> {} <- LSTDump END'.format(str(raw_camera_data)))
def finish(self):
self.log.info("--- LSTDump finish ---")
self.log.error(f"{err}. Use --help for more info")
exit_status = 2 # wrong cmd line parameter
except KeyboardInterrupt:
self.log.warning("WAS INTERRUPTED BY CTRL-C")
Provenance().finish_activity(activity_name=self.name, status="interrupted")
exit_status = 130 # Script terminated by Control-C
except Exception as err:
self.log.exception(f"Caught unexpected exception: {err}")
Provenance().finish_activity(activity_name=self.name, status="error")
exit_status = 1 # any other error
finally:
for activity in Provenance().finished_activities:
output_str = " ".join([x["url"] for x in activity.output])
self.log.info("Output: %s", output_str)
self.log.debug("PROVENANCE: '%s'", Provenance().as_json(indent=3))
with open("provenance.log", mode="w+") as provlog:
provlog.write(Provenance().as_json(indent=3))
self.exit(exit_status)
"Minimum number of pixels after cleaning and ring finding"
"required to process an event"
),
default_value=100,
).tag(config=True)
pedestal = traits.FloatTelescopeParameter(
help="Pedestal noise rms", default_value=1.1,
).tag(config=True)
extractor_name = traits.create_class_enum_trait(
ImageExtractor, default_value="GlobalPeakWindowSum",
).tag(config=True)
classes = [
CameraCalibrator,
TailcutsImageCleaner,
EventSource,
MuonRingFitter,
MuonIntensityFitter,
] + traits.classes_with_traits(ImageExtractor)
aliases = {
"i": "EventSource.input_url",
"input": "EventSource.input_url",
"o": "MuonAnalysis.output",
"output": "MuonAnalysis.output",
"max-events": "EventSource.max_events",
"allowed-tels": "EventSource.allowed_tels",
}
flags = {
name = "ctapipe-display-integration"
description = __doc__
event_index = Int(0, help="Event index to view.").tag(config=True)
use_event_id = Bool(
False, help="event_index will obtain an event using event_id instead of index.",
).tag(config=True)
telescope = Int(
None,
allow_none=True,
help="Telescope to view. Set to None to display the first"
"telescope with data.",
).tag(config=True)
channel = Enum([0, 1], 0, help="Channel to view").tag(config=True)
extractor_product = traits.create_class_enum_trait(
ImageExtractor, default_value="NeighborPeakWindowSum"
)
aliases = Dict(
dict(
f="EventSource.input_url",
max_events="EventSource.max_events",
extractor="DisplayIntegrator.extractor_product",
E="DisplayIntegrator.event_index",
T="DisplayIntegrator.telescope",
C="DisplayIntegrator.channel",
)
)
flags = Dict(
dict(
id=(
).tag(config=True)
extractor_product = traits.create_class_enum_trait(
ImageExtractor, default_value="NeighborPeakWindowSum"
)
aliases = Dict(
dict(
f="SimTelEventSource.input_url",
max_events="SimTelEventSource.max_events",
T="SimTelEventSource.allowed_tels",
extractor="ChargeResolutionGenerator.extractor_product",
O="ChargeResolutionGenerator.output_path",
)
)
classes = List([SimTelEventSource] + traits.classes_with_traits(ImageExtractor))
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.eventsource = None
self.calibrator = None
self.calculator = None
def setup(self):
self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
self.eventsource = self.add_component(SimTelEventSource(parent=self))
extractor = self.add_component(
ImageExtractor.from_name(
self.extractor_product, parent=self, subarray=self.eventsource.subarray,
)
"simulation and store within a HDF5 file."
)
telescopes = List(
Int(),
None,
allow_none=True,
help="Telescopes to include from the event file. Default = All telescopes",
).tag(config=True)
output_path = Path(
default_value="charge_resolution.h5",
directory_ok=False,
help="Path to store the output HDF5 file",
).tag(config=True)
extractor_product = traits.create_class_enum_trait(
ImageExtractor, default_value="NeighborPeakWindowSum"
)
aliases = Dict(
dict(
f="SimTelEventSource.input_url",
max_events="SimTelEventSource.max_events",
T="SimTelEventSource.allowed_tels",
extractor="ChargeResolutionGenerator.extractor_product",
O="ChargeResolutionGenerator.output_path",
)
)
classes = List([SimTelEventSource] + traits.classes_with_traits(ImageExtractor))
def __init__(self, **kwargs):
super().__init__(**kwargs)