From 2336ae18a3f519ae0fe0fe810795ef48f290eddf Mon Sep 17 00:00:00 2001 From: JoschD <26184899+JoschD@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:06:32 +0200 Subject: [PATCH] rescale error only if present --- omc3/optics_measurements/data_models.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/omc3/optics_measurements/data_models.py b/omc3/optics_measurements/data_models.py index 1a19cb86..a433531f 100644 --- a/omc3/optics_measurements/data_models.py +++ b/omc3/optics_measurements/data_models.py @@ -126,7 +126,7 @@ def bpms(self, plane=None, dpp_value=None): def calibrate(self, calibs: Dict[str, pd.DataFrame]): """ - Use calibration data to rescale amplitude and amplitude error. + Use calibration data to rescale amplitude and amplitude error (if present). Args: calibs (Dict): Plane-Dictionary with DataFrames of calibration data. @@ -145,13 +145,14 @@ def calibrate(self, calibs: Dict[str, pd.DataFrame]): value={CALIBRATION: 1.}) # ERR_CALIBRATION is relative, NaN filled with absolute value below # Scale amplitude with the calibration - self[plane][i][f"AMP{plane}"] = self[plane][i].loc[:, f"AMP{plane}"] * data.loc[:, CALIBRATION] - - # Sum Amplitude Error (absolute) and Calibration Error (relative) - self[plane][i][f"{ERR}{AMPLITUDE}{plane}"] = np.sqrt( - self[plane][i][f"{ERR}{AMPLITUDE}{plane}"]**2 + - ((self[plane][i][f"{AMPLITUDE}{plane}"] * data.loc[:, ERR_CALIBRATION]).fillna(bpm_resolution))**2 - ) + self[plane][i][f"{AMPLITUDE}{plane}"] = self[plane][i].loc[:, f"{AMPLITUDE}{plane}"] * data.loc[:, CALIBRATION] + + if f"{ERR}{AMPLITUDE}{plane}" in self[plane][i].columns: + # Sum Amplitude Error (absolute) and Calibration Error (relative) + self[plane][i][f"{ERR}{AMPLITUDE}{plane}"] = np.sqrt( + self[plane][i][f"{ERR}{AMPLITUDE}{plane}"]**2 + + ((self[plane][i][f"{AMPLITUDE}{plane}"] * data.loc[:, ERR_CALIBRATION]).fillna(bpm_resolution))**2 + ) @ staticmethod def get_columns(frame, column):