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

Thermal tests + CI in DQM #122

Merged
merged 9 commits into from
Aug 22, 2024
3 changes: 2 additions & 1 deletion src/nectarchain/dqm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .db_utils import DQMDB
from .dqm_summary_processor import DQMSummary
from .pixel_participation import PixelParticipationHighLowGain

__all__ = ["DQMDB", "DQMSummary"]
__all__ = ["DQMDB", "DQMSummary", "PixelParticipationHighLowGain"]
jlenain marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 2 additions & 3 deletions src/nectarchain/dqm/camera_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import numpy as np
from astropy import time as astropytime
from ctapipe.coordinates import EngineeringCameraFrame
from ctapipe.instrument import CameraGeometry
from ctapipe.visualization import CameraDisplay
from dqm_summary_processor import DQMSummary
from matplotlib import pyplot as plt

from nectarchain.dqm.dqm_summary_processor import DQMSummary

jlenain marked this conversation as resolved.
Show resolved Hide resolved

class CameraMonitoring(DQMSummary):
def __init__(self, gaink):
Expand Down Expand Up @@ -139,7 +139,6 @@ def GetResults(self):
return self.CameraMonitoring_Results_Dict

def PlotResults(self, name, FigPath):

try:
fig, disp = plt.subplots()
disp = CameraDisplay(self.camera)
Expand Down
95 changes: 84 additions & 11 deletions src/nectarchain/dqm/charge_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import numpy as np
from ctapipe.coordinates import EngineeringCameraFrame
from ctapipe.image import LocalPeakWindowSum
from ctapipe.instrument import CameraGeometry
from ctapipe.visualization import CameraDisplay
from dqm_summary_processor import DQMSummary
from matplotlib import pyplot as plt
from traitlets.config.loader import Config

from nectarchain.dqm.dqm_summary_processor import DQMSummary

jlenain marked this conversation as resolved.
Show resolved Hide resolved

class ChargeIntegrationHighLowGain(DQMSummary):
def __init__(self, gaink):
Expand All @@ -20,21 +20,31 @@
self.peakpos_all = []
self.image_ped = []
self.peakpos_ped = []
self.camera = None
self.ped_all = []
self.ped_ped = []
self.camera = None
self.cmap = None
self.subarray = None
self.subarray = None
self.integrator = None
self.pixelBAD = None
self.pixelBAD = None
self.image_all = []
self.image_all_median = None
self.image_all_average = None
self.image_all_std = None
self.image_all_rms = None
self.ped_all_median = None
self.ped_all_average = None
self.ped_all_std = None
self.ped_all_rms = None
self.image_ped = []
self.image_ped_median = None
self.image_ped_average = None
self.image_ped_std = None
self.image_ped_rms = None
self.ped_ped_median = None
self.ped_ped_average = None
self.ped_ped_std = None
self.ped_ped_rms = None
self.ChargeInt_Results_Dict = {}
self.ChargeInt_Figures_Dict = {}
self.ChargeInt_Figures_Names_Dict = {}
Expand All @@ -50,7 +60,7 @@
self.camera = Reader1.subarray.tel[0].camera.geometry.transform_to(
EngineeringCameraFrame()
)

self.cmap = "gnuplot2"

self.subarray = Reader1.subarray
Expand All @@ -64,8 +74,6 @@

self.integrator = LocalPeakWindowSum(subarray, config=config)



def ProcessEvent(self, evt, noped):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
pixel = evt.nectarcam.tel[0].svc.pixel_ids
Expand All @@ -80,8 +88,9 @@

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

ped = np.mean(waveform[:, 20])

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L91

Added line #L91 was not covered by tests

