コード例 #1
0
def test_droplettracklist_plotting():
    """test plotting droplet tracks"""
    t1 = DropletTrack()
    ds = [DiffuseDroplet([0, 1], 10, 0.5)] * 2
    t2 = DropletTrack(droplets=ds, times=[0, 10])
    DropletTrackList([t1, t2]).plot()
    DropletTrackList([t1, t2]).plot_positions()
コード例 #2
0
def test_droplettrack_plotting():
    """test writing and reading droplet tracks"""
    ds = [DiffuseDroplet([0, 1], 10, 0.5)] * 2
    t = DropletTrack(droplets=ds, times=[0, 10])
    t.plot("radius")
    t.plot("volume")
    t.plot_positions()
    t.plot_positions(grid=UnitGrid([5, 5], periodic=True))
コード例 #3
0
def test_emulsion_processing():
    """test identifying emulsions in phase fields"""
    grid = UnitGrid([32, 32], periodic=True)

    e1 = Emulsion(
        [
            DiffuseDroplet(position=[5, 6], radius=9, interface_width=1),
            DiffuseDroplet(position=[20, 19], radius=8, interface_width=1),
        ],
        grid=grid,
    )
    field = e1.get_phasefield()

    e2 = image_analysis.locate_droplets(field, refine=True)

    np.testing.assert_allclose(
        structured_to_unstructured(e1.data),
        structured_to_unstructured(e2.data),
        rtol=0.02,
    )
コード例 #4
0
def test_localization_threshold():
    """tests different localization thresholds"""
    pos = np.random.random(2) * 16
    radius = np.random.uniform(2, 5)
    width = np.random.uniform(1, 2)
    d1 = DiffuseDroplet(pos, radius, interface_width=width)

    grid = UnitGrid((16, 16), periodic=False)
    field = d1.get_phase_field(grid)

    for threshold in [0.25, 0.75, "auto"]:
        emulsion = image_analysis.locate_droplets(
            field, threshold=threshold, refine=True
        )
        assert len(emulsion) == 1
        d2 = emulsion[0]

        np.testing.assert_almost_equal(d1.position, d2.position)
        assert d1.radius == pytest.approx(d2.radius, rel=1e-4)
        assert d1.interface_width == pytest.approx(d2.interface_width)
コード例 #5
0
def test_localization_spherical():
    """tests simple droplets localization in spherical grid"""
    radius = np.random.uniform(2, 3)
    width = np.random.uniform(0.5, 1.5)
    d1 = DiffuseDroplet((0, 0, 0), radius, interface_width=width)

    grid_radius = 6 + 2 * np.random.random()
    grid = SphericalSymGrid(grid_radius, 16)
    field = d1.get_phase_field(grid)

    emulsion = image_analysis.locate_droplets(field, refine=True)
    assert len(emulsion) == 1
    d2 = emulsion[0]

    np.testing.assert_almost_equal(d1.position, d2.position, decimal=5)
    assert d1.radius == pytest.approx(d2.radius, rel=1e-5)
    assert d1.interface_width == pytest.approx(d2.interface_width, rel=1e-5)

    emulsion = image_analysis.locate_droplets(ScalarField(grid))
    assert len(emulsion) == 0
コード例 #6
0
def test_droplettracklist_io(tmp_path):
    """test writing and reading droplet tracks"""
    path = tmp_path / "test_droplettracklist_io.hdf5"

    t1 = DropletTrack()
    ds = [DiffuseDroplet([0, 1], 10, 0.5)] * 2
    t2 = DropletTrack(droplets=ds, times=[0, 10])
    tl_out = DropletTrackList([t1, t2])

    tl_out.to_file(path)
    tl_in = DropletTrackList.from_file(path)
    assert tl_in == tl_out
コード例 #7
0
def test_droplettracklist():
    """test droplet tracks"""
    t1 = DropletTrack()
    ds = [DiffuseDroplet([0, 1], 10, 0.5)] * 2
    t2 = DropletTrack(droplets=ds, times=[0, 10])
    tl = DropletTrackList([t1, t2])

    assert len(tl) == 2
    assert tl[0] == t1
    assert tl[1] == t2

    tl.remove_short_tracks()
    assert len(tl) == 1
