Skip to content

Commit a89ab9a

Browse files
committed
Read number of samples from RunHeaders.
1 parent bd321b6 commit a89ab9a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

ctapipe_io_magic/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
DATA_MONO_SUMT_TRIGGER_PATTERN,
5454
PEDESTAL_TRIGGER_PATTERN,
5555
DATA_STEREO_TRIGGER_PATTERN,
56-
N_SAMPLES,
5756
)
5857

5958
__all__ = [
@@ -668,12 +667,28 @@ def prepare_subarray_info(self):
668667
f"Invalid focal length choice: {self.focal_length_choice}"
669668
)
670669

671-
672670
# camera info from MAGICCam.camgeom.fits.gz file
673671
camera_geom = load_camera_geometry()
674672

675673
n_pixels = camera_geom.n_pixels
676674

675+
n_samples_array_list = ["MRawRunHeader.fNumSamplesHiGain"]
676+
n_samples_list = []
677+
678+
for rootf in self.files_:
679+
nsample_info = rootf['RunHeaders'].arrays(n_samples_array_list, library="np")
680+
n_samples_file = int(nsample_info['MRawRunHeader.fNumSamplesHiGain'][0])
681+
n_samples_list.append(n_samples_file)
682+
683+
n_samples_list = np.unique(n_samples_list).tolist()
684+
685+
if len(n_samples_list) > 1:
686+
raise ValueError(
687+
"Loaded files contain different number of readout samples. \
688+
Please load files with the same readout configuration.")
689+
690+
n_samples = n_samples_list[0]
691+
677692
pulse_shape_lo_gain = np.array([0., 1., 2., 1., 0.])
678693
pulse_shape_hi_gain = np.array([1., 2., 3., 2., 1.])
679694
pulse_shape = np.vstack((pulse_shape_lo_gain, pulse_shape_hi_gain))
@@ -688,7 +703,7 @@ def prepare_subarray_info(self):
688703
reference_pulse_sample_width=u.Quantity(0.5, u.ns),
689704
n_channels=1,
690705
n_pixels=n_pixels,
691-
n_samples=N_SAMPLES,
706+
n_samples=n_samples,
692707
)
693708

694709
camera = CameraDescription('MAGICCam', camera_geom, camera_readout)

ctapipe_io_magic/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
MC_SUMT_TRIGGER_PATTERN = 32
1010
# also for data taken in stereo with SumTrigger
1111
DATA_STEREO_TRIGGER_PATTERN = 128
12-
N_SAMPLES = 50

0 commit comments

Comments
 (0)