Пример #1
0
def test_laser_widget(qtbot: QtBot):
    x = rand_data(["A1", "B2"])
    y = x["A1"].copy()
    viewspace = LaserViewSpace()
    qtbot.addWidget(viewspace)
    viewspace.show()

    view = viewspace.activeView()
    view.addLaser(Laser(x))
    widget = view.activeWidget()

    widget.applyConfig(Config(1.0, 1.0, 1.0))
    assert widget.laser.config.spotsize == 1.0
    widget.applyCalibration({"B2": Calibration(2.0, 2.0)})
    assert widget.laser.calibration["B2"].intercept == 2.0

    widget.updateNames({"A1": "A1", "B2": "2B"})
    assert np.all(viewspace.uniqueElements() == ["2B", "A1"])

    widget.transform(flip="horizontal")
    assert np.all(widget.laser.get("A1") == np.flip(y, axis=1))
    widget.transform(flip="horizontal")
    widget.transform(flip="vertical")
    assert np.all(widget.laser.get("A1") == np.flip(y, axis=0))
    widget.transform(flip="vertical")
    assert np.all(widget.laser.get("A1") == y)
    widget.transform(rotate="right")
    assert np.all(widget.laser.get("A1") == np.rot90(y, k=1, axes=(1, 0)))
    widget.transform(rotate="left")
    assert np.all(widget.laser.get("A1") == y)
Пример #2
0
 def __init__(
     self,
     orientaion: QtCore.Qt.Orientation = QtCore.Qt.Horizontal,
     parent: QtWidgets.QWidget = None,
 ):
     super().__init__(orientaion, parent)
     self.config = Config()
     self.options = GraphicsOptions()
Пример #3
0
def test_import_thread(qtbot: QtBot):
    path = Path(__file__).parent.joinpath("data", "io")
    paths = [
        path.joinpath("agilent", "test_ms.b"),
        path.joinpath("csv", "generic"),
        path.joinpath("npz", "test.npz"),
        path.joinpath("perkinelmer", "perkinelmer"),
        path.joinpath("textimage", "csv.csv"),
        path.joinpath("textimage", "text.text"),
        path.joinpath("thermo", "icap_columns.csv"),
    ]
    thread = ImportThread(paths, Config())

    signals = [(thread.importFinished, path.name) for path in paths]
    signals.extend([(thread.progressChanged, path.name) for path in paths])
    with qtbot.waitSignals(signals):
        thread.run()

    # Failing import
    paths = [path.joinpath("fake", "data.npz")]
    thread = ImportThread(paths, Config())

    with qtbot.waitSignal(thread.importFailed):
        thread.run()
Пример #4
0
 def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
     if event.matches(QtGui.QKeySequence.Cancel):
         self.graphics.endSelection()
         self.graphics.endWidget()
     elif event.matches(QtGui.QKeySequence.Paste):
         mime = QtWidgets.QApplication.clipboard().mimeData()
         if mime.hasFormat("arplication/x-pew2config"):
             with BytesIO(mime.data("application/x-pew2config")) as fp:
                 array = np.load(fp)
             if self.is_srr:
                 config = SRRConfig.from_array(array)
             else:
                 config = Config.from_array(array)
             self.applyConfig(config)
         elif mime.hasFormat("application/x-pew2calibration"):
             with BytesIO(mime.data("application/x-pew2calibration")) as fp:
                 npy = np.load(fp)
                 calibrations = {k: Calibration.from_array(npy[k]) for k in npy}
             self.applyCalibration(calibrations)
     super().keyPressEvent(event)
