Skip to content

Commit c1cbe82

Browse files
Need frame counts for tomography dose weighting (#469)
Adds frame count finding for tomography, and passes this on to the processing. Storing the frame count requires a database change, so we may not want to merge this change immediately.
1 parent 3308176 commit c1cbe82

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

src/murfey/client/contexts/tomo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class TomographyContext(Context):
7878
ProcessingParameter("image_size_y", "Image Size Y"),
7979
ProcessingParameter("pixel_size_on_image", "Pixel Size"),
8080
ProcessingParameter("motion_corr_binning", "Motion Correction Binning"),
81+
ProcessingParameter("frame_count", "Number of image frames"),
8182
ProcessingParameter("num_eer_frames", "Number of EER Frames"),
8283
]
8384

@@ -361,6 +362,9 @@ def _add_tilt(
361362
"dose_per_frame": environment.data_collection_parameters.get(
362363
"dose_per_frame", 0
363364
),
365+
"frame_count": environment.data_collection_parameters.get(
366+
"frame_count", 0
367+
),
364368
"mc_binning": environment.data_collection_parameters.get(
365369
"motion_corr_binning", 1
366370
),
@@ -591,6 +595,7 @@ def gather_metadata(
591595
mdoc_metadata: OrderedDict = OrderedDict({})
592596
mdoc_metadata["experiment_type"] = "tomography"
593597
mdoc_metadata["voltage"] = float(mdoc_data["Voltage"])
598+
mdoc_metadata["frame_count"] = int(mdoc_data_block["NumSubFrames"])
594599
mdoc_metadata["image_size_x"] = int(mdoc_data["ImageSize"][0])
595600
mdoc_metadata["image_size_y"] = int(mdoc_data["ImageSize"][1])
596601
mdoc_metadata["magnification"] = int(mdoc_data_block["Magnification"])
@@ -658,6 +663,9 @@ def gather_metadata(
658663
mdoc_metadata["num_eer_frames"] = murfey.util.eer.num_frames(
659664
metadata_file.parent / data_file
660665
)
666+
mdoc_metadata["frame_count"] = int(
667+
mdoc_metadata["eer_fractionation"] / mdoc_metadata["num_eer_frames"]
668+
)
661669
except Exception as e:
662670
logger.error(f"Exception encountered in metadata gathering: {str(e)}")
663671
return OrderedDict({})

src/murfey/server/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,11 +1951,7 @@ def _flush_tomography_preprocessing(message: dict):
19511951
.where(db.DataCollectionGroup.session_id == session_id)
19521952
.where(db.DataCollectionGroup.tag == message["data_collection_group_tag"])
19531953
).first()
1954-
proc_params = murfey_db.exec(
1955-
select(db.TomographyPreprocessingParameters).where(
1956-
db.TomographyPreprocessingParameters.dcg_id == collected_ids.id
1957-
)
1958-
).one()
1954+
proc_params = get_tomo_preproc_params(collected_ids.id)
19591955
if not proc_params:
19601956
visit_name = message["visit_name"].replace("\r\n", "").replace("\n", "")
19611957
logger.warning(
@@ -2009,6 +2005,7 @@ def _flush_tomography_preprocessing(message: dict):
20092005
"mc_uuid": murfey_ids[0],
20102006
"ft_bin": proc_params.motion_corr_binning,
20112007
"fm_dose": proc_params.dose_per_frame,
2008+
"frame_count": proc_params.frame_count,
20122009
"gain_ref": (
20132010
str(machine_config.rsync_basepath / proc_params.gain_ref)
20142011
if proc_params.gain_ref
@@ -2471,6 +2468,9 @@ def feedback_callback(header: dict, message: dict) -> None:
24712468
"dcid": ids.dcid,
24722469
"appid": ids.appid,
24732470
"stack_file": str(stack_file),
2471+
"dose_per_frame": preproc_params.dose_per_frame,
2472+
"frame_count": preproc_params.frame_count,
2473+
"kv": preproc_params.voltage,
24742474
"pixel_size": preproc_params.pixel_size,
24752475
"manual_tilt_offset": -tilt_offset,
24762476
"node_creator_queue": machine_config.node_creator_queue,
@@ -2829,6 +2829,7 @@ def feedback_callback(header: dict, message: dict) -> None:
28292829
pixel_size=float(message["pixel_size_on_image"]) * 10**10,
28302830
voltage=message["voltage"],
28312831
dose_per_frame=message["dose_per_frame"],
2832+
frame_count=message["frame_count"],
28322833
motion_corr_binning=message["motion_corr_binning"],
28332834
gain_ref=message["gain_ref"],
28342835
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
@@ -729,6 +729,9 @@ def register_completed_tilt_series(
729729
"dcid": ids.dcid,
730730
"appid": ids.appid,
731731
"stack_file": str(stack_file),
732+
"dose_per_frame": preproc_params.dose_per_frame,
733+
"frame_count": preproc_params.frame_count,
734+
"kv": preproc_params.voltage,
732735
"pixel_size": preproc_params.pixel_size,
733736
"manual_tilt_offset": -tilt_offset,
734737
"node_creator_queue": machine_config.node_creator_queue,
@@ -1120,6 +1123,9 @@ async def request_tomography_preprocessing(
11201123
/ str(ppath.stem + "_motion_corrected.mrc")
11211124
)
11221125
mrc_out = Path("/".join(secure_filename(p) for p in mrc_out.parts))
1126+
1127+
recipe_name = machine_config.recipes.get("em-tomo-preprocess", "em-tomo-preprocess")
1128+
11231129
data_collection = db.exec(
11241130
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
11251131
.where(DataCollectionGroup.session_id == session_id)
@@ -1128,7 +1134,7 @@ async def request_tomography_preprocessing(
11281134
.where(DataCollection.dcg_id == DataCollectionGroup.id)
11291135
.where(ProcessingJob.dc_id == DataCollection.id)
11301136
.where(AutoProcProgram.pj_id == ProcessingJob.id)
1131-
.where(ProcessingJob.recipe == "em-tomo-preprocess")
1137+
.where(ProcessingJob.recipe == recipe_name)
11321138
).all()
11331139
if data_collection:
11341140
if registered_tilts := db.exec(
@@ -1143,7 +1149,7 @@ async def request_tomography_preprocessing(
11431149
if not mrc_out.parent.exists():
11441150
mrc_out.parent.mkdir(parents=True, exist_ok=True)
11451151
zocalo_message: dict = {
1146-
"recipes": ["em-tomo-preprocess"],
1152+
"recipes": [recipe_name],
11471153
"parameters": {
11481154
"node_creator_queue": machine_config.node_creator_queue,
11491155
"dcid": dcid,
@@ -1158,6 +1164,7 @@ async def request_tomography_preprocessing(
11581164
"mc_uuid": murfey_ids[0],
11591165
"ft_bin": proc_file.mc_binning,
11601166
"fm_dose": proc_file.dose_per_frame,
1167+
"frame_count": proc_file.frame_count,
11611168
"gain_ref": (
11621169
str(machine_config.rsync_basepath / proc_file.gain_ref)
11631170
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
@@ -349,6 +349,7 @@ class CompletedTiltSeries(BaseModel):
349349

350350
class PreprocessingParametersTomo(BaseModel):
351351
dose_per_frame: float
352+
frame_count: int
352353
gain_ref: Optional[str]
353354
experiment_type: str
354355
voltage: float

0 commit comments

Comments
 (0)