Skip to content

Commit

Permalink
simplify plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
bleykauf committed May 31, 2024
1 parent e7a193d commit d11d15a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
10 changes: 7 additions & 3 deletions linien-common/linien_common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from enum import IntEnum
from time import time
from typing import Dict, List, Tuple, Union
from typing import Dict, Iterable, List, Tuple, Union

import numpy as np
from scipy.signal import correlate, resample
Expand Down Expand Up @@ -278,8 +278,12 @@ def convert_channel_mixing_value(value: int) -> Tuple[int, int]:


def combine_error_signal(
error_signals, dual_channel, channel_mixing, combined_offset, chain_factor_width=8
):
error_signals: tuple[Iterable[int], Iterable[int]],
dual_channel: bool,
channel_mixing: int,
combined_offset: int,
chain_factor_width: int = 8,
) -> np.ndarray:
if not dual_channel:
signal = error_signals[0]
else:
Expand Down
44 changes: 22 additions & 22 deletions linien-gui/linien_gui/ui/plot_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def on_plot_settings_changed(*args):
self.control_signal_history_data = self.parameters.control_signal_history.value
self.monitor_signal_history_data = self.parameters.monitor_signal_history.value

self.parameters.to_plot.add_callback(self.replot)
self.parameters.to_plot.add_callback(self.on_new_plot_data_received)

def on_autolock_selection_changed(value):
if value:
Expand Down Expand Up @@ -391,10 +391,13 @@ def mouseReleaseEvent(self, event):
)
self.autolock_ref_spectrum = rolled_error_signal
elif self.parameters.optimization_selection.value:
dual_channel = self.parameters.dual_channel.value
channel = self.parameters.optimization_channel.value
spectrum = self.last_plot_data[
0 if not dual_channel else (0, 1)[channel]
(
0
if not self.parameters.dual_channel.value
else (0, 1)[channel]
)
]
self.parameters.optimization_selection.value = False
points = sorted([int(x0), int(x)])
Expand All @@ -403,7 +406,7 @@ def mouseReleaseEvent(self, event):
self.overlay.setVisible(False)
self.touch_start = None

def replot(self, to_plot):
def on_new_plot_data_received(self, to_plot):
time_beginning = time()

if self._should_reposition_reset_view_button:
Expand Down Expand Up @@ -470,17 +473,24 @@ def replot(self, to_plot):
)
all_signals = (error_signal, control_signal, history, slow_history)

self.plot_data_locked(to_plot)
self.combined_signal.setData(
list(range(len(to_plot["error_signal"]))),
to_plot["error_signal"] / V,
)
self.control_signal.setData(
list(range(len(to_plot["control_signal"]))),
to_plot["control_signal"] / V,
)
self.plot_autolock_target_line(None)
else:
dual_channel = self.parameters.dual_channel.value
self.signal1.setVisible(True)
self.signal1.setVisible(dual_channel)
monitor_signal = to_plot.get("monitor_signal")
error_signal_2 = to_plot.get("error_signal_2")
self.signal2.setVisible(
error_signal_2 is not None or monitor_signal is not None
)
self.combined_signal.setVisible(dual_channel)
self.combined_signal.setVisible(True)
self.control_signal.setVisible(False)
self.control_signal_history.setVisible(False)
self.slow_history.setVisible(False)
Expand All @@ -505,7 +515,11 @@ def replot(self, to_plot):
all_signals = [s1, s2] + [combined_error_signal]
self.last_plot_data = all_signals

self.plot_data_unlocked((s1, s2), combined_error_signal)
self.signal2.setData(list(range(len(s2))), s2 / V)
self.signal1.setData(list(range(len(s1))), s1 / V)
self.combined_signal.setData(
list(range(len(combined_error_signal))), combined_error_signal / V
)
self.plot_autolock_target_line(combined_error_signal)

if (self.parameters.modulation_frequency.value != 0) and (
Expand Down Expand Up @@ -618,20 +632,6 @@ def plot_signal_strength(
neg_signal.setData(x, lower, pen=invisible_pen)
return np.max([np.max(upper), -1 * np.min(lower)]) * V

def plot_data_unlocked(self, error_signals, combined_signal):
error_signal1, error_signal2 = error_signals
self.signal1.setData(list(range(len(error_signal1))), error_signal1 / V)
self.signal2.setData(list(range(len(error_signal2))), error_signal2 / V)
self.combined_signal.setData(
list(range(len(combined_signal))), combined_signal / V
)

def plot_data_locked(self, signals):
error_signal = signals["error_signal"]
control_signal = signals["control_signal"]
self.combined_signal.setData(list(range(len(error_signal))), error_signal / V)
self.control_signal.setData(list(range(len(error_signal))), control_signal / V)

def plot_autolock_target_line(self, combined_error_signal):
if (
self.autolock_ref_spectrum is not None
Expand Down

0 comments on commit d11d15a

Please sign in to comment.