Skip to content

Commit 1218721

Browse files
committed
Move 'MillingStep' record creation into 'do_insert_milling_step' instead, since the 'MillingStepNameId' requires a DB query
1 parent f57a1f5 commit 1218721

2 files changed

Lines changed: 100 additions & 25 deletions

File tree

src/murfey/server/ispyb.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
FoilHole,
2222
GridSquare,
2323
MillingStep,
24+
MillingStepName,
2425
ProcessingJob,
2526
ProcessingJobParameter,
2627
Proposal,
@@ -711,9 +712,71 @@ def do_update_processing_status(self, record: AutoProcProgram, **kwargs):
711712
)
712713
return {"success": False, "return_value": None}
713714

714-
def do_insert_milling_step(self, record: MillingStep):
715+
def do_insert_milling_step(
716+
self,
717+
# MillingStepName identifiers
718+
recipe_name: str,
719+
activity_name: str,
720+
grid_square_id: int,
721+
# Values
722+
is_enabled: bool | None = None,
723+
status: str | None = None,
724+
execution_time: float | None = None,
725+
stage_x: float | None = None,
726+
stage_y: float | None = None,
727+
stage_z: float | None = None,
728+
rotation: float | None = None,
729+
tilt_alpha: float | None = None,
730+
beam_type: str | None = None,
731+
beam_voltage: float | None = None,
732+
beam_current: float | None = None,
733+
milling_angle: float | None = None,
734+
depth_correction: float | None = None,
735+
lamella_offset: float | None = None,
736+
trench_height_front: float | None = None,
737+
trench_height_rear: float | None = None,
738+
width_overlap_front_left: float | None = None,
739+
width_overlap_front_right: float | None = None,
740+
width_overlap_rear_left: float | None = None,
741+
width_overlap_rear_right: float | None = None,
742+
):
715743
try:
716744
with ISPyBSession() as db:
745+
# Find the ID of this MillingStep
746+
milling_step_name = (
747+
db.query(MillingStepName)
748+
.filter(
749+
MillingStepName.recipe == recipe_name,
750+
MillingStepName.step == activity_name,
751+
)
752+
.one()
753+
)
754+
record = MillingStep(
755+
# IDs
756+
millingStepNameId=milling_step_name.millingStepNameId,
757+
gridSquareId=grid_square_id,
758+
# Values
759+
isEnabled=is_enabled,
760+
status=status,
761+
executionTime=execution_time,
762+
stageX=stage_x,
763+
stageY=stage_y,
764+
stageZ=stage_z,
765+
rotation=rotation,
766+
alphaTilt=tilt_alpha,
767+
beamType=beam_type,
768+
beamVoltage=beam_voltage,
769+
beamCurrent=beam_current,
770+
millingAngle=milling_angle,
771+
depthCorrection=depth_correction,
772+
lamellaOffset=lamella_offset,
773+
trenchHeightFront=trench_height_front,
774+
trenchHeightRear=trench_height_rear,
775+
widthOverlapFrontLeft=width_overlap_front_left,
776+
widthOverlapFrontRight=width_overlap_front_right,
777+
widthOverlapRearLeft=width_overlap_rear_left,
778+
widthOverlapRearRight=width_overlap_rear_right,
779+
)
717780
db.add(record)
718781
db.commit()
719782
log.info(f"Created MillingStep {record.millingStepId}")

src/murfey/workflows/fib/register_milling_progress.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from importlib.metadata import entry_points
44
from typing import Any
55

6-
import ispyb.sqlalchemy._auto_db_schema as ISPyBDB
76
from sqlmodel import Session as SQLModelSession, select
87

98
import murfey.util.db as MurfeyDB
@@ -202,15 +201,28 @@ def _register_milling_step(
202201
if site_info.stage_info is None:
203202
logger.error("No stage info found in current message")
204203
return None
204+
# Check that GridSquare has ID (for type checking)
205+
if grid_square.id is None:
206+
logger.error("Current GridSquare entry has no ID")
207+
return None
205208

206209
# Iteratively go through the LamellaSiteInfo model and insert for each step
207210
for steps, stage_name in MILLING_STEP_LOOKUP:
208-
for step_name, step_id in steps:
211+
for step_name, _ in steps:
209212
step_info: MillingStepInfo | None = site_info.steps.__getattribute__(
210213
step_name
211214
)
215+
# Early continues if key information is missing
212216
if step_info is None:
217+
logger.debug(f"No step info found for {step_name}")
218+
continue
219+
if step_info.recipe_name is None:
220+
logger.debug(f"No recipe name found for {step_name}")
213221
continue
222+
if step_info.step_name is None:
223+
logger.debug(f"No step name found for {step_name}")
224+
continue
225+
214226
stage_values: StagePositionValues | None = (
215227
site_info.stage_info.__getattribute__(stage_name)
216228
)
@@ -227,33 +239,33 @@ def _register_milling_step(
227239

228240
if milling_step_entry is None:
229241
# Create a new ISPyB entry if no Murfey one is found
230-
record = ISPyBDB.MillingStep(
242+
result = _transport_object.do_insert_milling_step(
231243
# IDs
232-
millingStepNameId=step_id,
233-
gridSquareId=grid_square.id,
244+
recipe_name=step_info.recipe_name,
245+
activity_name=step_info.step_name,
246+
grid_square_id=grid_square.id,
234247
# Values
235-
isEnabled=step_info.is_enabled,
248+
is_enabled=step_info.is_enabled,
236249
status=step_info.status,
237-
executionTime=step_info.execution_time,
238-
stageX=stage_values.x,
239-
stageY=stage_values.y,
240-
stageZ=stage_values.z,
250+
execution_time=step_info.execution_time,
251+
stage_x=stage_values.x,
252+
stage_y=stage_values.y,
253+
stage_z=stage_values.z,
241254
rotation=stage_values.rotation,
242-
alphaTilt=stage_values.tilt_alpha,
243-
beamType=step_info.beam_type,
244-
beamVoltage=step_info.voltage,
245-
beamCurrent=step_info.current,
246-
millingAngle=step_info.milling_angle,
247-
depthCorrection=step_info.depth_correction,
248-
lamellaOffset=step_info.lamella_offset,
249-
trenchHeightFront=step_info.trench_height_front,
250-
trenchHeightRear=step_info.trench_height_rear,
251-
widthOverlapFrontLeft=step_info.width_overlap_front_left,
252-
widthOverlapFrontRight=step_info.width_overlap_front_right,
253-
widthOverlapRearLeft=step_info.width_overlap_rear_left,
254-
widthOverlapRearRight=step_info.width_overlap_rear_right,
255+
tilt_alpha=stage_values.tilt_alpha,
256+
beam_type=step_info.beam_type,
257+
beam_voltage=step_info.voltage,
258+
beam_current=step_info.current,
259+
milling_angle=step_info.milling_angle,
260+
depth_correction=step_info.depth_correction,
261+
lamella_offset=step_info.lamella_offset,
262+
trench_height_front=step_info.trench_height_front,
263+
trench_height_rear=step_info.trench_height_rear,
264+
width_overlap_front_left=step_info.width_overlap_front_left,
265+
width_overlap_front_right=step_info.width_overlap_front_right,
266+
width_overlap_rear_left=step_info.width_overlap_rear_left,
267+
width_overlap_rear_right=step_info.width_overlap_rear_right,
255268
)
256-
result = _transport_object.do_insert_milling_step(record)
257269
if result.get("return_value") is None:
258270
logger.error(
259271
f"No MillingStep entry created for {step_info.step_name}"

0 commit comments

Comments
 (0)