示例#1
0
def test_get_data_by_id_order(dataset):
    """
    Test if the values of the setpoints/dependent parameters is dependent on
    the order of the `depends_on` value. This sounds far fetch but was
    actually the case before #1250.
    """
    indepA = ParamSpec('indep1', "numeric")
    indepB = ParamSpec('indep2', "numeric")
    depAB = ParamSpec('depAB', "numeric", depends_on=[indepA, indepB])
    depBA = ParamSpec('depBA', "numeric", depends_on=[indepB, indepA])
    dataset.add_parameters([indepA, indepB, depAB, depBA])

    dataset.add_result({'depAB': 12,
                        'indep2': 2,
                        'indep1': 1})

    dataset.add_result({'depBA': 21,
                        'indep2': 2,
                        'indep1': 1})
    dataset.mark_complete()

    data = get_data_by_id(dataset.run_id)
    data_dict = {el['name']: el['data'] for el in data[0]}
    assert data_dict['indep1'] == 1
    assert data_dict['indep2'] == 2

    data_dict = {el['name']: el['data'] for el in data[1]}
    assert data_dict['indep1'] == 1
    assert data_dict['indep2'] == 2
def test_get_data_by_id_order(dataset):
    """
    Test that the added values of setpoints end up associated with the correct
    setpoint parameter, irrespective of the ordering of those setpoint
    parameters
    """
    indepA = ParamSpecBase('indep1', "numeric")
    indepB = ParamSpecBase('indep2', "numeric")
    depAB = ParamSpecBase('depAB', "numeric")
    depBA = ParamSpecBase('depBA', "numeric")

    idps = InterDependencies_(
        dependencies={depAB: (indepA, indepB), depBA: (indepB, indepA)})

    dataset.set_interdependencies(idps)

    dataset.mark_started()

    dataset.add_result({'depAB': 12,
                        'indep2': 2,
                        'indep1': 1})

    dataset.add_result({'depBA': 21,
                        'indep2': 2,
                        'indep1': 1})
    dataset.mark_completed()

    data = get_data_by_id(dataset.run_id)
    data_dict = {el['name']: el['data'] for el in data[0]}
    assert data_dict['indep1'] == 1
    assert data_dict['indep2'] == 2

    data_dict = {el['name']: el['data'] for el in data[1]}
    assert data_dict['indep1'] == 1
    assert data_dict['indep2'] == 2
示例#3
0
def _plot_ds(ds: DataSet) -> None:
    try:
        # `get_data_by_id` might fail
        nplots = len(get_data_by_id(ds.run_id))  # TODO: might be a better way
        nrows = math.ceil(nplots / 2) if nplots != 1 else 1
        ncols = 2 if nplots != 1 else 1
        fig, axes = plt.subplots(nrows, ncols, figsize=(6 * ncols, 4 * nrows))
        # `plot_dataset` might also fail.
        plot_dataset(ds, axes=axes.flatten())
        fig.tight_layout()
        plt.show(fig)
    except Exception as e:
        print(e)  # TODO: print complete traceback
示例#4
0
def do_1d_sweep(_min_v, _max_v, _step, _freq, _expName, _sampleName):
    # Create the DAQ object
    daq = Daq("Dev1", "testdaq")

    # Initialize the database you want to save data to
    try:
        experimentName = _expName
        sampleName = _sampleName
        initialise_or_create_database_at(
            'C:\\Users\\erunb\\MeasureIt\\Databases\\testdatabase.db')
        qc.new_experiment(name=experimentName, sample_name=sampleName)
    except:
        print("Error opening database")
        daq.device.reset_device()
        daq.__del__()
        quit()

    # Set our sweeping parameters
    min_v = _min_v
    max_v = _max_v
    step = _step
    freq = _freq

    # Create the sweep argument, tell it which channel to listen to
    s = Sweep1D(daq.submodules["ao0"].voltage,
                min_v,
                max_v,
                step,
                freq,
                bidirectional=True,
                meas=None,
                plot=True,
                auto_figs=True)
    s.follow_param(daq.submodules["ai3"].voltage)
    s._create_measurement((s.set_param))

    # Run the sweep automatically
    s.autorun()

    # Clean up the DAQ
    daq.__del__()

    # Show the experiment data
    ex = qc.dataset.experiment_container.load_experiment_by_name(
        experimentName, sampleName)
    fii = get_data_by_id(ex.data_sets()[0].run_id)
    print(fii)
示例#5
0
    def __getitem__(self, layout):

        layout = sorted(layout.split(","))
        all_data = get_data_by_id(self._run_id)
        data_layouts = [sorted([d["name"] for d in ad]) for ad in all_data]

        i = np.array([
            set(layout).issubset(set(data_layout))
            for data_layout in data_layouts
        ])

        ind = np.flatnonzero(i)
        if len(ind) == 0:
            raise ValueError(f"No such layout {layout}. "
                             f"Available layouts: {data_layouts}")

        data = all_data[ind[0]]
        return {d["name"]: d["data"] for d in data}
示例#6
0
    def update_plots(self):

        alldata = get_data_by_id(self.id)

        # update all plots
        for trace, data in zip(self.traces, alldata):
            x = data[0]
            y = data[1]
            if len(data) == 2:  # 1D PLOTTING
                trace['plot_object'].setData(
                    *self._line_data(x['data'], y['data']))

            elif len(data) == 3:  # 2D PLOTTING
                z = data[2]
                xrow, yrow, z_to_plot = self._get_2d_data(x, y, z)
                self._update_image(trace['plot_object'], {
                    'x': xrow,
                    'y': yrow,
                    'z': z_to_plot
                })
示例#7
0
def write_sample_to_txt(exp, count=0):
    """
    Creates a new file to print the sample data from the experiment.
    
    Parameters
    ---------
    exp:
        The QCoDeS experiment containing the desired data.
    count:
        Optional argument to start at a desired dataset.
    """

    # print(exp.data_sets())
    for a in exp.data_sets():
        print(a.run_id)
        data = get_data_by_id(a.run_id)
        print(data)
        for dataset in data:
            file_name = "{:02d}".format(count) + "_" + exp.sample_name + '.txt'
            print(file_name)
            file_path = os.environ[
                'MeasureItHome'] + '\\Origin Files\\' + exp.name + "\\" + file_name
            print(file_path)
            file = open(file_path, "w")
            count += 1
            num_params = len(dataset)

            for param in dataset:
                file.write(param['label'] + " (" + param['unit'] + ")\t")

            file.write("\n")

            for i in range(len(dataset[0]['data'])):
                for param in dataset:
                    file.write(str(param['data'][i]) + "\t")
                file.write("\n")
            file.close()
示例#8
0
    def __init__(self, *args, id, refresh=1):

        super().__init__(*args)

        self.id = id

        alldata = get_data_by_id(self.id)
        self.nplots = len(alldata)

        # initiate plots
        for i, data in enumerate(alldata):

            x = data[0]
            y = data[1]

            if len(data) == 2:  # 1D PLOTTING

                po = self._add_1d(i, x, y)

            elif len(data) == 3:  # 2D PLOTTING

                z = data[2]

                po = self._add_2d(i, x, y, z)

        # add subscriber
        #dataset = load_by_id(self.id)
        #dataset.subscribe(self.update_from_subscriber, min_wait=0, min_count=1, state=[])

        dataset = load_by_id(self.id)
        self.completed = dataset.completed

        while not self.completed:
            dataset = load_by_id(self.id)
            self.completed = dataset.completed
            self.update_plots()
            time.sleep(refresh)