-
-
Notifications
You must be signed in to change notification settings - Fork 64
Fix random choice of coordinates within true values of a binary mask #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #256 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 1203 1206 +3
Branches 114 114
=========================================
+ Hits 1203 1206 +3
Continue to review full report at Codecov.
|
ernestoarbitrio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per comments
| def random_choice_true_mask2d(binary_mask: np.ndarray) -> Tuple[int, int]: | ||
| """Return a random pair of indices where the ``binary_mask`` is True. | ||
| Parameters | ||
| ---------- | ||
| binary_mask : np.ndarray | ||
| Binary array. | ||
| Returns | ||
| ------- | ||
| Tuple[int, int] | ||
| Random pair of indices where the ``binary_mask`` is True. | ||
| """ | ||
| x = np.random.choice(np.where(binary_mask)[0]) | ||
| y = np.random.choice(np.where(binary_mask[x])[0]) | ||
|
|
||
| return x, y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any reason of a new util functions that is used basically in one single place. If in future we need this in more than 1 code portion so we can introduce it in the util module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, should it be a private static method of RandomTiler then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for 2 lines and then used in only one part in the randomtiler? i don't think so just copy and paste that 2 lines when you need those :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm not so easily testable in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? you could check the call args and assert that the y has the correct value you are expecting and that depends on the x.
scale_coordinates(
reference_coords=CoordinatePair(x_ul_lvl, y_ul_lvl, x_br_lvl, y_br_lvl),
reference_size=binary_mask.shape[::-1],
target_size=slide.dimensions,
)
during the test you can assert that the scale_coordinates has been called with the right x_ul_lvl and y_ul_lvl .. do you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the test I want to check that the coordinates I sampled correspond to a True value in the mask, and I won't be checking that with your proposal...
| _scale_coordinates.assert_called_once_with( | ||
| reference_coords=CP(x_ul=0, y_ul=0, x_br=128, y_br=128), | ||
| reference_size=(500, 500), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand why this is not enough?
this
_random_choice_true_mask2d.return_value = (0, 0)
is basically asserting that x and y are 0 and so this line asserts the same thing i believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I assert the fact that starting from (0,0) - which I know because I mocked random_choice_true_mask2d - I get to (128,128) via the scaling of the tile dimensions and then the sum.. but I'm not really testing if the coordinates UL are correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see they're random that's the point. I don't know maybe the integration tests are enough to cover this .... but if you feel more safe this way, i can buy that. So... just let me know and I'll stamp the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep the unit test as it is, via the integration tests we have we never noticed (visually), probably due to a lucky seed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aight
fixes #246