def record_first_error_signal(self, error_signal, auto_offset): ( mean_signal, target_slope_rising, target_zoom, error_signal_rolled, line_width, peak_idxs, ) = get_lock_point(error_signal, self.x0, self.x1) self.central_y = int(mean_signal) if auto_offset: self.control.pause_acquisition() self.parameters.combined_offset.value = -1 * self.central_y error_signal -= self.central_y error_signal_rolled -= self.central_y self.additional_spectra = [ s - self.central_y for s in self.additional_spectra ] self.control.exposed_write_data() self.control.continue_acquisition() self.parameters.target_slope_rising.value = target_slope_rising self.control.exposed_write_data() return error_signal, error_signal_rolled, line_width, peak_idxs
def test_approacher(): def _get_signal(shift): return get_signal(parameters.ramp_amplitude.value, parameters.center.value, shift) for ref_shift in (-0.4, -0.2, 0.3): for target_shift in (-0.3, 0.6): print( f"----- ref_shift={ref_shift}, target_shift={target_shift} -----" ) parameters = Parameters() control = FakeControl(parameters) # approaching a line at the center is too easy # we generate a reference signal that is shifted in some direction # and then simulate that the user wants to approach a line that is not at # the center (this is done using get_lock_point) reference_signal = _get_signal(ref_shift) ( central_y, target_slope_rising, _, rolled_reference_signal, line_width, peak_idxs, ) = get_lock_point(reference_signal, 0, len(reference_signal)) """plt.plot(reference_signal) plt.plot(rolled_reference_signal) plt.show()""" assert abs(central_y - Y_SHIFT) < 1 approacher = Approacher( control, parameters, rolled_reference_signal, 100, central_y, wait_time_between_current_corrections=0, ) found = False for i in range(100): shift = target_shift * (1 + (0.025 * np.random.randn())) error_signal = _get_signal(shift)[:] approacher.approach_line(error_signal) if parameters.ramp_amplitude.value <= 0.2: found = True break assert found assert abs((-1 * target_shift) - parameters.center.value) < 0.1 print("found!")
def mouseReleaseEvent(self, event): super().mouseReleaseEvent(event) if self.selection_running: if self.touch_start is None: return x, y = self._to_data_coords(event) x = self._within_boundaries(x) x0, y0 = self.touch_start xdiff = np.abs(x0 - x) xmax = len(self.last_plot_data[0]) - 1 if xdiff / xmax < 0.01: # it was a click pass else: # it was a selection if self.selection_running: if self.parameters.autolock_selection.value: last_combined_error_signal = self.last_plot_data[2] self.parameters.autolock_selection.value = False self.control.start_autolock( # we pickle it here because otherwise a netref is # transmitted which blocks the autolock *sorted([x0, x]), pickle.dumps(last_combined_error_signal), additional_spectra=pickle.dumps(self._cached_plot_data) ) ( mean_signal, target_slope_rising, target_zoom, rolled_error_signal, line_width, peak_idxs, ) = get_lock_point( last_combined_error_signal, *sorted((int(x0), int(x))) ) 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] ] self.parameters.optimization_selection.value = False points = sorted([int(x0), int(x)]) self.control.start_optimization(*points, pickle.dumps(spectrum)) self.overlay.setVisible(False) self.touch_start = None
def record_first_error_signal(self, error_signal): mean_signal, target_slope_rising, target_zoom, rolled_error_signal = \ get_lock_point(error_signal, self.x0, self.x1) if self.auto_offset: self.parameters.combined_offset.value = -1 * mean_signal rolled_error_signal -= int(mean_signal) self.parameters.target_slope_rising.value = target_slope_rising self.control.exposed_write_data() self.target_zoom = target_zoom self.first_error_signal = rolled_error_signal
def record_first_error_signal(self, error_signal): _, _2, target_zoom, rolled_error_signal = get_lock_point( error_signal, *list(sorted([self.x0, self.x1])), final_zoom_factor=FINAL_ZOOM_FACTOR ) self.target_zoom = target_zoom self.first_error_signal = rolled_error_signal self.approacher = Approacher( self.control, self.parameters, self.first_error_signal, self.target_zoom, allow_ramp_speed_change=False ) params = self.parameters self.initial_params = ( params.modulation_frequency.value, params.modulation_amplitude.value, self.get_demod_phase_param().value ) self.parameters.optimization_optimized_parameters.value = self.initial_params
def record_first_error_signal(self, error_signal): ( mean_signal, _2, target_zoom, rolled_error_signal, line_width, peak_idxs, ) = get_lock_point(error_signal, *list(sorted([self.x0, self.x1])), final_zoom_factor=FINAL_ZOOM_FACTOR) self.target_zoom = target_zoom self.first_error_signal = rolled_error_signal self.approacher = Approacher( self.control, self.parameters, self.first_error_signal, self.target_zoom, mean_signal, allow_ramp_speed_change=False, )