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

Commit

Permalink
Log errors from bsread.source
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-usov committed Mar 13, 2023
1 parent 77b8423 commit a3957e3
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 72 deletions.
45 changes: 26 additions & 19 deletions photodiag_web/app/panel_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,32 @@ def _collect_data():
i0_ch = f"{device_name}:INTENSITY"
i02_ch = f"{device2_name}:INTENSITY"

with bsread.source(
channels=[i0_ch, xpos_ch, ypos_ch, i02_ch, xpos2_ch, ypos2_ch]
) as stream:
while update_toggle.active:
message = stream.receive()
is_odd = message.data.pulse_id % 2
data = message.data.data
xpos = data[xpos_ch].value
xpos2 = data[xpos2_ch].value
ypos = data[ypos_ch].value
ypos2 = data[ypos2_ch].value
i0 = data[i0_ch].value
i02 = data[i02_ch].value

# Normalize by values of the first device
xpos_ratio = None if (xpos is None or xpos2 is None or xpos == 0) else xpos2 / xpos
ypos_ratio = None if (ypos is None or ypos2 is None or ypos == 0) else ypos2 / ypos
i0_ratio = None if (i0 is None or i02 is None or i0 == 0) else i02 / i0
buffer.append((is_odd, xpos, ypos, i0, xpos_ratio, ypos_ratio, i0_ratio))
try:
with bsread.source(
channels=[i0_ch, xpos_ch, ypos_ch, i02_ch, xpos2_ch, ypos2_ch]
) as stream:
while update_toggle.active:
message = stream.receive()
is_odd = message.data.pulse_id % 2
data = message.data.data
xpos = data[xpos_ch].value
xpos2 = data[xpos2_ch].value
ypos = data[ypos_ch].value
ypos2 = data[ypos2_ch].value
i0 = data[i0_ch].value
i02 = data[i02_ch].value

# Normalize by values of the first device
xpos_ratio = (
None if (xpos is None or xpos2 is None or xpos == 0) else xpos2 / xpos
)
ypos_ratio = (
None if (ypos is None or ypos2 is None or ypos == 0) else ypos2 / ypos
)
i0_ratio = None if (i0 is None or i02 is None or i0 == 0) else i02 / i0
buffer.append((is_odd, xpos, ypos, i0, xpos_ratio, ypos_ratio, i0_ratio))
except Exception as e:
log.error(e)

async def _update_plots():
if not buffer:
Expand Down
46 changes: 25 additions & 21 deletions photodiag_web/app/panel_diode_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

def create():
doc = curdoc()
log = doc.logger
device_name = ""
diode_name = ""

Expand Down Expand Up @@ -52,27 +53,30 @@ def _collect_data():
config = client.get_pipeline_config(device_name + "_proc")
diodes_ch = [config[diode] for diode in DIODES]

with bsread.source(channels=diodes_ch) as stream:
while update_toggle.active:
message = stream.receive()
data = message.data.data

i0 = data[config[diode_name]].value
if i0 is None or i0 == 0:
# Normalization is not possible
buffer.append((None, None, None, None))
continue

ratios = []
for diode in DIODES:
if diode == diode_name:
continue # i0 case

# Normalize by values of the selected diode
val = data[config[diode]].value
ratios.append(None if val is None else val / i0)

buffer.append((i0, *ratios))
try:
with bsread.source(channels=diodes_ch) as stream:
while update_toggle.active:
message = stream.receive()
data = message.data.data

i0 = data[config[diode_name]].value
if i0 is None or i0 == 0:
# Normalization is not possible
buffer.append((None, None, None, None))
continue

ratios = []
for diode in DIODES:
if diode == diode_name:
continue # i0 case

# Normalize by values of the selected diode
val = data[config[diode]].value
ratios.append(None if val is None else val / i0)

buffer.append((i0, *ratios))
except Exception as e:
log.error(e)

async def _update_plots():
if not buffer:
Expand Down
17 changes: 11 additions & 6 deletions photodiag_web/app/panel_jitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ def _collect_data():
ypos_ch = f"{device_name}:YPOS"
i0_ch = f"{device_name}:INTENSITY"

