Skip to content

Commit

Permalink
fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickcleeve2 committed Feb 10, 2025
1 parent a1a0656 commit 3c6cd2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
5 changes: 4 additions & 1 deletion src/odemis/acq/drift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ def align_reference_image(
if (ref_image.ndim != 2 or new_image.ndim != 2 or ref_image.shape != new_image.shape):
raise ValueError(f"Only equally sized 2D images are supported for alignment. {ref_image.shape}, {new_image.shape}")

shift_px = MeasureShift(ref_image, new_image, 10)
if ref_image.metadata[model.MD_PIXEL_SIZE] != new_image.metadata[model.MD_PIXEL_SIZE]:
raise ValueError("The images must have the same pixel size.")

shift_px = MeasureShift(ref_image, new_image, 2)

pixelsize = ref_image.metadata[model.MD_PIXEL_SIZE]
shift_m = (shift_px[0] * pixelsize[0], shift_px[1] * pixelsize[1])
Expand Down
32 changes: 11 additions & 21 deletions src/odemis/acq/milling/millmng.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
class MillingTaskManager:
"""This class manages running milling tasks."""

def __init__(self, future: Future, tasks: List[MillingTaskSettings]):
def __init__(self, future: Future, tasks: List[MillingTaskSettings], fib_stream: FIBStream):
"""
:param future: the future that will be executing the task
:param tasks: The milling tasks to run (in order)
Expand All @@ -58,18 +58,8 @@ def __init__(self, future: Future, tasks: List[MillingTaskSettings]):
self.microscope = model.getComponent(role="fibsem")
self.tasks = tasks

# for reference image alignment,
self.ion_beam = model.getComponent(role="ion-beam")
self.ion_det = model.getComponent(role="se-detector-ion")
self.ion_focus = model.getComponent(role="ion-focus")

self.fib_stream = FIBStream(
name="FIB",
detector=self.ion_det,
dataflow=self.ion_det.data,
emitter=self.ion_beam,
focuser=self.ion_focus,
)
# for reference image alignment
self.fib_stream = fib_stream

self._future = future
if future is not None:
Expand Down Expand Up @@ -118,7 +108,7 @@ def run_milling(self, settings: MillingTaskSettings):
imaging_fov = microscope.get_field_of_view(milling_channel)

# error management
e, ce = False, False
exception = False
try:

# acquire a reference image at the imaging settings
Expand Down Expand Up @@ -171,8 +161,10 @@ def run_milling(self, settings: MillingTaskSettings):

except CancelledError as ce:
logging.debug(f"Cancelled milling: {ce}")
exception = ce
except Exception as e:
logging.error(f"Error while milling: {e}")
exception = e
finally:
# restore imaging state
microscope.set_beam_current(imaging_current, milling_channel)
Expand All @@ -182,10 +174,8 @@ def run_milling(self, settings: MillingTaskSettings):
microscope.set_active_view(2)
microscope.clear_patterns()

if e:
raise e
if ce:
raise ce # future excepts error to be raised
if exception:
raise exception
return

def run(self):
Expand All @@ -210,14 +200,14 @@ def run(self):
logging.debug("Stopping because milling was cancelled")
raise
except Exception:
logging.exception("The milling failed")
logging.warning("The milling failed")
raise
finally:
self._future._task_state = FINISHED


# TODO: replace with run_milling_tasks_openfibsem
def run_milling_tasks(tasks: List[MillingTaskSettings]) -> Future:
def run_milling_tasks(tasks: List[MillingTaskSettings], fib_stream: FIBStream) -> Future:
"""
Run multiple milling tasks in order.
:param tasks: List of milling tasks to be executed in order.
Expand All @@ -226,7 +216,7 @@ def run_milling_tasks(tasks: List[MillingTaskSettings]) -> Future:
# Create a progressive future with running sub future
future = model.ProgressiveFuture()
# create acquisition task
milling_task_manager = MillingTaskManager(future, tasks)
milling_task_manager = MillingTaskManager(future, tasks, fib_stream)
# add the ability of cancelling the future during execution
future.task_canceller = milling_task_manager.cancel

Expand Down
3 changes: 0 additions & 3 deletions src/odemis/acq/milling/test/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,3 @@ def test_milling_task_settings(self):
self.assertEqual(milling_task_settings_from_json.patterns[0].depth.value, trench_pattern.depth.value)
self.assertEqual(milling_task_settings_from_json.patterns[0].spacing.value, trench_pattern.spacing.value)
self.assertEqual(milling_task_settings_from_json.patterns[0].center.value, trench_pattern.center.value)

def test_save_load_milling_tasks(self):
pass

0 comments on commit 3c6cd2b

Please sign in to comment.