Skip to content

Commit

Permalink
rebase:a new class: pixel_participation
Browse files Browse the repository at this point in the history
  • Loading branch information
hashkar committed Oct 31, 2023
1 parent 12a5cc7 commit e9f72e1
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
152 changes: 152 additions & 0 deletions src/nectarchain/dqm/pixel_participation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
from dqm_summary_processor import dqm_summary
from matplotlib import pyplot as plt
from ctapipe.visualization import CameraDisplay
from ctapipe.instrument import CameraGeometry
from ctapipe.coordinates import EngineeringCameraFrame
import numpy as np


class PixelParticipation_HighLowGain(dqm_summary):
def __init__(self, gaink):
self.k = gaink
return None

def ConfigureForRun(self, path, Pix, Samp, Reader1):
# define number of pixels and samples
self.Pix = Pix
self.Samp = Samp

self.CameraAverage = np.zeros(self.Pix)
self.CameraAverage_ped = np.zeros(self.Pix)
self.counter_evt = 0
self.counter_ped = 0

self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())
self.camera2 = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())

self.cmap = "gnuplot2"
self.cmap2 = "gnuplot2"

self.CameraAverage = []
self.CameraAverage_ped = []

self.BadPixels_ped = np.zeros(self.Pix)
self.BadPixels = np.zeros(self.Pix)

def ProcessEvent(self, evt, noped):
pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels[self.k]
pixel = evt.nectarcam.tel[0].svc.pixel_ids
if len(pixel) < self.Pix:
pixel21 = list(np.arange(0, self.Pix - len(pixel), 1, dtype=int))
pixel = list(pixel)
pixels = np.concatenate([pixel21, pixel])
else:
pixels = pixel

if evt.trigger.event_type.value == 32: # count peds
self.counter_ped += 1
BadPixels_ped1 = list(map(int, pixelBAD))
self.BadPixels_ped += BadPixels_ped1

else:
self.counter_evt += 1
BadPixels1 = list(map(int, pixelBAD))
self.BadPixels += BadPixels1
return None

def FinishRun(self):
self.BadPixels_ped = np.array(self.BadPixels_ped)
self.BadPixels = np.array(self.BadPixels)



def GetResults(self):
# INITIATE DICT
self.PixelParticipation_Results_Dict = {}

# ASSIGN RESUTLS TO DICT
if self.k == 0:

if self.counter_evt > 0:
self.PixelParticipation_Results_Dict[
"CAMERA-BadPix-PHY-OverEVENTS-HIGH-GAIN"
] = self.BadPixels

if self.counter_ped > 0:
self.PixelParticipation_Results_Dict[
"CAMERA-BadPix-PED-PHY-OverEVENTS-HIGH-GAIN"
] = self.BadPixels_ped

if self.k == 1:
if self.counter_evt > 0:
self.PixelParticipation_Results_Dict[
"CAMERA-BadPix-PHY-OverEVENTS-LOW-GAIN"
] = self.BadPixels

if self.counter_ped > 0:
self.PixelParticipation_Results_Dict[
"CAMERA-BadPix-PED-PHY-OverEVENTS-LOW-GAIN"
] = self.BadPixels_ped

return self.PixelParticipation_Results_Dict

def PlotResults(self, name, FigPath):
self.PixelParticipation_Figures_Dict = {}
self.PixelParticipation_Figures_Names_Dict = {}

# titles = ['All', 'Pedestals']
if self.k == 0:
gain_c = "High"
if self.k == 1:
gain_c = "Low"

if self.counter_evt > 0:
fig1, self.disp1 = plt.subplots()
self.disp1 = CameraDisplay(
geometry=self.camera,
image=self.BadPixels,
cmap=self.cmap,
)
self.disp1.cmap = self.cmap
self.disp1.cmap = plt.cm.coolwarm
self.disp1.add_colorbar()
self.disp1.axes.text(2.0, 0, "Bad Pixels", rotation=90)
plt.title("Camera BPX %s gain (ALL)" % gain_c)