with bsread.source(channels=[xpos_ch, ypos_ch, i0_ch]) as stream:
while update_toggle.active:
message = stream.receive()
is_odd = message.data.pulse_id % 2
data = message.data.data
buffer.append((is_odd, data[xpos_ch].value, data[ypos_ch].value, data[i0_ch].value))
try:
with bsread.source(channels=[xpos_ch, ypos_ch, i0_ch]) as stream:
while update_toggle.active:
message = stream.receive()
is_odd = message.data.pulse_id % 2
data = message.data.data
buffer.append(
(is_odd, data[xpos_ch].value, data[ypos_ch].value, data[i0_ch].value)
)
except Exception as e:
log.error(e)

async def _update_plots():
if not buffer:
Expand Down
26 changes: 15 additions & 11 deletions photodiag_web/app/panel_spect_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def spectra_bin_I0(I0, I0_bins, spectra):

def create():
doc = curdoc()
log = doc.logger

# correlation coefficient figure
corr_coef_fig = figure(
Expand Down Expand Up @@ -88,17 +89,20 @@ def _collect_data():
spec_y_ch = "SARFE10-PSSS059:SPECTRUM_Y"
i0_ch = "SARFE10-PBPS053:INTENSITY"

with bsread.source(channels=[spec_x_ch, spec_y_ch, i0_ch]) as stream:
while update_toggle.active:
message = stream.receive()
data = message.data.data
spec_x = data[spec_x_ch].value
spec_y = data[spec_y_ch].value
i0 = data[i0_ch].value
if spec_x is not None and spec_y is not None and i0 is not None:
cache_spec_x = spec_x
buffer_spec_y.append(spec_y)
buffer_i0.append(i0)
try:
with bsread.source(channels=[spec_x_ch, spec_y_ch, i0_ch]) as stream:
while update_toggle.active:
message = stream.receive()
data = message.data.data
spec_x = data[spec_x_ch].value
spec_y = data[spec_y_ch].value
i0 = data[i0_ch].value
if spec_x is not None and spec_y is not None and i0 is not None:
cache_spec_x = spec_x
buffer_spec_y.append(spec_y)
buffer_i0.append(i0)
except Exception as e:
log.error(e)

num_shots_spinner = Spinner(title="Number shots:", mode="int", value=100, step=100, low=100)

Expand Down
34 changes: 19 additions & 15 deletions photodiag_web/app/panel_spect_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

def create():
doc = curdoc()
log = doc.logger

# single shot spectrum figure
single_shot_fig = figure(
Expand Down Expand Up @@ -67,21 +68,24 @@ def _collect_data():
peak_dist = peak_dist_spinner.value
peak_height = peak_height_spinner.value

with bsread.source(channels=[spec_x_ch, spec_y_ch]) as stream:
while update_toggle.active:
message = stream.receive()
data = message.data.data
spec_x = data[spec_x_ch].value
spec_y = data[spec_y_ch].value
if spec_x is not None and spec_y is not None:
spec_y = spec_y / np.max(spec_y)
spec_y_convolved = np.convolve(spec_y, kernel, mode="same")
spec_y_grad = np.abs(np.gradient(spec_y_convolved))
peaks, _ = find_peaks(spec_y_grad, distance=peak_dist, height=peak_height)
num_peaks = len(peaks) / 2

single_shot_cache = [spec_x, spec_y, spec_y_convolved, spec_y_grad, peaks]
buffer_num_peaks.append(num_peaks)
try:
with bsread.source(channels=[spec_x_ch, spec_y_ch]) as stream:
while update_toggle.active:
message = stream.receive()
data = message.data.data
spec_x = data[spec_x_ch].value
spec_y = data[spec_y_ch].value
if spec_x is not None and spec_y is not None:
spec_y = spec_y / np.max(spec_y)
spec_y_convolved = np.convolve(spec_y, kernel, mode="same")
spec_y_grad = np.abs(np.gradient(spec_y_convolved))
peaks, _ = find_peaks(spec_y_grad, distance=peak_dist, height=peak_height)
num_peaks = len(peaks) / 2

single_shot_cache = [spec_x, spec_y, spec_y_convolved, spec_y_grad, peaks]
buffer_num_peaks.append(num_peaks)
except Exception as e:
log.error(e)

num_shots_spinner = Spinner(title="Number shots:", mode="int", value=100, step=100, low=100)
kernel_size_spinner = Spinner(title="Kernel size:", mode="int", value=100, low=1)
Expand Down

0 comments on commit a3957e3

Please sign in to comment.