Exemplo n.º 1
0
def test_bg_correction_index():
    qpi, path, dout = setup_test_data(num=2)

    path_out = drymass.convert(path_in=path,
                               dir_out=dout,
                               bg_data_amp=1,
                               bg_data_pha=1)
    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qps:
        # background correction with same input image will result
        # in a flat QPImage.
        assert np.all(qps[0].pha == 0)
        assert np.all(qps[0].amp == 1)

    # To be absolutely sure this works, append a blank
    # QPImage and do it again.
    with qpimage.QPSeries(h5file=path, h5mode="a") as qps:
        pha = .5 * np.ones(qps[0].shape)
        amp = .9 * np.ones(qps[0].shape)
        qps.add_qpimage(
            qpimage.QPImage(data=(pha, amp), which_data="phase,amplitude"))

    path_out = drymass.convert(path_in=path,
                               dir_out=dout,
                               bg_data_amp=3,
                               bg_data_pha=3)
    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qps:
        # background correction with same input image will result
        # in a flat QPImage.
        assert np.allclose(qps[0].pha, qpi.pha - .5)
        assert np.allclose(qps[0].amp, qpi.amp / .9)
Exemplo n.º 2
0
def test_bg_correction_index_bad():
    _qpi, path, dout = setup_test_data(num=2)

    try:
        drymass.convert(path_in=path, dir_out=dout, bg_data_amp=0)
    except ValueError:
        pass
    else:
        assert False

    try:
        drymass.convert(path_in=path, dir_out=dout, bg_data_pha=-1)
    except ValueError:
        pass
    else:
        assert False

    try:
        drymass.convert(path_in=path, dir_out=dout, bg_data_amp=3)
    except ValueError:
        pass
    else:
        assert False

    try:
        drymass.convert(path_in=path, dir_out=dout, bg_data_pha=3)
    except ValueError:
        pass
    else:
        assert False
Exemplo n.º 3
0
def test_reuse():
    _qpi, path, dout = setup_test_data(num=2)

    _po, changed1 = drymass.convert(path_in=path,
                                    dir_out=dout,
                                    bg_data_amp=1,
                                    bg_data_pha=1,
                                    ret_changed=True)
    _po, changed2 = drymass.convert(path_in=path,
                                    dir_out=dout,
                                    bg_data_amp=1,
                                    bg_data_pha=1,
                                    ret_changed=True)
    assert changed1
    assert not changed2
Exemplo n.º 4
0
def test_bg_correction_none_bad():
    _qpi, path, dout = setup_test_data(num=2)

    path_out = drymass.convert(path_in=path, dir_out=dout, bg_data_amp=1)
    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qps:
        # background correction with same input image will result
        # in a flat QPImage.
        assert not np.all(qps[0].pha == 0)
        assert np.all(qps[0].amp == 1)

    path_out = drymass.convert(path_in=path, dir_out=dout, bg_data_pha=1)
    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qps:
        # background correction with same input image will result
        # in a flat QPImage.
        assert np.all(qps[0].pha == 0)
        assert not np.all(qps[0].amp == 1)
Exemplo n.º 5
0
def test_bg_correction_invalid():
    _qpi, path, dout = setup_test_data(num=2)

    try:
        drymass.convert(path_in=path, dir_out=dout, bg_data_pha=np.zeros(10))
    except ValueError:
        pass
    else:
        assert False

    try:
        drymass.convert(path_in=path, dir_out=dout, bg_data_pha=1.2)
    except ValueError:
        pass
    else:
        assert False
Exemplo n.º 6
0
def test_change_wavelength():
    _qpi, path, dout = setup_test_data()
    path_out = drymass.convert(path_in=path,
                               dir_out=dout,
                               meta_data={"wavelength": 500e-9})

    with qpimage.QPSeries(h5file=path_out, h5mode="r") as qpso:
        id1 = qpso.identifier

    path_out2 = drymass.convert(path_in=path,
                                dir_out=dout,
                                meta_data={"wavelength": 333e-9})

    with qpimage.QPSeries(h5file=path_out2, h5mode="r") as qpso:
        id2 = qpso.identifier

    assert id1 != id2, "Files should have different identifiers"