Skip to content

Commit

Permalink
add simple reproducibility test with bhfield
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Dec 12, 2017
1 parent 8e3c697 commit 8d256ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions qpsphere/models/_bhfield/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
see https://github.com/RI-imaging/QPI-binaries/tree/master/BHFIELD
"""
from . import fetch # noqa: F401
from .wrap import simulate_sphere # noqa: F401
21 changes: 11 additions & 10 deletions qpsphere/models/_bhfield/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ class BHFIELDExecutionError(BaseException):
pass


def clear_temp(wdir="."):
""" Remove all files in wdir"""
def clear_temp(wdir=".", rmdir=True):
"""Remove all files in wdir"""
wdir = pathlib.Path(wdir)
extensions = ["*.log", "*.dat", "*.txt"]

for ext in extensions:
for ff in wdir.glob(ext):
ff.unlink()

wdir.rmdir()
if rmdir:
wdir.rmdir()


def load_field(wdir=".", size_grid=None):
Expand Down Expand Up @@ -119,11 +120,11 @@ def load_field(wdir=".", size_grid=None):


def simulate_sphere(radius_sphere_um=2.5,
size_simulation_um=(5, 5),
size_grid=50,
size_simulation_um=(7, 7),
size_grid=(50, 50),
refractive_index_medium=1.0,
refractive_index_sphere=1.001,
measurement_position_um=3.0,
refractive_index_sphere=1.01,
measurement_position_um=2.5,
wavelength_nm=500,
offset_x_um=0,
offset_y_um=0,
Expand All @@ -133,11 +134,11 @@ def simulate_sphere(radius_sphere_um=2.5,
----------
radius_sphere_um : float
radius of sphere in um
size_simulation_um : float or tuple of floats
size_simulation_um : tuple of floats
Size of simulation volume in lateral dimension in um.
If a float is given, then a square simulation size is assumed. If
a tuple is given, then a rectangular shape is assumed.
size_grid : int or tuple
size_grid : tuple of ints
grid points in each lateral dimension.
If a float is given, then a square simulation size is assumed. If
a tuple is given, then a rectangular shape is assumed.
Expand Down Expand Up @@ -282,7 +283,7 @@ def run_simulation(wdir=".", arp=True, **kwargs):
kwargs["pathbhfield"] = get_binary(arp=arp)

if arp:
kwargs["mpdigit"] = 5
kwargs["mpdigit"] = 16
else:
kwargs["mpdigit"] = ""

Expand Down
16 changes: 16 additions & 0 deletions tests/test_mie_bhfield.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

from qpsphere.models import _bhfield as bh


Expand All @@ -8,6 +10,20 @@ def test_get_binary():
assert path2.exists()


def test_default_simulation():
data = np.array([0.99915+0.0059473j, 1.01950-0.0067643j,
1.01950-0.0067643j, 0.99915+0.0059473j,
1.02340-0.0037607j, 0.97630+0.4906j,
0.97630+0.4906j, 1.02340-0.0037607j,
1.02340-0.0037607j, 0.97630+0.4906j,
0.97630+0.4906j, 1.02340-0.0037607j,
0.99915+0.0059473j, 1.01950-0.0067643j,
1.01950-0.0067643j, 0.99915+0.0059473j])

field = bh.simulate_sphere(size_grid=(4, 4))
assert np.allclose(field.flatten(), data)


if __name__ == "__main__":
# Run all tests
loc = locals()
Expand Down

0 comments on commit 8d256ac

Please sign in to comment.