Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmdocherty committed Jul 26, 2024
1 parent d7878e1 commit 168cc95
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_cls_squares(self):
"## Test case: characteristic length scale on random squares of increasing size"
)
target_vf = 0.5
y, x = 800, 800
y, x = 500, 500
for l in [1, 5, 10, 15, 20]:
n_rects = int((y / l) * target_vf) ** 2
arr = np.zeros((y, x), dtype=np.uint8)
Expand All @@ -125,7 +125,6 @@ def test_cls_squares(self):

tpc = model.radial_tpc(arr, False, False)
integral_range = model.tpc_to_cls(tpc, arr)
plt.imsave(f"s{l}.png", arr)
print(f"square cls of length {l}: {integral_range} with {n_rects}")

def test_cls_disks(self):
Expand All @@ -134,7 +133,7 @@ def test_cls_disks(self):
)
# TODO: test TPC drops off around the radius
target_vf = 0.5
y, x = 800, 800
y, x = 500, 500
for l in [1, 5, 10, 15, 20]:
n_disks = int((y / l) * target_vf) ** 2
arr = np.zeros((y, x), dtype=np.uint8)
Expand All @@ -145,7 +144,6 @@ def test_cls_disks(self):

tpc = model.radial_tpc(arr, False, False)
integral_range = model.tpc_to_cls(tpc, arr)
plt.imsave(f"d{l}.png", arr)
print(
f"disk cls of radius {l}: {integral_range} with {n_disks} with vf: {np.mean(arr)}"
)
Expand All @@ -156,14 +154,14 @@ def test_blobs_vf_cls(self):
h, l, vf = 750, 10, 0.4
percent_l = l / h
test_arr = binary_blobs(h, percent_l, 2, vf)
result = model.make_error_prediction(test_arr, model_error=False)
result = model.make_error_prediction(test_arr, model_error=True)
assert np.isclose(result["integral_range"], l, atol=5)

def test_repr_pred(self):
"""Test the percentage error of a random binomial size (500,500) - should be small"""
print("## Test case: representativity of random binomial")
test_arr = np.random.binomial(1, 0.5, (500, 500))
result = model.make_error_prediction(test_arr, model_error=False)
result = model.make_error_prediction(test_arr, model_error=True)
assert result["percent_err"] < 0.05

def test_binary(self):
Expand All @@ -173,8 +171,8 @@ def test_binary(self):
percent_l = l / h
test_arr = binary_blobs(h, percent_l, 2, vf)
inv_test_arr = ~test_arr
result_1 = model.make_error_prediction(test_arr, model_error=False)
result_2 = model.make_error_prediction(inv_test_arr, model_error=False)
result_1 = model.make_error_prediction(test_arr, model_error=True)
result_2 = model.make_error_prediction(inv_test_arr, model_error=True)

print(
f"abs err phase 1: {result_1['abs_err']}, abs err phase 2: {result_2['abs_err']}"
Expand All @@ -191,15 +189,15 @@ def test_repr_zoom_pred(self):
desired_error = 0.1
crop = DEFAULT_BINARY_IMG[:300, :300]
result = model.make_error_prediction(
crop, 0.95, desired_error, model_error=False
crop, 0.95, desired_error, model_error=True
)
l_for_err = int(result["l"])
print(
f"Need edge length {l_for_err} for better than {desired_error:.3f}% phase fraction error, currently {result['percent_err']:.3f}%"
)
wider_crop = DEFAULT_BINARY_IMG[:l_for_err, :l_for_err]
refined_result = model.make_error_prediction(
wider_crop, 0.95, 0.05, model_error=False
wider_crop, 0.95, 0.05, model_error=True
)
print(
f"{refined_result['percent_err']:.3f}% phase fraction error at l={l_for_err}\n"
Expand Down

0 comments on commit 168cc95

Please sign in to comment.