diff --git a/src/openflexure_microscope_server/things/__init__.py b/src/openflexure_microscope_server/things/__init__.py index 255e0379..b0c5768f 100644 --- a/src/openflexure_microscope_server/things/__init__.py +++ b/src/openflexure_microscope_server/things/__init__.py @@ -34,6 +34,8 @@ class OFMThing(lt.Thing): self._data_dir = os.path.join( os.path.normpath(str(app_data_dir)), os.path.normpath(self.name) ) + if not os.path.exists(self.data_dir): + os.makedirs(self.data_dir) return self def __exit__( diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 43cc3e2b..3d1f599c 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -737,11 +737,9 @@ class AutofocusThing(lt.Thing): # Loop through the range, saving each capture to disk for capture in captures[slice_to_save]: - self._cam.save_from_memory( - jpeg_path=os.path.join(capture_parameters.images_dir, capture.filename), - save_resolution=capture_parameters.save_resolution, - buffer_id=capture.buffer_id, - ) + path = os.path.join(capture_parameters.images_dir, capture.filename) + self._cam.save_from_memory(path=path, buffer_id=capture.buffer_id) + self._cam.clear_buffers() return sharpest_index @@ -823,7 +821,9 @@ class AutofocusThing(lt.Thing): camera buffer_id needed for saving. """ stage_location = self._stage.position - buffer_id = self._cam.capture_to_memory(buffer_max=buffer_max) + buffer_id = self._cam.capture_to_memory( + capture_mode="standard", buffer_max=buffer_max + ) return CaptureInfo( buffer_id=buffer_id, position=stage_location, @@ -956,14 +956,8 @@ class AutofocusThing(lt.Thing): # Save all captures for capture in captures: - self._cam.save_from_memory( - jpeg_path=os.path.join( - capture_parameters.images_dir, - capture.filename, - ), - save_resolution=capture_parameters.save_resolution, - buffer_id=capture.buffer_id, - ) + path = os.path.join(capture_parameters.images_dir, capture.filename) + self._cam.save_from_memory(path=path, buffer_id=capture.buffer_id) self._cam.clear_buffers() diff --git a/src/openflexure_microscope_server/things/scan_workflows.py b/src/openflexure_microscope_server/things/scan_workflows.py index fe4ee898..4eeb419b 100644 --- a/src/openflexure_microscope_server/things/scan_workflows.py +++ b/src/openflexure_microscope_server/things/scan_workflows.py @@ -164,9 +164,9 @@ class ScanWorkflow(Generic[SettingModelType], lt.Thing): self._autofocus.fast_autofocus(dz=dz) focus_height = self._stage.get_xyz_position()[2] filename = f"img_{xyz_pos[0]}_{xyz_pos[1]}_{focus_height}.jpeg" - self._cam.capture_and_save( - jpeg_path=os.path.join(images_dir, filename), - save_resolution=save_resolution, + self._cam.capture_and_save_to_path( + path=os.path.join(images_dir, filename), + capture_mode="standard", ) return True, focus_height diff --git a/src/openflexure_microscope_server/things/stage_measure.py b/src/openflexure_microscope_server/things/stage_measure.py index 0f633ee1..c6dc122b 100644 --- a/src/openflexure_microscope_server/things/stage_measure.py +++ b/src/openflexure_microscope_server/things/stage_measure.py @@ -197,9 +197,6 @@ class RangeofMotionThing(OFMThing): "time": total_time, } - if not os.path.exists(self.data_dir): - os.makedirs(self.data_dir) - timestamp = datetime.now().strftime("%Y_%m_%d_%H_%M") datafile_path = os.path.join(self.data_dir, f"rom_data_{timestamp}.json") with open(datafile_path, "w", encoding="utf-8") as f: