Esempio n. 1
0
    def __init__(
        self, parent, details, ID, status, name, kind="1d", ls=23, gw=384, gh=192, pl=320, bl=12, ll=128, ih=96
    ):
        super(sweepInstance, self).__init__()
        # info/control bar at top
        self.parent = parent
        self.det = details
        self.status = status
        self.name = name
        self.ID = ID
        self.kind = kind  # '1d' or '2d'

        self.measurements_completed = 0
        self.total_time = 0.0  # total amount of time spent sweeping.
        self.current_rate = 0.0  # current sweep rate
        self.finished_time = None  # None = not finished
        self.was_paused = False  # Used to skip paused time when counting average rate
        self.completed = False  # has it finished?

        self.np_swept = 0.0  # amount of setting swept while not paused
        self.np_time = 0.0  # amount of time passed while not paused

        self.ls = ls  # line spacing
        self.gw = gw  # graph width
        self.gh = gh  # graph height

        self.pl = pl  # plot(2d) sidelength
        self.bl = bl  # bar (and bar spacing) length
        self.ll = ll  # label length

        self.setting_details = self.det["setting_details"]
        self.colormap = None
        self.custom_map = None

        # parameters
        self.parameter_names = []

        # dataset
        if kind == "1d":
            independents = [self.det["custom_name"] if self.det["custom_name"] else self.det["xlabel"]]
        else:
            independents = [
                "xnum",
                "ynum",
                self.det["fast_custom_name"] if self.det["fast_custom_name"] else self.det["xlabel"],
                self.det["slow_custom_name"] if self.det["slow_custom_name"] else self.det["ylabel"],
            ]

        dependents = [setting.name for setting in self.setting_details]

        self.data_set = DataSet(self.det["dv_name"], self.det["dv_loc"], independents, dependents)

        # comment, paremeters
        # self.comment_list    = []
        # self.parameter_list  = []
        # self.parameter_names = []
        # self.has_written     = False

        # dataset location (None = not set yet)
        # self.dataset_location = None

        o = array([0, ls * 5])  # origin
        self.graphs = {}
        n = 0
        if self.kind == "1d":
            lbl = [setting.ID for setting in self.setting_details]
        elif self.kind == "2d":
            lbl = [setting.ID for setting in self.setting_details]
        for pos in range(len(lbl)):
            ylabel = self.setting_details[pos].name
            ID = self.setting_details[pos].ID
            if kind == "1d":
                x = o[0] + (gw + ls) * (n % 3)
                xlabel = self.det["custom_name"] if self.det["custom_name"] else self.det["xlabel"]
                y = o[1] + (gh + ls) * int(floor(n / 3.0))  # rectangular graphs for 1d
                self.graphs.update([[ID, plotInstance(xlabel, ylabel, None, parent=self, geometry=[x, y, gw, gh])]])

            elif kind == "2d":
                xname = self.det["fast_custom_name"] if self.det["fast_custom_name"] else self.det["xlabel"]
                yname = self.det["slow_custom_name"] if self.det["slow_custom_name"] else self.det["ylabel"]
                # print(xname,yname)
                x = o[0] + (n % 3) * (pl + 7 * ls + ih)  # (ls*2+pl+bl*3+ll)
                y = o[1] + int(floor(n / 3.0)) * (pl + 2 * ls + ih)  # (gw+ls) *  # square graphs for 2d
                self.graphs.update(
                    [
                        [
                            ID,
                            colorplotShell(
                                xname,
                                yname,
                                self.det["xnum"],
                                self.det["ynum"],
                                [self.det["xstart"], self.det["xstop"]],
                                [self.det["ystart"], self.det["ystop"]],
                                parent=self,
                                geometry=[x, y, ls + pl + bl * 3 + ll, pl + ls],
                                name=self.det["setting_details"][pos].name,
                                ls=ls,
                                pl=pl,
                                bl=bl,
                                ll=ll,
                            ),
                        ]
                    ]
                )

            n += 1

        if self.kind == "2d":
            self.current_delay = self.det["xdelay"]

        # User defined input handling
        if self.kind == "1d":
            self.inputs = self.det["inputs"]
            self.to_sweep = self.det["to_sweep"]
        if self.kind == "2d":
            self.inputs_fast = self.det["inputs_fast"]
            self.to_sweep_fast = self.det["to_sweep_fast"]
            self.inputs_slow = self.det["inputs_slow"]
            self.to_sweep_slow = self.det["to_sweep_slow"]

        self.first_meas = True
        self.doUI()
        self.time = time.time()
Esempio n. 2
0
    def __init__(self,
                 parent,
                 details,
                 ID,
                 status,
                 name,
                 kind='1d',
                 ls=23,
                 gw=384,
                 gh=192,
                 pl=320,
                 bl=12,
                 ll=128,
                 ih=96):
        super(sweepInstance, self).__init__()
        # info/control bar at top
        self.parent = parent
        self.det = details
        self.status = status
        self.name = name
        self.ID = ID
        self.kind = kind  # '1d' or '2d'

        self.measurements_completed = 0
        self.total_time = 0.0  # total amount of time spent sweeping.
        self.current_rate = 0.0  # current sweep rate
        self.finished_time = None  # None = not finished
        self.was_paused = False  # Used to skip paused time when counting average rate
        self.completed = False  # has it finished?

        self.np_swept = 0.0  # amount of setting swept while not paused
        self.np_time = 0.0  # amount of time passed while not paused

        self.ls = ls  # line spacing
        self.gw = gw  # graph width
        self.gh = gh  # graph height

        self.pl = pl  # plot(2d) sidelength
        self.bl = bl  # bar (and bar spacing) length
        self.ll = ll  # label length

        self.setting_details = self.det['setting_details']
        self.colormap = None
        self.custom_map = None

        # parameters
        self.parameter_names = []

        # dataset
        if kind == '1d':
            independents = [
                self.det['custom_name']
                if self.det['custom_name'] else self.det['xlabel']
            ]
        else:
            independents = [
                'xnum', 'ynum', self.det['fast_custom_name']
                if self.det['fast_custom_name'] else self.det['xlabel'],
                self.det['slow_custom_name']
                if self.det['slow_custom_name'] else self.det['ylabel']
            ]

        dependents = [setting.name for setting in self.setting_details]

        self.data_set = DataSet(
            self.det['dv_name'],
            self.det['dv_loc'],
            independents,
            dependents,
        )

        # comment, paremeters
        # self.comment_list    = []
        # self.parameter_list  = []
        # self.parameter_names = []
        # self.has_written     = False

        # dataset location (None = not set yet)
        # self.dataset_location = None

        o = array([0, ls * 5])  # origin
        self.graphs = {}
        n = 0
        if self.kind == '1d':
            lbl = [setting.ID for setting in self.setting_details]
        elif self.kind == '2d':
            lbl = [setting.ID for setting in self.setting_details]
        for pos in range(len(lbl)):
            ylabel = self.setting_details[pos].name
            ID = self.setting_details[pos].ID
            if kind == '1d':
                x = o[0] + (gw + ls) * (n % 3)
                xlabel = self.det['custom_name'] if self.det[
                    'custom_name'] else self.det['xlabel']
                y = o[1] + (gh + ls) * int(floor(
                    n / 3.0))  # rectangular graphs for 1d
                self.graphs.update([[
                    ID,
                    plotInstance(xlabel,
                                 ylabel,
                                 None,
                                 parent=self,
                                 geometry=[x, y, gw, gh])
                ]])

            elif kind == '2d':
                xname = self.det['fast_custom_name'] if self.det[
                    'fast_custom_name'] else self.det['xlabel']
                yname = self.det['slow_custom_name'] if self.det[
                    'slow_custom_name'] else self.det['ylabel']
                #print(xname,yname)
                x = o[0] + (n % 3) * (pl + 7 * ls + ih)  #(ls*2+pl+bl*3+ll)
                y = o[1] + int(floor(n / 3.0)) * (
                    pl + 2 * ls + ih)  #(gw+ls) *  # square graphs for 2d
                self.graphs.update([[
                    ID,
                    colorplotShell(xname,
                                   yname,
                                   self.det['xnum'],
                                   self.det['ynum'],
                                   [self.det['xstart'], self.det['xstop']],
                                   [self.det['ystart'], self.det['ystop']],
                                   parent=self,
                                   geometry=[
                                       x, y, ls + pl + bl * 3 + ll, pl + ls
                                   ],
                                   name=self.det['setting_details'][pos].name,
                                   ls=ls,
                                   pl=pl,
                                   bl=bl,
                                   ll=ll)
                ]])

            n += 1

        if self.kind == '2d':
            self.current_delay = self.det['xdelay']

        # User defined input handling
        if self.kind == '1d':
            self.inputs = self.det['inputs']
            self.to_sweep = self.det['to_sweep']
        if self.kind == '2d':
            self.inputs_fast = self.det['inputs_fast']
            self.to_sweep_fast = self.det['to_sweep_fast']
            self.inputs_slow = self.det['inputs_slow']
            self.to_sweep_slow = self.det['to_sweep_slow']

        self.first_meas = True
        self.doUI()
        self.time = time.time()
