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

DQM: Adding protections for runs with 21 masked pixels (due to shutter) #63

Closed
wants to merge 11 commits into from
52 changes: 22 additions & 30 deletions src/nectarchain/dqm/camera_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
self.k = gaink
return None

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

Check warning on line 16 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L16

Added line #L16 was not covered by tests
# define number of pixels and samples
self.Pix = Pix

Check warning on line 18 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L18

Added line #L18 was not covered by tests
self.Samp = Samp

self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())#CameraGeometry.from_name("NectarCam", 3)
self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())

Check warning on line 21 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L21

Added line #L21 was not covered by tests
self.cmap = "gnuplot2"

self.subarray = Reader1.subarray
Expand All @@ -29,7 +29,7 @@
for i, evt1 in enumerate(Reader1):
self.run_start1 = evt1.nectarcam.tel[0].svc.date

SqlFileDate = (astropytime.Time(self.run_start1, format="unix").iso).split(" ")[
SqlFileDate = astropytime.Time(self.run_start1, format="unix").iso.split(" ")[

Check warning on line 32 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L32

Added line #L32 was not covered by tests
0
]

Expand All @@ -42,18 +42,17 @@
con = sqlite3.connect(SqlFileName)
cursor = con.cursor()
try:
#print(cursor.fetchall())
# print(cursor.fetchall())
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
TempData=cursor.execute('''SELECT * FROM monitoring_drawer_temperatures''')
#print(TempData.description)
TempData = cursor.execute('''SELECT * FROM monitoring_drawer_temperatures''')

Check warning on line 47 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L47

Added line #L47 was not covered by tests
# print(TempData.description)
self.DrawerTemp = cursor.fetchall()
cursor.close()

except sqlite3.Error as err:
print("Error Code: ", err)
print("DRAWER TEMPERATURE COULD NOT BE RETRIEVED!")


def ProcessEvent(self, evt, noped):
trigger_time = evt.trigger.time.value
trigger_id = evt.index.event_id
Expand All @@ -71,15 +70,14 @@
self.run_end = np.max(self.event_times) + 100

self.DrawerTemp = np.array(self.DrawerTemp)
self.DrawerTimes = np.array(self.DrawerTemp[:,3])
self.DrawerTimes = np.array(self.DrawerTemp[:, 3])

Check warning on line 73 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L73

Added line #L73 was not covered by tests

for i in range(len(self.DrawerTimes)):
self.DrawerTimes[i] = astropytime.Time(self.DrawerTimes[i], format = 'iso').unix


self.DrawerTemp11 = self.DrawerTemp[:,4][self.DrawerTimes > self.run_start]
self.DrawerTemp21 = self.DrawerTemp[:,5][self.DrawerTimes > self.run_start]
self.DrawerNum1 = self.DrawerTemp[:,2][self.DrawerTimes > self.run_start]
self.DrawerTimes[i] = astropytime.Time(self.DrawerTimes[i], format='iso').unix

Check warning on line 76 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L76

Added line #L76 was not covered by tests

self.DrawerTemp11 = self.DrawerTemp[:, 4][self.DrawerTimes > self.run_start]
self.DrawerTemp21 = self.DrawerTemp[:, 5][self.DrawerTimes > self.run_start]
self.DrawerNum1 = self.DrawerTemp[:, 2][self.DrawerTimes > self.run_start]

Check warning on line 80 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L78-L80

Added lines #L78 - L80 were not covered by tests

self.DrawerTimes_new = self.DrawerTimes[self.DrawerTimes > self.run_start]

Expand All @@ -103,7 +101,6 @@
print("Error Code: ", err)
print("DRAWER TEMPERATURE COULD NOT BE RETRIEVED!")


def GetResults(self):
self.CameraMonitoring_Results_Dict = {}
try:
Expand All @@ -124,49 +121,44 @@
disp = CameraDisplay(self.camera)
disp.image = self.DrawerTemp_mean
disp.cmap = plt.cm.coolwarm
disp.axes.text(1.8, -0.3, 'Temperature', fontsize=12,rotation=90)
disp.axes.text(1.8, -0.3, 'Temperature', fontsize=12, rotation=90)

Check warning on line 124 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L124

Added line #L124 was not covered by tests
disp.add_colorbar()
plt.title("Camera temperature average")
full_name = name + '_CameraTemperature_Mean.png'
FullPath = FigPath +full_name
FullPath = FigPath + '/' + full_name

Check warning on line 128 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L128

Added line #L128 was not covered by tests
self.ChargeInt_Figures_Dict["CAMERA-TEMPERATURE-IMAGE-AVERAGE"] = fig
self.ChargeInt_Figures_Names_Dict["CAMERA-TEMPERATURE-IMAGE-AVERAGE"] = FullPath

plt.close()




fig1, disp = plt.subplots()
disp = CameraDisplay(self.camera)
disp.image = self.DrawerTemp1_mean
disp.cmap = plt.cm.coolwarm
disp.axes.text(1.8, -0.3, 'Temperature 1', fontsize=12,rotation=90)
disp.axes.text(1.8, -0.3, 'Temperature 1', fontsize=12, rotation=90)

Check warning on line 138 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L138

Added line #L138 was not covered by tests
disp.add_colorbar()
plt.title("Camera temperature average 1")
full_name = name + '_CameraTemperature_average1.png'
FullPath = FigPath +full_name
FullPath = FigPath + '/' + full_name

Check warning on line 142 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L142

Added line #L142 was not covered by tests
self.ChargeInt_Figures_Dict["CAMERA-TEMPERATURE-IMAGE-AVERAGE-1"] = fig1
self.ChargeInt_Figures_Names_Dict["CAMERA-TEMPERATURE-IMAGE-AVERAGE-1"] = FullPath

plt.close()




fig2, disp = plt.subplots()
disp = CameraDisplay(self.camera)
disp.image = self.DrawerTemp2_mean
disp.cmap = plt.cm.coolwarm
disp.axes.text(1.8, -0.3, 'Temperature 2', fontsize=12,rotation=90)
disp.axes.text(1.8, -0.3, 'Temperature 2', fontsize=12, rotation=90)

Check warning on line 152 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L152

Added line #L152 was not covered by tests
disp.add_colorbar()
plt.title("Camera temperature average 2")
full_name = name + '_CameraTemperature_average2.png'
FullPath = FigPath +full_name
FullPath = FigPath + '/' + full_name

Check warning on line 156 in src/nectarchain/dqm/camera_monitoring.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/camera_monitoring.py#L156

Added line #L156 was not covered by tests
self.ChargeInt_Figures_Dict["CAMERA-TEMPERATURE-IMAGE-AVERAGE-2"] = fig2
self.ChargeInt_Figures_Names_Dict["CAMERA-TEMPERATURE-IMAGE-AVERAGE-2"] = FullPath

plt.close()


except Exception as err:
print("Error Code: ", err)

Expand Down
28 changes: 13 additions & 15 deletions src/nectarchain/dqm/charge_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
self.k = gaink
return None

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

Check warning on line 17 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L17

Added line #L17 was not covered by tests
# define number of pixels and samples
self.Pix = Pix

Check warning on line 19 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L19

Added line #L19 was not covered by tests
self.Samp = Samp

self.counter_evt = 0
self.counter_ped = 0

self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())#CameraGeometry.from_name("NectarCam", 3)
self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame())

