Exemplo n.º 1
0
def test_relative_paths():
    tempdir = pathlib.Path(tempfile.mkdtemp(prefix="test_shapeout2_session_"))
    # custom path for data
    p0 = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
    datadir = tempdir / "data"
    datadir.mkdir()
    pp = datadir / "calibration_beads_47.rtdc"
    shutil.copy(p0, pp)
    # custom path for session
    sessiondir = tempdir / "session"
    sessiondir.mkdir()
    spath = sessiondir / "session.so2"
    # pipeline
    pl = make_pipeline(paths=[pp])
    session.save_session(spath, pl)
    session.clear_session(pl)
    # new session directory
    new_sessiondir = tempdir / "new" / "path" / "abracadabra"
    new_sessiondir.mkdir(parents=True)
    new_spath = new_sessiondir / spath.name
    spath.rename(new_spath)
    # new path directory (same relative path)
    new_datadir = tempdir / "new" / "path" / "data"
    new_datadir.mkdir(parents=True)
    new_pp = new_datadir / pp.name
    pp.rename(new_pp)
    # and load it (without search_paths as arguments)
    session.open_session(new_spath)
Exemplo n.º 2
0
def test_wrong_hash():
    tempdir = pathlib.Path(tempfile.mkdtemp(prefix="test_shapeout2_session_"))
    spath = tempdir / "session.so2"
    # custom path to measurement
    p0 = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
    pp = pathlib.Path(tempdir) / "calibration_beads_47.rtdc"
    shutil.copy(p0, pp)
    pl = make_pipeline(paths=[pp])
    session.save_session(spath, pl)
    session.clear_session(pl)  # clear session before opening h5 file rw
    session.hash_file_partially.cache_clear()  # force recomputation of hashes
    # modify the file
    with h5py.File(pp, mode="a") as h5:
        h5.attrs["setup:medium"] = "unknown"
    # opening modified file should just work if the path matches
    pl2 = session.open_session(spath)
    session.clear_session(pl2)
    # but when the directory changes, the hash is checked
    other = tempdir / "other"
    other.mkdir()
    pp.rename(other / pp.name)
    try:
        session.open_session(spath, search_paths=[other])
    except session.DataFileNotFoundError as e:
        assert pp in e.missing_paths
    else:
        assert False, "should have raised an error!"
Exemplo n.º 3
0
def test_missing_path_in_session():
    tempdir = pathlib.Path(tempfile.mkdtemp(prefix="test_shapeout2_session_"))
    spath = tempdir / "session.so2"
    # custom path to measurement
    p0 = pathlib.Path(__file__).parent / "data" / "calibration_beads_47.rtdc"
    pp = tempdir / "calibration_beads_47.rtdc"
    shutil.copy(p0, pp)
    pl = make_pipeline(paths=[pp])
    session.save_session(spath, pl)
    session.clear_session(pl)
    # rename the file
    pc = pp.with_name("calibration_beads_47_moved.rtdc")
    pp.rename(pc)
    # load bad session
    try:
        session.open_session(spath)
    except session.DataFileNotFoundError as e:
        assert pp in e.missing_paths
    else:
        assert False, "should have raised an error!"
    # try again with proper search path
    pl3 = session.open_session(spath, search_paths=[pc])
    session.clear_session(pl3)
    # try again with a directory as search path
    other = tempdir / "other"
    other.mkdir()
    pc.rename(other / pp.name)  # must have same name as `pp`
    pl4 = session.open_session(spath, search_paths=[other])
    session.clear_session(pl4)