コード例 #8
0
def test_localization_cylindrical(periodic):
    """tests simple droplets localization in cylindrical grid"""
    pos = (0, 0, np.random.uniform(-4, 4))
    radius = np.random.uniform(2, 3)
    width = np.random.uniform(0.5, 1.5)
    d1 = DiffuseDroplet(pos, radius, interface_width=width)

    grid_radius = 6 + 2 * np.random.random()
    bounds_z = np.random.uniform(1, 2, size=2) * np.array([-4, 4])
    grid = CylindricalSymGrid(grid_radius, bounds_z, (16, 32), periodic_z=periodic)
    field = d1.get_phase_field(grid)

    emulsion = image_analysis.locate_droplets(field, refine=True)
    assert len(emulsion) == 1
    d2 = emulsion[0]

    np.testing.assert_almost_equal(d1.position, d2.position, decimal=5)
    assert d1.radius == pytest.approx(d2.radius, rel=1e-5)
    assert d1.interface_width == pytest.approx(d2.interface_width)

    emulsion = image_analysis.locate_droplets(ScalarField(grid))
    assert len(emulsion) == 0
コード例 #9
0
def test_droplettrack_io(tmp_path):
    """test writing and reading droplet tracks"""
    path = tmp_path / "test_droplettrack_io.hdf5"

    t1 = DropletTrack()
    ds = [DiffuseDroplet([0, 1], 10, 0.5)] * 2
    t2 = DropletTrack(droplets=ds, times=[0, 10])

    for t_out in [t1, t2]:
        t_out.to_file(path)
        t_in = DropletTrack.from_file(path)
        assert t_in == t_out
        assert t_in.times == t_out.times
        assert t_in.droplets == t_out.droplets
コード例 #10
0
def test_localization_sym_unit(size, periodic):
    """tests simple droplets localization in 2d"""
    pos = np.random.random(2) * size
    radius = np.random.uniform(2, 5)
    width = np.random.uniform(1, 2)
    d1 = DiffuseDroplet(pos, radius, interface_width=width)

    grid = UnitGrid((size, size), periodic=periodic)
    field = d1.get_phase_field(grid)

    emulsion = image_analysis.locate_droplets(field, refine=True)
    assert len(emulsion) == 1
    d2 = emulsion[0]

    np.testing.assert_almost_equal(d1.position, d2.position)
    assert d1.radius == pytest.approx(d2.radius, rel=1e-4)
    assert d1.interface_width == pytest.approx(d2.interface_width)

    emulsion = image_analysis.locate_droplets(field, minimal_radius=size)
    assert len(emulsion) == 0

    emulsion = image_analysis.locate_droplets(ScalarField(grid))
    assert len(emulsion) == 0
コード例 #11
0
def test_localization_sym_rect(periodic):
    """tests simple droplets localization in 2d with a rectangular grid"""
    size = 16

    pos = np.random.uniform(-4, 4, size=2)
    radius = np.random.uniform(2, 5)
    width = np.random.uniform(0.5, 1.5)
    d1 = DiffuseDroplet(pos, radius, interface_width=width)

    a = np.random.random(2) - size / 2
    b = np.random.random(2) + size / 2
    grid = CartesianGrid(np.c_[a, b], 3 * size, periodic=periodic)
    field = d1.get_phase_field(grid)

    emulsion = image_analysis.locate_droplets(field, refine=True)
    assert len(emulsion) == 1
    d2 = emulsion[0]

    np.testing.assert_almost_equal(d1.position, d2.position)
    assert d1.radius == pytest.approx(d2.radius, rel=1e-5)
    assert d1.interface_width == pytest.approx(d2.interface_width)

    emulsion = image_analysis.locate_droplets(ScalarField(grid))
    assert len(emulsion) == 0