if noped:
ped = np.mean(waveform[:, 20])
w_noped = waveform - ped
output = self.integrator(
w_noped, 0, np.zeros(self.Pix, dtype=int), self.pixelBAD
Expand All @@ -104,10 +113,12 @@
self.counter_ped += 1
self.image_ped.append(image)
self.peakpos_ped.append(peakpos)
self.ped_ped.append(ped)

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L116

Added line #L116 was not covered by tests
else:
self.counter_evt += 1
self.image_all.append(image)
self.peakpos_all.append(peakpos)
self.ped_all.append(ped)

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L121

Added line #L121 was not covered by tests

def FinishRun(self):
self.peakpos_all = np.array(self.peakpos_all, dtype=float)
Expand All @@ -121,15 +132,26 @@
self.image_all_std = np.std(self.image_all, axis=0)
self.image_all_rms = np.sqrt(np.sum(self.image_all**2, axis=0))

self.ped_all = np.array(self.ped_all, dtype=float)
self.ped_all_average = np.mean(self.ped_all, axis=0)
self.ped_all_median = np.median(self.ped_all, axis=0)
self.ped_all_std = np.std(self.ped_all, axis=0)
self.ped_all_rms = np.sqrt(np.sum(self.ped_all**2, axis=0))

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L135-L139

Added lines #L135 - L139 were not covered by tests

if self.counter_ped > 0:
self.image_ped = np.array(self.image_ped, dtype=float)
self.image_ped_median = np.median(self.image_ped, axis=0)
self.image_ped_average = np.mean(self.image_ped, axis=0)
self.image_ped_std = np.std(self.image_ped, axis=0)
self.image_ped_rms = np.sqrt(np.sum(self.image_ped**2, axis=0))

def GetResults(self):
self.ped_ped = np.array(self.ped_ped, dtype=float)
self.ped_ped_average = np.mean(self.ped_ped, axis=0)
self.ped_ped_median = np.median(self.ped_ped, axis=0)
self.ped_ped_std = np.std(self.ped_ped, axis=0)
self.ped_ped_rms = np.sqrt(np.sum(self.ped_ped**2, axis=0))

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L148-L152

Added lines #L148 - L152 were not covered by tests

def GetResults(self):
if self.k == 0:
self.ChargeInt_Results_Dict[
"CHARGE-INTEGRATION-IMAGE-ALL-AVERAGE-HIGH-GAIN"
Expand All @@ -144,6 +166,19 @@
"CHARGE-INTEGRATION-IMAGE-ALL-STD-HIGH-GAIN"
] = self.image_all_std

self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L169

Added line #L169 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-AVERAGE-HIGH-GAIN"
] = self.ped_all_average
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L172

Added line #L172 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-MEDIAN-HIGH-GAIN"
] = self.ped_all_median
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L175

Added line #L175 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-RMS-HIGH-GAIN"
] = self.ped_all_rms
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L178

Added line #L178 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-STD-HIGH-GAIN"
] = self.ped_all_std

if self.counter_ped > 0:
self.ChargeInt_Results_Dict[
"CHARGE-INTEGRATION-PED-ALL-AVERAGE-HIGH-GAIN"
Expand All @@ -158,6 +193,19 @@
"CHARGE-INTEGRATION-PED-ALL-STD-HIGH-GAIN"
] = self.image_ped_std

self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L196

Added line #L196 was not covered by tests
"PED-INTEGRATION-PED-ALL-AVERAGE-HIGH-GAIN"
] = self.ped_ped_average
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L199

Added line #L199 was not covered by tests
"PED-INTEGRATION-PED-ALL-MEDIAN-HIGH-GAIN"
] = self.ped_ped_median
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L202

Added line #L202 was not covered by tests
"PED-INTEGRATION-PED-ALL-RMS-HIGH-GAIN"
] = self.ped_ped_rms
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L205

Added line #L205 was not covered by tests
"PED-INTEGRATION-PED-ALL-STD-HIGH-GAIN"
] = self.ped_ped_std

if self.k == 1:
self.ChargeInt_Results_Dict[
"CHARGE-INTEGRATION-IMAGE-ALL-AVERAGE-LOW-GAIN"
Expand All @@ -172,6 +220,19 @@
"CHARGE-INTEGRATION-IMAGE-ALL-STD-LOW-GAIN"
] = self.image_all_std

self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L223

Added line #L223 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-AVERAGE-LOW-GAIN"
] = self.ped_all_average
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L226

Added line #L226 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-MEDIAN-LOW-GAIN"
] = self.ped_all_median
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L229

