diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 4ebbab00..d885c6b8 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -484,28 +484,26 @@ class AutofocusThing(lt.Thing): images_dir: str, autofocus_dz: int, save_resolution: tuple[int, int], - logger: lt.deps.InvocationLogger, ) -> StackParams: """Set up the parameters used for all stacks in a scan. :param images_dir: the folder to save all images :param autofocus_dz: the range to autofocus over if a stack fails :param save_resolution: The resolution to save the captures to disk with - :param logger: A logger passed from the calling Thing :returns: A StackParams object with the required parameters. """ # Coerce min_images_to_test parameter min_images_to_test = self.stack_min_images_to_test if min_images_to_test < MIN_TEST_IMAGE_COUNT: - logger.warning( + self.logger.warning( f"Cannot test only {min_images_to_test} image(s) as this will fail. " "Setting min images to test to lowest possible value of" f"{MIN_TEST_IMAGE_COUNT}." ) min_images_to_test = MIN_TEST_IMAGE_COUNT elif min_images_to_test > MAX_TEST_IMAGE_COUNT: - logger.warning( + self.logger.warning( f"Testing {min_images_to_test} images will cause defocus. " "Setting min images to test to highest possible value of " f"{MAX_TEST_IMAGE_COUNT}." @@ -513,7 +511,7 @@ class AutofocusThing(lt.Thing): min_images_to_test = MAX_TEST_IMAGE_COUNT elif min_images_to_test % 2 == 0: min_images_to_test += 1 - logger.warning( + self.logger.warning( "Minimum number of images to test should be odd, setting to " f"{min_images_to_test}." ) @@ -524,19 +522,19 @@ class AutofocusThing(lt.Thing): # min_images_to_save images_to_save = self.stack_images_to_save if images_to_save <= 0: - logger.warning( + self.logger.warning( "At least 1 images must be saved. Setting images to save to 1." ) images_to_save = 1 elif images_to_save > min_images_to_test: - logger.warning( + self.logger.warning( f"Cannot save {images_to_save} images as this above the minimum " f"number to test. Setting images to save to {MAX_TEST_IMAGE_COUNT}." ) images_to_save = min_images_to_test elif images_to_save % 2 == 0: images_to_save += 1 - logger.warning( + self.logger.warning( f"Images to save should be odd, setting to {images_to_save}." ) # Set the Thing property to the coerced value diff --git a/src/openflexure_microscope_server/things/smart_scan.py b/src/openflexure_microscope_server/things/smart_scan.py index 62db3062..0ee5880b 100644 --- a/src/openflexure_microscope_server/things/smart_scan.py +++ b/src/openflexure_microscope_server/things/smart_scan.py @@ -378,7 +378,6 @@ class SmartScanThing(lt.Thing): images_dir=self._ongoing_scan.images_dir, autofocus_dz=self.autofocus_dz, save_resolution=self._scan_data.save_resolution, - logger=self._scan_logger, ) self._preview_stitcher = stitching.PreviewStitcher( self._ongoing_scan.images_dir, diff --git a/tests/test_stack.py b/tests/test_stack.py index 17ccec94..6683c719 100644 --- a/tests/test_stack.py +++ b/tests/test_stack.py @@ -26,7 +26,6 @@ from openflexure_microscope_server.things.autofocus import ( _get_peak_turning_point, ) -LOGGER = logging.getLogger("mock-invocation_logger") RANDOM_GENERATOR = np.random.default_rng() @@ -274,10 +273,7 @@ def test_create_stack(autofocus_thing, caplog): initial_images_to_save = autofocus_thing.stack_images_to_save with caplog.at_level(logging.INFO): stack_params = autofocus_thing.create_stack_params( - autofocus_dz=2000, - images_dir="/this/is/fake", - save_resolution=(1640, 1232), - logger=LOGGER, + autofocus_dz=2000, images_dir="/this/is/fake", save_resolution=(1640, 1232) ) assert len(caplog.records) == 0 @@ -304,10 +300,7 @@ def test_coercing_stack_test_ims( with caplog.at_level(logging.WARNING): stack_params = autofocus_thing.create_stack_params( - autofocus_dz=2000, - images_dir="/this/is/fake", - save_resolution=(1640, 1232), - logger=LOGGER, + autofocus_dz=2000, images_dir="/this/is/fake", save_resolution=(1640, 1232) ) assert len(caplog.records) == 1 @@ -335,10 +328,7 @@ def test_coercing_stack_save_ims( with caplog.at_level(logging.WARNING): stack_params = autofocus_thing.create_stack_params( - autofocus_dz=2000, - images_dir="/this/is/fake", - save_resolution=(1640, 1232), - logger=LOGGER, + autofocus_dz=2000, images_dir="/this/is/fake", save_resolution=(1640, 1232) ) assert len(caplog.records) == 1 @@ -353,10 +343,7 @@ def test_coercing_stack_save_ims( def test_run_smart_stack(pass_on, autofocus_thing, mocker): """Test Running smart stack with the stack passing on different attempts.""" stack_params = autofocus_thing.create_stack_params( - autofocus_dz=2000, - images_dir="/this/is/fake", - save_resolution=(1640, 1232), - logger=LOGGER, + autofocus_dz=2000, images_dir="/this/is/fake", save_resolution=(1640, 1232) ) assert stack_params.max_attempts == 3 @@ -417,10 +404,7 @@ def setup_and_run_z_stack(check_returns, check_turning_points, autofocus_thing, 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, - images_dir="/this/is/fake", - save_resolution=(1640, 1232), - logger=LOGGER, + autofocus_dz=2000, images_dir="/this/is/fake", save_resolution=(1640, 1232) ) stack_params.settling_time = 0 # Don't settle or tests take forever.