def plot_update(date, num): plots = [] data = open_data(date, num) for lockin in range(1, 5): plot = qc.QtPlot() name = "SR860_{}_X".format(lockin) name_res = "SR860_{}_resistance".format(lockin) label = "V<sub>xy</sub>" if (lockin%2) == 1 else "V<sub>xx</sub>" label = (label, "V") tr = getattr(data, name_res, []) if not tr: tr = getattr(data, name, []) else: name = name_res label = ("Resistance", "Ohms") plot.add(tr, name=name, color=color_cycle[lockin-1]) format_plot(plot, label) plots.append(plot) while True: data.read() for plot in plots: plot.update() sleep(10)
def plot_cooldown_update(date, num): plots = [] data = open_data(date, num) for lockin in range(1, 2): for i, switch in enumerate(("A", "B", "C", "D", "E")): plot = qc.QtPlot() name = "{}_SR860_{}_X".format(switch, lockin) name_res = "{}_SR860_{}_resistance".format(switch, lockin) label = "V<sub>xy</sub>" if (lockin%2) == 1 else "V<sub>xx</sub>" label = (label, "V") tr = getattr(data, name_res, []) if not tr: tr = getattr(data, name, []) else: name = name_res label = ("Resistance", "Ohms") plot.add(tr, name=name, color=color_cycle[((lockin-1)*5 + i) % 10]) plot.win.resize(600, 450) plots.append(plot) while True: data.read() for plot in plots: plot.update() sleep(10)
def plot_all_field_sweeps(date, start_num, switches=("B", "C", "D", "E")): """ Plot field sweeps where data is split into multiple consecutive datasets. This is the case when one DataSet is taken for each switch configuration """ plots = [] for i, sw in enumerate(switches): data = open_data(date, start_num+i) for lockin in range(1, 5): plot = qc.QtPlot() name = "SR860_{}_X_preamp".format(lockin) name_res = "Voltage_{}".format(lockin) # fyi I changed label = "V<sub>xx</sub>" if (lockin%2) == 1 else "V<sub>xy</sub>" # some of these label = (label, "V") tr = getattr(data, name_res, []) if not tr: tr = getattr(data, name, []) else: name = name_res label = ("Resistance", "Ohms") plot.add(tr, name=name, color=color_cycle[lockin-1]) format_plot(plot, label) plots.append(plot) plot.save(filename="{}_{}.png".format(sw, name)) return plots
def plot_update_currents(date, num): plots = [] data = open_data(date, num) for lockin in range(1, 4): plot = qc.QtPlot() name_ithaco = "SR860_{}_X_ithaco".format(lockin) name_volt = "SR860_{}_X_preamp".format(lockin) tr = getattr(data, name_ithaco, []) if not tr: tr = getattr(data, name_volt, []) label = ("Voltage", "V") name = name_volt else: label = ("Current", "A") name = name_ithaco plot.add(tr, name=name, color=color_cycle[lockin-1]) format_plot(plot, label) plots.append(plot) while True: data.read() for plot in plots: plot.update() sleep(10)
def plot_data(data, key=None, matplot=False): """ Plotting function for plotting arrays of a dataset in seperate QtPlots, cannot be used with live_plot if there is more than one subplot. If key is specified returns only the plot for the array with the key in the name. Args: data (qcodes dataset): dataset to be plotted key (str): key which if specified is used to select the first array from the dataset for plotting with a name which contains this key. matplot (bool) (default False): default is to QtPlot the data Returns: qc Matplot or QtPlot """ if hasattr(data, "data_num"): title = title = get_title(data.data_num) else: title = "" if key is None: plots = [] for value in data.arrays.keys(): if "set" not in value: if matplot: pl = qc.MatPlot(getattr(data, value)) else: pl = qc.QtPlot(getattr(data, value), figsize=(700, 500)) pl.subplots[0].setTitle(title) pl.subplots[0].showGrid(True, True) plots.append(pl) return plots else: try: key_array_name = [v for v in data.arrays.keys() if key in v][0] except IndexError: raise KeyError('key: {} not in data array ' 'names: {}'.format(key, list(data.arrays.keys()))) if matplot: pl = qc.MatPlot(getattr(data, key_array_name)) else: pl = qc.QtPlot(getattr(data, key_array_name), figsize=(700, 500)) pl.subplots[0].setTitle(title) pl.subplots[0].showGrid(True, True) return pl
def do_bg_iv(md, tg_set, V_sd, states, params, tg, sd, plot_params=[], bg_step=0.02, iv_step=0.00004, wait_time=5): for state in states: md.select(state) tg_set.set(tg[0]) V_sd.set(sd[0]) sleep(wait_time) # Inner Loop (V_sd) inner_loop = qc.Loop(V_sd.sweep(sd[0], sd[1], step=iv_step)) inner_loop = inner_loop.each(*params) inner_loop = inner_loop.then(qc.Task(V_sd.set, sd[0]), qc.Wait(wait_time)) # Outer Loop (tg) loop = qc.Loop(tg_set.sweep(tg[0], tg[1], step=bg_step)) loop = loop.each(inner_loop) data = loop.get_data_set() # Show each plot plots = [] for param in plot_params: param_data = getattr(data, param, None) if param_data is None: warnings.warn("Missing parameter {} not plotted".format(param), RuntimeWarning) continue plot = qc.QtPlot() plot.add(param_data, name=param, title=param) plots.append(plot) # Define function to live update all plots def upd(): for plot in plots: plot.update() # Update plots at the end of each line loop = loop.with_bg_task(upd) # Run the loop loop.run() # Set parameters to zero tg_set.set(0) V_sd.set(0) # Clear mulberry at end md.clear()
def plot_data_single_window(dataset, meas_param, key=None): """ Plotting function for plotting arrays of a dataset in a single window (works with live plot but not great if you want to save a png) Args: dataset (qcodes dataset): dataset to be plotted meas_param: parameter being measured key (str) (default None): string to search the array names of the measured param for, all arrays with key in name will be added as subplots. Default is to plot all. Returns: QtPlot """ if hasattr(dataset, "data_num"): title = title = get_title(dataset.data_num) else: title = "" plot_array_names = [] if hasattr(meas_param, 'full_names'): for array_name in meas_param.full_names: if (key is None) or (key in array_name): plot_array_names.append(array_name) elif hasattr(meas_param, 'full_name'): if (key is None) or (key in array_name): plot_array_names.append(meas_param.full_name) if len(plot_array_names) == 0: raise KeyError('key: {} not in parameter array ' 'names: {}'.format(key, list(meas_param.names))) plot = qc.QtPlot(figsize=(700 * len(plot_array_names), 500)) for i, plot_array_name in enumerate(plot_array_names): plot.add(getattr(dataset, plot_array_name), subplot=i+1) plot.subplots[i].showGrid(True, True) plot.subplots[0].setTitle(title) return plot
def plot_all_field_sweeps_comb(data): """ Plot field sweeps under the condition that all sweeps are included in a single data file """ plots = [] for sw in ("B", "C", "D", "E"): for lockin in range(1, 4): plot = qc.QtPlot() name = "{}_SR860_{}_X".format(sw, lockin) name_res = "{}_SR860_{}_resistance".format(sw, lockin) label = "V<sub>xy</sub>" if (lockin%2) == 1 else "V<sub>xx</sub>" label = (label, "V") tr = getattr(data, name_res, []) if not tr: tr = getattr(data, name, []) else: name = name_res label = ("Resistance", "Ohms") plot.add(tr, name=name, color=color_cycle[lockin-1]) format_plot(plot, label) plots.append(plot) plot.save(filename="{}.png".format(name)) return plots
def single_param_sweep(SetParam, SetArray, delay, *MeasParams, DataName='', XParam=None, YParam=None, plot_results=True, save_plots=True): """ Single parameter sweep, single measure (for more measurements, add parameters to the .each() part). Includes live plot. Returns: data (a qcodes DataSet object), plot Arguments: SetParam: The parameter to sweep (such as a voltage) SetArray: should be a list or numpy array of values you want to set SetParam to. delay: The delay time between when SetParam is set till the MeasParams are measured (0 by default). *MeasParam: The comma-separated parameters you want to measure at each setpoint Keyword Arguments: DataName: A name to tag the data (defaults to nothing) XParam: Optional, the x parameter to be used in plotting (if not used, will default to the set parameter for every plot). Must be either a list that is the same length as YParam, a single parameter, or None. YParam: Allows you to pick only a few parameters to plot out of those measured. (if not mentioned, will plot all *MeasParams) plot_results: True by default, if false, suppresses plotting save_plots: True by default. If false, doesn't save plots at the end of the sweep """ loop = qc.Loop(SetParam[SetArray], delay=delay).each(*MeasParams) data = loop.get_data_set(name=DataName) plot = [] def _plot_update(): if type(plot) is list: for p in plot: p.update() else: plot.update() def _plot_save(): if type(plot) is list: for i in range(len(plot)): fname = '{}_{}.png'.format( plot[i].get_default_title(), str(XParam[i]) + 'vs' + str(YParam[i])) plot[i].save(filename=fname) else: fname = '{}_{}.png'.format(plot.get_default_title(), str(XParam) + 'vs' + str(*MeasParams)) plot.save(filename=fname) if plot_results: if XParam is None: XParam = SetParam if len(MeasParams) == 1: plot = qc.QtPlot(getattr(data, str(XParam) + '_set'), getattr(data, str(*MeasParams)), window_title=str(XParam) + ' vs. ' + str(*MeasParams)) loop.with_bg_task(plot.update) else: if YParam is None: YParam = MeasParams if type(XParam) is not list and type(XParam) is not tuple: if type(YParam) is not list and type(YParam) is not tuple: XParam = [XParam] YParam = [YParam] else: XParam = [XParam] * len(MeasParams) elif len(XParam) != len(YParam): raise ValueError('length of XParam list must be the same as' + 'length of YParam list') # Create a str for XParam so we can account for _set in the str XParamStr = [] for i in range(len(XParam)): xpi = str(XParam[i]) if xpi == str(SetParam): XParamStr.append(xpi + '_set') else: XParamStr.append(xpi) for i in range(len(YParam)): title = str(YParam[i]) + ' vs. ' + str(XParam[i]) plot.append( qc.QtPlot(getattr(data, XParamStr[i]), getattr(data, str(YParam[i])), window_title=title)) loop.with_bg_task(_plot_update) try: loop.run() if save_plots and plot_results: _plot_save() return data, plot except KeyboardInterrupt: if plot_results: _plot_update() if save_plots: _plot_save() print('Keyboard Interrupt') return data, plot
def data_log(delay, *MeasParams, N=None, minutes=None, DataName='', XParam=None, YParam=None, breakif=None, plot_results=True, save_plots=True): """A loop that takes measurements every "delay" seconds (starts measuring at startup, and each delay comes after the measurement). Either choose to measure N times or for minutes. The arrays of the data are: count_set (the number of the data point), time0 (the time since the start), *MeasParams (comma-separated collection of parameters (instr.param) measured at each point) Note that the amount of minutes may be slightly larger than min because this assumes the time of measurement for the parameters is 0. Returns: data (a DataSet object), plot (a plot or a list of plots if MeasParams has more than one parameter) Arguments: delay: Seconds between each measurement *MeasParams: a comma-separated collection of parameters to measure Keyword Arguments: N: The number of data points to take (if left None, need to use minutes) minutes: The number of minutes to take data points (if left as None, need to use N). If minutes/delay is not an integer, rounds up DataName: the name to be placed on the file (defaults to '') XParam: an optional specification of the x-axis parameter to plot (defaults to time0 for all plots). If you want different x-axes for different plots, use a list. To include time0 in that list, use the string 'time' or 'time0'. The list must be the same length as YParam or MeasParams YParam: optional specification of y-axis parameters to plot (if not specified, it will create one plot per MeasParam). breakif: specify a parameterless function that returns true when the break condition is met (example ppms temperature < 2.01) plot_results: if you want to do the data log without plots, set this to False save_plots: True by default. If false, doesn't save plots at the end of the sweep """ if breakif is None: def breakif(): pass count = qc.ManualParameter('count') time0 = time_from_start('time0') if N is None and minutes is None: return ValueError('Must have either N or minutes arguments') elif N is not None and minutes is not None: return ValueError('Only use N or minutes arguments') elif N is not None and minutes is None: loop = qc.Loop(count.sweep(1, int(N), step=1)).each(time0, *MeasParams, qc.Wait(delay), qc.BreakIf(breakif)) elif minutes is not None and N is None: N = ceil(minutes * 60 / delay) loop = qc.Loop(count.sweep(1, int(N), step=1)).each(time0, *MeasParams, qc.Wait(delay), qc.BreakIf(breakif)) data = loop.get_data_set(name=DataName) plot = [] def _plot_update(): if type(plot) is list: for p in plot: p.update() else: plot.update() def _plot_save(): if type(plot) is list: for p in plot: p.save() else: plot.save() if plot_results: if XParam is None: XParam = time0 if len(MeasParams) == 1: plot = qc.QtPlot(getattr(data, str(XParam)), getattr(data, str(*MeasParams)), window_title=str(XParam) + ' vs. ' + str(*MeasParams)) loop.with_bg_task(plot.update) else: if YParam is None: YParam = MeasParams if type(XParam) is not list and type(XParam) is not tuple: if type(YParam) is not list and type(YParam) is not tuple: XParam = [XParam] YParam = [YParam] else: XParam = [XParam] * len(MeasParams) elif len(XParam) != len(YParam): raise ValueError('length of XParam list must be the same as' + 'length of YParam list') for i in range(len(XParam)): if type(XParam[i]) is str: if XParam[i] == 'time' or XParam[i] == 'time0': XParam[i] = time0 # plot = [] for i in range(len(YParam)): title = str(YParam[i]) + ' vs. ' + str(XParam[i]) plot.append( qc.QtPlot(getattr(data, str(XParam[i])), getattr(data, str(YParam[i])), window_title=title)) # def _plot_update(): # for p in plot: # p.update() # # def _plot_save(): # for p in plot: # p.save() loop.with_bg_task(_plot_update) try: time0.reset() loop.run() if save_plots and plot_results: _plot_save() return data, plot except KeyboardInterrupt: if plot_results: _plot_update() if save_plots: _plot_save() print('Keyboard Interrupt') return data, plot
def twod_param_sweep(SetParam1, SetArray1, SetParam2, SetArray2, *MeasParams, SetDelay1=0, SetDelay2=0, Param2_SetBetween=None, DataName='', ZParam=None, plot_results=True, save_plots=True): """ Single parameter sweep, single measure (for more measurements, add parameters to the .each() part). Includes live plot. Note: if the SetParam1 array is nonuniform, the y axis of the plot will be messed up. Try MatPlot instead of QtPlot in that situation. Returns: data (a qcodes DataSet object), plot Arguments: SetParam1: The outer parameter to sweep (such as a temperature) SetArray1: should be a list or numpy array of values you want to set SetParam1 to. This array will be run through once SetParam2: The inner parameter to sweep (such as a voltage) Param2_SetBetween: Sets parameter 2 to this value at the end of each sweep of the parameter (completion of one row) and before changing parameter 1. SetArray1: should be a list or numpy array of values you want to set SetParam2 to. This array will be run through for each value of SetArray1 MeasParams: The parameter(s) you want to measure at each setpoint Keyword Arguments: SetDelay1: The delay time between when SetParam1 is set till the SetParam2 is set to its first value (0 by default) SetDelay2: Delay time between when SetParam2 is set and the MeasParam is measured (0 by default) DataName: A name to tag the data (defaults to nothing) ZParam: Allows you to pick only a few parameters to plot out of those measured. (if not mentioned, will plot all *MeasParams) plot_results: True by default, if false, suppresses plotting save_plots: True by default. If false, doesn't save plots at the end of the sweep """ if Param2_SetBetween is None: def between_func(): pass else: def between_func(): SetParam2(Param2_SetBetween) return innerloop = qc.Loop(SetParam2[SetArray2], delay=SetDelay2).each(*MeasParams) twodloop = qc.Loop(SetParam1[SetArray1], delay=SetDelay1).each(innerloop, qc.Task(between_func)) data = twodloop.get_data_set(name=DataName) plot = [] def _plot_update(): if type(plot) is list: for p in plot: p.update() else: plot.update() def _plot_save(): if type(plot) is list: for i in range(len(plot)): fname = '{}_{}.png'.format(plot[i].get_default_title(), str(ZParam[i])) plot[i].save(filename=fname) else: fname = '{}_{}.png'.format(plot.get_default_title(), str(*MeasParams)) plot.save(filename=fname) if plot_results: if len(MeasParams) == 1: plot = qc.QtPlot(getattr(data, str(*MeasParams)), window_title=str(*MeasParams)) twodloop.with_bg_task(plot.update) else: if ZParam is None: ZParam = MeasParams if type(ZParam) is not list and type(ZParam) is not tuple: ZParam = [ZParam] for zp in ZParam: plot.append( qc.QtPlot(getattr(data, str(zp)), window_title=str(zp))) twodloop.with_bg_task(_plot_update) try: twodloop.run() if save_plots and plot_results: _plot_save() return data, plot except KeyboardInterrupt: if plot_results: _plot_update() if save_plots: _plot_save() print('Keyboard Interrupt') return data, plot
y = y + 360 y_degNew.append(y) x = x[350:700] y_deg = y_degNew[350:700] print(result.fit_report()) plt.plot(x, y_deg, 'bo') plt.plot(x, result.init_fit, 'k--') plt.plot(x, result.best_fit, 'r-') plt.show() # %% import qcodes as qc plot_phaseQt = qc.QtPlot() plot_redchiPhase = qc.QtPlot() for p in range(N_power_points): bT = [] qt_phaseList = [] redchiPhaseList = [] for i in range(p * N_power_magnet, (p + 1) * N_power_magnet): qt_phaseList.append(res_phase[i].best_values['Qt']) redchiPhaseList.append(res_phase[i].redchi) bT.append(b_s21T[i * N]) plot_phaseQt.add(bT, qt_phaseList) plot_redchiPhase.add(bT, redchiPhaseList) plt.plot(bT, qt_phaseList, 'bo')
def showImage(data, im): pl = qc.QtPlot(qtt.scans.getDefaultParameter(data)) return pl
def run_qcodes(self, with_plot=False): """ Runs qcodes with specified instruments and parameters. Checks for errors in data prior to runing qcodes Adds all instruments to qc.Station and runs the last created loop (i think this is not good, but hey theres a button for each loop to run that specific loop) Loop is ran in a separate thread so that it does not block GUI thread (and the program) :param with_plot: if set to true, runs (and saves) live plot while measurement is running :return: NoneType """ self.stop_loop_requested = False self.loop_started.emit() self.line_trace_count = 0 # first create a station and add all instruments to it, to have the data available in the output files station = qc.Station() for name, instrument in self.instruments.items(): station.add_component(instrument, name) # grab the last action added to the actions list. Set its data_set to None in case that loop has already been # ran. Create a new data set with the name and location provided by user input if len(self.actions): loop = self.actions[-1] loop.data_set = None # adjust save location of the file if self.save_location != "": loc_provider = qc.data.location.FormatLocation( fmt=self.save_location + '/{date}/#{counter}_{name}_{time}') qc.data.data_set.DataSet.location_provider = loc_provider data = loop.get_data_set(name=self.output_file_name.text()) # Check if the function was called with plot in background, if it was, create a new plot, delete backgroud # action of the loop (if a loop has been ran before with a background action [loop cannot have more then # 1 background action]), attach a new background action and run a loop by calling a worker to run it in a # separate thread if with_plot: # if you are running loop in a loop then create one more graph that will display 10 most recent line # traces if isinstance(loop.actions[0], ActiveLoop): line_traces_plot = qc.QtPlot(fig_x_position=0.05, fig_y_position=0.4, window_title="Line traces") self.live_plots.append(line_traces_plot) if len(loop.actions) < 3: loop.actions.append( Task(lambda: self.update_line_traces( line_traces_plot, data, parameter_name))) else: loop.actions[-1] = Task( lambda: self.update_line_traces( line_traces_plot, data, parameter_name)) loop.actions[0].progress_interval = None else: if loop.progress_interval is None: loop.progress_interval = 20 parameter = get_plot_parameter(loop) plot = qc.QtPlot(fig_x_position=0.05, fig_y_position=0.4, window_title=self.output_file_name.text()) self.live_plots.append(plot) parameter_name = str(parameter) plot.add(getattr(data, parameter_name)) # loop.with_bg_task(plot.update, plot.save).run(use_threads=True) loop.bg_task = None worker = Worker( loop.with_bg_task(plot.update, plot.save).run, False) else: # loop.run(use_threads=True) -> this has something to do with multiple gets at the same time # i guess it would get them all at the same time instead of one by one # otherwise if plot was not requested, just run a loop (also in separate thread) worker = Worker(loop.run, False) self.workers.append(worker) # connect the signals of a worker worker.signals.result.connect(print_output) worker.signals.finished.connect(self.cleanup) worker.signals.progress.connect(progress_func) # start the worker del self.workers[:] # starting live mode of all opened instruments # commented cause it causes collision in the instrument when two different sources send commands to the # instrument. Sometimes this causes crashing of the loop. """for widget in self.active_isntruments: # only if that instrument has this parameter, then start its live mode if self.actions[-1].sweep_values.name in widget.textboxes.keys(): widget.toggle_live()""" self.disable_run_buttons() self.thread_pool.start(worker) # Just in case someone presses run with no loops created else: show_error_message("Oops !", "Looks like there is no loop to be ran !")