Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmdocherty committed Jul 26, 2024
1 parent ce43d67 commit c55762d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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?
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
47 changes: 32 additions & 15 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"])

0 comments on commit c55762d

Please sign in to comment.