Exemplo n.º 4
0
def test_save_all_polygon_filters_issue_101():
    pl = make_pipeline()

    # add a polygon filter
    ds = pl.get_dataset(0)
    pf1 = dclab.PolygonFilter(
        axes=("deform", "area_um"),
        points=[
            [ds["deform"].min(), ds["area_um"].min()],
            [ds["deform"].min(), ds["area_um"].mean()],
            [ds["deform"].mean(), ds["area_um"].mean()],
        ],
        name="Triangle of Minimum",
    )
    pf2_state = dclab.PolygonFilter(
        axes=("deform", "area_um"),
        points=[
            [ds["deform"].max(), ds["area_um"].max()],
            [ds["deform"].max(), ds["area_um"].mean()],
            [ds["deform"].mean(), ds["area_um"].mean()],
        ],
        name="Triangle of Maximum",
    ).__getstate__()
    pl.filters[0].polylist.append(pf1.unique_id)
    old_state = pl.__getstate__()

    tempdir = pathlib.Path(tempfile.mkdtemp(prefix="test_shapeout2_session_"))
    spath = tempdir / "session.so2"

    session.save_session(spath, pl)

    assert len(dclab.PolygonFilter.instances) == 2

    session.clear_session(pl)

    assert len(dclab.PolygonFilter.instances) == 0

    # currently, there may only be one pipeline
    session.open_session(spath, pl)
    new_state = pl.__getstate__()

    # This is the actual test for issue #101
    assert len(dclab.PolygonFilter.instances) == 2

    # This is a sanity check
    assert equal_state(old_state, new_state)

    # This is another sanity check
    pf2_id = pf2_state["identifier"]
    assert equal_state(
        pf2_state,
        dclab.PolygonFilter.get_instance_from_id(pf2_id).__getstate__())
Exemplo n.º 5
0
def test_2_5_1_replace_emodulus_model():
    """In Shape-Out 2.5.1 we replace "emodulus model" with "emodulus lut"."""
    spath = pathlib.Path(__file__).parent / "data" / "version_2_1_0_basic.so2"
    pl = session.open_session(spath)
    sc = pl.slots[0].config
    assert "emodulus" in sc
    assert "emodulus model" not in sc["emodulus"]
    assert "emodulus lut" in sc["emodulus"]
    assert sc["emodulus"]["emodulus lut"] == "LE-2D-FEM-19"
Exemplo n.º 6
0
def test_simple_save_open_session():
    pl = make_pipeline()
    old_state = pl.__getstate__()

    tempdir = pathlib.Path(tempfile.mkdtemp(prefix="test_shapeout2_session_"))
    spath = tempdir / "session.so2"

    session.save_session(spath, pl)

    # currently, there may only be one pipeline
    session.open_session(spath, pl)
    new_state = pl.__getstate__()

    assert equal_state(old_state, new_state)

    # test opposite
    old_state["slots"][0]["emodulus"]["emodulus temperature"] = 10
    assert not equal_state(old_state, new_state)
Exemplo n.º 7
0
def test_2_1_1_new_key_emodulus_enabled():
    """In Shape-Out 2.1.1 we introduces the "emodulus enabled" key

    If it is disabled (reservoir measurements), then the emodulus
    analysis options are not shown in the Slot options. See also
    changes made in dclab 0.22.4 (test for reservoir existence).
    """
    spath = pathlib.Path(__file__).parent / "data" / "version_2_1_0_basic.so2"
    pl = session.open_session(spath)
    sc = pl.slots[0].config
    assert "emodulus" in sc
    assert "emodulus enabled" in sc["emodulus"]
    assert sc["emodulus"]["emodulus enabled"]
Exemplo n.º 8
0
import dclab
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication
from shapeout2.gui.main import ShapeOut2
from shapeout2 import session

app = QApplication(sys.argv)

QtCore.QLocale.setDefault(QtCore.QLocale(QtCore.QLocale.C))

mw = ShapeOut2()
mw.settings.setValue("check for updates", 0)
mw.settings.setValue("advanced/check pyqtgraph version", 0)

# build up a session
session.open_session(pathlib.Path(__file__).parent / "scrots.so2",
                     pipeline=mw.pipeline)
mw.reload_pipeline()

# analysis view
mw.on_modify_slot(mw.pipeline.slot_ids[0])
mw.widget_ana_view.repaint()
QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)
mw.widget_ana_view.grab().save("_ui_ana_slot.png")

mw.subwindows["analysis_view"].move(200, 300)

# main window
mw.update()
QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)
mw.grab().save("_ui_main.png")