Esempio n. 1
0
def _do_MatPlot(data,meas_params):
    plt.ioff()
    plot, num_subplots = _plot_setup(data, meas_params, useQT=False)
    # pad a bit more to prevent overlap between
    # suptitle and title
    plot.rescale_axis()
    plot.fig.tight_layout(pad=3)

    if 'pdf_subfolder' in CURRENT_EXPERIMENT:
        title_list = plot.get_default_title().split(sep)
        title_list.insert(-1, CURRENT_EXPERIMENT['pdf_subfolder'])
        title = sep.join(title_list)
        plot.save("{}.pdf".format(title))

    if 'png_subfolder' in CURRENT_EXPERIMENT:
        title_list = plot.get_default_title().split(sep)
        title_list.insert(-1, CURRENT_EXPERIMENT['png_subfolder'])
        title = sep.join(title_list)
        plot.fig.savefig("{}.png".format(title),dpi=500)

    if (pdfdisplay['combined'] or
            (num_subplots == 1 and pdfdisplay['individual'])):
        plot.fig.canvas.draw()
        plt.show()
    else:
        plt.close(plot.fig)
    if num_subplots > 1:
        _save_individual_plots(data, meas_params,
                               pdfdisplay['individual'])
    plt.ion()
Esempio n. 2
0
def _do_measurement_single(measurement: Measure, meas_params: tuple,
                           do_plots: Optional[bool]=True,
                           use_threads: bool=True) -> Tuple[QtPlot, DataSet]:

    try:
        parameters = list(meas_params)
        _flush_buffers(*parameters)
        interrupted = False

        try:
            data = measurement.run(use_threads=use_threads)
        except KeyboardInterrupt:
            interrupted = True
            print("Measurement Interrupted")

        if do_plots:
            plot, _ = _plot_setup(data, meas_params)
            # Ensure the correct scaling before saving
            plot.autorange()
            plot.save()

            if 'pdf_subfolder' in CURRENT_EXPERIMENT or 'png_subfolder' in CURRENT_EXPERIMENT:
                _do_MatPlot(data,meas_params)

        else:
            plot = None

        log.info("#[QCoDeS]# Saved dataset to: {}".format(data.location))

        if interrupted:
            raise KeyboardInterrupt
    except:
        log.exception("Exception in doO")
        raise
    return plot, data
Esempio n. 3
0
def _do_measurement(loop: Loop, set_params: tuple, meas_params: tuple,
                    do_plots: Optional[bool]=True,
                    use_threads: bool=True) -> Tuple[QtPlot, DataSet]:
    """
    The function to handle all the auxiliary magic of the T10 users, e.g.
    their plotting specifications, the device image annotation etc.
    The input loop should just be a loop ready to run and perform the desired
    measurement. The two params tuple are used for plotting.
    Args:
        loop: The QCoDeS loop object describing the actual measurement
        set_params: tuple of tuples. Each tuple is of the form
            (param, start, stop)
        meas_params: tuple of parameters to measure
        do_plots: Whether to do a live plot
        use_threads: Whether to use threads to parallelise simultaneous
            measurements. If only one thing is being measured at the time
            in loop, this does nothing.
    Returns:
        (plot, data)
    """
    try:
        parameters = [sp[0] for sp in set_params] + list(meas_params)
        _flush_buffers(*parameters)

        # startranges for _plot_setup
        try:
            startranges = {}
            for sp in set_params:
                minval = min(sp[1], sp[2])
                maxval = max(sp[1], sp[2])
                startranges[sp[0].full_name] = {'max': maxval, 'min': minval}
        except Exception:
            startranges = None

        interrupted = False

        data = loop.get_data_set()

        if do_plots:
            try:
                plot, _ = _plot_setup(data, meas_params, startranges=startranges)
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
        else:
            plot = None
        try:
            if do_plots:
                _ = loop.with_bg_task(plot.update).run(use_threads=use_threads)
            else:
                _ = loop.run(use_threads=use_threads)
        except KeyboardInterrupt:
            interrupted = True
            print("Measurement Interrupted")
        if do_plots:
            # Ensure the correct scaling before saving
            try:
                plot.autorange()
                plot.save()
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')

            if 'pdf_subfolder' in CURRENT_EXPERIMENT or 'png_subfolder' in CURRENT_EXPERIMENT:
                _do_MatPlot(data,meas_params)

        if CURRENT_EXPERIMENT.get('device_image'):
            log.debug('Saving device image')
            save_device_image(tuple(sp[0] for sp in set_params))

        # add the measurement ID to the logfile
        with open(CURRENT_EXPERIMENT['logfile'], 'a') as fid:
            print("#[QCoDeS]# Saved dataset to: {}".format(data.location),
                  file=fid)
        if interrupted:
            raise KeyboardInterrupt
    except:
        log.exception("Exception in doND")
        raise
    return plot, data
