11import ctapipe .instrument .camera .readout
22import numpy as np
33from ctapipe .coordinates import EngineeringCameraFrame
4- from ctapipe .image import LocalPeakWindowSum
4+ from ctapipe .image .extractor import FixedWindowSum # noqa: F401
5+ from ctapipe .image .extractor import FullWaveformSum # noqa: F401
6+ from ctapipe .image .extractor import LocalPeakWindowSum # noqa: F401
7+ from ctapipe .image .extractor import NeighborPeakWindowSum # noqa: F401
8+ from ctapipe .image .extractor import SlidingWindowMaxSum # noqa: F401
9+ from ctapipe .image .extractor import TwoPassWindowSum # noqa: F401
10+ from ctapipe .image .extractor import GlobalPeakWindowSum
511from ctapipe .visualization import CameraDisplay
12+ from ctapipe_io_nectarcam import constants
613from matplotlib import pyplot as plt
714from traitlets .config .loader import Config
815
16+ from ..makers .component import ChargesComponent
17+ from ..makers .component .core import ArrayDataComponent
18+ from ..makers .extractor .utils import CtapipeExtractor
919from .dqm_summary_processor import DQMSummary
1020
1121__all__ = ["ChargeIntegrationHighLowGain" ]
@@ -51,7 +61,7 @@ def __init__(self, gaink):
5161 self .ChargeInt_Figures_Dict = {}
5262 self .ChargeInt_Figures_Names_Dict = {}
5363
54- def ConfigureForRun (self , path , Pix , Samp , Reader1 ):
64+ def ConfigureForRun (self , path , Pix , Samp , Reader1 , ** charges_kwargs ):
5565 # define number of pixels and samples
5666 self .Pix = Pix
5767 self .Samp = Samp
@@ -72,44 +82,60 @@ def ConfigureForRun(self, path, Pix, Samp, Reader1):
7282 ].camera .readout = ctapipe .instrument .camera .readout .CameraReadout .from_name (
7383 "NectarCam"
7484 )
75- config = Config ({"LocalPeakWindowSum" : {"window_shift" : 4 , "window_width" : 12 }})
76-
77- self .integrator = LocalPeakWindowSum (subarray , config = config )
85+ if charges_kwargs :
86+ extractor_kwargs = (
87+ ChargesComponent ._get_extractor_kwargs_from_method_and_kwargs (
88+ method = charges_kwargs ["method" ],
89+ kwargs = charges_kwargs ["extractor_kwargs" ],
90+ )
91+ )
92+ self .integrator = eval (charges_kwargs ["method" ])(
93+ subarray , ** extractor_kwargs
94+ )
95+ else :
96+ config = Config (
97+ {"GlobalPeakWindowSum" : {"window_shift" : 4 , "window_width" : 12 }}
98+ )
99+ self .integrator = GlobalPeakWindowSum (subarray , config = config )
78100
79101 def ProcessEvent (self , evt , noped ):
80- self .pixelBAD = evt .mon .tel [0 ].pixel_status .hardware_failing_pixels
81102 pixel = evt .nectarcam .tel [0 ].svc .pixel_ids
82- if len (pixel ) < self .Pix :
83- pixel_masked_shutter = list (
84- np .arange (0 , self .Pix - len (pixel ), 1 , dtype = int )
85- )
86- pixel = list (pixel )
87- pixels = np .concatenate ([pixel_masked_shutter , pixel ])
88- else :
89- pixels = pixel
103+ self .pixelBADplot = evt .mon .tel [0 ].pixel_status .hardware_failing_pixels
104+ pixels = pixel
105+ self .pixels = pixels
90106
91- waveform = evt .r0 .tel [0 ].waveform [self .k ]
107+ (
108+ broken_pixels_hg ,
109+ broken_pixels_lg ,
110+ ) = ArrayDataComponent ._compute_broken_pixels_event (evt , pixels )
111+
112+ if self .k == 0 :
113+ self .pixelBAD = broken_pixels_hg
114+ channel = constants .HIGH_GAIN
115+ if self .k == 1 :
116+ self .pixelBAD = broken_pixels_lg
117+ channel = constants .LOW_GAIN
92118
119+ waveform = evt .r0 .tel [0 ].waveform [self .k ]
120+ waveform = waveform [pixels ]
93121 ped = np .mean (waveform [:, 20 ])
94122
95123 if noped :
96124 w_noped = waveform - ped
97- output = self . integrator (
98- w_noped , 0 , np . zeros ( self . Pix , dtype = int ), self .pixelBAD
125+ output = CtapipeExtractor . get_image_peak_time (
126+ self . integrator ( w_noped , 0 , channel , self .pixelBAD )
99127 )
100- image = output .image
101- peakpos = output .peak_time
102- image = image [pixels ]
103- peakpos = peakpos [pixels ]
128+
129+ image = output [0 ]
130+ peakpos = output [1 ]
104131
105132 else :
106- output = self . integrator (
107- waveform , 0 , np . zeros ( self . Pix , dtype = int ), self .pixelBAD
133+ output = CtapipeExtractor . get_image_peak_time (
134+ self . integrator ( waveform , 0 , channel , self .pixelBAD )
108135 )
109- image = output .image
110- peakpos = output .peak_time
111- image = image [pixels ]
112- peakpos = peakpos [pixels ]
136+
137+ image = output [0 ]
138+ peakpos = output [1 ]
113139
114140 if evt .trigger .event_type .value == 32 : # count peds
115141 self .counter_ped += 1
@@ -274,9 +300,9 @@ def PlotResults(self, name, FigPath):
274300 # Charge integration MEAN plot
275301 if self .counter_evt > 0 :
276302 fig1 , disp = plt .subplots ()
277- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
303+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
278304 # disp = CameraDisplay(self.subarray.tels[0].camera)
279- disp .image = self .image_all_average [ ~ self . pixelBAD [ 0 ]]
305+ disp .image = self .image_all_average
280306 disp .cmap = plt .cm .coolwarm
281307 disp .axes .text (
282308 2 ,
@@ -302,8 +328,8 @@ def PlotResults(self, name, FigPath):
302328
303329 if self .counter_ped > 0 :
304330 fig2 , disp = plt .subplots ()
305- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
306- disp .image = self .image_ped_average [ ~ self . pixelBAD [ 0 ]]
331+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
332+ disp .image = self .image_ped_average
307333 disp .cmap = plt .cm .coolwarm
308334 disp .axes .text (
309335 2 ,
@@ -330,8 +356,8 @@ def PlotResults(self, name, FigPath):
330356 # Charge integration MEDIAN plot
331357 if self .counter_evt > 0 :
332358 fig3 , disp = plt .subplots ()
333- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
334- disp .image = self .image_all_median [ ~ self . pixelBAD [ 0 ]]
359+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
360+ disp .image = self .image_all_median
335361 disp .cmap = plt .cm .coolwarm
336362 disp .axes .text (
337363 2 ,
@@ -357,8 +383,8 @@ def PlotResults(self, name, FigPath):
357383
358384 if self .counter_ped > 0 :
359385 fig4 , disp = plt .subplots ()
360- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
361- disp .image = self .image_ped_median [ ~ self . pixelBAD [ 0 ]]
386+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
387+ disp .image = self .image_ped_median
362388 disp .cmap = plt .cm .coolwarm
363389 disp .axes .text (
364390 2 ,
@@ -385,8 +411,8 @@ def PlotResults(self, name, FigPath):
385411 # Charge integration STD plot
386412 if self .counter_evt > 0 :
387413 fig5 , disp = plt .subplots ()
388- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
389- disp .image = self .image_all_std [ ~ self . pixelBAD [ 0 ]]
414+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
415+ disp .image = self .image_all_std
390416 disp .cmap = plt .cm .coolwarm
391417 disp .axes .text (
392418 2 ,
@@ -412,8 +438,8 @@ def PlotResults(self, name, FigPath):
412438
413439 if self .counter_ped > 0 :
414440 fig6 , disp = plt .subplots ()
415- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
416- disp .image = self .image_ped_std [ ~ self . pixelBAD [ 0 ]]
441+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
442+ disp .image = self .image_ped_std
417443 disp .cmap = plt .cm .coolwarm
418444 disp .axes .text (
419445 2 ,
@@ -440,8 +466,8 @@ def PlotResults(self, name, FigPath):
440466 # Charge integration RMS plot
441467 if self .counter_evt > 0 :
442468 fig7 , disp = plt .subplots ()
443- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
444- disp .image = self .image_all_rms [ ~ self . pixelBAD [ 0 ]]
469+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
470+ disp .image = self .image_all_rms
445471 disp .cmap = plt .cm .coolwarm
446472 disp .axes .text (
447473 2 ,
@@ -467,8 +493,8 @@ def PlotResults(self, name, FigPath):
467493
468494 if self .counter_ped > 0 :
469495 fig8 , disp = plt .subplots ()
470- disp = CameraDisplay (self .camera [~ self .pixelBAD [0 ]])
471- disp .image = self .image_ped_rms [ ~ self . pixelBAD [ 0 ]]
496+ disp = CameraDisplay (self .camera [~ self .pixelBADplot [0 ]])
497+ disp .image = self .image_ped_rms
472498 disp .cmap = plt .cm .coolwarm
473499 disp .axes .text (
474500 2 ,
@@ -495,7 +521,7 @@ def PlotResults(self, name, FigPath):
495521 # Charge integration SPECTRUM
496522 if self .counter_evt > 0 :
497523 fig9 , disp = plt .subplots ()
498- for i in range (self .Pix ):
524+ for i in range (len ( self .pixels ) ):
499525 plt .hist (
500526 self .image_all [:, i ],
501527 100 ,
@@ -532,7 +558,7 @@ def PlotResults(self, name, FigPath):
532558
533559 if self .counter_ped > 0 :
534560 fig10 , disp = plt .subplots ()
535- for i in range (self .Pix ):
561+ for i in range (len ( self .pixels ) ):
536562 plt .hist (
537563 self .image_ped [:, i ],
538564 100 ,
0 commit comments