Skip to content

Commit

Permalink
Merge pull request #311 from DeMarcoLab/v0.2-dev
Browse files Browse the repository at this point in the history
v0.2.5 Release
  • Loading branch information
patrickcleeve2 authored Oct 18, 2023
2 parents 0605dd6 + 6a59f43 commit c27430c
Show file tree
Hide file tree
Showing 188 changed files with 5,950 additions and 9,790 deletions.
33 changes: 31 additions & 2 deletions fibsem/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def beam_shift_alignment(
image_settings: ImageSettings,
ref_image: FibsemImage,
reduced_area: Optional[FibsemRectangle] = None,
alignment_current: Optional[float] = None,
):
"""Aligns the images by adjusting the beam shift instead of moving the stage.
Expand All @@ -71,6 +72,10 @@ def beam_shift_alignment(
ValueError: If `image_settings.beam_type` is not set to `BeamType.ION`.
"""
if alignment_current is not None:
initial_current = microscope.get("current", image_settings.beam_type)
microscope.set("current", alignment_current, image_settings.beam_type)

import time
time.sleep(3) # threading is too fast?
image_settings = ImageSettings.fromFibsemImage(ref_image)
Expand All @@ -86,6 +91,10 @@ def beam_shift_alignment(
# adjust beamshift
microscope.beam_shift(dx, dy, image_settings.beam_type)

# reset beam current
if alignment_current is not None:
microscope.set("current", initial_current, image_settings.beam_type)


def correct_stage_drift(
microscope: FibsemMicroscope,
Expand Down Expand Up @@ -233,7 +242,7 @@ def align_using_reference_images(

# vertical constraint = eucentric movement
if constrain_vertical:
microscope.eucentric_move(
microscope.vertical_move(
settings=settings, dx=0, dy=-dy
) # FLAG_TEST
else:
Expand Down Expand Up @@ -457,4 +466,24 @@ def _save_alignment_data(
df_tmp = pd.read_csv(DATAFRAME_PATH)
df = pd.concat([df_tmp, df], axis=0, ignore_index=True)

df.to_csv(DATAFRAME_PATH, index=False)
df.to_csv(DATAFRAME_PATH, index=False)

from fibsem.structures import ImageSettings
def _multi_step_alignment(microscope: FibsemMicroscope, image_settings: ImageSettings,
ref_image: FibsemImage, reduced_area: FibsemRectangle, alignment_current: float, steps:int = 3) -> None:

# set alignment current
if alignment_current is not None:
initial_current = microscope.get("current", image_settings.beam_type)
microscope.set("current", alignment_current, image_settings.beam_type)

base_label = image_settings.label
for i in range(steps):
image_settings.label = f"{base_label}_{i:02d}"
image_settings.beam_type = BeamType.ION
beam_shift_alignment(microscope, image_settings,
ref_image=ref_image,
reduced_area=reduced_area)
# reset beam current
if alignment_current is not None:
microscope.set("current", initial_current, image_settings.beam_type)
4 changes: 2 additions & 2 deletions fibsem/alignment2.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def eucentric_correct_stage_drift(

# target images
targets = (BeamType.ELECTRON, BeamType.ELECTRON, BeamType.ION)#, BeamType.ELECTRON, BeamType.ION)
eucentric_move = (False, False, True)
vertical_move = (False, False, True)

# lp, hp, sigma
params = [
Expand All @@ -237,7 +237,7 @@ def eucentric_correct_stage_drift(
# TODO: this is wrong now

# align lowres, then highres
for i, (ref_image, target, euc_move) in enumerate(zip(ref_order, targets, eucentric_move)):
for i, (ref_image, target, euc_move) in enumerate(zip(ref_order, targets, vertical_move)):

ref_mask = masks.create_circle_mask(ref_image.data.shape, radius=512)

Expand Down
57 changes: 57 additions & 0 deletions fibsem/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,60 @@ def auto_home_and_link_v2(
# move to saved linked state
microscope.set_microscope_state(state)


def _calibrate_manipulator_thermo(microscope:FibsemMicroscope, settings:MicroscopeSettings, parent_ui = None):
from fibsem.detection import detection
from fibsem.segmentation.model import load_model
import matplotlib.pyplot as plt

from autolamella.workflows.ui import _validate_det_ui_v2, ask_user

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.")


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]:
settings.image.hfw = hfw
settings.image.beam_type = beam_type

features = [detection.NeedleTip(), detection.ImageCentre()] if np.isclose(microscope.get("scan_rotation", beam_type), 0) else [detection.NeedleTipBottom(), detection.ImageCentre()]

if parent_ui:
det = _validate_det_ui_v2(microscope, settings, features, parent_ui, validate = True, msg = f"Confirm Feature Detection. Press Continue to proceed.")
else:
image = acquire.new_image(microscope, settings.image)
det = detection.detect_features(image, model, features=features, pixelsize=image.metadata.pixel_size.x)
detection.plot_detection(det)
ret = input("continue? (y/n)")

if ret != "y":
return

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.")
10 changes: 8 additions & 2 deletions fibsem/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@
os.makedirs(DATA_CC_PATH, exist_ok=True)
os.makedirs(DATA_TILE_PATH, exist_ok=True)

DATABASE_PATH = os.path.join(BASE_PATH, "fibsem", "db", "fibsem.db")
os.makedirs(os.path.dirname(DATABASE_PATH), exist_ok=True)
import yaml


def load_yaml(fname):
"""
Load a YAML file and return its contents as a dictionary.
Expand All @@ -89,4 +90,9 @@ def load_yaml(fname):

__SUPPORTED_MANUFACTURERS__ = ["Thermo", "Tescan", "Demo"]
__DEFAULT_MANUFACTURER__ = "Thermo"
__DEFAULT_IP_ADDRESS__ = "10.0.0.1"
__DEFAULT_IP_ADDRESS__ = "10.0.0.1"


_LIVE_IMAGING_ENABLED = False
_MINIMAP_VISUALISATION = False
_MINIMAP_MOVE_WITH_TRANSLATION = True
35 changes: 0 additions & 35 deletions fibsem/config/model.yaml

This file was deleted.

Loading

0 comments on commit c27430c

Please sign in to comment.