Esempio n. 4
0
def _do_measurement(loop: Loop, set_params: tuple, meas_params: tuple,
                    do_plots: Optional[bool]=True,
                    use_threads: bool=True,
                    auto_color_scale: Optional[bool]=None,
                    cutoff_percentile: Optional[Union[Tuple[Number, Number], Number]]=None) -> Tuple[QtPlot, DataSet]:
    """
    The function to handle all the auxiliary magic of the T10 users, e.g.
    their plotting specifications, the device image annotation etc.
    The input loop should just be a loop ready to run and perform the desired
    measurement. The two params tuple are used for plotting.
    Args:
        loop: The QCoDeS loop object describing the actual measurement
        set_params: tuple of tuples. Each tuple is of the form
            (param, start, stop)
        meas_params: tuple of parameters to measure
        do_plots: Whether to do a live plot
        use_threads: Whether to use threads to parallelise simultaneous
            measurements. If only one thing is being measured at the time
            in loop, this does nothing.
        auto_color_scale: if True, the colorscale of heatmap plots will be
            automatically adjusted to disregard outliers.
        cutoff_percentile: percentile of data that may maximally be clipped
            on both sides of the distribution.
            If given a tuple (a,b) the percentile limits will be a and 100-b.
            See also the plotting tuorial notebook.
    Returns:
        (plot, data)
    """
    try:
        parameters = [sp[0] for sp in set_params] + list(meas_params)
        _flush_buffers(*parameters)

        # startranges for _plot_setup
        try:
            startranges = {}
            for sp in set_params:
                minval = min(sp[1], sp[2])
                maxval = max(sp[1], sp[2])
                startranges[sp[0].full_name] = {'max': maxval, 'min': minval}
        except Exception:
            startranges = None

        interrupted = False

        data = loop.get_data_set()

        if do_plots:
            try:
                plot, _ = _plot_setup(data, meas_params, startranges=startranges,
                                      auto_color_scale=auto_color_scale,
                                      cutoff_percentile=cutoff_percentile)
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
                # if remote process crashed continue without plots
                do_plots = False
        else:
            plot = None
        try:
            if do_plots:
                _ = loop.with_bg_task(plot.update).run(use_threads=use_threads)
            else:
                _ = loop.run(use_threads=use_threads)
        except KeyboardInterrupt:
            interrupted = True
            print("Measurement Interrupted")
        if do_plots:
            # Ensure the correct scaling before saving
            try:
                plot.autorange()
                plot.save()
            except (ClosedError, ConnectionError):
                log.warning('Remote process crashed png will not be saved')
                # if remote process crashed continue without plots
                do_plots = False

            if 'pdf_subfolder' in CURRENT_EXPERIMENT or 'png_subfolder' in CURRENT_EXPERIMENT:
                _do_MatPlot(data,meas_params,
                            auto_color_scale=auto_color_scale,
                            cutoff_percentile=cutoff_percentile)

        if CURRENT_EXPERIMENT.get('device_image'):
            log.debug('Saving device image')
            save_device_image(tuple(sp[0] for sp in set_params))

        log.info("#[QCoDeS]# Saved dataset to: {}".format(data.location))
        if interrupted:
            raise KeyboardInterrupt
    except:
        log.exception("Exception in doND")
        raise
    return plot, data