Skip to content
Snippets Groups Projects
Commit 2f5994bd authored by Philipp Niedermayer's avatar Philipp Niedermayer
Browse files

Background subtraction for IPM data

parent b004b936
No related branches found
No related tags found
No related merge requests found
...@@ -150,8 +150,8 @@ class IPMData(Trace): ...@@ -150,8 +150,8 @@ class IPMData(Trace):
hf: np.ndarray = None hf: np.ndarray = None
def apply_calibration(self, time_range): def subtract_background(self, time_range):
"""Calibrates the profile data by subtracting the average profile measured in the given timespan """Subtract the average profile measured in the given timespan
Note that this does not affect rms beam sizes Note that this does not affect rms beam sizes
...@@ -162,13 +162,16 @@ class IPMData(Trace): ...@@ -162,13 +162,16 @@ class IPMData(Trace):
self.y -= np.mean(self.y[window], axis=0) self.y -= np.mean(self.y[window], axis=0)
@classmethod @classmethod
def from_file(cls, fname, clean=False, from_event=None, time_offset=0, verbose=0): def from_file(cls, fname, *, clean=False, subtract_background=True, from_event=None, time_offset=0, verbose=0):
"""Read in profile data from a *.tgz file saved with IPM application """Read in profile data from a *.tgz file saved with IPM application
:param fname: path to filename :param fname: path to filename
:param clean: use adc_clean.dat instead of adc.dat :param clean: if True, use calibrated data from adc_clean.dat instead of raw data from adc.dat
:param from_event: return data from this event, time will also be relative to this event :param from_event: return data from this event on, time will also be relative to this event
:param subtract_background: if True, subtract background level prior to injection
References: References:
Giacomini, Tino <T.Giacomini@gsi.de> Giacomini, Tino <T.Giacomini@gsi.de>
...@@ -209,6 +212,15 @@ class IPMData(Trace): ...@@ -209,6 +212,15 @@ class IPMData(Trace):
scl = np.loadtxt(tar.extractfile('scl.dat'), skiprows=1) scl = np.loadtxt(tar.extractfile('scl.dat'), skiprows=1)
index, beam_current, dipole, hf, event_40, event_45, event_51, event_user = scl.T index, beam_current, dipole, hf, event_40, event_45, event_51, event_user = scl.T
# background subtraction
if subtract_background:
assert np.max(event_40) == 1, f'Requested background subtraction prior to injection (event 40), but event 40 not found in data'
nbg = np.argmax(event_40) - 3 # before injection
x -= np.mean(x[:nbg, :], axis=0)
y -= np.mean(y[:nbg, :], axis=0)
if verbose: print(f'Background subtracted (first {nbg} profiles or {t[nbg]} s)')
# offset relative to from_event
offset = 0 offset = 0
if from_event is None: if from_event is None:
offset = 0 offset = 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment