2
2
3
3
np .random .seed (0 )
4
4
from skimage .draw import disk , rectangle
5
+ from skimage .data import binary_blobs
5
6
from tifffile import imread
6
7
import matplotlib .pyplot as plt
7
8
@@ -123,7 +124,38 @@ def test_cls_squares(self):
123
124
# plt.imsave("foo.png", arr)
124
125
print (integral_range , np .sqrt (2 ) * l )
125
126
127
+ def test_blobs_vf_cls (self ):
128
+ """Test the cls of random binary blobs, should be around the set length scale"""
129
+ print ("## Test case: cls of random blobs" )
130
+ h , l , vf = 750 , 10 , 0.4
131
+ percent_l = l / h
132
+ test_arr = binary_blobs (h , percent_l , 2 , vf )
133
+ result = model .make_error_prediction (test_arr , model_error = False )
134
+ assert np .isclose (result ["integral_range" ], l , atol = 5 )
135
+
126
136
def test_repr_pred (self ):
137
+ """Test the percentage error of a random binomial size (500,500) - should be small"""
138
+ print ("## Test case: representativity of random binomial" )
139
+ test_arr = np .random .binomial (1 , 0.5 , (500 , 500 ))
140
+ result = model .make_error_prediction (test_arr , model_error = False )
141
+ assert result ["percent_err" ] < 0.05
142
+
143
+ def test_binary (self ):
144
+ """Test that abs_err of repr of phase 1 of binary = abs_err of phase 2 of binary"""
145
+ print ("## Test case: repr of two phases of binary materials the same" )
146
+ h , l , vf = 750 , 10 , 0.4
147
+ percent_l = l / h
148
+ test_arr = binary_blobs (h , percent_l , 2 , vf )
149
+ inv_test_arr = ~ test_arr
150
+ result_1 = model .make_error_prediction (test_arr , model_error = False )
151
+ result_2 = model .make_error_prediction (inv_test_arr , model_error = False )
152
+
153
+ print (
154
+ f"abs err phase 1: { result_1 ['abs_err' ]} , abs err phase 2: { result_2 ['abs_err' ]} "
155
+ )
156
+ assert np .isclose (result_1 ["abs_err" ], result_2 ["abs_err" ], rtol = 0.001 )
157
+
158
+ def test_repr_zoom_pred (self ):
127
159
"""Measure the representativity of a crop of our default microstructure, finding the image edge length
128
160
needed to reach a given $desired_error. Then crop the microstructure to this (larger) edge length,
129
161
measuring the representativity and percent error again. If our model is correct (and conservative),
@@ -148,6 +180,8 @@ def test_repr_pred(self):
148
180
)
149
181
assert refined_result ["percent_err" ] < result ["percent_err" ]
150
182
183
+ # TODO: test that reprs of each phase of binary microstrucutre are the same
184
+
151
185
152
186
if __name__ == "__main__" :
153
187
unittest .main (argv = ["example" ])
0 commit comments