Check warning on line 25 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L25

Added line #L25 was not covered by tests
self.cmap = "gnuplot2"

# reader1=EventSource(input_url=path, max_events = 1)
Expand All @@ -45,19 +45,17 @@
self.image_ped = []
self.peakpos_ped = []




def ProcessEvent(self, evt, noped):
#print("test", evt.r0.tel[0].waveform[0])
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
pixel = evt.nectarcam.tel[0].svc.pixel_ids
pixel21 = np.arange(0, 21, 1, dtype=int)
pixel = list(pixel)
pixel21 = list(pixel21)
pixels = np.concatenate([pixel21, pixel])
if len(pixel) < self.Pix:
pixel_masked_shutter = list(np.arange(0, self.Pix - len(pixel), 1, dtype=int))
pixel = list(pixel)
pixels = np.concatenate([pixel_masked_shutter, pixel])

Check warning on line 54 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L51-L54

Added lines #L51 - L54 were not covered by tests
else:
pixels = pixel

Check warning on line 56 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L56

Added line #L56 was not covered by tests

waveform=evt.r0.tel[0].waveform[self.k]
waveform = evt.r0.tel[0].waveform[self.k]

Check warning on line 58 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L58

Added line #L58 was not covered by tests

if noped:
ped = np.mean(waveform[:, 20])
Expand Down Expand Up @@ -398,7 +396,7 @@
# Charge integration SPECTRUM
if self.counter_evt > 0:
fig9, disp = plt.subplots()
for i in range(self.Chan):
for i in range(self.Pix):

Check warning on line 399 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L399

