Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alessiamarcolini
Copy link
Collaborator

fixes #246

@alessiamarcolini alessiamarcolini added this to the 0.2.5 milestone Apr 24, 2021
@alessiamarcolini alessiamarcolini added the bug Something isn't working label Apr 24, 2021
@codecov
Copy link

codecov bot commented Apr 24, 2021

Codecov Report

Merging #256 (1426cca) into master (50be1c1) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #256   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1203      1206    +3     
  Branches       114       114           
=========================================
+ Hits          1203      1206    +3     
Impacted Files Coverage Δ
src/histolab/tiler.py 100.00% <100.00%> (ø)
src/histolab/util.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50be1c1...1426cca. Read the comment docs.

Copy link
Member

@ernestoarbitrio ernestoarbitrio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per comments

Comment on lines +120 to +136
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
Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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 :)

Copy link
Collaborator Author

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

Copy link
Member

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?

Copy link
Collaborator Author

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...

Comment on lines 158 to 160
_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),
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aight

@alessiamarcolini alessiamarcolini merged commit 21730a6 into master Apr 24, 2021
@alessiamarcolini alessiamarcolini deleted the fix-random-coordinates branch April 24, 2021 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Random tile coordinates

3 participants