Exemple #1
0
def test_no_roi_found():
    _, path_in, path_out = setup_test_data(radius_px=0)

    with pytest.raises(SystemExit) as pytest_wrapped_e:
        # catches sys.exit() calls
        cli_extract_roi(path=path_in, ret_data=True)
        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == 1
Exemple #2
0
def test_exclude_roi_bad():
    _, path_in, path_out = setup_test_data(num=2)
    cli_extract_roi(path=path_in)
    cfg = config.ConfigFile(path_out)
    h5data = cli_extract_roi(path=path_in, ret_data=True)
    with qpimage.QPSeries(h5file=h5data) as qps:
        assert len(qps) == 2

    # bad image
    cfg.set_value(section="roi", key="ignore data", value="3")
    try:
        cli_extract_roi(path=path_in, ret_data=True)
    except ValueError:
        pass
    else:
        assert False

    # bad roi
    cfg.set_value(section="roi", key="ignore data", value="1.2")
    try:
        cli_extract_roi(path=path_in, ret_data=True)
    except ValueError:
        pass
    else:
        assert False

    # bad image and roi
    cfg.set_value(section="roi", key="ignore data", value="4.2")
    try:
        cli_extract_roi(path=path_in, ret_data=True)
    except ValueError:
        pass
    else:
        assert False
Exemple #3
0
def test_reuse():
    _, path_in, path_out = setup_test_data(num=2)
    cfg = config.ConfigFile(path_out)
    cfg.set_value(section="meta", key="pixel size um", value=1)

    h5data = cli_extract_roi(path=path_in, ret_data=True)

    time = h5data.stat().st_mtime

    # Do the same thing
    cli_extract_roi(path=path_in, ret_data=True)
    assert time == h5data.stat().st_mtime

    # Change something
    cfg.set_value(section="meta", key="pixel size um", value=1.01)
    cli_extract_roi(path=path_in, ret_data=True)
    assert time != h5data.stat().st_mtime
Exemple #4
0
def test_force_roi():
    qpi, path_in, path_out = setup_test_data(num=2)
    cfg = config.ConfigFile(path_out)
    cfg.set_value(section="meta", key="pixel size um", value=1)
    cfg.set_value(section="roi", key="force", value=((10, 160), (24, 178)))
    h5data = cli_extract_roi(path=path_in, ret_data=True)
    with qpimage.QPSeries(h5file=h5data) as qps:
        assert qps[0].shape == (150, 154)
        assert np.allclose(qpi.pha[10:160, 24:178], qps[0].pha)
        assert np.all(qps[0].pha == qps[1].pha)
Exemple #5
0
def test_exclude_roi():
    _, path_in, path_out = setup_test_data(num=2)
    cli_extract_roi(path=path_in)
    cfg = config.ConfigFile(path_out)
    h5data = cli_extract_roi(path=path_in, ret_data=True)
    with qpimage.QPSeries(h5file=h5data) as qps:
        assert len(qps) == 2

    # remove first image
    cfg.set_value(section="roi", key="ignore data", value="1.1")
    h5data = cli_extract_roi(path=path_in, ret_data=True)
    with qpimage.QPSeries(h5file=h5data) as qps:
        assert len(qps) == 1

    # remove second image
    cfg.set_value(section="roi", key="ignore data", value="2")
    h5data = cli_extract_roi(path=path_in, ret_data=True)
    with qpimage.QPSeries(h5file=h5data) as qps:
        assert len(qps) == 1

    # remove all
    cfg.set_value(section="roi", key="ignore data", value=["1", "2"])
    h5data = cli_extract_roi(path=path_in, ret_data=True)
    with qpimage.QPSeries(h5file=h5data) as qps:
        assert len(qps) == 0
Exemple #6
0
def test_base():
    _, path_in, path_out = setup_test_data(num=2)
    h5data = cli_extract_roi(path=path_in, ret_data=True)

    with qpimage.QPSeries(h5file=h5data, h5mode="r") as qps:
        assert len(qps) == 2
        # This might fail when the algorithms or default parameters for
        # finding ROIs change:
        assert qps[0].shape == (139, 139)

    # check existence of files
    pathtif = path_out / FILE_ROI_DATA_TIF
    assert pathtif.exists()
    assert pathtif.stat().st_size > 1500

    pathsl = path_out / FILE_SLICES
    assert pathsl.exists()
    assert len(pathsl.read_bytes()) > 100
Exemple #7
0
# setup output directory
path_in, path_out = cli.dialog.main(path)

cfg = path_out / "drymass.cfg"
if cfg.exists():
    # cleanup first
    cfg.unlink()

# set metadata
cfg = cli.config.ConfigFile(path_out)
cfg.set_value("meta", "medium index", 1.335)
cfg.set_value("meta", "pixel size um", 0.107)
cfg.set_value("meta", "wavelength nm", 633)

# extract ROIs
cli.cli_extract_roi(path=path_in)

# get image 27
# Note: Remove the DHM_HL60_cells.zip_dm folder to reproduce the figure
senpath = path_out / cli.extracting.FILE_SENSOR_WITH_ROI_IMAGE
sentif = imageio.mimread(senpath)[26]
imageio.imsave("_t02_roi_search1.jpg", sentif[..., :3])

# rerun with updated configuration
cfg.set_value("specimen", "size um", 13)
cfg.set_value("roi", "pad border px", 80)
cfg.set_value("roi", "size variation", .2)
cfg.set_value("roi", "exclude overlap px", 100)
cli.cli_extract_roi(path=path_in)

# remove ROI slices
from drymass import cli
import matplotlib.pylab as plt
import qpimage

path = "data/QLSR_PAA_beads_modified.h5"

# setup output directory
path_in, path_out = cli.dialog.main(path)
shutil.rmtree(path_out)

# Select 2nd order polynomial background correction
# -------------------------------------------------

# initial run with standard parameters
h5roi = cli.cli_extract_roi(path=path_in, ret_data=True)
h5sim = cli.cli_analyze_sphere(path=path_in, ret_data=True)

# get qpimage data of phase images with quadratic background
with qpimage.QPSeries(h5file=h5roi, h5mode="r") as qproi, \
        qpimage.QPSeries(h5file=h5sim, h5mode="r") as qpsim:
    qe1 = [qproi[3].pha - qpsim[3].pha, qproi[4].pha - qpsim[4].pha]

# get configuration handle
cfg = cli.config.ConfigFile(path_out)

kwerr = {
    "px_um": cfg["meta"]["pixel size um"],
    "imtype": "phase error",
    "vmin": -0.5,
    "vmax": +0.5,