From 649bf8da63b47103d381ef71543f7ea3deb879a0 Mon Sep 17 00:00:00 2001 From: jlenain Date: Wed, 6 Nov 2024 13:36:25 +0100 Subject: [PATCH] Simplify existing unit tests --- .../dqm/tests/test_camera_monitoring.py | 20 ++---- .../dqm/tests/test_charge_integration.py | 62 +------------------ .../dqm/tests/test_mean_camera_display.py | 19 +----- .../dqm/tests/test_mean_waveforms.py | 14 +---- .../dqm/tests/test_pixel_participation.py | 13 +--- .../dqm/tests/test_pixel_timeline.py | 13 +--- .../dqm/tests/test_trigger_statistics.py | 9 --- 7 files changed, 15 insertions(+), 135 deletions(-) diff --git a/src/nectarchain/dqm/tests/test_camera_monitoring.py b/src/nectarchain/dqm/tests/test_camera_monitoring.py index 89fe1992..89e2f43c 100644 --- a/src/nectarchain/dqm/tests/test_camera_monitoring.py +++ b/src/nectarchain/dqm/tests/test_camera_monitoring.py @@ -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 @@ -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( @@ -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" diff --git a/src/nectarchain/dqm/tests/test_charge_integration.py b/src/nectarchain/dqm/tests/test_charge_integration.py index bffbbe0e..35b83b46 100644 --- a/src/nectarchain/dqm/tests/test_charge_integration.py +++ b/src/nectarchain/dqm/tests/test_charge_integration.py @@ -1,6 +1,3 @@ -import argparse -import json - import numpy as np from ctapipe.io import EventSource from ctapipe.utils import get_dataset_path @@ -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( @@ -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 diff --git a/src/nectarchain/dqm/tests/test_mean_camera_display.py b/src/nectarchain/dqm/tests/test_mean_camera_display.py index f07a1bad..e5ac3825 100644 --- a/src/nectarchain/dqm/tests/test_mean_camera_display.py +++ b/src/nectarchain/dqm/tests/test_mean_camera_display.py @@ -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 @@ -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( @@ -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 diff --git a/src/nectarchain/dqm/tests/test_mean_waveforms.py b/src/nectarchain/dqm/tests/test_mean_waveforms.py index c5d76009..dbb3e452 100644 --- a/src/nectarchain/dqm/tests/test_mean_waveforms.py +++ b/src/nectarchain/dqm/tests/test_mean_waveforms.py @@ -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 @@ -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( @@ -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 diff --git a/src/nectarchain/dqm/tests/test_pixel_participation.py b/src/nectarchain/dqm/tests/test_pixel_participation.py index 3c69e783..ae9fb22a 100644 --- a/src/nectarchain/dqm/tests/test_pixel_participation.py +++ b/src/nectarchain/dqm/tests/test_pixel_participation.py @@ -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 @@ -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 @@ -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 diff --git a/src/nectarchain/dqm/tests/test_pixel_timeline.py b/src/nectarchain/dqm/tests/test_pixel_timeline.py index 5c8d06bd..f6b58c37 100644 --- a/src/nectarchain/dqm/tests/test_pixel_timeline.py +++ b/src/nectarchain/dqm/tests/test_pixel_timeline.py @@ -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 @@ -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( @@ -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 diff --git a/src/nectarchain/dqm/tests/test_trigger_statistics.py b/src/nectarchain/dqm/tests/test_trigger_statistics.py index c5fcc43a..fee7f9d5 100644 --- a/src/nectarchain/dqm/tests/test_trigger_statistics.py +++ b/src/nectarchain/dqm/tests/test_trigger_statistics.py @@ -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 @@ -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( @@ -29,7 +22,6 @@ def test_trigger_statistics(self): ) ) ) - print(path) reader1 = EventSource(input_url=path, config=config, max_events=1) @@ -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