From c55762d96e295cdf9c4c5f51de8c8eb3d430fcb9 Mon Sep 17 00:00:00 2001 From: rmdocherty Date: Fri, 26 Jul 2024 10:12:26 +0100 Subject: [PATCH] minor changes --- README.md | 8 +++++++- tests/tests.py | 47 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8b01f7f..11ba871 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Representativity -You take a micrograph of a material. You segment it, and measure the phase fractions. How sure are you that the phase fraction of the whole material is close to your measurements? \ No newline at end of file +You take a micrograph of a material. You segment it, and measure the phase fractions. How sure are you that the phase fraction of the whole material is close to your measurements? + +Questions: +- Website name (isitrepresentative.com) +- model err problem +- refactoring +- cls for squares \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index 7863b90..a6d06cc 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -110,19 +110,38 @@ def test_cls_squares(self): "## Test case: characteristic length scale on random squares of increasing size" ) target_vf = 0.5 - y, x, l = 500, 500, 10 - n_rects = int((y / l) * target_vf) ** 2 - print(n_rects) - arr = np.zeros((y, x), dtype=np.uint8) - for i in range(n_rects): - dx, dy = np.random.randint(0, y), np.random.randint(0, x) - rr, cc = rectangle((dy, dx), extent=(l, l), shape=(y, x)) - arr[rr, cc] = 1 - - tpc = model.radial_tpc(arr, False, False) - integral_range = model.tpc_to_cls(tpc, arr) - # plt.imsave("foo.png", arr) - print(integral_range, np.sqrt(2) * l) + y, x = 800, 800 + for l in [1, 5, 10, 15, 20]: + n_rects = int((y / l) * target_vf) ** 2 + arr = np.zeros((y, x), dtype=np.uint8) + for i in range(n_rects): + dx, dy = np.random.randint(0, y), np.random.randint(0, x) + rr, cc = rectangle((dy, dx), extent=(l, l), shape=(y, x)) + arr[rr, cc] = 1 + + 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): + print( + "## Test case: characteristic length scale on random disks of increasing size" + ) + target_vf = 0.5 + y, x = 800, 800 + for l in [1, 5, 10, 15, 20]: + n_disks = int((y / l) * target_vf) ** 2 + arr = np.zeros((y, x), dtype=np.uint8) + for i in range(n_disks): + dx, dy = np.random.randint(0, y), np.random.randint(0, x) + rr, cc = disk((dy, dx), radius=l, shape=(y, x)) + arr[rr, cc] = 1 + + 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}") def test_blobs_vf_cls(self): """Test the cls of random binary blobs, should be around the set length scale""" @@ -180,8 +199,6 @@ def test_repr_zoom_pred(self): ) assert refined_result["percent_err"] < result["percent_err"] - # TODO: test that reprs of each phase of binary microstrucutre are the same - if __name__ == "__main__": unittest.main(argv=["example"])