Skip to content

Commit

Permalink
fix calibrate manipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Cleeve committed Oct 18, 2023
1 parent 28deed1 commit 6a59f43
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
29 changes: 26 additions & 3 deletions fibsem/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,27 @@ def _calibrate_manipulator_thermo(microscope:FibsemMicroscope, settings:Microsco
from fibsem.segmentation.model import load_model
import matplotlib.pyplot as plt

from autolamella.workflows.ui import _validate_det_ui_v2
from autolamella.workflows.ui import _validate_det_ui_v2, ask_user

model = load_model("autolamella-mega-01-nc5-34.pt", encoder="resnet34", nc=5)
if parent_ui:
ret = ask_user(parent_ui,
msg="Please complete the EasyLift alignment procedure in the xT UI until Step 5. Press Continue to proceed.",
pos="Continue", neg="Cancel")
if ret is False:
return
else:
input("Please complete the EasyLift alignment procedure in the xT UI until Step 5. Press Enter to proceed.")

hfws = [900e-6, 400e-6, 150e-6]

model = load_model("autolamella-mega-latest.pt", encoder="resnet34", nc=5)
settings.protocol["ml"]["checkpoint"] = "autolamella-mega-latest.pt"
settings.image.autocontrast = True

hfws = [2000e-6, 900e-6, 400e-6, 150e-6]

# set working distance
wd = microscope.get("working_distance", BeamType.ELECTRON)
microscope.set("working_distance", settings.system.electron.eucentric_height, BeamType.ELECTRON)

for hfw in hfws:
for beam_type in [BeamType.ELECTRON, BeamType.ION]:
Expand All @@ -298,4 +314,11 @@ def _calibrate_manipulator_thermo(microscope:FibsemMicroscope, settings:Microsco
move_x = bool(beam_type == BeamType.ELECTRON) # ION calibration only in z
detection.move_based_on_detection(microscope, settings, det, beam_type, move_x=move_x, _move_system="manipulator")

# restore working distance
microscope.set("working_distance", wd, BeamType.ELECTRON)

if parent_ui:
ask_user(parent_ui,
msg="Alignment of EasyLift complete. Please complete the procedure in xT UI. Press Continue to proceed.",
pos="Continue")
print(f"The manipulator should now be centred in both beams.")
5 changes: 3 additions & 2 deletions fibsem/detection/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def take_image_and_detect_features(

# load model
ml_protocol = settings.protocol.get("ml", {})
checkpoint = ml_protocol.get("checkpoint", "openfibsem-baseline-34.pt")
checkpoint = ml_protocol.get("checkpoint", "autolamella-mega-latest.pt")
encoder = ml_protocol.get("encoder", "resnet34")
num_classes = int(ml_protocol.get("num_classes", 3))
model = load_model(checkpoint=checkpoint, encoder=encoder, nc=num_classes)
Expand Down Expand Up @@ -950,7 +950,8 @@ def detect_multi_features(image: np.ndarray, mask: np.ndarray, feature: Feature,

if features == []:
logging.info(f"No features detected for {feature.name}")
feature.px = Point(0, 0)
# set at centre of image
feature.px = Point(x=image.shape[1]//2, y=image.shape[0]//2)
features = [deepcopy(feature)]

return features
Expand Down

0 comments on commit 6a59f43

Please sign in to comment.