diff --git a/photodiag_web/app/panel_correlation.py b/photodiag_web/app/panel_correlation.py index f35a3cc..e028da6 100644 --- a/photodiag_web/app/panel_correlation.py +++ b/photodiag_web/app/panel_correlation.py @@ -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: diff --git a/photodiag_web/app/panel_diode_check.py b/photodiag_web/app/panel_diode_check.py index d938d77..9420844 100644 --- a/photodiag_web/app/panel_diode_check.py +++ b/photodiag_web/app/panel_diode_check.py @@ -17,6 +17,7 @@ def create(): doc = curdoc() + log = doc.logger device_name = "" diode_name = "" @@ -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: diff --git a/photodiag_web/app/panel_jitter.py b/photodiag_web/app/panel_jitter.py index 2333861..f7cc687 100644 --- a/photodiag_web/app/panel_jitter.py +++ b/photodiag_web/app/panel_jitter.py @@ -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: diff --git a/photodiag_web/app/panel_spect_corr.py b/photodiag_web/app/panel_spect_corr.py index cf1fd2f..37318fc 100644 --- a/photodiag_web/app/panel_spect_corr.py +++ b/photodiag_web/app/panel_spect_corr.py @@ -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( @@ -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) diff --git a/photodiag_web/app/panel_spect_peaks.py b/photodiag_web/app/panel_spect_peaks.py index 8b3773f..b81ce2d 100644 --- a/photodiag_web/app/panel_spect_peaks.py +++ b/photodiag_web/app/panel_spect_peaks.py @@ -11,6 +11,7 @@ def create(): doc = curdoc() + log = doc.logger # single shot spectrum figure single_shot_fig = figure( @@ -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)