Пример #5
0
def test_wizard_srr_config(qtbot: QtBot):
    path = Path(__file__).parent.joinpath("data", "io")
    wiz = SRRImportWizard(
        [
            path.joinpath("textimage", "csv.csv"),
            path.joinpath("textimage", "csv.csv"),
        ],
        config=Config(10.0, 40.0, 0.25),
    )
    qtbot.addWidget(wiz)
    wiz.show()
    qtbot.waitExposed(wiz)

    # Format
    page = wiz.currentPage()
    page.radio_text.setChecked(True)
    wiz.next()
    assert wiz.currentId() == wiz.page_text

    # Path and Options
    wiz.next()

    # Config
    page = wiz.currentPage()
    assert page.getNames() == ("_Element_", )
    assert not page.isComplete()
    page.lineedit_warmup.setText("0")
    assert page.isComplete()

    page.lineedit_warmup.setText("-1")
    assert not page.isComplete()

    page.lineedit_speed.setText("0")
    assert not page.isComplete()

    dlg = page.buttonNamesPressed()
    dlg.close()

    page.updateNames({"_Element_": "Pew"})
    assert page.getNames() == ("Pew", )
Пример #6
0
    def accept(self) -> None:
        if self.field("agilent"):
            paths = [Path(p) for p in self.field("agilent.paths")]
        elif self.field("csv"):
            paths = [Path(p) for p in self.field("csv.paths")]
        elif self.field("perkinelmer"):
            paths = [Path(p) for p in self.field("perkinelmer.paths")]
        elif self.field("text"):
            paths = [Path(p) for p in self.field("text.paths")]
        elif self.field("thermo"):
            paths = [Path(p) for p in self.field("thermo.paths")]
        else:  # pragma: no cover
            raise ValueError("Invalid filetype selection.")

        datas = self.field("laserdata")
        infos = self.field("laserinfo")

        for path, data, info in zip(paths, datas, infos):
            config = Config(
                spotsize=float(self.field("spotsize")),
                scantime=float(self.field("scantime")),
                speed=float(self.field("speed")),
            )
            info.update({
                "Name":
                path.stem,
                "File Path":
                str(path.resolve()),
                "Import Date":
                time.strftime("%Y-%m-%dT%H:%M:%S%z",
                              time.localtime(time.time())),
                "Import Path":
                str(path.resolve()),
                "Import Version pewlib":
                pewlib_version,
                "Import Version pew2":
                pewpew_version,
            })
            self.laserImported.emit(Laser(data, config=config, info=info))
        super().accept()
Пример #7
0
def test_config_dialog(qtbot: QtBot):
    config = Config()

    dialog = dialogs.ConfigDialog(config)
    qtbot.addWidget(dialog)
    dialog.open()

    assert not hasattr(dialog, "lineedit_warmup")
    assert not hasattr(dialog, "spinbox_offsets")
    # Check the texts are correct
    assert dialog.lineedit_spotsize.text() == str(config.spotsize)
    assert dialog.lineedit_speed.text() == str(config.speed)
    assert dialog.lineedit_scantime.text() == str(config.scantime)
    dialog.lineedit_spotsize.setText("1")
    dialog.lineedit_speed.setText("2.")
    dialog.lineedit_scantime.setText("3.0000")
    dialog.updateConfig()
    # Check it updated
    assert dialog.config.spotsize == 1.0
    assert dialog.config.speed == 2.0
    assert dialog.config.scantime == 3.0

    assert dialog.isComplete()
    dialog.lineedit_scantime.setText("-1")
    assert not dialog.isComplete()
    dialog.lineedit_speed.setText("-1")
    assert not dialog.isComplete()
    dialog.lineedit_spotsize.setText("-1")
    assert not dialog.isComplete()

    # Just run code as can't test clipboard
    dialog.copyToClipboard()

    dialog.apply()
    dialog.check_all.setChecked(True)
    dialog.apply()
