Apply suggestions from code review of branch scanning-stability
Co-authored-by: Joe Knapper <joe.knapper@glasgow.ac.uk>
This commit is contained in:
parent
2749a1818c
commit
9b58f4d59e
5 changed files with 15 additions and 15 deletions
|
|
@ -264,7 +264,7 @@ class ColourChannelDetectLUV(BackgroundDetectAlgorithm):
|
|||
std = np.std(image_luv, axis=(0, 1))
|
||||
|
||||
if np.any(std == 0):
|
||||
raise ChannelBlankError("Some LUV channels have no standard devaition.")
|
||||
raise ChannelBlankError("Some LUV channels have no standard deviation.")
|
||||
std = np.maximum(std, self.min_stds)
|
||||
|
||||
self.background_data = ChannelDistributions(
|
||||
|
|
@ -298,7 +298,7 @@ class ChannelDeviationLUV(BackgroundDetectAlgorithm):
|
|||
deviations of an 8x8 grid of sub-images to the median standard deviation
|
||||
from a background image.
|
||||
|
||||
:returns: A value (between 0 and 100) is the percentage of the image that is
|
||||
:returns: A value (between 0 and 100) that is the percentage of the image that is
|
||||
sample.
|
||||
"""
|
||||
if not self.background_data:
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ class NoFocusFoundError(RuntimeError):
|
|||
|
||||
|
||||
def _get_peak_turning_point(sharpnesses: np.ndarray) -> float:
|
||||
"""Get the turing point for a sharpnesses in a z-stack.
|
||||
"""Get the turning point for a sharpnesses in a z-stack.
|
||||
|
||||
:param sharpnesses: A numpy array of sharpnesses
|
||||
:return: The x value of the turning point where x-axis is 0 to N-1 for the N
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from openflexure_microscope_server.things.autofocus import (
|
|||
)
|
||||
|
||||
|
||||
def fake_sharpeness_data(
|
||||
def fake_sharpness_data(
|
||||
dz: int, start_z: int, max_loc: int, length: int = 41
|
||||
) -> tuple[list[float], np.ndarray, np.ndarray]:
|
||||
"""Create some fake data for the shapeness.
|
||||
|
|
@ -23,7 +23,7 @@ def fake_sharpeness_data(
|
|||
times = [i / 10 + 100000 for i in range(length)]
|
||||
img_dz = dz / (length - 1)
|
||||
heights = [round(start_z + i * img_dz) for i in range(length)]
|
||||
# Shapeness is falls off linearly in this model.
|
||||
# Sharpnesses fall off linearly in this model.
|
||||
sharpnesses = [10 * dz - abs(max_loc - h) for h in heights]
|
||||
return times, np.array(heights), np.array(sharpnesses)
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ def fake_sharpeness_data(
|
|||
@pytest.mark.parametrize(
|
||||
("start_z", "max_loc", "centre", "attempts_expected", "passes"),
|
||||
[
|
||||
# To complete the max must be in the central 1200, so -600 to 600 when looping
|
||||
# To complete, the max must be in the central 1200, so -600 to 600 when looping
|
||||
# from -1000 to 1000
|
||||
(0, 550, True, 1, True), # Found in loop1 from -1000 to 1000
|
||||
(0, 650, True, 2, True), # Just outside the limit in loop1
|
||||
|
|
@ -67,15 +67,15 @@ def test_looping_autofocus(start_z, max_loc, centre, attempts_expected, passes,
|
|||
sharpness_monitor = mocker.MagicMock()
|
||||
sharpness_monitor.focus_rel.return_value = (0, 0)
|
||||
|
||||
def return_shapness(*_args) -> tuple[list[float], np.ndarray, np.ndarray]:
|
||||
"""Generate shapenesses based on parameterised input, and mock stage position."""
|
||||
return fake_sharpeness_data(
|
||||
def return_sharpness(*_args) -> tuple[list[float], np.ndarray, np.ndarray]:
|
||||
"""Generate sharpnesses based on parameterised input, and mock stage position."""
|
||||
return fake_sharpness_data(
|
||||
dz=dz,
|
||||
start_z=stage.position["z"],
|
||||
max_loc=max_loc,
|
||||
)
|
||||
|
||||
sharpness_monitor.move_data.side_effect = return_shapness
|
||||
sharpness_monitor.move_data.side_effect = return_sharpness
|
||||
|
||||
autofocus_thing = AutofocusThing()
|
||||
if passes:
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ def test_channel_deviation_luv_get_sample_coverage(background_image, mocker):
|
|||
"""Check _get_sample_coverage returns the values expected."""
|
||||
cd_luv = ChannelDeviationLUV()
|
||||
|
||||
# Create fake chunked STD data where each channel os the numbers 0 -> 31.5 in 0.5
|
||||
# Create fake chunked STD data where each channel is the numbers 0 -> 31.5 in 0.5
|
||||
# steps
|
||||
grid = np.arange(0, 32, 0.5).reshape(8, 8)
|
||||
fake_stds = np.stack([grid, grid, grid], axis=-1)
|
||||
|
|
@ -313,7 +313,7 @@ def test_channel_deviation_luv_get_sample_coverage(background_image, mocker):
|
|||
means=[0, 0, 0], standard_deviations=[1.6, 1.6, 1.1]
|
||||
)
|
||||
assert cd_luv.get_sample_coverage(background_image) == 75
|
||||
# This is but increases if any channels has a lower background value.
|
||||
# But coverage increases if any channels has a lower background value.
|
||||
cd_luv.background_data = ChannelDistributions(
|
||||
means=[0, 0, 0], standard_deviations=[1.6, 0.6, 1.1]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -425,8 +425,8 @@ def setup_and_run_z_stack(check_returns, check_turning_points, autofocus_thing,
|
|||
"""Set up a z_stack, run it, and return the result.
|
||||
|
||||
:param check_returns: The return values from check_stack_result. Note that if this
|
||||
is a list it will be set as a side effect (and should be a list of tuples of
|
||||
results. If it a tuple (or anything else) it is set as a return value.
|
||||
is a list, it will be set as a side effect (and should be a list of tuples of
|
||||
results). If it a tuple (or anything else), it is set as a return value.
|
||||
"""
|
||||
stack_params = autofocus_thing.create_stack_params(
|
||||
autofocus_dz=2000,
|
||||
|
|
@ -578,7 +578,7 @@ def _run_check_stack_with_good_peak(autofocus_thing, count_turnings=False):
|
|||
result, cap_id = autofocus_thing.check_stack_result(
|
||||
captures, check_turning_points=count_turnings
|
||||
)
|
||||
# Nothing a mocked function does should change which is the sharpedt image.
|
||||
# Nothing a mocked function does should change which is the sharpest image.
|
||||
assert cap_id == 4
|
||||
return result
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue