Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
FIX: fix #69
Browse files Browse the repository at this point in the history
  • Loading branch information
leloup314 committed Jul 27, 2022
1 parent 7b16fa9 commit f6a0c99
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
43 changes: 28 additions & 15 deletions irrad_control/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,23 +458,36 @@ def _interpret_beam_data(self, server, data, meta):
ro_device=self.readout_setup[server]['device']),
full_scale_voltage=self._lookups[server]['full_scale_voltage'])

try:
loss = blm_current / self.data_arrays[server]['beam']['beam_current'][0]
if loss >= self._beam_cut_off_threshold:
logging.warning("Beam cut-off detected! Losing {:.2f} % of beam at extraction!".format(loss * 100))
except ZeroDivisionError:
pass

# Correct extracted beam current when blm_current is above self._beam_correction_threshold
if blm_current > self._beam_correction_threshold * self.data_arrays[server]['beam']['beam_current'][0]:
extracted_current = self.data_arrays[server]['beam']['beam_current'][0] - blm_current
logging.warning("Correcting extracted beam current from {:.2E} A to {:.2E} A".format(self.data_arrays[server]['beam']['beam_current'][0],
extracted_current))
self.data_arrays[server]['beam']['beam_current'] = extracted_current

# Only add beam loss to data if we have BLM data
beam_data['data']['current']['beam_loss'] = blm_current

# This should always be the case, at leasanything else is unphysical
if blm_current <= self.data_arrays[server]['beam']['beam_current'][0]:

try:
# Get beam loss
beam_loss = blm_current / self.data_arrays[server]['beam']['beam_current'][0]

# Warn when cut-off is detected
if beam_loss >= self._beam_cut_off_threshold:
logging.warning("Beam cut-off detected! Losing {:.2f} % of beam at extraction!".format(beam_loss * 100))

# Warn when extracted beam current is corrected
if beam_loss >= self._beam_correction_threshold:
extracted_current = self.data_arrays[server]['beam']['beam_current'][0] - blm_current
logging.warning("Correcting extracted beam current from {:.2E} A to {:.2E} A".format(self.data_arrays[server]['beam']['beam_current'][0],
extracted_current))
self.data_arrays[server]['beam']['beam_current'] = extracted_current

except ZeroDivisionError:
pass

# This case should not exist because blm_current can be at most beam current
# Due to different sampling timestamps for the ADC channels, this can occure in unstable beam conditions
# See https://github.com/SiLab-Bonn/irrad_control/issues/69
else:
self.data_arrays[server]['beam']['beam_current'] = 0

else:
blm_current = np.nan

Expand Down Expand Up @@ -567,7 +580,7 @@ def _interpret_scan_data(self, server, data, meta):
eta_n_scans = int(remainder_fluence / row_proton_fluence.n)
eta_time = eta_n_scans * row_scan_time * self.data_arrays[server]['scan']['n_rows'][0]
except ZeroDivisionError:
eta_time = eta_n_scans = 0
eta_time = eta_n_scans = -1

scan_data = {'meta': {'timestamp': meta['timestamp'], 'name': server, 'type': 'scan'},
'data': {'fluence_hist': unumpy.nominal_values(self._row_fluence_hist[server]).tolist(),
Expand Down
9 changes: 5 additions & 4 deletions irrad_control/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,12 @@ def handle_data(self, data):
elif data['meta']['type'] == 'scan':
self.monitor_tab.plots[server]['fluence_plot'].set_data(data)
self.control_tab.update_info(row=data['data']['row_mean_proton_fluence'][0], unit='p/cm^2')
self.control_tab.update_info(nscan=data['data']['eta_n_scans'])

# FIXME: more precise result would be helpful
if data['data']['eta_n_scans'] < 0:
self.send_cmd(server, 'stage', 'finish')
if data['data']['eta_n_scans'] >= 0:
self.control_tab.update_info(nscan=data['data']['eta_n_scans'])
# FIXME: more precise result would be helpful
if data['data']['eta_n_scans'] == 0:
self.send_cmd(server, 'stage', 'finish')

elif data['meta']['type'] == 'damage':

Expand Down

0 comments on commit f6a0c99

Please sign in to comment.