diff --git a/sed/calibrator/energy.py b/sed/calibrator/energy.py index d56ba5b3..a60c341e 100644 --- a/sed/calibrator/energy.py +++ b/sed/calibrator/energy.py @@ -1517,6 +1517,10 @@ def apply_energy_offset( print(msg) else: # use passed parameters + if columns is not None and (signs is None or subtract_mean is None): + raise ValueError( + "If columns is passed, signs and subtract_mean must also be passed.", + ) if isinstance(columns, str): columns = [columns] if isinstance(signs, int): @@ -1530,6 +1534,10 @@ def apply_energy_offset( # flip sign for binding energy scale energy_scale = self.get_current_calibration().get("energy_scale", None) if energy_scale == "binding": + if None in signs: + raise ValueError( + "Cannot apply binding energy offset to columns with unknown sign.", + ) signs = [-s for s in signs] elif energy_scale == "kinetic": pass diff --git a/sed/core/dfops.py b/sed/core/dfops.py index ee2c897b..9e1532b4 100644 --- a/sed/core/dfops.py +++ b/sed/core/dfops.py @@ -359,6 +359,8 @@ def apply_offset_from_columns( signs = [signs] if len(signs) != len(offset_columns): raise ValueError("signs and offset_columns must have the same length!") + if isinstance(subtract_mean, bool): + subtract_mean = [subtract_mean] * len(offset_columns) for col, sign, red, submean in zip(offset_columns, signs, reductions, subtract_mean): assert col in df.columns, f"{col} not in dataframe!"