Esempio n. 3
0
class sweepInstance(gui.QMainWindow):
    def __init__(
        self, parent, details, ID, status, name, kind="1d", ls=23, gw=384, gh=192, pl=320, bl=12, ll=128, ih=96
    ):
        super(sweepInstance, self).__init__()
        # info/control bar at top
        self.parent = parent
        self.det = details
        self.status = status
        self.name = name
        self.ID = ID
        self.kind = kind  # '1d' or '2d'

        self.measurements_completed = 0
        self.total_time = 0.0  # total amount of time spent sweeping.
        self.current_rate = 0.0  # current sweep rate
        self.finished_time = None  # None = not finished
        self.was_paused = False  # Used to skip paused time when counting average rate
        self.completed = False  # has it finished?

        self.np_swept = 0.0  # amount of setting swept while not paused
        self.np_time = 0.0  # amount of time passed while not paused

        self.ls = ls  # line spacing
        self.gw = gw  # graph width
        self.gh = gh  # graph height

        self.pl = pl  # plot(2d) sidelength
        self.bl = bl  # bar (and bar spacing) length
        self.ll = ll  # label length

        self.setting_details = self.det["setting_details"]
        self.colormap = None
        self.custom_map = None

        # parameters
        self.parameter_names = []

        # dataset
        if kind == "1d":
            independents = [self.det["custom_name"] if self.det["custom_name"] else self.det["xlabel"]]
        else:
            independents = [
                "xnum",
                "ynum",
                self.det["fast_custom_name"] if self.det["fast_custom_name"] else self.det["xlabel"],
                self.det["slow_custom_name"] if self.det["slow_custom_name"] else self.det["ylabel"],
            ]

        dependents = [setting.name for setting in self.setting_details]

        self.data_set = DataSet(self.det["dv_name"], self.det["dv_loc"], independents, dependents)

        # comment, paremeters
        # self.comment_list    = []
        # self.parameter_list  = []
        # self.parameter_names = []
        # self.has_written     = False

        # dataset location (None = not set yet)
        # self.dataset_location = None

        o = array([0, ls * 5])  # origin
        self.graphs = {}
        n = 0
        if self.kind == "1d":
            lbl = [setting.ID for setting in self.setting_details]
        elif self.kind == "2d":
            lbl = [setting.ID for setting in self.setting_details]
        for pos in range(len(lbl)):
            ylabel = self.setting_details[pos].name
            ID = self.setting_details[pos].ID
            if kind == "1d":
                x = o[0] + (gw + ls) * (n % 3)
                xlabel = self.det["custom_name"] if self.det["custom_name"] else self.det["xlabel"]
                y = o[1] + (gh + ls) * int(floor(n / 3.0))  # rectangular graphs for 1d
                self.graphs.update([[ID, plotInstance(xlabel, ylabel, None, parent=self, geometry=[x, y, gw, gh])]])

            elif kind == "2d":
                xname = self.det["fast_custom_name"] if self.det["fast_custom_name"] else self.det["xlabel"]
                yname = self.det["slow_custom_name"] if self.det["slow_custom_name"] else self.det["ylabel"]
                # print(xname,yname)
                x = o[0] + (n % 3) * (pl + 7 * ls + ih)  # (ls*2+pl+bl*3+ll)
                y = o[1] + int(floor(n / 3.0)) * (pl + 2 * ls + ih)  # (gw+ls) *  # square graphs for 2d
                self.graphs.update(
                    [
                        [
                            ID,
                            colorplotShell(
                                xname,
                                yname,
                                self.det["xnum"],
                                self.det["ynum"],
                                [self.det["xstart"], self.det["xstop"]],
                                [self.det["ystart"], self.det["ystop"]],
                                parent=self,
                                geometry=[x, y, ls + pl + bl * 3 + ll, pl + ls],
                                name=self.det["setting_details"][pos].name,
                                ls=ls,
                                pl=pl,
                                bl=bl,
                                ll=ll,
                            ),
                        ]
                    ]
                )

            n += 1

        if self.kind == "2d":
            self.current_delay = self.det["xdelay"]

        # User defined input handling
        if self.kind == "1d":
            self.inputs = self.det["inputs"]
            self.to_sweep = self.det["to_sweep"]
        if self.kind == "2d":
            self.inputs_fast = self.det["inputs_fast"]
            self.to_sweep_fast = self.det["to_sweep_fast"]
            self.inputs_slow = self.det["inputs_slow"]
            self.to_sweep_slow = self.det["to_sweep_slow"]

        self.first_meas = True
        self.doUI()
        self.time = time.time()

    def doUI(self):
        # background
        # self.setBackground(gui.QColor('black'))

        # use self.det
        if self.kind == "1d":
            self.stepsize = (self.det["stop"] - self.det["start"]) / (self.det["steps"])
            self.xsetting = self.det["start"]  # current value of setting. Starts at beginning.
        elif self.kind == "2d":
            self.x_stepsize = (self.det["xstop"] - self.det["xstart"]) / (self.det["xsteps"])
            self.y_stepsize = (self.det["ystop"] - self.det["ystart"]) / (self.det["ysteps"])
            self.x_setting = self.det["xstart"]
            self.y_setting = self.det["ystart"]
            self.x_num = 0
            self.y_num = 0

        # labels / info
        t = self.det["start_timestamp"]
        time_text = "Sweep started at: %i/%i/%i %i:%i:%i" % (
            t.tm_mon,
            t.tm_mday,
            t.tm_year,
            t.tm_hour,
            t.tm_min,
            t.tm_sec,
        )
        self.label_starttime = simpleText(self, time_text, [0, 0, self.gw // 2 + 74, self.ls])
        self.label_stepsdone = simpleText(
            self, "Measurements done: %i" % (self.measurements_completed), [0, self.ls * 1, self.gw // 2, self.ls]
        )

        if self.kind == "1d":
            self.meas_total = self.det["steps"] + 1
        elif self.kind == "2d":
            self.meas_total = self.det["xnum"] * self.det["ynum"]

        self.label_stepstotal = simpleText(
            self, "Measurements total: %i" % (self.meas_total), [0, self.ls * 2, self.gw // 2, self.ls]
        )
        self.progress_bar = gui.QProgressBar(self)
        self.progress_bar.setRange(0, self.meas_total)
        self.progress_bar.setGeometry(0, self.ls * 3, self.gw // 2, self.ls)

        # sweep control
        self.button_pause = queryButton("Pause", self, "", [self.gw // 2, self.ls * 1], self.pause)
        self.button_resume = queryButton("Resume", self, "", [self.gw // 2, self.ls * 2], self.resume)
        self.button_cancel = queryButton("Cancel", self, "", [self.gw // 2, self.ls * 3], self.cancel)
        self.checkbox_cancel = checkBox(self, "Confirm", [self.gw // 2 + 76, self.ls * 3 - 3])

        # 'set graphs to automatic' button
        self.button_graph_auto = queryButton("Reset graph view", self, "", [0, self.ls * 4], self.reset_graph_views)

        # completion readout
        self.label_complete_time = simpleText(
            self, "Completed at:", [self.gw // 2 + 76 + self.ls, self.ls * 0, self.gw // 2, self.ls]
        )
        self.label_complete_rate = simpleText(
            self, "Average rate:", [self.gw // 2 + 76 + self.ls, self.ls * 1, self.gw // 2, self.ls]
        )
        self.label_current_rate = simpleText(
            self, "Current rate:", [self.gw // 2 + 76 + self.ls, self.ls * 2, self.gw // 2, self.ls]
        )

        # data set name, location
        self.input_logname = textInput(self, "", [self.gw + 76 + self.ls * 2, self.ls * 0, self.ll, self.ls])
        self.input_logdest = textInput(self, "", [self.gw + 76 + self.ls * 2, self.ls * 1, self.ll, self.ls])
        self.input_logname.setPlaceholderText("Dataset name")
        self.input_logdest.setPlaceholderText("Dataset location")
        self.input_logdest.setText(self.det["dv_loc"])
        self.input_logname.setText(self.det["dv_name"])
        self.input_logdest.setToolTip(
            "Folders separated by '\\' characters.\nNo leading or trailing backslash.\nExample: data\\testing\\2016\nDefault: data"
        )

        # data logging (data vault) details
        self.button_add_comments = queryButton(
            "Add comment(s)", self, "", [self.ll + self.gw + 76 + self.ls * 3, self.ls * 0], self.add_comments
        )
        self.button_add_parameters = queryButton(
            "Add parameter(s)", self, "", [self.ll + self.gw + 76 + self.ls * 3, self.ls * 1], self.add_parameters
        )
        self.button_log_data = queryButton(
            "Write data set", self, "", [self.ll + self.gw + 76 + self.ls * 3, self.ls * 2], self.log_data
        )

        # colormap
        if self.kind == "2d":
            self.label_colormap = simpleText(
                self, "Color map:", [self.ll * 2 + self.ls * 2 + self.gw + 76 + self.ls * 2, 0, 64, self.ls]
            )
            self.dropdown_colormap = simpleDropdown(
                self,
                ["None", "Custom"] + maps.keys(),
                [self.ll * 2 + self.ls * 2 + self.gw + self.ls * 2 + 76 + 64, 0, 64, self.ls],
                self.change_colormap,
            )
            self.button_custommap = queryButton(
                "Custom", self, "", [self.ll * 2 + self.ls * 2 + self.gw + 76 + self.ls * 2, self.ls], self.cust_map
            )
        elif self.kind == "1d":
            self.label_colormap = self.dropdown_colormap = self.button_custommap = None

        # open dataset if autosave is on
        if self.det["dv_autosave"]:
            self.open_dataset()

    def open_dataset(self):
        location_raw = str(self.input_logdest.getValue())
        name_raw = str(self.input_logname.getValue())
        if location_raw:
            while location_raw.startswith("\\"):  # Remove leading backslashes
                location_raw = location_raw[1:]  #
            while location_raw.endswith("\\"):  # Remove trailing backslashes
                location_raw = location_raw[:-1]  #
            lines = location_raw.replace("\\", "\n").splitlines()
            location = [""] + lines
        else:
            location = ["", "data"]
        self.data_set.location = location
        self.data_set.name = name_raw
        self.data_set.create_dataset()

        self.input_logdest.setReadOnly(True)
        self.input_logname.setReadOnly(True)

        self.data_set.write_comments()
        self.data_set.write_parameters()

    def log_data(self):

        if not self.data_set.dataset_open:
            # if this is the first time we're writing to the set...
            self.open_dataset()

        # data_set.data populated while measurements ongoing, just need to write it here.
        # If set to autowrite, write_data() will be called each time a data is added
        print("Writing {datalen} data lines...".format(datalen=len(self.data_set.data)))
        self.data_set.write_data()

    def add_comments(self):
        commentbox = commentBoxWidget(self)

    def send_comments(self, comments):
        self.data_set.add_comments(comments, self.data_set.dataset_open)

    def add_parameters(self):
        parameterbox = parameterBoxWidget(self, self.parameter_names)

    def send_parameters(self, parameters):
        self.parameter_names += [param[0] for param in parameters]
        self.data_set.add_parameters(parameters, self.data_set.dataset_open)

    def cust_map(self):
        self.dropdown_colormap.setCurrentIndex(1)  # Custom
        self.change_colormap()
        go = customMapWidget(self)

    def change_colormap(self):
        choice = str(self.dropdown_colormap.currentText())
        if choice == "None":
            self.colormap = None
        elif choice == "Custom":
            self.colormap = self.custom_map
        else:
            self.colormap = maps[choice]
        self.update_graphs()

    def add_data(self, x_datum=None, y_data=None, pos=None, yvalues=None):
        if self.kind == "1d":
            # x_datum is float
            # y_datum is dict {label:value,...}
            for label in self.graphs.keys():
                self.graphs[label].add_datum(x_datum, y_data[label])
        elif self.kind == "2d":
            # pos = [x,y]
            # yvalues is dict {label:value,...}
            for label in self.graphs.keys():
                self.graphs[label].colorplot.add_datum(pos[0], pos[1], yvalues[label])

    def update_graphs(self):
        for label in self.graphs.keys():
            if self.kind == "1d":
                self.graphs[label].update_plot()
            elif self.kind == "2d":
                self.graphs[label].colorplot.update_plot(self.colormap)
        self.label_stepsdone.setText("Measurements done: %i" % self.measurements_completed)
        self.progress_bar.setValue(self.measurements_completed)
        self.label_current_rate.setText("Current rate: %f" % self.current_rate)

    def reset_graph_views(self):
        if self.kind == "1d":
            for label in self.graphs.keys():
                self.graphs[label].plot.enableAutoRange()
        elif self.kind == "2d":
            for label in self.graphs.keys():
                self.graphs[label].colorplot.view.enableAutoRange()
                pass

    def update_tab_name(self):
        for tab_pos in range(self.parent.tabs.count()):
            if str(self.parent.tabs.tabText(tab_pos)) == str(self.name):
                newname = "ID: %i (%s)" % (self.ID, self.status)
                self.parent.tabs.setTabText(tab_pos, newname)
                self.name = newname

    def pause(self):
        if self.status == "running":
            self.status = "paused"
            self.update_tab_name()
            self.was_paused = True

    def resume(self):
        if self.status == "paused":
            self.status = "running"
            self.update_tab_name()

    def cancel(self, force_cancel=False):
        if (not self.checkbox_cancel.isChecked()) and (not (force_cancel is True)):
            return
        else:
            self.status = "CANCELLED"
            self.data_set.close_dataset()  # close the LabRAD connection
            self.parent.IDs.remove(self.ID)
            self.parent.sweepers.pop(self.ID)
            # remove tab
            for tab_pos in range(self.parent.tabs.count()):
                if str(self.parent.tabs.tabText(tab_pos)) == str(self.name):
                    self.parent.tabs.removeTab(tab_pos)
                    return

    def initialize_sweep(self, connection):
        if self.kind == "1d":
            swept = self.det["setting_swept"]
            self.inputs[self.to_sweep] = self.xsetting
            connection.servers[swept[0]].select_device(swept[1])
            if len(self.inputs) > 1:
                connection[swept[0]].settings[swept[2]](self.inputs)
            else:
                connection[swept[0]].settings[swept[2]](self.inputs[0])
        elif self.kind == "2d":
            fast_swept = self.det["fast_swept"]
            slow_swept = self.det["slow_swept"]
            self.inputs_fast[self.to_sweep_fast] = self.x_setting
            self.inputs_slow[self.to_sweep_slow] = self.y_setting

            connection.servers[fast_swept[0]].select_device(fast_swept[1])
            if len(self.inputs_fast) > 1:
                connection[fast_swept[0]].settings[fast_swept[2]](self.inputs_fast)
            else:
                connection[fast_swept[0]].settings[fast_swept[2]](self.inputs_fast[0])

            connection.servers[slow_swept[0]].select_device(slow_swept[1])
            if len(self.inputs_slow) > 1:
                connection[slow_swept[0]].settings[slow_swept[2]](self.inputs_slow)
            else:
                connection[slow_swept[0]].settings[slow_swept[2]](self.inputs_slow[0])

    def do_measurement(self, connection):
        """Takes a measurement of all logged variables and sends the data to the graphs. Does not advance to the next step."""
        if self.kind == "1d":
            yval = {}
            dependents = []
            for setting in self.setting_details:
                connection.servers[setting.server].select_device(setting.device)
                n_entries = len(setting.inputs)
                if n_entries == 0:  # if no inputs required:
                    value = connection.servers[setting.server].settings[setting.setting]()  # call empty
                elif n_entries == 1:  # if one input required
                    value = connection.servers[setting.server].settings[setting.setting](
                        setting.inputs[0]
                    )  # call with single value
                else:  # if more than one input required
                    value = connection.servers[setting.server].settings[setting.setting](setting.inputs)
                yval.update([[setting.ID, value]])
                dependents += [value]

            if self.first_meas:
                self.first_meas = False
                units = {}
                for key in yval.keys():
                    try:
                        unit = str(yval[key].unit)
                    except:
                        unit = "unitless"
                    units.update([[key, unit]])
                for setting in self.setting_details:
                    setting.unit = units[setting.ID]

            self.add_data(self.xsetting, yval)
            self.data_set.add_data([[self.xsetting] + dependents], self.det["dv_autosave"])

        elif self.kind == "2d":
            values = {}
            dependents = []
            for setting in self.setting_details:
                connection.servers[setting.server].select_device(setting.device)
                n_entries = len(setting.inputs)
                if n_entries == 0:  # if no inputs required:
                    value = connection.servers[setting.server].settings[setting.setting]()  # call empty
                elif n_entries == 1:  # if one input required
                    value = connection.servers[setting.server].settings[setting.setting](
                        setting.inputs[0]
                    )  # call with single value
                else:  # if more than one input required
                    value = connection.servers[setting.server].settings[setting.setting](setting.inputs)
                values.update([[setting.ID, value]])
                dependents += [value]

            if self.first_meas:
                self.first_meas = False
                units = {}
                for key in values.keys():
                    try:
                        unit = str(values[key].unit)
                    except:
                        unit = "unitless"
                    units.update([[key, unit]])
                for setting in self.setting_details:
                    setting.unit = units[setting.ID]

            self.add_data(pos=[self.x_num, self.y_num], yvalues=values)
            self.data_set.add_data(
                [[self.x_num, self.y_num, self.x_setting, self.y_setting] + dependents], self.det["dv_autosave"]
            )

    def advance(self, connection, elapsed):
        """ Advances the swept setting(s) one step """

        if self.kind == "1d":
            step = self.stepsize
        elif self.kind == "2d":
            step = self.x_stepsize

        self.total_time += elapsed  # increment total time elapsed
        self.current_rate = step / elapsed  # update the current sweep rate stat
        completed = False

        if self.kind == "1d":
            self.xsetting += self.stepsize
            self.inputs[self.to_sweep] = self.xsetting
            swept = self.det["setting_swept"]
            connection[swept[0]].select_device(swept[1])

            self.measurements_completed += 1
            if self.measurements_completed >= 1 + self.det["steps"]:
                completed = True
                # print("COMPLETE")

            if not completed:
                # print("ADVANCING...")
                if len(self.inputs) > 1:
                    connection[swept[0]].settings[swept[2]](self.inputs)
                else:
                    connection[swept[0]].settings[swept[2]](self.inputs[0])

            if (self.np_time == 0.0) or (not self.was_paused):
                self.np_swept += self.stepsize
                self.np_time += elapsed
            else:
                self.was_paused = False

        elif self.kind == "2d":
            self.measurements_completed += 1
            y_changed = False
            self.x_setting += self.x_stepsize  # increment x setting
            self.x_num += 1  # increment x number
            if self.x_num > self.det["xsteps"]:  # if x number exceeds row length
                self.x_setting = self.det["xstart"]  # reset x setting
                self.x_num = 0  # reset x number
                self.y_setting += self.y_stepsize  # increment y setting
                self.y_num += 1  # increment y number
                y_changed = True  # y has changed

                if self.y_num > self.det["ysteps"]:  # sweep is completed
                    completed = True

            if not completed:  # if not done, update x setting (it always changes)
                connection.servers[self.det["fast_swept"][0]].select_device(self.det["fast_swept"][1])
                self.inputs_fast[self.to_sweep_fast] = self.x_setting
                if len(self.inputs_fast) > 1:
                    connection.servers[self.det["fast_swept"][0]].settings[self.det["fast_swept"][2]](self.inputs_fast)
                else:
                    connection.servers[self.det["fast_swept"][0]].settings[self.det["fast_swept"][2]](
                        self.inputs_fast[0]
                    )
            if y_changed:  # if y has changed, update y setting
                connection.servers[self.det["slow_swept"][0]].select_device(self.det["slow_swept"][1])
                self.inputs_slow[self.to_sweep_slow] = self.y_setting
                if len(self.inputs_slow) > 1:
                    connection.servers[self.det["slow_swept"][0]].settings[self.det["slow_swept"][2]](self.inputs_slow)
                else:
                    connection.servers[self.det["slow_swept"][0]].settings[self.det["slow_swept"][2]](
                        self.inputs_slow[0]
                    )
            self.current_delay = self.det["ydelay"] if y_changed else self.det["xdelay"]

            if ((self.np_time == 0.0) or (not self.was_paused)) and (self.current_delay == self.det["xdelay"]):
                self.np_swept += self.x_stepsize
                self.np_time += elapsed
            else:
                self.was_paused = False

        if completed:
            self.status = "completed"
            self.update_tab_name()
            self.button_cancel.setText("Close")
            t = time.localtime()
            self.finished_time = t
            self.label_complete_time.setText(
                "Completed at: %i/%i/%i %i:%i:%i" % (t.tm_mon, t.tm_mday, t.tm_year, t.tm_hour, t.tm_min, t.tm_sec)
            )
        self.label_complete_rate.setText("Average rate: %f" % (self.np_swept / self.np_time))
Esempio n. 4
0
class sweepInstance(gui.QMainWindow):
    def __init__(self,
                 parent,
                 details,
                 ID,
                 status,
                 name,
                 kind='1d',
                 ls=23,
                 gw=384,
                 gh=192,
                 pl=320,
                 bl=12,
                 ll=128,
                 ih=96):
        super(sweepInstance, self).__init__()
        # info/control bar at top
        self.parent = parent
        self.det = details
        self.status = status
        self.name = name
        self.ID = ID
        self.kind = kind  # '1d' or '2d'

        self.measurements_completed = 0
        self.total_time = 0.0  # total amount of time spent sweeping.
        self.current_rate = 0.0  # current sweep rate
        self.finished_time = None  # None = not finished
        self.was_paused = False  # Used to skip paused time when counting average rate
        self.completed = False  # has it finished?

        self.np_swept = 0.0  # amount of setting swept while not paused
        self.np_time = 0.0  # amount of time passed while not paused

        self.ls = ls  # line spacing
        self.gw = gw  # graph width
        self.gh = gh  # graph height

        self.pl = pl  # plot(2d) sidelength
        self.bl = bl  # bar (and bar spacing) length
        self.ll = ll  # label length

        self.setting_details = self.det['setting_details']
        self.colormap = None
        self.custom_map = None

        # parameters
        self.parameter_names = []

        # dataset
        if kind == '1d':
            independents = [
                self.det['custom_name']
                if self.det['custom_name'] else self.det['xlabel']
            ]
        else:
            independents = [
                'xnum', 'ynum', self.det['fast_custom_name']
                if self.det['fast_custom_name'] else self.det['xlabel'],
                self.det['slow_custom_name']
                if self.det['slow_custom_name'] else self.det['ylabel']
            ]

        dependents = [setting.name for setting in self.setting_details]

        self.data_set = DataSet(
            self.det['dv_name'],
            self.det['dv_loc'],
            independents,
            dependents,
        )

        # comment, paremeters
        # self.comment_list    = []
        # self.parameter_list  = []
        # self.parameter_names = []
        # self.has_written     = False

        # dataset location (None = not set yet)
        # self.dataset_location = None

        o = array([0, ls * 5])  # origin
        self.graphs = {}
        n = 0
        if self.kind == '1d':
            lbl = [setting.ID for setting in self.setting_details]
        elif self.kind == '2d':
            lbl = [setting.ID for setting in self.setting_details]
        for pos in range(len(lbl)):
            ylabel = self.setting_details[pos].name
            ID = self.setting_details[pos].ID
            if kind == '1d':
                x = o[0] + (gw + ls) * (n % 3)
                xlabel = self.det['custom_name'] if self.det[
                    'custom_name'] else self.det['xlabel']
                y = o[1] + (gh + ls) * int(floor(
                    n / 3.0))  # rectangular graphs for 1d
                self.graphs.update([[
                    ID,
                    plotInstance(xlabel,
                                 ylabel,
                                 None,
                                 parent=self,
                                 geometry=[x, y, gw, gh])
                ]])

            elif kind == '2d':
                xname = self.det['fast_custom_name'] if self.det[
                    'fast_custom_name'] else self.det['xlabel']
                yname = self.det['slow_custom_name'] if self.det[
                    'slow_custom_name'] else self.det['ylabel']
                #print(xname,yname)
                x = o[0] + (n % 3) * (pl + 7 * ls + ih)  #(ls*2+pl+bl*3+ll)
                y = o[1] + int(floor(n / 3.0)) * (
                    pl + 2 * ls + ih)  #(gw+ls) *  # square graphs for 2d
                self.graphs.update([[
                    ID,
                    colorplotShell(xname,
                                   yname,
                                   self.det['xnum'],
                                   self.det['ynum'],
                                   [self.det['xstart'], self.det['xstop']],
                                   [self.det['ystart'], self.det['ystop']],
                                   parent=self,
                                   geometry=[
                                       x, y, ls + pl + bl * 3 + ll, pl + ls
                                   ],
                                   name=self.det['setting_details'][pos].name,
                                   ls=ls,
                                   pl=pl,
                                   bl=bl,
                                   ll=ll)
                ]])

            n += 1

        if self.kind == '2d':
            self.current_delay = self.det['xdelay']

        # User defined input handling
        if self.kind == '1d':
            self.inputs = self.det['inputs']
            self.to_sweep = self.det['to_sweep']
        if self.kind == '2d':
            self.inputs_fast = self.det['inputs_fast']
            self.to_sweep_fast = self.det['to_sweep_fast']
            self.inputs_slow = self.det['inputs_slow']
            self.to_sweep_slow = self.det['to_sweep_slow']

        self.first_meas = True
        self.doUI()
        self.time = time.time()

    def doUI(self):
        # background
        #self.setBackground(gui.QColor('black'))

        # use self.det
        if self.kind == '1d':
            self.stepsize = (self.det['stop'] -
                             self.det['start']) / (self.det['steps'])
            self.xsetting = self.det[
                'start']  # current value of setting. Starts at beginning.
        elif self.kind == '2d':
            self.x_stepsize = (self.det['xstop'] -
                               self.det['xstart']) / (self.det['xsteps'])
            self.y_stepsize = (self.det['ystop'] -
                               self.det['ystart']) / (self.det['ysteps'])
            self.x_setting = self.det['xstart']
            self.y_setting = self.det['ystart']
            self.x_num = 0
            self.y_num = 0

        # labels / info
        t = self.det['start_timestamp']
        time_text = "Sweep started at: %i/%i/%i %i:%i:%i" % (
            t.tm_mon, t.tm_mday, t.tm_year, t.tm_hour, t.tm_min, t.tm_sec)
        self.label_starttime = simpleText(self, time_text,
                                          [0, 0, self.gw // 2 + 74, self.ls])
        self.label_stepsdone = simpleText(
            self, "Measurements done: %i" % (self.measurements_completed),
            [0, self.ls * 1, self.gw // 2, self.ls])

        if self.kind == '1d':
            self.meas_total = self.det['steps'] + 1
        elif self.kind == '2d':
            self.meas_total = self.det['xnum'] * self.det['ynum']

        self.label_stepstotal = simpleText(
            self, "Measurements total: %i" % (self.meas_total),
            [0, self.ls * 2, self.gw // 2, self.ls])
        self.progress_bar = gui.QProgressBar(self)
        self.progress_bar.setRange(0, self.meas_total)
        self.progress_bar.setGeometry(0, self.ls * 3, self.gw // 2, self.ls)

        # sweep control
        self.button_pause = queryButton("Pause", self, '',
                                        [self.gw // 2, self.ls * 1],
                                        self.pause)
        self.button_resume = queryButton("Resume", self, '',
                                         [self.gw // 2, self.ls * 2],
                                         self.resume)
        self.button_cancel = queryButton("Cancel", self, '',
                                         [self.gw // 2, self.ls * 3],
                                         self.cancel)
        self.checkbox_cancel = checkBox(self, "Confirm",
                                        [self.gw // 2 + 76, self.ls * 3 - 3])

        # 'set graphs to automatic' button
        self.button_graph_auto = queryButton("Reset graph view", self, "",
                                             [0, self.ls * 4],
                                             self.reset_graph_views)

        # completion readout
        self.label_complete_time = simpleText(
            self, "Completed at:",
            [self.gw // 2 + 76 + self.ls, self.ls * 0, self.gw // 2, self.ls])
        self.label_complete_rate = simpleText(
            self, "Average rate:",
            [self.gw // 2 + 76 + self.ls, self.ls * 1, self.gw // 2, self.ls])
        self.label_current_rate = simpleText(
            self, "Current rate:",
            [self.gw // 2 + 76 + self.ls, self.ls * 2, self.gw // 2, self.ls])

        # data set name, location
        self.input_logname = textInput(
            self, '',
            [self.gw + 76 + self.ls * 2, self.ls * 0, self.ll, self.ls])
        self.input_logdest = textInput(
            self, '',
            [self.gw + 76 + self.ls * 2, self.ls * 1, self.ll, self.ls])
        self.input_logname.setPlaceholderText("Dataset name")
        self.input_logdest.setPlaceholderText("Dataset location")
        self.input_logdest.setText(self.det['dv_loc'])
        self.input_logname.setText(self.det['dv_name'])
        self.input_logdest.setToolTip(
            "Folders separated by '\\' characters.\nNo leading or trailing backslash.\nExample: data\\testing\\2016\nDefault: data"
        )

        # data logging (data vault) details
        self.button_add_comments = queryButton(
            "Add comment(s)", self, '',
            [self.ll + self.gw + 76 + self.ls * 3, self.ls * 0],
            self.add_comments)
        self.button_add_parameters = queryButton(
            "Add parameter(s)", self, '',
            [self.ll + self.gw + 76 + self.ls * 3, self.ls * 1],
            self.add_parameters)
        self.button_log_data = queryButton(
            "Write data set", self, '',
            [self.ll + self.gw + 76 + self.ls * 3, self.ls * 2], self.log_data)

        # colormap
        if self.kind == '2d':
            self.label_colormap = simpleText(self, "Color map:", [
                self.ll * 2 + self.ls * 2 + self.gw + 76 + self.ls * 2, 0, 64,
                self.ls
            ])
            self.dropdown_colormap = simpleDropdown(
                self, ["None", "Custom"] + maps.keys(), [
                    self.ll * 2 + self.ls * 2 + self.gw + self.ls * 2 + 76 +
                    64, 0, 64, self.ls
                ], self.change_colormap)
            self.button_custommap = queryButton("Custom", self, '', [
                self.ll * 2 + self.ls * 2 + self.gw + 76 + self.ls * 2, self.ls
            ], self.cust_map)
        elif self.kind == '1d':
            self.label_colormap = self.dropdown_colormap = self.button_custommap = None

        # open dataset if autosave is on
        if self.det['dv_autosave']: self.open_dataset()

    def open_dataset(self):
        location_raw = str(self.input_logdest.getValue())
        name_raw = str(self.input_logname.getValue())
        if location_raw:
            while location_raw.startswith('\\'):  # Remove leading backslashes
                location_raw = location_raw[1:]  #
            while location_raw.endswith('\\'):  # Remove trailing backslashes
                location_raw = location_raw[:-1]  #
            lines = location_raw.replace('\\', '\n').splitlines()
            location = [''] + lines
        else:
            location = ['', 'data']
        self.data_set.location = location
        self.data_set.name = name_raw
        self.data_set.create_dataset()

        self.input_logdest.setReadOnly(True)
        self.input_logname.setReadOnly(True)

        self.data_set.write_comments()
        self.data_set.write_parameters()

    def log_data(self):

        if not self.data_set.dataset_open:
            # if this is the first time we're writing to the set...
            self.open_dataset()

        # data_set.data populated while measurements ongoing, just need to write it here.
        # If set to autowrite, write_data() will be called each time a data is added
        print("Writing {datalen} data lines...".format(
            datalen=len(self.data_set.data)))
        self.data_set.write_data()

    def add_comments(self):
        commentbox = commentBoxWidget(self)

    def send_comments(self, comments):
        self.data_set.add_comments(comments, self.data_set.dataset_open)

    def add_parameters(self):
        parameterbox = parameterBoxWidget(self, self.parameter_names)

    def send_parameters(self, parameters):
        self.parameter_names += [param[0] for param in parameters]
        self.data_set.add_parameters(parameters, self.data_set.dataset_open)

    def cust_map(self):
        self.dropdown_colormap.setCurrentIndex(1)  # Custom
        self.change_colormap()
        go = customMapWidget(self)

    def change_colormap(self):
        choice = str(self.dropdown_colormap.currentText())
        if choice == 'None':
            self.colormap = None
        elif choice == 'Custom':
            self.colormap = self.custom_map
        else:
            self.colormap = maps[choice]
        self.update_graphs()

    def add_data(self, x_datum=None, y_data=None, pos=None, yvalues=None):
        if self.kind == '1d':
            # x_datum is float
            # y_datum is dict {label:value,...}
            for label in self.graphs.keys():
                self.graphs[label].add_datum(x_datum, y_data[label])
        elif self.kind == '2d':
            # pos = [x,y]
            # yvalues is dict {label:value,...}
            for label in self.graphs.keys():
                self.graphs[label].colorplot.add_datum(pos[0], pos[1],
                                                       yvalues[label])

    def update_graphs(self):
        for label in self.graphs.keys():
            if self.kind == '1d':
                self.graphs[label].update_plot()
            elif self.kind == '2d':
                self.graphs[label].colorplot.update_plot(self.colormap)
        self.label_stepsdone.setText("Measurements done: %i" %
                                     self.measurements_completed)
        self.progress_bar.setValue(self.measurements_completed)
        self.label_current_rate.setText("Current rate: %f" % self.current_rate)

    def reset_graph_views(self):
        if self.kind == '1d':
            for label in self.graphs.keys():
                self.graphs[label].plot.enableAutoRange()
        elif self.kind == '2d':
            for label in self.graphs.keys():
                self.graphs[label].colorplot.view.enableAutoRange()
                pass

    def update_tab_name(self):
        for tab_pos in range(self.parent.tabs.count()):
            if str(self.parent.tabs.tabText(tab_pos)) == str(self.name):
                newname = 'ID: %i (%s)' % (self.ID, self.status)
                self.parent.tabs.setTabText(tab_pos, newname)
                self.name = newname

    def pause(self):
        if self.status == 'running':
            self.status = 'paused'
            self.update_tab_name()
            self.was_paused = True

    def resume(self):
        if self.status == 'paused':
            self.status = 'running'
            self.update_tab_name()

    def cancel(self, force_cancel=False):
        if (not self.checkbox_cancel.isChecked()) and (
                not (force_cancel is True)):
            return
        else:
            self.status = 'CANCELLED'
            self.data_set.close_dataset()  # close the LabRAD connection
            self.parent.IDs.remove(self.ID)
            self.parent.sweepers.pop(self.ID)
            #remove tab
            for tab_pos in range(self.parent.tabs.count()):
                if str(self.parent.tabs.tabText(tab_pos)) == str(self.name):
                    self.parent.tabs.removeTab(tab_pos)
                    return

    def initialize_sweep(self, connection):
        if self.kind == '1d':
            swept = self.det['setting_swept']
            self.inputs[self.to_sweep] = self.xsetting
            connection.servers[swept[0]].select_device(swept[1])
            if len(self.inputs) > 1:
                connection[swept[0]].settings[swept[2]](self.inputs)
            else:
                connection[swept[0]].settings[swept[2]](self.inputs[0])
        elif self.kind == '2d':
            fast_swept = self.det['fast_swept']
            slow_swept = self.det['slow_swept']
            self.inputs_fast[self.to_sweep_fast] = self.x_setting
            self.inputs_slow[self.to_sweep_slow] = self.y_setting

            connection.servers[fast_swept[0]].select_device(fast_swept[1])
            if len(self.inputs_fast) > 1:
                connection[fast_swept[0]].settings[fast_swept[2]](
                    self.inputs_fast)
            else:
                connection[fast_swept[0]].settings[fast_swept[2]](
                    self.inputs_fast[0])

            connection.servers[slow_swept[0]].select_device(slow_swept[1])
            if len(self.inputs_slow) > 1:
                connection[slow_swept[0]].settings[slow_swept[2]](
                    self.inputs_slow)
            else:
                connection[slow_swept[0]].settings[slow_swept[2]](
                    self.inputs_slow[0])

    def do_measurement(self, connection):
        '''Takes a measurement of all logged variables and sends the data to the graphs. Does not advance to the next step.'''
        if self.kind == '1d':
            yval = {}
            dependents = []
            for setting in self.setting_details:
                connection.servers[setting.server].select_device(
                    setting.device)
                n_entries = len(setting.inputs)
                if n_entries == 0:  # if no inputs required:
                    value = connection.servers[setting.server].settings[
                        setting.setting]()  # call empty
                elif n_entries == 1:  # if one input required
                    value = connection.servers[setting.server].settings[
                        setting.setting](
                            setting.inputs[0])  # call with single value
                else:  # if more than one input required
                    value = connection.servers[setting.server].settings[
                        setting.setting](setting.inputs)
                yval.update([[setting.ID, value]])
                dependents += [value]

            if self.first_meas:
                self.first_meas = False
                units = {}
                for key in yval.keys():
                    try:
                        unit = str(yval[key].unit)
                    except:
                        unit = 'unitless'
                    units.update([[key, unit]])
                for setting in self.setting_details:
                    setting.unit = units[setting.ID]

            self.add_data(self.xsetting, yval)
            self.data_set.add_data([[self.xsetting] + dependents],
                                   self.det['dv_autosave'])

        elif self.kind == '2d':
            values = {}
            dependents = []
            for setting in self.setting_details:
                connection.servers[setting.server].select_device(
                    setting.device)
                n_entries = len(setting.inputs)
                if n_entries == 0:  # if no inputs required:
                    value = connection.servers[setting.server].settings[
                        setting.setting]()  # call empty
                elif n_entries == 1:  # if one input required
                    value = connection.servers[setting.server].settings[
                        setting.setting](
                            setting.inputs[0])  # call with single value
                else:  # if more than one input required
                    value = connection.servers[setting.server].settings[
                        setting.setting](setting.inputs)
                values.update([[setting.ID, value]])
                dependents += [value]

            if self.first_meas:
                self.first_meas = False
                units = {}
                for key in values.keys():
                    try:
                        unit = str(values[key].unit)
                    except:
                        unit = 'unitless'
                    units.update([[key, unit]])
                for setting in self.setting_details:
                    setting.unit = units[setting.ID]

            self.add_data(pos=[self.x_num, self.y_num], yvalues=values)
            self.data_set.add_data(
                [[self.x_num, self.y_num, self.x_setting, self.y_setting] +
                 dependents], self.det['dv_autosave'])

    def advance(self, connection, elapsed):
        ''' Advances the swept setting(s) one step '''

        if self.kind == '1d':
            step = self.stepsize
        elif self.kind == '2d':
            step = self.x_stepsize

        self.total_time += elapsed  # increment total time elapsed
        self.current_rate = step / elapsed  # update the current sweep rate stat
        completed = False

        if self.kind == '1d':
            self.xsetting += self.stepsize
            self.inputs[self.to_sweep] = self.xsetting
            swept = self.det['setting_swept']
            connection[swept[0]].select_device(swept[1])

            self.measurements_completed += 1
            if self.measurements_completed >= 1 + self.det['steps']:
                completed = True
                #print("COMPLETE")

            if not completed:
                #print("ADVANCING...")
                if len(self.inputs) > 1:
                    connection[swept[0]].settings[swept[2]](self.inputs)
                else:
                    connection[swept[0]].settings[swept[2]](self.inputs[0])

            if (self.np_time == 0.0) or (not self.was_paused):
                self.np_swept += self.stepsize
                self.np_time += elapsed
            else:
                self.was_paused = False

        elif self.kind == '2d':
            self.measurements_completed += 1
            y_changed = False
            self.x_setting += self.x_stepsize  # increment x setting
            self.x_num += 1  # increment x number
            if self.x_num > self.det[
                    'xsteps']:  # if x number exceeds row length
                self.x_setting = self.det['xstart']  # reset x setting
                self.x_num = 0  # reset x number
                self.y_setting += self.y_stepsize  # increment y setting
                self.y_num += 1  # increment y number
                y_changed = True  # y has changed

                if self.y_num > self.det['ysteps']:  # sweep is completed
                    completed = True

            if not completed:  # if not done, update x setting (it always changes)
                connection.servers[self.det['fast_swept'][0]].select_device(
                    self.det['fast_swept'][1])
                self.inputs_fast[self.to_sweep_fast] = self.x_setting
                if len(self.inputs_fast) > 1:
                    connection.servers[self.det['fast_swept'][0]].settings[
                        self.det['fast_swept'][2]](self.inputs_fast)
                else:
                    connection.servers[self.det['fast_swept'][0]].settings[
                        self.det['fast_swept'][2]](self.inputs_fast[0])
            if y_changed:  # if y has changed, update y setting
                connection.servers[self.det['slow_swept'][0]].select_device(
                    self.det['slow_swept'][1])
                self.inputs_slow[self.to_sweep_slow] = self.y_setting
                if len(self.inputs_slow) > 1:
                    connection.servers[self.det['slow_swept'][0]].settings[
                        self.det['slow_swept'][2]](self.inputs_slow)
                else:
                    connection.servers[self.det['slow_swept'][0]].settings[
                        self.det['slow_swept'][2]](self.inputs_slow[0])
            self.current_delay = self.det['ydelay'] if y_changed else self.det[
                'xdelay']

            if ((self.np_time == 0.0) or
                (not self.was_paused)) and (self.current_delay
                                            == self.det['xdelay']):
                self.np_swept += self.x_stepsize
                self.np_time += elapsed
            else:
                self.was_paused = False

        if completed:
            self.status = 'completed'
            self.update_tab_name()
            self.button_cancel.setText("Close")
            t = time.localtime()
            self.finished_time = t
            self.label_complete_time.setText(
                "Completed at: %i/%i/%i %i:%i:%i" %
                (t.tm_mon, t.tm_mday, t.tm_year, t.tm_hour, t.tm_min,
                 t.tm_sec))
        self.label_complete_rate.setText("Average rate: %f" %
                                         (self.np_swept / self.np_time))