Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #846 from DiamondLightSource/845_gridscan_width
Browse files Browse the repository at this point in the history
Allow specifying the grid size in microns
  • Loading branch information
DominicOram authored Aug 9, 2023
2 parents 55dd101 + b8153c5 commit 104351d
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion live_test_rotation_params.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03I",
"insertion_prefix": "SR03I",
Expand Down
2 changes: 1 addition & 1 deletion live_test_rotation_params_move_xyz.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03I",
"insertion_prefix": "SR03I",
Expand Down
1 change: 1 addition & 0 deletions src/artemis/experiment_plans/full_grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def run_grid_detection_plan(
fgs_params,
snapshot_template,
snapshot_dir,
grid_width_microns=experiment_params.grid_width_microns,
)

yield from run_grid_detection_plan(
Expand Down
18 changes: 10 additions & 8 deletions src/artemis/experiment_plans/oav_grid_detection_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def grid_detection_plan(
out_parameters: GridScanParams,
snapshot_template: str,
snapshot_dir: str,
width=600,
grid_width_microns: float,
box_size_microns=20,
):
yield from finalize_wrapper(
Expand All @@ -43,7 +43,7 @@ def grid_detection_plan(
out_parameters,
snapshot_template,
snapshot_dir,
width,
grid_width_microns,
box_size_microns,
),
reset_oav(),
Expand All @@ -56,7 +56,7 @@ def grid_detection_main_plan(
out_parameters: GridScanParams,
snapshot_template: str,
snapshot_dir: str,
grid_width_px: int,
grid_width_microns: int,
box_size_um: float,
):
"""
Expand All @@ -68,7 +68,7 @@ def grid_detection_main_plan(
out_parameters (GridScanParams): The returned parameters for the gridscan
snapshot_template (str): A template for the name of the snapshots, expected to be filled in with an angle
snapshot_dir (str): The location to save snapshots
grid_width_px (int): The width of the grid to scan in pixels
grid_width_microns (int): The width of the grid to scan in microns
box_size_um (float): The size of each box of the grid in microns
"""
oav: OAV = i03.oav()
Expand All @@ -88,6 +88,8 @@ def grid_detection_main_plan(
box_size_x_pixels = box_size_um / parameters.micronsPerXPixel
box_size_y_pixels = box_size_um / parameters.micronsPerYPixel

grid_width_pixels = int(grid_width_microns / parameters.micronsPerXPixel)

# The FGS uses -90 so we need to match it
for angle in [0, -90]:
yield from bps.mv(smargon.omega, angle)
Expand All @@ -105,8 +107,8 @@ def grid_detection_main_plan(
full_image_height_px = yield from bps.rd(oav.cam.array_size.array_size_y)

# only use the area from the start of the pin onwards
top_edge = top_edge[tip_x_px : tip_x_px + grid_width_px]
bottom_edge = bottom_edge[tip_x_px : tip_x_px + grid_width_px]
top_edge = top_edge[tip_x_px : tip_x_px + grid_width_pixels]
bottom_edge = bottom_edge[tip_x_px : tip_x_px + grid_width_pixels]

# the edge detection line can jump to the edge of the image sometimes, filter
# those points out, and if empty after filter use the whole image
Expand All @@ -118,10 +120,10 @@ def grid_detection_main_plan(
max_y = max(filtered_bottom)
grid_height_px = max_y - min_y

LOGGER.info(f"Drawing snapshot {grid_width_px} by {grid_height_px}")
LOGGER.info(f"Drawing snapshot {grid_width_pixels} by {grid_height_px}")

boxes = (
math.ceil(grid_width_px / box_size_x_pixels),
math.ceil(grid_width_pixels / box_size_x_pixels),
math.ceil(grid_height_px / box_size_y_pixels),
)
box_numbers.append(boxes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _fake_grid_detection(
out_parameters,
snapshot_template: str,
snapshot_dir: str,
grid_width_px: int = 0,
grid_width_microns: float = 0,
box_size_um: float = 0.0,
):
out_parameters.x_start = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_grid_detection_plan_runs_and_triggers_snapshots(
out_parameters=gridscan_params,
snapshot_dir="tmp",
snapshot_template="test_{angle}",
grid_width_microns=161.2,
)
)
assert fake_devices[3].save.call_count == 6
Expand Down Expand Up @@ -99,6 +100,7 @@ def test_grid_detection_plan_gives_warningerror_if_tip_not_found(
out_parameters=gridscan_params,
snapshot_dir="tmp",
snapshot_template="test_{angle}",
grid_width_microns=161.2,
)
)
assert "No pin found" in excinfo.value.args[0]
Expand Down Expand Up @@ -148,6 +150,7 @@ def test_given_when_grid_detect_then_upper_left_and_start_position_as_expected(
snapshot_dir="tmp",
snapshot_template="test_{angle}",
box_size_microns=0.2,
grid_width_microns=161.2,
)
)

Expand Down Expand Up @@ -181,6 +184,7 @@ def test_when_grid_detection_plan_run_twice_then_values_do_not_persist_in_callba
out_parameters=gridscan_params,
snapshot_dir="tmp",
snapshot_template="test_{angle}",
grid_width_microns=161.2,
)
)
assert len(cb.snapshot_filenames) == 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any
from typing import Any, Optional

import numpy as np
from dodal.devices.detector import TriggerMode
Expand Down Expand Up @@ -31,6 +31,9 @@ class GridScanWithEdgeDetectParams(AbstractExperimentParameterBase):
detector_distance: float
omega_start: float

# This is the correct grid size for single pin
grid_width_microns: Optional[float] = 161

def get_num_images(self):
return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
},
"omega_start": {
"type": "number"
},
"grid_width_microns": {
"type": "number"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "object",
"properties": {
"params_version": {
"const": "2.1.0"
"const": "2.2.0"
},
"artemis_params": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down Expand Up @@ -41,6 +41,7 @@
"snapshot_dir": "/tmp",
"exposure_time": 0.1,
"detector_distance": 100.0,
"omega_start": 0.0
"omega_start": 0.0,
"grid_width_microns": 151
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
2 changes: 1 addition & 1 deletion test_parameter_defaults.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"zocalo_environment": "dev_artemis",
"beamline": "BL03S",
Expand Down
2 changes: 1 addition & 1 deletion test_parameters.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "2.1.0",
"params_version": "2.2.0",
"artemis_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down

0 comments on commit 104351d

Please sign in to comment.