Skip to content

Commit

Permalink
Simplify existing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenain committed Nov 6, 2024
1 parent f1c8efb commit 649bf8d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 135 deletions.
20 changes: 6 additions & 14 deletions src/nectarchain/dqm/tests/test_camera_monitoring.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from astropy import time as astropytime
from ctapipe.image.extractor import LocalPeakWindowSum # noqa: F401
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
Expand All @@ -10,15 +9,9 @@


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(
Expand All @@ -30,18 +23,17 @@ def test_camera_monitoring(self):
)
)
)
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)

sql_file_date = None
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()
sql_file_date = astropytime.Time(run_start1, format="unix").iso.split(" ")[
0
]

assert Pix + Samp == 1915
assert SqlFileDate == "2023-01-23"
assert sql_file_date == "2023-01-23"
62 changes: 2 additions & 60 deletions src/nectarchain/dqm/tests/test_charge_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import argparse
import json

import numpy as np
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
Expand All @@ -9,19 +6,12 @@
from traitlets.config import Config

from nectarchain.dqm.charge_integration import ChargeIntegrationHighLowGain
from nectarchain.makers import ChargesNectarCAMCalibrationTool


class TestChargeIntegrationHighLowGain:
run_number = 3938
max_events = 1

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

config = None

config = Config(
dict(
NectarCAMEventSource=dict(
Expand All @@ -34,63 +24,15 @@ def test_charge_integration(self):
)
)

parser = argparse.ArgumentParser(
description="NectarCAM Data Quality Monitoring tool"
)
# extractor arguments
parser.add_argument(
"--method",
choices=[
"FullWaveformSum",
"FixedWindowSum",
"GlobalPeakWindowSum",
"LocalPeakWindowSum",
"SlidingWindowMaxSum",
"TwoPassWindowSum",
],
default="GlobalPeakWindowSum",
help="charge extractor method",
type=str,
)

parser.add_argument(
"--extractor_kwargs",
default='{"window_shift": 4, "window_width": 16}',
help="charge extractor kwargs",
type=json.loads,
)

args, leftovers = parser.parse_known_args()

reader1 = EventSource(input_url=path, config=config, max_events=1)
self.subarray = reader1.subarray

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

method = args.method
extractor_kwargs = args.extractor_kwargs

kwargs = {"method": method, "extractor_kwargs": extractor_kwargs}
charges_kwargs = {}

tool = ChargesNectarCAMCalibrationTool()
for key in tool.traits().keys():
if key in kwargs.keys():
charges_kwargs[key] = kwargs[key]

ChargeIntegrationHighLowGain(HIGH_GAIN).ConfigureForRun(
path, Pix, Samp, reader1, **charges_kwargs
)

ped = None
for evt in tqdm(reader1, total=1):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
waveform = evt.r0.tel[0].waveform[HIGH_GAIN]
ped = np.mean(waveform[:, 20])
# w_noped = waveform - ped
# self.integrator = eval(charges_kwargs["method"])(
# subarray, **extractor_kwargs
# )
# ChargeIntegrationHighLowGain(HIGH_GAIN).ProcessEvent(evt, noped = True)
# ChargeIntegrationHighLowGain(HIGH_GAIN).FinishRun()

assert Pix + Samp == 1915
assert np.sum(ped) == 985.8636118598383
19 changes: 3 additions & 16 deletions src/nectarchain/dqm/tests/test_mean_camera_display.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ctapipe.image.extractor import LocalPeakWindowSum # noqa: F401
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
Expand All @@ -9,15 +8,9 @@


class TestMeanCameraDisplayHighLowGain:
run_number = 3798
max_events = 1

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

config = None

config = Config(
dict(
NectarCAMEventSource=dict(
Expand All @@ -29,20 +22,14 @@ def test_mean_camera_display(self):
)
)
)
print(path)

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

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

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

camera_average = None
for evt in tqdm(reader1, total=1):
# MeanCameraDisplayHighLowGain(HIGH_GAIN).ProcessEvent(evt, noped = False)
CameraAverage = evt.r0.tel[0].waveform[HIGH_GAIN].sum(axis=1)
camera_average = evt.r0.tel[0].waveform[HIGH_GAIN].sum(axis=1)

# MeanCameraDisplayHighLowGain(HIGH_GAIN).FinishRun()
assert Pix + Samp == 1915
assert CameraAverage.sum(axis=0) == 109723121
assert camera_average.sum(axis=0) == 109723121
14 changes: 2 additions & 12 deletions src/nectarchain/dqm/tests/test_mean_waveforms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from ctapipe.image.extractor import LocalPeakWindowSum # noqa: F401
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
Expand All @@ -10,15 +9,9 @@


class TestMeanWaveForms:
run_number = 3798
max_events = 1

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

config = None

config = Config(
dict(
NectarCAMEventSource=dict(
Expand All @@ -35,12 +28,9 @@ def test_mean_waveforms(self):

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

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

evt = None
for evt in tqdm(reader1, total=1):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
# MeanWaveFormsHighLowGain(HIGH_GAIN).ProcessEvent(evt, noped = False)
# MeanWaveFormsHighLowGain(HIGH_GAIN).FinishRun()
assert Pix + Samp == 1915

assert Pix + Samp == 1915
assert np.sum(evt.r0.tel[0].waveform[HIGH_GAIN][0]) == 3932100
13 changes: 1 addition & 12 deletions src/nectarchain/dqm/tests/test_pixel_participation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from ctapipe.image.extractor import LocalPeakWindowSum # noqa: F401
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
Expand All @@ -10,11 +9,7 @@


class TestPixelParticipation:
run_number = 3798
max_events = 1

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

config = None
Expand All @@ -35,15 +30,9 @@ def test_pixel_participation(self):

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

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

evt = None
for evt in tqdm(reader1, total=1):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
# PixelParticipationHighLowGain(HIGH_GAIN).ProcessEvent(evt, noped = False)

PixelParticipationHighLowGain(HIGH_GAIN).FinishRun()

assert Pix + Samp == 1915
assert np.sum(evt.nectarcam.tel[0].svc.pixel_ids) == 1719375
13 changes: 1 addition & 12 deletions src/nectarchain/dqm/tests/test_pixel_timeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from ctapipe.image.extractor import LocalPeakWindowSum # noqa: F401
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
Expand All @@ -10,15 +9,9 @@


class TestPixelTimeline:
run_number = 3798
max_events = 1

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

config = None

config = Config(
dict(
NectarCAMEventSource=dict(
Expand All @@ -35,13 +28,9 @@ def test_pixel_timeline(self):

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

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

evt = None
for evt in tqdm(reader1, total=1):
self.pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels
# PixelTimelineHighLowGain(HIGH_GAIN).ProcessEvent(evt, noped = False)

PixelTimelineHighLowGain(HIGH_GAIN).FinishRun()

assert Pix + Samp == 1915
assert np.sum(evt.nectarcam.tel[0].svc.pixel_ids) == 1719375
9 changes: 0 additions & 9 deletions src/nectarchain/dqm/tests/test_trigger_statistics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from ctapipe.image.extractor import LocalPeakWindowSum # noqa: F401
from ctapipe.io import EventSource
from ctapipe.utils import get_dataset_path
from ctapipe_io_nectarcam.constants import HIGH_GAIN
Expand All @@ -9,15 +8,9 @@


class TestTriggerStatistics:
run_number = 3798
max_events = 1

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

config = None

config = Config(
dict(
NectarCAMEventSource=dict(
Expand All @@ -29,7 +22,6 @@ def test_trigger_statistics(self):
)
)
)
print(path)

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

Expand All @@ -41,6 +33,5 @@ def test_trigger_statistics(self):
time = evt.trigger.time.value
TriggerStatistics(HIGH_GAIN).ProcessEvent(evt, noped=False)

# TriggerStatistics(HIGH_GAIN).FinishRun()
assert Pix + Samp == 1915
assert time == 1674462932.6398556

0 comments on commit 649bf8d

Please sign in to comment.