Exemplo n.º 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)
Exemplo n.º 2
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()