Skip to content

Commit e2188f7

Browse files
committed
Need frame counts for tomography dose weighting
1 parent 153719e commit e2188f7

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

src/murfey/client/contexts/tomo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class TomographyContext(Context):
8989
ProcessingParameter("image_size_y", "Image Size Y"),
9090
ProcessingParameter("pixel_size_on_image", "Pixel Size"),
9191
ProcessingParameter("motion_corr_binning", "Motion Correction Binning"),
92+
ProcessingParameter("frame_count", "Number of image frames"),
9293
ProcessingParameter("num_eer_frames", "Number of EER Frames"),
9394
]
9495

@@ -190,6 +191,9 @@ def _complete_process_file(
190191
"dose_per_frame": environment.data_collection_parameters.get(
191192
"dose_per_frame"
192193
),
194+
"frame_count": environment.data_collection_parameters.get(
195+
"frame_count", 0
196+
),
193197
"mc_binning": environment.data_collection_parameters.get(
194198
"motion_corr_binning", 1
195199
),
@@ -452,6 +456,9 @@ def _add_tilt(
452456
"dose_per_frame": environment.data_collection_parameters.get(
453457
"dose_per_frame", 0
454458
),
459+
"frame_count": environment.data_collection_parameters.get(
460+
"frame_count", 0
461+
),
455462
"mc_binning": environment.data_collection_parameters.get(
456463
"motion_corr_binning", 1
457464
),
@@ -682,6 +689,7 @@ def gather_metadata(
682689
mdoc_metadata: OrderedDict = OrderedDict({})
683690
mdoc_metadata["experiment_type"] = "tomography"
684691
mdoc_metadata["voltage"] = float(mdoc_data["Voltage"])
692+
mdoc_metadata["frame_count"] = float(mdoc_data_block["NumSubFrames"])
685693
mdoc_metadata["image_size_x"] = int(mdoc_data["ImageSize"][0])
686694
mdoc_metadata["image_size_y"] = int(mdoc_data["ImageSize"][1])
687695
mdoc_metadata["magnification"] = int(mdoc_data_block["Magnification"])
@@ -749,6 +757,9 @@ def gather_metadata(
749757
mdoc_metadata["num_eer_frames"] = murfey.util.eer.num_frames(
750758
metadata_file.parent / data_file
751759
)
760+
mdoc_metadata["frame_count"] = int(
761+
mdoc_metadata["eer_fractionation"] / mdoc_metadata["num_eer_frames"]
762+
)
752763
except Exception as e:
753764
logger.error(f"Exception encountered in metadata gathering: {str(e)}")
754765
return OrderedDict({})

src/murfey/server/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,7 @@ def _flush_tomography_preprocessing(message: dict):
20122012
"mc_uuid": murfey_ids[0],
20132013
"ft_bin": proc_params.motion_corr_binning,
20142014
"fm_dose": proc_params.dose_per_frame,
2015+
"frame_count": proc_params.frame_count,
20152016
"gain_ref": (
20162017
str(machine_config.rsync_basepath / proc_params.gain_ref)
20172018
if proc_params.gain_ref
@@ -2474,6 +2475,9 @@ def feedback_callback(header: dict, message: dict) -> None:
24742475
"dcid": ids.dcid,
24752476
"appid": ids.appid,
24762477
"stack_file": str(stack_file),
2478+
"dose_per_frame": preproc_params.dose_per_frame,
2479+
"frame_count": preproc_params.frame_count,
2480+
"kv": preproc_params.voltage,
24772481
"pixel_size": preproc_params.pixel_size,
24782482
"manual_tilt_offset": -tilt_offset,
24792483
"node_creator_queue": machine_config.node_creator_queue,
@@ -2831,6 +2835,7 @@ def feedback_callback(header: dict, message: dict) -> None:
28312835
pixel_size=float(message["pixel_size_on_image"]) * 10**10,
28322836
voltage=message["voltage"],
28332837
dose_per_frame=message["dose_per_frame"],
2838+
frame_count=message["frame_count"],
28342839
motion_corr_binning=message["motion_corr_binning"],
28352840
gain_ref=message["gain_ref"],
28362841
eer_fractionation_file=message["eer_fractionation_file"],

src/murfey/server/api/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ def register_completed_tilt_series(
730730
"dcid": ids.dcid,
731731
"appid": ids.appid,
732732
"stack_file": str(stack_file),
733+
"dose_per_frame": preproc_params.dose_per_frame,
734+
"frame_count": preproc_params.frame_count,
735+
"kv": preproc_params.voltage,
733736
"pixel_size": preproc_params.pixel_size,
734737
"manual_tilt_offset": -tilt_offset,
735738
"node_creator_queue": machine_config.node_creator_queue,
@@ -1131,6 +1134,9 @@ async def request_tomography_preprocessing(
11311134
/ str(ppath.stem + "_motion_corrected.mrc")
11321135
)
11331136
mrc_out = Path("/".join(secure_filename(p) for p in mrc_out.parts))
1137+
1138+
recipe_name = machine_config.recipes.get("em-tomo-preprocess", "em-tomo-preprocess")
1139+
11341140
data_collection = db.exec(
11351141
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
11361142
.where(DataCollectionGroup.session_id == session_id)
@@ -1139,7 +1145,7 @@ async def request_tomography_preprocessing(
11391145
.where(DataCollection.dcg_id == DataCollectionGroup.id)
11401146
.where(ProcessingJob.dc_id == DataCollection.id)
11411147
.where(AutoProcProgram.pj_id == ProcessingJob.id)
1142-
.where(ProcessingJob.recipe == "em-tomo-preprocess")
1148+
.where(ProcessingJob.recipe == recipe_name)
11431149
).all()
11441150
if data_collection:
11451151
if registered_tilts := db.exec(
@@ -1154,7 +1160,7 @@ async def request_tomography_preprocessing(
11541160
if not mrc_out.parent.exists():
11551161
mrc_out.parent.mkdir(parents=True, exist_ok=True)
11561162
zocalo_message: dict = {
1157-
"recipes": ["em-tomo-preprocess"],
1163+
"recipes": [recipe_name],
11581164
"parameters": {
11591165
"node_creator_queue": machine_config.node_creator_queue,
11601166
"dcid": dcid,
@@ -1169,6 +1175,7 @@ async def request_tomography_preprocessing(
11691175
"mc_uuid": murfey_ids[0],
11701176
"ft_bin": proc_file.mc_binning,
11711177
"fm_dose": proc_file.dose_per_frame,
1178+
"frame_count": proc_file.frame_count,
11721179
"gain_ref": (
11731180
str(machine_config.rsync_basepath / proc_file.gain_ref)
11741181
if proc_file.gain_ref and machine_config.data_transfer_enabled

src/murfey/util/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ class TomographyPreprocessingParameters(SQLModel, table=True): # type: ignore
458458
dcg_id: int = Field(primary_key=True, foreign_key="datacollectiongroup.id")
459459
pixel_size: float
460460
dose_per_frame: float
461+
frame_count: int
461462
voltage: int
462463
eer_fractionation_file: Optional[str] = None
463464
motion_corr_binning: int = 1

src/murfey/util/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ class CompletedTiltSeries(BaseModel):
356356

357357
class PreprocessingParametersTomo(BaseModel):
358358
dose_per_frame: float
359+
frame_count: int
359360
gain_ref: Optional[str]
360361
experiment_type: str
361362
voltage: float

0 commit comments

Comments
 (0)