Пример #8
0
def test_laser_view_space(qtbot: QtBot):
    viewspace = LaserViewSpace()
    qtbot.addWidget(viewspace)
    viewspace.show()

    viewspace.toggleCalibrate(False)
    viewspace.toggleColorbar(False)
    viewspace.toggleLabel(False)
    viewspace.toggleScalebar(False)
    viewspace.toggleSmooth(False)

    assert not viewspace.options.calibrate
    assert not viewspace.options.items["colorbar"]
    assert not viewspace.options.items["label"]
    assert not viewspace.options.items["scalebar"]
    assert not viewspace.options.smoothing

    viewspace.splitActiveHorizontal()

    assert viewspace.currentElement() is None

    viewspace.views[0].addLaser(Laser(rand_data(["A1", "B2"])))
    viewspace.views[0].addLaser(Laser(rand_data(["A1", "C3"])))
    viewspace.views[1].addLaser(Laser(rand_data(["A1", "C3"])))
    viewspace.views[1].addLaser(Laser(rand_data(["B2", "D4"])))

    assert viewspace.uniqueElements() == ["A1", "B2", "C3", "D4"]
    assert viewspace.currentElement() == "A1"

    # Apply config
    viewspace.applyConfig(Config(10, 10, 10))
    for view in viewspace.views:
        for widget in view.widgets():
            assert widget.laser.config.spotsize == 10
            assert widget.laser.config.speed == 10
            assert widget.laser.config.scantime == 10
    # Try to apply calibraiton
    viewspace.applyCalibration({
        "A1": Calibration(1.0, 1.0),
        "B2": Calibration(2.0, 2.0)
    })
    qtbot.waitExposed(viewspace)
    for view in viewspace.views:
        for widget in view.widgets():
            if "A1" in widget.laser.elements:
                assert widget.laser.calibration["A1"].intercept == 1.0
                assert widget.laser.calibration["A1"].gradient == 1.0
            if "B2" in widget.laser.elements:
                assert widget.laser.calibration["B2"].intercept == 2.0
                assert widget.laser.calibration["B2"].gradient == 2.0
            if "C3" in widget.laser.elements:
                assert widget.laser.calibration["C3"].intercept == 0.0
                assert widget.laser.calibration["C3"].gradient == 1.0

    # Check element changed if avilable
    assert viewspace.views[0].activeWidget().combo_element.currentText(
    ) == "A1"
    assert viewspace.views[1].activeWidget().combo_element.currentText(
    ) == "A1"
    viewspace.setCurrentElement("B2")
    assert viewspace.views[0].activeWidget().combo_element.currentText(
    ) == "B2"
    assert viewspace.views[1].activeWidget().combo_element.currentText(
    ) == "A1"
    # Close all
    for view in viewspace.views:
        for widget in view.widgets():
            widget.close()
Пример #9
0
    def __init__(
        self,
        path: Union[str, Path] = "",
        config: Config = None,
        parent: QtWidgets.QWidget = None,
    ):
        super().__init__(parent)
        self.setWindowTitle("Import Wizard")

        if isinstance(path, str):  # pragma: no cover
            path = Path(path)

        config = config or Config()

        overview = (
            "This wizard will guide you through importing LA-ICP-MS data "
            "and provides a higher level to control than the standard import. "
            "To begin select the format of the file being imported.")

        format_page = FormatPage(
            overview,
            page_id_dict={
                "agilent": self.page_agilent,
                "csv": self.page_csv,
                "numpy": -1,
                "perkinelmer": self.page_perkinelmer,
                "text": self.page_text,
                "thermo": self.page_thermo,
            },
            parent=self,
        )
        format_page.radio_numpy.setEnabled(False)
        format_page.radio_numpy.setVisible(False)

        self.setPage(self.page_format, format_page)
        self.setPage(
            self.page_agilent,
            PathAndOptionsPage([path],
                               "agilent",
                               nextid=self.page_config,
                               parent=self),
        )
        self.setPage(
            self.page_csv,
            PathAndOptionsPage([path],
                               "csv",
                               nextid=self.page_config,
                               parent=self),
        )
        self.setPage(
            self.page_perkinelmer,
            PathAndOptionsPage([path],
                               "perkinelmer",
                               nextid=self.page_config,
                               parent=self),
        )
        self.setPage(
            self.page_text,
            PathAndOptionsPage([path],
                               "text",
                               nextid=self.page_config,
                               parent=self),
        )
        self.setPage(
            self.page_thermo,
            PathAndOptionsPage([path],
                               "thermo",
                               nextid=self.page_config,
                               parent=self),
        )

        self.setPage(self.page_config, ConfigPage(config, parent=self))