Added line #L229 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-RMS-LOW-GAIN"
] = self.ped_all_rms
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L232

Added line #L232 was not covered by tests
"PED-INTEGRATION-IMAGE-ALL-STD-LOW-GAIN"
] = self.ped_all_std

if self.counter_ped > 0:
self.ChargeInt_Results_Dict[
"CHARGE-INTEGRATION-PED-ALL-AVERAGE-LOW-GAIN"
Expand All @@ -186,10 +247,22 @@
"CHARGE-INTEGRATION-PED-ALL-STD-LOW-GAIN"
] = self.image_ped_std

self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L250

Added line #L250 was not covered by tests
"PED-INTEGRATION-PED-ALL-AVERAGE-LOW-GAIN"
] = self.ped_ped_average
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L253

Added line #L253 was not covered by tests
"PED-INTEGRATION-PED-ALL-MEDIAN-LOW-GAIN"
] = self.ped_ped_median
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L256

Added line #L256 was not covered by tests
"PED-INTEGRATION-PED-ALL-RMS-LOW-GAIN"
] = self.ped_ped_rms
self.ChargeInt_Results_Dict[

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

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/charge_integration.py#L259

Added line #L259 was not covered by tests
"PED-INTEGRATION-PED-ALL-STD-LOW-GAIN"
] = self.ped_ped_std

return self.ChargeInt_Results_Dict

def PlotResults(self, name, FigPath):

# titles = ['All', 'Pedestals']
if self.k == 0:
gain_c = "High"
Expand Down
10 changes: 4 additions & 6 deletions src/nectarchain/dqm/mean_camera_display.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import numpy as np
from ctapipe.coordinates import EngineeringCameraFrame
from ctapipe.visualization import CameraDisplay
from dqm_summary_processor import DQMSummary
from matplotlib import pyplot as plt

from nectarchain.dqm.dqm_summary_processor import DQMSummary

class MeanCameraDisplay_HighLowGain(DQMSummary):

class MeanCameraDisplayHighLowGain(DQMSummary):
def __init__(self, gaink):
self.k = gaink
self.Pix = None
Expand All @@ -22,7 +23,7 @@ def __init__(self, gaink):
self.CameraAverage_ped1 = []
self.CameraAverage_overEvents = None
self.CameraAverage_overEvents_overSamp = None
self.CameraAverage_ped_overEvents = None
self.CameraAverage_ped_overEvents = None
self.CameraAverage_ped_overEvents_overSamp = None
self.MeanCameraDisplay_Results_Dict = {}
self.MeanCameraDisplay_Figures_Dict = {}
Expand All @@ -42,7 +43,6 @@ def ConfigureForRun(self, path, Pix, Samp, Reader1):

self.cmap = "gnuplot2"


def ProcessEvent(self, evt, noped):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
pixel = evt.nectarcam.tel[0].svc.pixel_ids
Expand Down Expand Up @@ -86,7 +86,6 @@ def FinishRun(self):
)

def GetResults(self):

# ASSIGN RESUTLS TO DICT
if self.k == 0:
if self.counter_evt > 0:
Expand Down Expand Up @@ -125,7 +124,6 @@ def GetResults(self):
return self.MeanCameraDisplay_Results_Dict

def PlotResults(self, name, FigPath):

# titles = ['All', 'Pedestals']
if self.k == 0:
gain_c = "High"
Expand Down
5 changes: 2 additions & 3 deletions src/nectarchain/dqm/mean_waveforms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from dqm_summary_processor import DQMSummary
from matplotlib import pyplot as plt

from nectarchain.dqm.dqm_summary_processor import DQMSummary

jlenain marked this conversation as resolved.
Show resolved Hide resolved

class MeanWaveFormsHighLowGain(DQMSummary):
def __init__(self, gaink):
Expand Down Expand Up @@ -70,7 +71,6 @@ def FinishRun(self):
return None

def GetResults(self):

