Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel participation #81

Merged
merged 9 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/nectarchain/dqm/dqm_summary_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def PlotResults(
def WriteAllResults(self, path, DICT):
data2 = Table()
data1 = Table()
data0 = Table()
data = Table()
hdu, hdu1, hdu2 = None, None, None
hdulist = fits.HDUList()
for i, j in DICT.items():
if i == "Results_TriggerStatistics":
if (i == "Results_TriggerStatistics"):
for n2, m2 in j.items():
data2[n2] = m2
hdu2 = fits.BinTableHDU(data2)
Expand All @@ -52,7 +53,13 @@ def WriteAllResults(self, path, DICT):
for n1, m1 in j.items():
data1[n1] = m1
hdu1 = fits.BinTableHDU(data1)
hdu1.name = "MWF"
hdu1.name = "MWF"

elif (i == "Results_PixelTimeline_HighGain") or (i == "Results_PixelTimeline_LowGain"):
for n0, m0 in j.items():
data0[n0] = m0
hdu0 = fits.BinTableHDU(data0)
hdu0.name = "BPX"

else:
for n, m in j.items():
Expand All @@ -67,11 +74,25 @@ def WriteAllResults(self, path, DICT):
hdulist.append(hdu1)
else:
print("No MWF studies requests")
<<<<<<< HEAD
if hdu:
jlenain marked this conversation as resolved.
Show resolved Hide resolved
=======
try:
hdulist.append(hdu0)
except:
print("No Pixel Timeline studies requests")
try:
>>>>>>> cc29b1f (Adding BPX timeline module)
hdulist.append(hdu)
else:
print("No Camera studies requests")
<<<<<<< HEAD
FileName = path + "_Results.fits"
=======


FileName = path + '_Results.fits'
>>>>>>> cc29b1f (Adding BPX timeline module)
print(FileName)
hdulist.writeto(FileName, overwrite=True)
return None
148 changes: 148 additions & 0 deletions src/nectarchain/dqm/pixel_participation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
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
jlenain marked this conversation as resolved.
Show resolved Hide resolved

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

self.counter_evt = 0
self.counter_ped = 0

self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())
jlenain marked this conversation as resolved.
Show resolved Hide resolved
self.camera2 = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())

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


self.BadPixels_ped = np.zeros(self.Pix)
jlenain marked this conversation as resolved.
Show resolved Hide resolved
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[pixels]))
self.BadPixels_ped += BadPixels_ped1

else:
self.counter_evt += 1
BadPixels1 = list(map(int, pixelBAD[pixels]))
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):
jlenain marked this conversation as resolved.
Show resolved Hide resolved
# 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()
jlenain marked this conversation as resolved.
Show resolved Hide resolved
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,
)
155 changes: 155 additions & 0 deletions src/nectarchain/dqm/pixel_timeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
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 PixelTimeline_HighLowGain(dqm_summary):
def __init__(self, gaink):
self.k = gaink
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__init__ should not return anything.


def ConfigureForRun(self, path, Pix, Samp, Reader1):
# define number of pixels and samples
self.Pix = Pix
jlenain marked this conversation as resolved.
Show resolved Hide resolved
jlenain marked this conversation as resolved.
Show resolved Hide resolved
self.Samp = Samp


self.counter_evt = 0
jlenain marked this conversation as resolved.
Show resolved Hide resolved
self.counter_ped = 0

self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())
jlenain marked this conversation as resolved.
Show resolved Hide resolved
self.camera2 = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())

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


self.SumBadPixels_ped = []
self.SumBadPixels = []

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
self.counter_evt += 1
BadPixels_ped1 = list(map(int, pixelBAD[pixels]))
SumBadPixelsEvent_ped = sum(BadPixels_ped1)
self.SumBadPixels_ped.append(SumBadPixelsEvent_ped)
self.SumBadPixels.append(0)

else:
self.counter_evt += 1
self.counter_ped += 1
BadPixels1 = list(map(int, pixelBAD[pixels]))
SumBadPixelsEvent = sum(BadPixels1)
self.SumBadPixels.append(SumBadPixelsEvent)
self.SumBadPixels_ped.append(0)

return None

def FinishRun(self):

self.BadPixelTimeline_ped = np.array(self.SumBadPixels_ped, dtype=float)/self.Pix
self.BadPixelTimeline = np.array(self.SumBadPixels, dtype=float)/self.Pix
print(self.BadPixelTimeline)
print( self.BadPixelTimeline_ped)




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

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

if self.counter_evt > 0:
self.PixelTimeline_Results_Dict[
"CAMERA-BadPixTimeline-PHY-HIGH-GAIN"
] = self.BadPixelTimeline


if self.counter_ped > 0:
self.PixelTimeline_Results_Dict[
"CAMERA-BadPixTimeline-PED-HIGH-GAIN"
] = self.BadPixelTimeline_ped


if self.k == 1:
if self.counter_evt > 0:
self.PixelTimeline_Results_Dict[
"CAMERA-BadPixTimeline-PHY-LOW-GAIN"
] = self.BadPixelTimeline

if self.counter_ped > 0:
self.PixelTimeline_Results_Dict[
"CAMERA-BadPixTimeline-PED-LOW-GAIN"
] = self.BadPixelTimeline_ped


return self.PixelTimeline_Results_Dict

def PlotResults(self, name, FigPath):
self.PixelTimeline_Figures_Dict = {}
self.PixelTimeline_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, disp = plt.subplots()
plt.plot(np.arange(self.counter_evt), self.BadPixelTimeline*100, label = "Physical events")
plt.legend()
plt.xlabel("Timeline")
plt.ylabel("BPX fraction (%)")
plt.title("BPX Timeline %s gain (ALL)" % gain_c)

full_name = name + "_BPX_Timeline_%sGain_All.png" % gain_c
FullPath = FigPath + full_name
self.PixelTimeline_Figures_Dict[
"BPX-TIMELINE-ALL-%s-GAIN" % gain_c
] = fig1
self.PixelTimeline_Figures_Names_Dict[
"BPX-TIMELINE-ALL-%s-GAIN" % gain_c
] = FullPath

plt.close()

if self.counter_ped > 0:
fig2, disp = plt.subplots()
plt.plot(np.arange(self.counter_ped), self.BadPixelTimeline_ped*100, label = "Pedestal events")
plt.legend()
plt.xlabel("Timeline")
plt.ylabel("BPX fraction (%)")
plt.title("BPX Timeline %s gain (PED)" % gain_c)

full_name = name + "_BPX_Timeline_%sGain_Ped.png" % gain_c
FullPath = FigPath + full_name
self.PixelTimeline_Figures_Dict[
"BPX-TIMELINE-PED-%s-GAIN" % gain_c
] = fig2
self.PixelTimeline_Figures_Names_Dict[
"BPX-TIMELINE-PED-%s-GAIN" % gain_c
] = FullPath

plt.close()

return (
self.PixelTimeline_Figures_Dict,
self.PixelTimeline_Figures_Names_Dict,
)
Loading