示例#1
0
def test_dotfit_save_segmented_data(nt_dataset_doubledot, tmp_path,
                                    experiment_different_db_folder):
    delta_mesh = 0.05
    df = DotFit(1, "temp.db", db_folder=str(tmp_path), delta_mesh=delta_mesh)

    db_folder2 = os.path.join(str(tmp_path), "test")
    seg_info = df.save_segmented_data_return_info(segment_db_name="temp2.db",
                                                  segment_db_folder=db_folder2)

    db_name, db_folder = nt.get_database()
    assert db_name == "temp.db"
    assert db_folder == str(tmp_path)

    assert sorted(seg_info.keys()) == [1, 2, 3, 4]

    assert seg_info[1]['current']["range_x"] == (-0.2, -0.15125)
    assert seg_info[1]['current']["range_y"] == (-0.3, -0.252)

    assert seg_info[2]['current']["range_x"] == (-0.2, -0.15125)
    assert seg_info[2]['current']["range_y"] == (-0.25, -0.2)

    assert seg_info[3]['current']["range_x"] == (-0.15, -0.1)
    assert seg_info[3]['current']["range_y"] == (-0.3, -0.252)

    assert seg_info[4]['current']["range_x"] == (-0.15, -0.1)
    assert seg_info[4]['current']["range_y"] == (-0.25, -0.2)

    seg_df = nt.Dataset(1, "temp2.db", db_folder2)
    raw_current_new_df = seg_df.raw_data['current'].values

    raw_current_original = df.segmented_data[0]['current'].values

    assert np.allclose(raw_current_new_df, raw_current_original, rtol=atol)
示例#2
0
def switch_database(temp_db_name: str, temp_db_folder: str):
    """ """
    original_db, original_db_folder = nt.get_database()
    nt.set_database(temp_db_name, db_folder=temp_db_folder)
    try:
        yield
    finally:
        nt.set_database(original_db, db_folder=original_db_folder)
示例#3
0
    def __init__(
        self,
        qc_run_id: int,
        db_name: Optional[str] = None,
        db_folder: Optional[str] = None,
    ) -> None:

        if db_folder is None:
            db_folder = nt.config["db_folder"]
        self.db_folder = db_folder

        if db_name is None:
            self.db_name, _ = nt.get_database()
        else:
            nt.set_database(db_name, db_folder=db_folder)
            self.db_name = db_name

        self.qc_run_id = qc_run_id
        self._snapshot: Dict[str, Any] = {}
        self._nt_metadata: Dict[str, Any] = {}
        self._normalization_constants: Dict[str, List[float]] = {}

        self.exp_id: int
        self.guid: str
        self.qc_parameters: List[qc.Parameter]
        self.label: List[str]
        self.dimensions: Dict[str, int] = {}
        self.readout_methods: Dict[str, str] = {}

        self.raw_data: xr.Dataset = xr.Dataset()
        self.data: xr.Dataset = xr.Dataset()
        self.power_spectrum: xr.Dataset = xr.Dataset()
        self.filtered_data: xr.Dataset = xr.Dataset()

        self.from_qcodes_dataset()
        self.prepare_filtered_data()
        self.compute_power_spectrum()
示例#4
0
    def __init__(
        self,
        stage_summaries: Optional[Dict[str, List[List[int]]]],
        receiver: List[str],
        # = ['*****@*****.**', '*****@*****.**'],
        sender: Optional[str],
        #   = '*****@*****.**',
        sender_pwd: Optional[str],  # = 'N@notune',
        db_name: Optional[str] = None,
        db_folder: Optional[str] = None,
        guid: Optional[str] = None,
        comments: Optional[Dict[str, str]] = None,
        device_name: str = "nt device",
        section: Optional[str] = None,
        subject: Optional[str] = None,
        smalltalk: str = "",
        server: str = "smtp-mail.outlook.com",
        port: int = 587,
        pdf_folder: Optional[str] = None,
        pdf_name: str = "nanotune_results",
    ):
        """"""
        if db_name is None:
            db_name, _ = nt.get_database()
        if db_folder is None:
            db_folder = nt.config["db_folder"]

        if "*****@*****.**" not in receiver:
            receiver.append("*****@*****.**")

        self.receiver = receiver
        self.sender = sender
        self.smalltalk = smalltalk
        self.stage_summaries = stage_summaries
        self.comments = {} if comments is None else comments
        self.db_name = db_name
        self.device_name = device_name
        self.db_folder = db_folder

        if section is None:
            self.section = " @" + self.device_name
        else:
            self.section = "@Measurements"

        self.subject = subject
        if self.subject is None:
            self.subject = ""
        self.server = server
        self.port = port
        self.sender_pwd = sender_pwd
        self.pdf_name = pdf_name
        if pdf_folder is not None:
            self.pdf_folder = pdf_folder
        else:
            self.pdf_folder = os.path.join(self.db_folder, "tuning_results",
                                           self.device_name, "pdfs")
            if not os.path.exists(self.pdf_folder):
                os.makedirs(self.pdf_folder)

        self.fields = (
            ("name", "Parameter"),
            ("value", "Value"),
        )

        self.column_ratio = [0.55, 0.35]
