From 9b58f4d59e6fa2734a6f4ff3d9317be1a15f55e1 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Mon, 1 Dec 2025 17:00:55 +0000 Subject: [PATCH] Apply suggestions from code review of branch scanning-stability Co-authored-by: Joe Knapper --- .../background_detect.py | 4 ++-- .../things/autofocus.py | 2 +- tests/test_autofocus.py | 14 +++++++------- tests/test_background_detectors.py | 4 ++-- tests/test_stack.py | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/openflexure_microscope_server/background_detect.py b/src/openflexure_microscope_server/background_detect.py index 23dc8576..9bd056dc 100644 --- a/src/openflexure_microscope_server/background_detect.py +++ b/src/openflexure_microscope_server/background_detect.py @@ -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: diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 773c20a7..a8e3ec39 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -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 diff --git a/tests/test_autofocus.py b/tests/test_autofocus.py index 058625d4..b68dfb1a 100644 --- a/tests/test_autofocus.py +++ b/tests/test_autofocus.py @@ -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: diff --git a/tests/test_background_detectors.py b/tests/test_background_detectors.py index fbcaf0a3..37df95ae 100644 --- a/tests/test_background_detectors.py +++ b/tests/test_background_detectors.py @@ -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] ) diff --git a/tests/test_stack.py b/tests/test_stack.py index b2cd94b7..57e493db 100644 --- a/tests/test_stack.py +++ b/tests/test_stack.py @@ -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