From 3607de986422db592ce7ce9b95fa8c97fe791d94 Mon Sep 17 00:00:00 2001 From: Artur Glavic Date: Tue, 28 Jan 2025 16:00:52 +0100 Subject: [PATCH 1/3] replace pulseTimeS generation in for loop by filling of pulse gaps --- libeos/file_reader.py | 23 ++++++++++++++++------- libeos/reduction.py | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index 0ff259e..d336b41 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -236,7 +236,6 @@ class AmorData: # fill in missing pulse times # TODO: check for real end time - self.pulseTimeS = np.array([], dtype=np.int64) try: # further files # TODO: use the first pulse of the respective measurement @@ -247,12 +246,22 @@ class AmorData: # first file nextPulseTime = pulseTime[0] % np.int64(self.tau*2e9) - for tt in pulseTime: - while tt - nextPulseTime > self.tau*1e9: - self.pulseTimeS = np.append(self.pulseTimeS, nextPulseTime) - nextPulseTime += chopperPeriod - self.pulseTimeS = np.append(self.pulseTimeS, tt) - nextPulseTime = self.pulseTimeS[-1] + chopperPeriod + # calculate where time tiefference between pulses exceeds its time by more than 1/2 + # this yields the number of missing pulses + pulseLengths = pulseTime[1:]-pulseTime[:-1] + pulseExtra = (pulseLengths-np.int64(self.tau*1e9))//np.int64(self.tau*2e9) + gap_indices = np.where(pulseExtra>0)[0] + + self.pulseTimeS = np.array(pulseTime[:gap_indices[0]+1], dtype=np.int64) + last_index = gap_indices[0] + for gapi in gap_indices[1:]: + # insert missing pulses into each gap + gap_pulses = pulseTime[last_index]+np.arange(1, pulseExtra[last_index]+1)*chopperPeriod + self.pulseTimeS = np.append(self.pulseTimeS, gap_pulses) + self.pulseTimeS = np.append(self.pulseTimeS, pulseTime[last_index+1:gapi+1]) + last_index = gapi + if last_index Date: Tue, 28 Jan 2025 16:02:54 +0100 Subject: [PATCH 2/3] apply scaling factor when time slicing --- libeos/reduction.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libeos/reduction.py b/libeos/reduction.py index 6456a1c..717d86e 100644 --- a/libeos/reduction.py +++ b/libeos/reduction.py @@ -199,6 +199,12 @@ class AmorReduction: qz_lz, qx_lz, ref_lz, err_lz, res_lz, lamda_lz, theta_lz, int_lz, mask_lz = self.project_on_lz( self.file_reader, self.norm_lz, self.normAngle, lamda_e, detZ_e) + try: + ref_lz *= self.reduction_config.scale[i] + err_lz *= self.reduction_config.scale[i] + except IndexError: + ref_lz *= self.reduction_config.scale[-1] + err_lz *= self.reduction_config.scale[-1] q_q, R_q, dR_q, dq_q = self.project_on_qz(qz_lz, ref_lz, err_lz, res_lz, self.norm_lz, mask_lz) filter_q = np.where((self.experiment_config.qzRange[0] Date: Tue, 28 Jan 2025 16:17:48 +0100 Subject: [PATCH 3/3] fix case where there is no pulse missing --- libeos/file_reader.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libeos/file_reader.py b/libeos/file_reader.py index d336b41..351678d 100644 --- a/libeos/file_reader.py +++ b/libeos/file_reader.py @@ -252,6 +252,10 @@ class AmorData: pulseExtra = (pulseLengths-np.int64(self.tau*1e9))//np.int64(self.tau*2e9) gap_indices = np.where(pulseExtra>0)[0] + if len(gap_indices)==0: + # no missing pulses, just use given array + self.pulseTimeS = np.array(pulseTime, dtype=np.int64) + return self.pulseTimeS = np.array(pulseTime[:gap_indices[0]+1], dtype=np.int64) last_index = gap_indices[0] for gapi in gap_indices[1:]: