def fit_config(self, status: bool):
        """ Configures fitting add-on

        :param status: (bool) whether or not fit button is checked
        """

        # If box is newly checked, instantiate popup
        if status:
            self.fit_popup = FitPopup(ui='fit_popup_hist',
                                      x=np.array(range(self.gui.n_bins.value())) * int(self._get_binwidth()) / 1e12, #dummy values, not actually used None, #self.ctr.get_x_axis(self.hist)/1e12,
                                      data=np.zeros(self.gui.n_bins.value()), #dummy values, not actually used #None, #self.ctr.get_counts(self.hist)[0],
                                      p0=None,
                                      config=self.config,
                                      log=self.log)
            self.fit_popup.model_type.activated.connect(self.fit_popup.fit_selection)
            self.fit_curve = self.gui.graph.plot(
                pen=pg.mkPen(color=self.gui.COLOR_LIST[5])
            )
            add_to_legend(self.legend, self.fit_curve, 'Histogram Fit')

            self.fitting = True
            self.p0 = None

        # If box isn't checked, remove popup
        else:
            self.fit_popup = None
            self.fitting = False
Exemple #2
0
    def _initialize_channel(self, index, channel):
        """Initializes a channel and outputs to the GUI

        Should only be called in the beginning of channel use to assign physical GUI widgets
        """

        # Get wavelength and initialize data arrays
        channel.initialize(wavelength=self.wlm_client.get_wavelength(
            channel.number),
                           display_pts=self.display_pts)

        # Create curves
        # frequency
        self.widgets['curve'].append(self.widgets['graph'][2 * index].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[0])))
        add_to_legend(legend=self.widgets['legend'][2 * index],
                      curve=self.widgets['curve'][4 * index],
                      curve_name=channel.curve_name)

        # Setpoint
        self.widgets['curve'].append(self.widgets['graph'][2 * index].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[1])))
        add_to_legend(legend=self.widgets['legend'][2 * index],
                      curve=self.widgets['curve'][4 * index + 1],
                      curve_name=channel.setpoint_name)

        # Clear data
        self.widgets['clear'][2 * index].clicked.connect(
            lambda: self.clear_channel(channel))
        self.widgets['clear'][2 * index + 1].clicked.connect(
            lambda: self.clear_channel(channel))

        # Setpoint reset
        self.widgets['rs'][index].clicked.connect(
            lambda: self.update_parameters(
                dict(channel=channel.number, setpoint=channel.data[-1])))

        # Voltage
        self.widgets['curve'].append(self.widgets['graph'][2 * index + 1].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[0])))
        add_to_legend(legend=self.widgets['legend'][2 * index + 1],
                      curve=self.widgets['curve'][4 * index + 2],
                      curve_name=channel.voltage_curve)

        # Error
        self.widgets['curve'].append(self.widgets['graph'][2 * index + 1].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[1])))
        add_to_legend(legend=self.widgets['legend'][2 * index + 1],
                      curve=self.widgets['curve'][4 * index + 3],
                      curve_name=channel.error_curve)

        # zero
        self.widgets['zero'][2 * index].clicked.connect(
            lambda: self.zero_voltage(channel))
        self.widgets['zero'][2 * index + 1].clicked.connect(
            lambda: self.zero_voltage(channel))
    def _initialize_graphs(self):
        """Initializes a channel and outputs to the GUI

        Should only be called in the initialization of the project
        """
        # Add in teh cleared widgets array
        self.widgets['curve'] = []
        self.widgets['legend'] = [
            get_legend_from_graphics_view(legend)
            for legend in self.widgets['legend']
        ]

        # Create curves
        # Power
        self.widgets['curve'].append(self.widgets['graph'][0].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[0])))
        add_to_legend(legend=self.widgets['legend'][0],
                      curve=self.widgets['curve'][0],
                      curve_name="Power")

        # Setpoint
        self.widgets['curve'].append(self.widgets['graph'][0].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[1])))
        add_to_legend(legend=self.widgets['legend'][0],
                      curve=self.widgets['curve'][1],
                      curve_name="Setpoint")

        # Voltage
        self.widgets['curve'].append(self.widgets['graph'][1].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[0])))
        add_to_legend(legend=self.widgets['legend'][1],
                      curve=self.widgets['curve'][2],
                      curve_name="Voltage")

        # Error
        self.widgets['curve'].append(self.widgets['graph'][1].plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[1])))
        add_to_legend(legend=self.widgets['legend'][1],
                      curve=self.widgets['curve'][3],
                      curve_name="Error")

        self._clear_data_plots(1000)
    def __init__(self, ctr: si_tt.Client, log: LogClient, config, ui='histogram', **kwargs):
        """ Instantiates TimeTrace measurement

        :param ctr: (si_tt.Client) client to timetagger hardware
        :param log: (LogClient) instance of logclient for logging
        :param config: (str) name of config file
        :param ui: (str) name of ui file
        :param **kwargs: additional keyword arguments
            TODO: in future, can implement multiple histograms if useful
        """

        # Setup GUI
        self.gui = Window(
            gui_template='histogram',
            host=get_ip()
        )

        # Setup stylesheet.
        self.gui.apply_stylesheet()

        # Store config
        self.config = config

        self.correlation = False
        if 'type' in self.config:
            if self.config['type'] == 'correlation':
                self.correlation = True

        super().__init__(
            ctr=ctr,
            log=log,
            click_ch=self.config['click_ch'],
            start_ch=self.config['start_ch'],
            binwidth=int(self._get_binwidth()),
            n_bins=self.gui.n_bins.value(),
            update_interval=0,
            correlation=self.correlation
        )

        if not type(self.config['click_ch']) == int:
            combined_click_channel = f"{self.config['click_ch'][0]}+{self.config['click_ch'][1]}"
            ctr.create_combined_channel(
                channel_name=combined_click_channel,
                channel_list=self.config['click_ch']
            )
            self.config['click_ch'] = [combined_click_channel]

        self.gates = {}
        if 'gate_ch' in self.config:

            # Handle singular input
            if not isinstance(self.config['gate_ch'], list):
                self.config['gate_ch'] = [self.config['gate_ch']]

            # Update GUI to handle gates
            self._configure_gui_gates()

            # Setup gated channels
            for gate_ch in self.config['gate_ch']:
                ch_name = f'Gated histogram channel {gate_ch}'
                ctr.create_gated_channel(
                    ch_name,
                    self.config['click_ch'],
                    gate_ch,
                    delay=self.delays[ch_name].value()
                )
                self.gates[ch_name] = TimeTrace(
                    ctr=ctr,
                    log=log,
                    click_ch=ch_name,
                    start_ch=self.config['start_ch'],
                    binwidth=int(self._get_binwidth()),
                    n_bins=self.gui.n_bins.value(),
                    update_interval=0,
                    correlation=self.correlation
                )

        # Configure clicks
        self.gui.configure.clicked.connect(lambda: self.update_parameters(
            binwidth=int(self._get_binwidth()),
            n_bins=self.gui.n_bins.value()
        ))
        self.gui.clear.clicked.connect(self.clear_all)
        # Need Lambda to force it to use default args
        # https://stackoverflow.com/questions/60001583/pyqt5-slot-function-does-not-take-default-argument
        self.gui.save.clicked.connect(lambda: self.save())
        self.gui.run.clicked.connect(self.run)

        #### CHANGED CHANGED CHANGED
        self.gui.fit.clicked.connect(self.fit_config)

        self._configure_delay_updates()

        # Configure window length preview
        self.gui.n_bins.valueChanged.connect(self.update_window_length_label)
        self.gui.binwidth.valueChanged.connect(self.update_window_length_label)

        # Configure window length preview
        self.update_window_length_label()

        # Initialize plot info
        self.curve = self.gui.graph.plot(
            pen=pg.mkPen(color=self.gui.COLOR_LIST[0])
        )

        self.gui.graph.getPlotItem().setLabel('bottom', 'Time (s)')
        self.legend = get_legend_from_graphics_view(self.gui.legend)
        add_to_legend(self.legend, self.curve, 'Histogram')

        self.gate_curves = {}
        index = 1
        for gate in self.gates:
            self.gate_curves[gate] = self.gui.graph.plot(
                pen=pg.mkPen(color=self.gui.COLOR_LIST[index])
            )
            index += 1
            add_to_legend(self.legend, self.gate_curves[gate], gate)

        self.gui.apply_stylesheet()
        self.fitting = False
Exemple #5
0
    def _configure_plots(self, plot=True):
        """ Configures the plots """

        # Clear plots
        if len(self.widgets['curve']) > 0:
            # self.widgets['curve'][0].clear()
            # self.widgets['curve'][1].clear()
            self.widgets['graph'][0].getPlotItem().clear()
            self.widgets['graph'][1].getPlotItem().clear()
            self.widgets['hmap'][0].clear()
            self.widgets['hmap'][1].clear()
            self.widgets['legend'][0].clear()
            self.widgets['legend'][1].clear()
            self.widgets['curve_avg'][0].clear()
            self.widgets['curve_avg'][1].clear()
            self.widgets['fit_avg'][0].clear()
            self.widgets['fit_avg'][1].clear()
            self.data_fwd = []
            self.data_bwd = []
            self.avg_fwd = []
            self.avg_bwd = []
            self.fit_fwd = []
            self.fit_bwd = []
            self.p0_fwd = None
            self.p0_bwd = None
            self.x_fwd = self._generate_x_axis()
            if self.sweep_type != 'sawtooth':
                self.x_bwd = self._generate_x_axis(backward=True)
            else:
                self.x_bwd = self._generate_x_axis()

        self.widgets['curve'] = []
        self.widgets['curve_avg'] = []
        self.widgets['fit_avg'] = []

        for index, graph in enumerate(self.widgets['graph']):

            if self.sweep_type != 'sawtooth':
                self.widgets['curve'].append(
                    graph.plot(pen=pg.mkPen(color=self.gui.COLOR_LIST[6])))
                add_to_legend(self.widgets['legend'][index],
                              self.widgets['curve'][index],
                              f'{"Fwd" if index==0 else "Bwd"} trace')

                self.widgets['curve_avg'].append(
                    graph.plot(pen=pg.mkPen(color=self.gui.COLOR_LIST[0])))
                add_to_legend(self.widgets['legend'][index],
                              self.widgets['curve_avg'][index],
                              f'{"Fwd" if index==0 else "Bwd"} avg')

                self.widgets['fit_avg'].append(
                    graph.plot(pen=pg.mkPen(color=self.gui.COLOR_LIST[1])))
                add_to_legend(self.widgets['legend'][index],
                              self.widgets['fit_avg'][index],
                              f'{"Fwd" if index==0 else "Bwd"} fit avg')
            else:
                self.widgets['curve'].append(
                    graph.plot(pen=pg.mkPen(color=self.gui.COLOR_LIST[6])))
                add_to_legend(self.widgets['legend'][index],
                              self.widgets['curve'][index],
                              f'{"1st" if index==0 else "2nd"} trace')

                self.widgets['curve_avg'].append(
                    graph.plot(pen=pg.mkPen(color=self.gui.COLOR_LIST[0])))
                add_to_legend(self.widgets['legend'][index],
                              self.widgets['curve_avg'][index],
                              f'{"1st" if index==0 else "2nd"} avg')

                self.widgets['fit_avg'].append(
                    graph.plot(pen=pg.mkPen(color=self.gui.COLOR_LIST[1])))
                add_to_legend(self.widgets['legend'][index],
                              self.widgets['fit_avg'][index],
                              f'{"1st" if index==0 else "2nd"} fit avg')

        for hmap in self.widgets['hmap']:
            hmap.view.setLimits(xMin=self.min, xMax=self.max)