Added line #L399 was not covered by tests
plt.hist(
self.image_all[:, i],
100,
Expand Down Expand Up @@ -435,7 +433,7 @@

if self.counter_ped > 0:
fig10, disp = plt.subplots()
for i in range(self.Chan):
for i in range(self.Pix):

Check warning on line 436 in src/nectarchain/dqm/charge_integration.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L436

Added line #L436 was not covered by tests
plt.hist(
self.image_ped[:, i],
100,
Expand Down
42 changes: 5 additions & 37 deletions src/nectarchain/dqm/dqm_summary_processor.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import pickle

import os
import sys


#from ctapipe.io import event_source
import sys

from matplotlib import pyplot as plt
import numpy as np
from scipy.stats import norm
from traitlets.config.loader import Config
from astropy.io import fits
from astropy.table import Table

# ctapipe modules
from ctapipe import utils
from ctapipe.visualization import CameraDisplay
#from ctapipe.plotting.camera import CameraPlotter
from ctapipe.image.extractor import *
from ctapipe.io import EventSeeker
from ctapipe.instrument import CameraGeometry
from ctapipe.coordinates import EngineeringCameraFrame

from ctapipe.io.hdf5tableio import HDF5TableWriter, HDF5TableReader

from ctapipe.io import EventSource
import ctapipe.instrument.camera.readout
from ctapipe_io_nectarcam.constants import LOW_GAIN, HIGH_GAIN

from astropy import time as astropytime

class dqm_summary:
def __init__(self):
Expand All @@ -39,9 +10,9 @@
for i, evt1 in enumerate(reader1):
self.FirstReader = reader1
self.Samp = len(evt1.r0.tel[0].waveform[0][0])
self.Chan = len(evt1.r0.tel[0].waveform[0])
self.Pix = len(evt1.r0.tel[0].waveform[0])

Check warning on line 13 in src/nectarchain/dqm/dqm_summary_processor.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/dqm_summary_processor.py#L13

Added line #L13 was not covered by tests

return self.Chan, self.Samp
return self.Pix, self.Samp

Check warning on line 15 in src/nectarchain/dqm/dqm_summary_processor.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/dqm_summary_processor.py#L15

Added line #L15 was not covered by tests

def ConfigureForRun(self):
print("Processor 1")
Expand All @@ -56,12 +27,11 @@
print("Processor 4")

def PlotResults(
self, name, FigPath, k, M, M_ped, Mean_M_overChan, Mean_M_ped_overChan
self, name, FigPath, k, M, M_ped, Mean_M_overPix, Mean_M_ped_overPix
):
print("Processor 5")


def WriteAllResults(self,path, DICT):
def WriteAllResults(self, path, DICT):

Check warning on line 34 in src/nectarchain/dqm/dqm_summary_processor.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/dqm_summary_processor.py#L34

Added line #L34 was not covered by tests
data2 = Table()
data1 = Table()
data = Table()
Expand All @@ -72,15 +42,13 @@
data2[n2] = m2
hdu2 = fits.BinTableHDU(data2)
hdu2.name = "Trigger"


elif ((i == "Results_MeanWaveForms_HighGain") or (i == "Results_MeanWaveForms_LowGain")):
elif (i == "Results_MeanWaveForms_HighGain") or (i == "Results_MeanWaveForms_LowGain"):

Check warning on line 46 in src/nectarchain/dqm/dqm_summary_processor.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/dqm_summary_processor.py#L46

Added line #L46 was not covered by tests
for n1, m1 in j.items():
data1[n1] = m1
hdu1 = fits.BinTableHDU(data1)
hdu1.name = "MWF"


else:
for n, m in j.items():
data[n] = m
Expand Down
29 changes: 15 additions & 14 deletions src/nectarchain/dqm/mean_camera_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
import numpy as np



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

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

Check warning on line 14 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L14

Added line #L14 was not covered by tests
# define number of pixels and samples
self.Pix = Pix

Check warning on line 16 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L16

Added line #L16 was not covered by tests
self.Samp = Samp

self.CameraAverage = np.zeros((self.Chan))
self.CameraAverage_ped = np.zeros((self.Chan))
self.CameraAverage = np.zeros(self.Pix)
self.CameraAverage_ped = np.zeros(self.Pix)

Check warning on line 20 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L19-L20

Added lines #L19 - L20 were not covered by tests
self.counter_evt = 0
self.counter_ped = 0

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

Check warning on line 25 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L24-L25

Added lines #L24 - L25 were not covered by tests

self.cmap = "gnuplot2"
self.cmap2 = "gnuplot2"
Expand All @@ -35,12 +34,14 @@
def ProcessEvent(self, evt, noped):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
pixel = evt.nectarcam.tel[0].svc.pixel_ids
pixel21 = np.arange(0,21,1,dtype = int)
pixel = list(pixel)
pixel21 = list(pixel21)
pixels = np.concatenate([pixel21,pixel])

if evt.trigger.event_type.value == 32: #count peds
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])

Check warning on line 40 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L37-L40

Added lines #L37 - L40 were not covered by tests
else:
pixels = pixel

Check warning on line 42 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L42

Added line #L42 was not covered by tests

if evt.trigger.event_type.value == 32: # count peds

Check warning on line 44 in src/nectarchain/dqm/mean_camera_display.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/mean_camera_display.py#L44

Added line #L44 was not covered by tests
self.counter_ped += 1
self.CameraAverage_ped1 = (
evt.r0.tel[0].waveform[self.k].sum(axis=1))
Expand Down
Loading