Updated labthings dependencies
This commit is contained in:
parent
38906c8fff
commit
f7264441e1
1 changed files with 40 additions and 34 deletions
|
|
@ -16,20 +16,22 @@ import time
|
||||||
from ..utilities import quadratic
|
from ..utilities import quadratic
|
||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
from camera_stage_mapping import fft_image_tracking
|
from camera_stage_mapping import fft_image_tracking
|
||||||
from labthings_fastapi.thing import Thing
|
import labthings_fastapi as lt
|
||||||
from labthings_fastapi.dependencies.thing import direct_thing_client_dependency
|
|
||||||
from labthings_fastapi.dependencies.invocation import CancelHook, InvocationLogger
|
|
||||||
from labthings_fastapi.decorators import thing_action
|
|
||||||
from labthings_sangaboard import SangaboardThing
|
from labthings_sangaboard import SangaboardThing
|
||||||
from labthings_picamera2.thing import StreamingPiCamera2
|
from labthings_picamera2.thing import StreamingPiCamera2
|
||||||
from labthings_fastapi.types.numpy import DenumpifyingDict
|
from labthings_fastapi.types.numpy import DenumpifyingDict
|
||||||
from openflexure_microscope_server.things.autofocus import AutofocusThing
|
|
||||||
from openflexure_microscope_server.things.camera_stage_mapping import CameraStageMapper
|
|
||||||
|
|
||||||
StageDep = direct_thing_client_dependency(SangaboardThing, "/stage/")
|
# Things
|
||||||
CamDep = direct_thing_client_dependency(StreamingPiCamera2, "/camera/")
|
from .autofocus import AutofocusThing
|
||||||
CSMDep = direct_thing_client_dependency(CameraStageMapper, "/camera_stage_mapping/")
|
from .camera_stage_mapping import CameraStageMapper
|
||||||
AutofocusDep = direct_thing_client_dependency(AutofocusThing, "/autofocus/")
|
from .camera import CameraDependency as CamDep
|
||||||
|
from .stage import StageDependency as StageDep
|
||||||
|
|
||||||
|
CSMDep = lt.deps.direct_thing_client_dependency(
|
||||||
|
CameraStageMapper, "/camera_stage_mapping/"
|
||||||
|
)
|
||||||
|
AutofocusDep = lt.deps.direct_thing_client_dependency(AutofocusThing, "/autofocus/")
|
||||||
|
|
||||||
|
|
||||||
def generate_move_dicts(fov_perc: int, stream_resolution: list[int], direction: int, factor: float = 1) -> dict[str, float]:
|
def generate_move_dicts(fov_perc: int, stream_resolution: list[int], direction: int, factor: float = 1) -> dict[str, float]:
|
||||||
"""Create a single dictionary of x and y moves for moving in image coordinates.
|
"""Create a single dictionary of x and y moves for moving in image coordinates.
|
||||||
|
|
@ -100,19 +102,19 @@ def move_and_measure(
|
||||||
return delta, offset, focus_data, wrong_axis
|
return delta, offset, focus_data, wrong_axis
|
||||||
|
|
||||||
def medium_moves(
|
def medium_moves(
|
||||||
stream_resolution: list[int],
|
stream_resolution: list[int],
|
||||||
direction: int,
|
direction: int,
|
||||||
axis: str,
|
axis: str,
|
||||||
delta: dict[str,int],
|
delta: dict[str, int],
|
||||||
focus_data: list[float],
|
focus_data: list[float],
|
||||||
stage_coords: list,
|
stage_coords: list,
|
||||||
cor_lat_steps: list,
|
cor_lat_steps: list,
|
||||||
csm: CSMDep,
|
csm: CSMDep,
|
||||||
cam: CamDep,
|
cam: CamDep,
|
||||||
stage:StageDep,
|
stage: StageDep,
|
||||||
autofocus: AutofocusDep,
|
autofocus: AutofocusDep,
|
||||||
logger: InvocationLogger
|
logger: lt.deps.InvocationLogger,
|
||||||
) -> tuple:
|
) -> tuple:
|
||||||
"""Carries out the medium sized steps section of the range of motion test to get 5 points to make z position predictions with.
|
"""Carries out the medium sized steps section of the range of motion test to get 5 points to make z position predictions with.
|
||||||
|
|
||||||
:params stream_resolution: The resolution of the stream from the camera.
|
:params stream_resolution: The resolution of the stream from the camera.
|
||||||
|
|
@ -164,7 +166,7 @@ def small_moves(
|
||||||
cam: CamDep,
|
cam: CamDep,
|
||||||
stage: StageDep,
|
stage: StageDep,
|
||||||
autofocus: AutofocusDep,
|
autofocus: AutofocusDep,
|
||||||
logger: InvocationLogger,
|
logger: lt.deps.InvocationLogger,
|
||||||
) -> tuple:
|
) -> tuple:
|
||||||
"""Carries out 3 small moves in a given direction and axis.
|
"""Carries out 3 small moves in a given direction and axis.
|
||||||
|
|
||||||
|
|
@ -237,7 +239,14 @@ def small_moves(
|
||||||
break
|
break
|
||||||
return stage_coords, cor_lat_steps, delta
|
return stage_coords, cor_lat_steps, delta
|
||||||
|
|
||||||
def motion_detection(axis: str, direction: int, csm: CSMDep, stage: StageDep, cam: CamDep, logger: InvocationLogger) -> dict:
|
def motion_detection(
|
||||||
|
axis: str,
|
||||||
|
direction: int,
|
||||||
|
csm: CSMDep,
|
||||||
|
stage: StageDep,
|
||||||
|
cam: CamDep,
|
||||||
|
logger: lt.deps.InvocationLogger,
|
||||||
|
) -> dict:
|
||||||
"""Move the stage until motion is detected along a specified axis and direction.
|
"""Move the stage until motion is detected along a specified axis and direction.
|
||||||
|
|
||||||
:params axis: The axis in which the stage is moving. This must be 'x' or 'y'.
|
:params axis: The axis in which the stage is moving. This must be 'x' or 'y'.
|
||||||
|
|
@ -274,7 +283,7 @@ def motion_detection(axis: str, direction: int, csm: CSMDep, stage: StageDep, ca
|
||||||
|
|
||||||
return stage.position
|
return stage.position
|
||||||
|
|
||||||
class RangeofMotionThing(Thing):
|
class RangeofMotionThing(lt.Thing):
|
||||||
"""A class used to measure the range of motion of the stage in X and Y."""
|
"""A class used to measure the range of motion of the stage in X and Y."""
|
||||||
|
|
||||||
def rom_axis(
|
def rom_axis(
|
||||||
|
|
@ -283,9 +292,9 @@ class RangeofMotionThing(Thing):
|
||||||
stage: StageDep,
|
stage: StageDep,
|
||||||
cam: CamDep,
|
cam: CamDep,
|
||||||
csm: CSMDep,
|
csm: CSMDep,
|
||||||
logger: InvocationLogger,
|
logger: lt.deps.InvocationLogger,
|
||||||
axis: str,
|
axis: str,
|
||||||
direction: int
|
direction: int,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Measure the range of motion in a single axis and direction.
|
"""Measure the range of motion in a single axis and direction.
|
||||||
|
|
||||||
|
|
@ -400,15 +409,14 @@ class RangeofMotionThing(Thing):
|
||||||
|
|
||||||
return axis_results
|
return axis_results
|
||||||
|
|
||||||
@thing_action
|
@lt.thing_action
|
||||||
def rom_main(
|
def rom_main(
|
||||||
self,
|
self,
|
||||||
autofocus: AutofocusDep,
|
autofocus: AutofocusDep,
|
||||||
stage: StageDep,
|
stage: StageDep,
|
||||||
cam: CamDep,
|
cam: CamDep,
|
||||||
csm: CSMDep,
|
csm: CSMDep,
|
||||||
cancel: CancelHook,
|
logger: lt.deps.InvocationLogger,
|
||||||
logger: InvocationLogger
|
|
||||||
):
|
):
|
||||||
"""Measures the range of motion of the stage across the x and y axes.
|
"""Measures the range of motion of the stage across the x and y axes.
|
||||||
|
|
||||||
|
|
@ -424,7 +432,6 @@ class RangeofMotionThing(Thing):
|
||||||
stage,
|
stage,
|
||||||
cam,
|
cam,
|
||||||
csm,
|
csm,
|
||||||
cancel,
|
|
||||||
logger,
|
logger,
|
||||||
axis = axis_dir[0],
|
axis = axis_dir[0],
|
||||||
direction = axis_dir[1]
|
direction = axis_dir[1]
|
||||||
|
|
@ -445,10 +452,9 @@ class RangeofMotionThing(Thing):
|
||||||
rom_results["CSM Matrix"] = csm.image_to_stage_displacement_matrix
|
rom_results["CSM Matrix"] = csm.image_to_stage_displacement_matrix
|
||||||
rom_results["Step Range"] = step_range
|
rom_results["Step Range"] = step_range
|
||||||
|
|
||||||
self.thing_settings["rom_data"] = DenumpifyingDict(rom_results).model_dump()
|
self.rom_data = DenumpifyingDict(rom_results).model_dump()
|
||||||
|
|
||||||
with open("/var/openflexure/ROM_Test_Results.json", 'w') as file_object:
|
with open("/var/openflexure/ROM_Test_Results.json", 'w') as file_object:
|
||||||
json.dump(rom_results, file_object, indent = 3)
|
json.dump(rom_results, file_object, indent = 3)
|
||||||
|
|
||||||
return rom_results
|
return rom_results
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue