Beispiel #1
0
def test_no_search_missing_file_slices():
    radius = 30
    pxsize = 1e-6
    _qpi, path, dout = setup_test_data(radius=radius, pxsize=pxsize)
    try:
        drymass.extract_roi(path,
                            dir_out=dout,
                            size_m=2 * radius * pxsize,
                            search_enabled=False)
    except ValueError:
        pass
    else:
        assert False, "should not be possible to disable search without ROIs"
Beispiel #2
0
def test_ret_changed():
    radius = 30
    pxsize = 1e-6
    _qpi, path, dout = setup_test_data(radius=radius, pxsize=pxsize)
    _p1, ch1 = drymass.extract_roi(path,
                                   dir_out=dout,
                                   size_m=2 * radius * pxsize,
                                   ret_changed=True)
    _p2, ch2 = drymass.extract_roi(path,
                                   dir_out=dout,
                                   size_m=2 * radius * pxsize,
                                   ret_changed=True)
    assert ch1, "First call should create data on disk"
    assert not ch2, "Second call should reuse data on disk"
Beispiel #3
0
def test_bg_corr_mask():
    radius = 30
    pxsize = 1e-6
    size = 200
    bg = np.zeros((size, size)) + .1
    bg += np.linspace(-.3, .5, size).reshape(-1, 1)
    _, path, dout = setup_test_data(radius=radius,
                                    size=size,
                                    pxsize=pxsize,
                                    bg=bg)
    qpiref, p2, d2 = setup_test_data(radius=radius,
                                     size=size,
                                     pxsize=pxsize,
                                     bg=None)

    bg_pha_kw = {
        "fit_offset": "mean",
        "fit_profile": "tilt",
        "border_perc": 0,
        "border_px": 0
    }
    path_out = drymass.extract_roi(path,
                                   dir_out=dout,
                                   size_m=2 * radius * pxsize,
                                   bg_pha_kw=bg_pha_kw,
                                   bg_pha_mask_radial_clearance=1.1)
    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qpso:
        assert np.allclose(np.min(qpso[0].pha), 0, atol=4e-9, rtol=0)
        assert np.allclose(np.max(qpso[0].pha),
                           np.max(qpiref.pha),
                           atol=1.1e-7,
                           rtol=0)
Beispiel #4
0
def test_basic():
    radius = 30
    pxsize = 1e-6
    qpi, path, dout = setup_test_data(radius=radius, pxsize=pxsize)
    path_out = drymass.extract_roi(path,
                                   dir_out=dout,
                                   size_m=2 * radius * pxsize)

    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qpso:
        assert len(qpso) == 1
        qpi2 = qpso.get_qpimage(0)
        assert qpi != qpi2
        assert qpi.shape != qpi2.shape
Beispiel #5
0
def test_no_search():
    radius = 30
    pxsize = 1e-6
    identifier = "asdkn179"
    _qpi, path, dout = setup_test_data(radius=radius,
                                       pxsize=pxsize,
                                       identifier=identifier)
    _p1, rm1 = drymass.extract_roi(path,
                                   dir_out=dout,
                                   size_m=2 * radius * pxsize,
                                   ret_roimgr=True)
    _p2, rm2 = drymass.extract_roi(
        path,
        dir_out=dout,
        size_m=2 * radius * pxsize,
        search_enabled=False,
        ret_roimgr=True,
    )

    assert rm1.rois == rm2.rois
    assert rm1.identifier == identifier
    assert rm2.identifier == identifier
Beispiel #6
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
Beispiel #7
0
def test_bg_corr_thresh():
    radius = 30
    pxsize = 1e-6
    bg = .3
    qpi, path, dout = setup_test_data(radius=radius, pxsize=pxsize, bg=bg)

    bg_pha_kw = {
        "fit_offset": "mean",
        "fit_profile": "tilt",
        "border_perc": 0,
        "border_px": 0
    }
    path_out = drymass.extract_roi(path,
                                   dir_out=dout,
                                   size_m=2 * radius * pxsize,
                                   bg_pha_kw=bg_pha_kw,
                                   bg_pha_bin=bg * 1.1)
    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qpso:
        assert np.min(qpso[0].pha) == 0
        assert np.allclose(np.max(qpso[0].pha), np.max(qpi.pha) - bg)