Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need frame counts for tomography dose weighting #469

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/murfey/client/contexts/tomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class TomographyContext(Context):
ProcessingParameter("image_size_y", "Image Size Y"),
ProcessingParameter("pixel_size_on_image", "Pixel Size"),
ProcessingParameter("motion_corr_binning", "Motion Correction Binning"),
ProcessingParameter("frame_count", "Number of image frames"),
ProcessingParameter("num_eer_frames", "Number of EER Frames"),
]

Expand Down Expand Up @@ -190,6 +191,9 @@ def _complete_process_file(
"dose_per_frame": environment.data_collection_parameters.get(
"dose_per_frame"
),
"frame_count": environment.data_collection_parameters.get(
"frame_count", 0
),
"mc_binning": environment.data_collection_parameters.get(
"motion_corr_binning", 1
),
Expand Down Expand Up @@ -452,6 +456,9 @@ def _add_tilt(
"dose_per_frame": environment.data_collection_parameters.get(
"dose_per_frame", 0
),
"frame_count": environment.data_collection_parameters.get(
"frame_count", 0
),
"mc_binning": environment.data_collection_parameters.get(
"motion_corr_binning", 1
),
Expand Down Expand Up @@ -682,6 +689,7 @@ def gather_metadata(
mdoc_metadata: OrderedDict = OrderedDict({})
mdoc_metadata["experiment_type"] = "tomography"
mdoc_metadata["voltage"] = float(mdoc_data["Voltage"])
mdoc_metadata["frame_count"] = float(mdoc_data_block["NumSubFrames"])
stephen-riggs marked this conversation as resolved.
Show resolved Hide resolved
mdoc_metadata["image_size_x"] = int(mdoc_data["ImageSize"][0])
mdoc_metadata["image_size_y"] = int(mdoc_data["ImageSize"][1])
mdoc_metadata["magnification"] = int(mdoc_data_block["Magnification"])
Expand Down Expand Up @@ -749,6 +757,9 @@ def gather_metadata(
mdoc_metadata["num_eer_frames"] = murfey.util.eer.num_frames(
metadata_file.parent / data_file
)
mdoc_metadata["frame_count"] = int(
mdoc_metadata["eer_fractionation"] / mdoc_metadata["num_eer_frames"]
)
except Exception as e:
logger.error(f"Exception encountered in metadata gathering: {str(e)}")
return OrderedDict({})
Expand Down
5 changes: 5 additions & 0 deletions src/murfey/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,7 @@ def _flush_tomography_preprocessing(message: dict):
"mc_uuid": murfey_ids[0],
"ft_bin": proc_params.motion_corr_binning,
"fm_dose": proc_params.dose_per_frame,
"frame_count": proc_params.frame_count,
"gain_ref": (
str(machine_config.rsync_basepath / proc_params.gain_ref)
if proc_params.gain_ref
Expand Down Expand Up @@ -2474,6 +2475,9 @@ def feedback_callback(header: dict, message: dict) -> None:
"dcid": ids.dcid,
"appid": ids.appid,
"stack_file": str(stack_file),
"dose_per_frame": preproc_params.dose_per_frame,
"frame_count": preproc_params.frame_count,
"kv": preproc_params.voltage,
stephen-riggs marked this conversation as resolved.
Show resolved Hide resolved
"pixel_size": preproc_params.pixel_size,
"manual_tilt_offset": -tilt_offset,
"node_creator_queue": machine_config.node_creator_queue,
Expand Down Expand Up @@ -2831,6 +2835,7 @@ def feedback_callback(header: dict, message: dict) -> None:
pixel_size=float(message["pixel_size_on_image"]) * 10**10,
voltage=message["voltage"],
dose_per_frame=message["dose_per_frame"],
frame_count=message["frame_count"],
motion_corr_binning=message["motion_corr_binning"],
gain_ref=message["gain_ref"],
eer_fractionation_file=message["eer_fractionation_file"],
Expand Down
11 changes: 9 additions & 2 deletions src/murfey/server/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ def register_completed_tilt_series(
"dcid": ids.dcid,
"appid": ids.appid,
"stack_file": str(stack_file),
"dose_per_frame": preproc_params.dose_per_frame,
"frame_count": preproc_params.frame_count,
"kv": preproc_params.voltage,
"pixel_size": preproc_params.pixel_size,
"manual_tilt_offset": -tilt_offset,
"node_creator_queue": machine_config.node_creator_queue,
Expand Down Expand Up @@ -1131,6 +1134,9 @@ async def request_tomography_preprocessing(
/ str(ppath.stem + "_motion_corrected.mrc")
)
mrc_out = Path("/".join(secure_filename(p) for p in mrc_out.parts))

recipe_name = machine_config.recipes.get("em-tomo-preprocess", "em-tomo-preprocess")

data_collection = db.exec(
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
.where(DataCollectionGroup.session_id == session_id)
Expand All @@ -1139,7 +1145,7 @@ async def request_tomography_preprocessing(
.where(DataCollection.dcg_id == DataCollectionGroup.id)
.where(ProcessingJob.dc_id == DataCollection.id)
.where(AutoProcProgram.pj_id == ProcessingJob.id)
.where(ProcessingJob.recipe == "em-tomo-preprocess")
.where(ProcessingJob.recipe == recipe_name)
).all()
if data_collection:
if registered_tilts := db.exec(
Expand All @@ -1154,7 +1160,7 @@ async def request_tomography_preprocessing(
if not mrc_out.parent.exists():
mrc_out.parent.mkdir(parents=True, exist_ok=True)
zocalo_message: dict = {
"recipes": ["em-tomo-preprocess"],
"recipes": [recipe_name],
"parameters": {
"node_creator_queue": machine_config.node_creator_queue,
"dcid": dcid,
Expand All @@ -1169,6 +1175,7 @@ async def request_tomography_preprocessing(
"mc_uuid": murfey_ids[0],
"ft_bin": proc_file.mc_binning,
"fm_dose": proc_file.dose_per_frame,
"frame_count": proc_file.frame_count,
"gain_ref": (
str(machine_config.rsync_basepath / proc_file.gain_ref)
if proc_file.gain_ref and machine_config.data_transfer_enabled
Expand Down
1 change: 1 addition & 0 deletions src/murfey/util/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ class TomographyPreprocessingParameters(SQLModel, table=True): # type: ignore
dcg_id: int = Field(primary_key=True, foreign_key="datacollectiongroup.id")
pixel_size: float
dose_per_frame: float
frame_count: int
voltage: int
eer_fractionation_file: Optional[str] = None
motion_corr_binning: int = 1
Expand Down
1 change: 1 addition & 0 deletions src/murfey/util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class CompletedTiltSeries(BaseModel):

class PreprocessingParametersTomo(BaseModel):
dose_per_frame: float
frame_count: int
gain_ref: Optional[str]
experiment_type: str
voltage: float
Expand Down
Loading