# ASSIGN RESUTLS TO DICT
if self.k == 0:
self.MeanWaveForms_Results_Dict[
Expand All @@ -93,7 +93,6 @@ def GetResults(self):
return self.MeanWaveForms_Results_Dict

def PlotResults(self, name, FigPath):

wf_list = np.array(self.wf_list_plot)

counter_fig = 0
Expand Down
5 changes: 4 additions & 1 deletion src/nectarchain/dqm/pixel_participation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import numpy as np
from ctapipe.coordinates import EngineeringCameraFrame
from ctapipe.visualization import CameraDisplay
from dqm_summary_processor import DQMSummary
from matplotlib import pyplot as plt

from nectarchain.dqm.dqm_summary_processor import DQMSummary

__all__ = ["PixelParticipationHighLowGain"]


class PixelParticipationHighLowGain(DQMSummary):
def __init__(self, gaink):
Expand Down
3 changes: 2 additions & 1 deletion src/nectarchain/dqm/pixel_timeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from dqm_summary_processor import DQMSummary
from matplotlib import pyplot as plt

from nectarchain.dqm.dqm_summary_processor import DQMSummary


class PixelTimelineHighLowGain(DQMSummary):
def __init__(self, gaink):
Expand Down
6 changes: 3 additions & 3 deletions src/nectarchain/dqm/start_dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ctapipe_io_nectarcam.constants import HIGH_GAIN, LOW_GAIN
from db_utils import DQMDB
from matplotlib import pyplot as plt
from mean_camera_display import MeanCameraDisplay_HighLowGain
from mean_camera_display import MeanCameraDisplayHighLowGain

Check warning on line 12 in src/nectarchain/dqm/start_dqm.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/start_dqm.py#L12

Added line #L12 was not covered by tests
from mean_waveforms import MeanWaveFormsHighLowGain
from pixel_participation import PixelParticipationHighLowGain
from pixel_timeline import PixelTimelineHighLowGain
Expand Down Expand Up @@ -145,8 +145,8 @@
a = TriggerStatistics(HIGH_GAIN)
b = MeanWaveFormsHighLowGain(HIGH_GAIN)
c = MeanWaveFormsHighLowGain(LOW_GAIN)
d = MeanCameraDisplay_HighLowGain(HIGH_GAIN)
e = MeanCameraDisplay_HighLowGain(LOW_GAIN)
d = MeanCameraDisplayHighLowGain(HIGH_GAIN)
e = MeanCameraDisplayHighLowGain(LOW_GAIN)

Check warning on line 149 in src/nectarchain/dqm/start_dqm.py

View check run for this annotation

Codecov / codecov/patch

src/nectarchain/dqm/start_dqm.py#L148-L149

Added lines #L148 - L149 were not covered by tests
f = ChargeIntegrationHighLowGain(HIGH_GAIN)
g = ChargeIntegrationHighLowGain(LOW_GAIN)
h = CameraMonitoring(HIGH_GAIN)
Expand Down
46 changes: 46 additions & 0 deletions src/nectarchain/dqm/tests/test_camera_monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from astropy import time as astropytime
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
from tqdm import tqdm
from traitlets.config import Config

from nectarchain.dqm.camera_monitoring import CameraMonitoring


class TestCameraMonitoring:
run_number = 3798
max_events = 1

def test_camera_monitoring(self):
# run_number = 3938
path = get_dataset_path("NectarCAM.Run3938.30events.fits.fz")

config = None

config = Config(
dict(
NectarCAMEventSource=dict(
NectarCAMR0Corrections=dict(
calibration_path=None,
apply_flatfield=False,
select_gain=False,
)
)
)
)
print(path)

reader1 = EventSource(input_url=path, config=config, max_events=1)

Pix, Samp = CameraMonitoring(HIGH_GAIN).DefineForRun(reader1)

CameraMonitoring(HIGH_GAIN).ConfigureForRun(path, Pix, Samp, reader1)

for evt in tqdm(reader1, total=1):
run_start1 = evt.nectarcam.tel[0].svc.date
SqlFileDate = astropytime.Time(run_start1, format="unix").iso.split(" ")[0]
# print("SqlFileDate", SqlFileDate)
# CameraMonitoring(HIGH_GAIN).FinishRun()
assert Pix + Samp == 1915
assert SqlFileDate == "2023-01-23"
Loading
Loading