示例#5
0
def plot_dataset(
    qc_run_id: int,
    db_name: str,
    save_figures: bool = True,
    db_folder: Optional[str] = None,
    plot_filtered_data: bool = False,
    plot_params: Optional[plot_params_type] = None,
    ax: Optional[matplotlib.axes.Axes] = None,
    colorbar: Optional[matplotlib.colorbar.Colorbar] = None,
    filename: Optional[str] = None,
    file_location: Optional[str] = None,
) -> AxesTuple:
    """
    If to be saved and no file location specified, the figure will be saved at
    os.path.join(nt.config['db_folder'], 'tuning_results', dataset.device_name)
    in both eps and png
    """

    if plot_params is None:
        plot_params = default_plot_params
    matplotlib.rcParams.update(plot_params)
    if db_folder is None:
        _, db_folder = nt.get_database()

    dataset = Dataset(qc_run_id, db_name, db_folder=db_folder)

    if plot_filtered_data:
        data = dataset.filtered_data
    else:
        data = dataset.data

    if ax is None:
        fig_size = copy.deepcopy(plot_params["figure.figsize"])
        fig_size[1] *= len(dataset.data) * 0.8  # type: ignore
        fig, ax = plt.subplots(
            len(dataset.data),
            1,
            squeeze=False,
            figsize=fig_size,
        )

        colorbars: List[matplotlib.colorbar.Colorbar] = []

    fig_title = dataset.guid

    for r_i, read_meth in enumerate(dataset.readout_methods):
        c_name = default_coord_names['voltage'][0]
        voltage_x = data[read_meth][c_name].values
        signal = data[read_meth].values.T

        if dataset.dimensions[read_meth] == 1:
            colorbar = None
            ax[r_i, 0].plot(
                voltage_x,
                signal,
                zorder=6,
            )
            ax[r_i, 0].set_xlabel(dataset.get_plot_label(read_meth, 0))
            ax[r_i, 0].set_ylabel(dataset.get_plot_label(read_meth, 1))
            ax[r_i, 0].set_title(str(fig_title))

            divider = make_axes_locatable(ax[r_i, 0])
            cbar_ax = divider.append_axes("right", size="5%", pad=0.06)
            cbar_ax.set_facecolor("none")
            for caxis in ["top", "bottom", "left", "right"]:
                cbar_ax.spines[caxis].set_linewidth(0)
            cbar_ax.set_xticks([])
            cbar_ax.set_yticks([])
            colorbars.append(colorbars)

            ax[r_i, 0].figure.tight_layout()

        elif dataset.dimensions[read_meth] == 2:
            c_name = default_coord_names['voltage'][1]
            voltage_y = data[read_meth][c_name].values
            colormesh = ax[r_i, 0].pcolormesh(
                voltage_x,
                voltage_y,
                signal,
                shading="auto",
            )

            if colorbar is not None:
                colorbars.append(ax[r_i, 0].figure.colorbar(colormesh,
                                                            ax=ax[r_i, 0],
                                                            cax=colorbar.ax))
            else:
                # colorbar = fig.colorbar(colormesh, ax=ax[r_i, 0])
                divider = make_axes_locatable(ax[r_i, 0])
                cbar_ax = divider.append_axes("right", size="5%", pad=0.06)
                colorbars.append(
                    fig.colorbar(
                        colormesh,
                        ax=ax[r_i, 0],
                        cax=cbar_ax,
                    ))
            colorbars[-1].set_label(
                dataset.get_plot_label(read_meth, 2),
                rotation=-270,
            )

            ax[r_i, 0].set_xlabel(dataset.get_plot_label(read_meth, 0))
            ax[r_i, 0].set_ylabel(dataset.get_plot_label(read_meth, 1))
            ax[r_i, 0].set_title(str(fig_title))

            ax[r_i, 0].figure.tight_layout()

        else:
            raise NotImplementedError

    if save_figures:
        if file_location is None:
            file_location = os.path.join(nt.config["db_folder"],
                                         "tuning_results", dataset.device_name)
        if not os.path.exists(file_location):
            os.makedirs(file_location)

        if filename is None:
            filename = "dataset_" + str(dataset.guid)
        else:
            filename = os.path.splitext(filename)[0]

        path = os.path.join(file_location, filename + ".png")
        plt.savefig(path, format="png", dpi=600, bbox_inches="tight")
    return ax, colorbars