Exemplo n.º 1
0
def test_radius_exceeds_image_size_error():
    pxsize = 1e-6
    size = 200
    _qpi, path, dout = setup_test_data(pxsize=pxsize, size=size)
    try:
        drymass.analyze_sphere(path, dir_out=dout, r0=size * pxsize * 2)
    except qpsphere.edgefit.RadiusExceedsImageSizeError:
        pass
    else:
        assert False
Exemplo n.º 2
0
def test_recreate_file_sphere_stat():
    _qpi, path, dout = setup_test_data()
    spkw = {"method": "edge", "model": "projection"}
    drymass.analyze_sphere(path, dir_out=dout, **spkw)
    stats = (pathlib.Path(dout) / drymass.anasphere.FILE_SPHERE_STAT.format(
        spkw["method"], spkw["model"]))
    stats.unlink()
    assert not stats.exists()
    drymass.analyze_sphere(path, dir_out=dout, **spkw)
    assert stats.exists()
Exemplo n.º 3
0
def test_recompute_broken_output_path():
    _qpi, path, dout = setup_test_data()
    path_out = drymass.analyze_sphere(path, dir_out=dout)
    # break it
    with path_out.open("w") as fd:
        fd.write("This file is broken intentionally!")
    _p, changed = drymass.analyze_sphere(path, dir_out=dout, ret_changed=True)
    assert changed, "broken file should be recomputed"
    # delete it
    path_out.unlink()
    _p, changed = drymass.analyze_sphere(path, dir_out=dout, ret_changed=True)
    assert changed, "non-existent file should be recomputed"
Exemplo n.º 4
0
def test_recompute_edge_when_imagekw_changes():
    _qpi, path, dout = setup_test_data()
    drymass.analyze_sphere(path, dir_out=dout, imagekw={"stop_dc": .9})
    _p, changed = drymass.analyze_sphere(path,
                                         dir_out=dout,
                                         imagekw={"stop_dc": .9},
                                         ret_changed=True)
    assert not changed, "same arguments"
    _p, changed = drymass.analyze_sphere(path,
                                         dir_out=dout,
                                         imagekw={"stop_dc": .8},
                                         ret_changed=True)
    assert not changed, "different imagekw when method is edge"
Exemplo n.º 5
0
def test_recompute_edge_when_otherkw_changes():
    _qpi, path, dout = setup_test_data()
    drymass.analyze_sphere(path,
                           dir_out=dout,
                           alpha=0.18,
                           edgekw={"clip_rmax": 1.1})
    _p, changed = drymass.analyze_sphere(path,
                                         dir_out=dout,
                                         alpha=0.19,
                                         edgekw={"clip_rmax": 1.1},
                                         ret_changed=True)
    assert changed, "change due to other alpha"
    _p, changed = drymass.analyze_sphere(path,
                                         dir_out=dout,
                                         alpha=0.19,
                                         edgekw={"clip_rmax": 1.2},
                                         ret_changed=True)
    assert changed, "change due to other edgekw"
Exemplo n.º 6
0
def test_basic():
    qpi, path, dout = setup_test_data(num=2)
    path_out = drymass.analyze_sphere(path, dir_out=dout)

    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qpso:
        assert qpso[0].shape == qpi.shape
        assert qpso[0]["wavelength"] == qpi["wavelength"]
        assert qpso[0]["pixel size"] == qpi["pixel size"]
        assert qpso[0]["medium index"] == qpi["medium index"]
        assert qpso[0]["identifier"].count("projection")
Exemplo n.º 7
0
def test_recompute_reuse():
    cx = 14
    cy = 16
    radius = 7
    size = 30
    pxsize = 1e-6
    _qpi, path, dout = setup_test_data_roi(num=2,
                                           radius=radius,
                                           pxsize=pxsize,
                                           size=size,
                                           cx=cx,
                                           cy=cy)

    # extract ROIs
    roikw = {"size_m": 2 * radius * pxsize, "dist_border": 0, "pad_border": 3}
    path_rois = drymass.extract_roi(path, dir_out=dout, **roikw)
    # perform sphere analysis
    ta0 = time.perf_counter()
    drymass.analyze_sphere(path_rois,
                           dir_out=dout,
                           method="image",
                           model="projection")
    ta1 = time.perf_counter()

    # extract ROIs, ignoring first image
    drymass.extract_roi(path, dir_out=dout, ignore_data=["1"], **roikw)
    # this time it should be very fast
    tb0 = time.perf_counter()
    _out, changed = drymass.analyze_sphere(path_rois,
                                           dir_out=dout,
                                           method="image",
                                           model="projection",
                                           ret_changed=True)
    tb1 = time.perf_counter()

    assert changed, "One ROI was removed, thus change"
    # there should still be a marging of .6s
    assert 10 * (tb1 - tb0) < ta1 - ta0