self.PixelParticipation_Figures_Dict[
"CAMERA-BADPIX-PHY-DISPLAY-%s-GAIN" % gain_c
] = fig1
full_name = name + "_Camera_BPX_%sGain.png" % gain_c
FullPath = FigPath + full_name
self.PixelParticipation_Figures_Names_Dict[
"CAMERA-BADPIX-PHY-DISPLAY-%s-GAIN" % gain_c
] = FullPath
plt.close()

if self.counter_ped > 0:
fig2, self.disp2 = plt.subplots()
self.disp2 = CameraDisplay(
geometry=self.camera2,
image=self.BadPixels_ped,
cmap=self.cmap2,
)
self.disp2.cmap = self.cmap2
self.disp2.cmap = plt.cm.coolwarm
self.disp2.add_colorbar()
self.disp2.axes.text(2.0, 0, "Bad Pixels", rotation=90)
plt.title("Camera BPX %s gain (PED)" % gain_c)

self.PixelParticipation_Figures_Dict[
"CAMERA-BADPIX-PED-DISPLAY-%s-GAIN" % gain_c
] = fig2
full_name = name + "_Pedestal_BPX_%sGain.png" % gain_c
FullPath = FigPath + full_name
self.PixelParticipation_Figures_Names_Dict[
"CAMERA-BADPIX-PED-DISPLAY-%s-GAIN" % gain_c
] = FullPath
plt.close()

return (
self.PixelParticipation_Figures_Dict,
self.PixelParticipation_Figures_Names_Dict,
)
13 changes: 13 additions & 0 deletions src/nectarchain/dqm/start_dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import time

from camera_monitoring import CameraMonitoring
<<<<<<< HEAD:src/nectarchain/dqm/start_dqm.py
from charge_integration import ChargeIntegrationHighLowGain
from ctapipe.io import EventSeeker, EventSource
from ctapipe_io_nectarcam.constants import HIGH_GAIN, LOW_GAIN
=======
from pixel_participation import PixelParticipation_HighLowGain

>>>>>>> b92cee1 (Adding a new class: pixel_participation):src/nectarchain/dqm/start_calib.py
from db_utils import DQMDB
from matplotlib import pyplot as plt
from mean_camera_display import MeanCameraDisplay_HighLowGain
Expand Down Expand Up @@ -126,6 +131,8 @@ def CreateFigFolder(name, type):
f = ChargeIntegrationHighLowGain(HIGH_GAIN)
g = ChargeIntegrationHighLowGain(LOW_GAIN)
h = CameraMonitoring(HIGH_GAIN)
e = PixelParticipation_HighLowGain(HIGH_GAIN)
f = PixelParticipation_HighLowGain(LOW_GAIN)

processors = list()

Expand All @@ -137,6 +144,8 @@ def CreateFigFolder(name, type):
processors.append(f)
processors.append(g)
processors.append(h)
processors.append(e)
processors.append(f)


# LIST OF DICT RESULTS
Expand All @@ -148,6 +157,8 @@ def CreateFigFolder(name, type):
Results_ChargeIntegration_LowGain = {}
Results_TriggerStatistics = {}
Results_CameraMonitoring = {}
Results_PixelParticipation_HighGain = {}
Results_PixelParticipation_LowGain = {}

NESTED_DICT = {} # The final results dictionary
NESTED_DICT_KEYS = [
Expand All @@ -159,6 +170,8 @@ def CreateFigFolder(name, type):
"Results_ChargeIntegration_HighGain",
"Results_ChargeIntegration_LowGain",
"Results_CameraMonitoring",
"Results_PixelParticipation_HighGain",
"Results_PixelParticipation_LowGain",
]
# NESTED_DICT_KEYS = ["Results_CameraMonitoring"]

Expand Down

0 comments on commit e9f72e1

Please sign in to comment.