Merge branch 'fixed-scanning' into 'master'

Fixed scanning fast autofocus

See merge request openflexure/openflexure-microscope-server!39
This commit is contained in:
Joel Collins 2020-02-17 11:44:26 +00:00
commit 6ab9c971ab

View file

@ -166,25 +166,19 @@ def tile(
else:
autofocus_enabled = False
z_stack_dz = (
grid[2] * stride_size[2] if grid[2] > 1 else 0
) # shorthand for Z stack range
# Construct an x-y grid (worry about z later)
x_y_grid = construct_grid(initial_position, stride_size[:2], grid[:2], style=style)
# Keep the initial Z position the same as our current position
next_z = initial_position[2]
if fast_autofocus: # If fast autofocus is enabled, make
next_z += autofocus_dz / 2 # sure we start from the top of the range
initial_z = next_z # Save this value for use in raster scans
initial_z = initial_position[2]
next_z = initial_z # Save this value for use in raster scans
# Now step through each point in the x-y coordinate array
for line in x_y_grid:
# If rastering, rather than snake (or eventually spiral)
# Return focus to initial position
if style == "raster":
next_z = initial_z
next_z = initial_z # Reset z position at start of each new row
logging.debug("Returning to initial z position")
microscope.stage.move_abs(
[line[0][0], line[0][1], next_z]
@ -199,10 +193,7 @@ def tile(
if fast_autofocus:
# Run fast autofocus. Client should provide dz ~ 2000
autofocus_extension.fast_up_down_up_autofocus(
microscope,
dz=autofocus_dz,
target_z=-z_stack_dz / 2.0, # Finish below the focus
initial_move_up=False, # We're already at the top of the scan
microscope, dz=autofocus_dz
)
else:
# Run slow autofocus. Client should provide dz ~ 50
@ -236,7 +227,6 @@ def tile(
temporary=temporary,
step_size=stride_size[2],
steps=grid[2],
return_to_start=not fast_autofocus,
use_video_port=use_video_port,
resize=resize,
bayer=bayer,
@ -246,14 +236,6 @@ def tile(
)
# Make sure we use our current best estimate of focus (i.e. the current position) next point
next_z = microscope.stage.position[2]
if fast_autofocus:
next_z += (
autofocus_dz / 2
) # Fast autofocus requires us to start at the top of the range
if grid[2] > 1:
next_z -= int(
grid[2] / 2.0 * stride_size[2]
) # Z stacking means we're higher up to start with
logging.debug("Returning to {}".format(initial_position))
microscope.stage.move_abs(initial_position)
@ -277,15 +259,17 @@ def stack(
# Store initial position
initial_position = microscope.stage.position
logging.debug(f"Starting z-stack from position {microscope.stage.position}")
with microscope.lock:
# Move to center scan
logging.debug("Moving to starting position")
logging.debug("Moving to z-stack starting position")
microscope.stage.move_rel([0, 0, int((-step_size * steps) / 2)])
logging.debug(f"Starting scan from position {microscope.stage.position}")
for i in range(steps):
time.sleep(0.1)
logging.debug("Capturing...")
logging.debug(f"Capturing from position {microscope.stage.position}")
capture(
microscope,
basename,