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 all commits
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
8 changes: 8 additions & 0 deletions src/murfey/client/contexts/tomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
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 @@ -361,6 +362,9 @@
"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 @@ -591,6 +595,7 @@
mdoc_metadata: OrderedDict = OrderedDict({})
mdoc_metadata["experiment_type"] = "tomography"
mdoc_metadata["voltage"] = float(mdoc_data["Voltage"])
mdoc_metadata["frame_count"] = int(mdoc_data_block["NumSubFrames"])

Check warning on line 598 in src/murfey/client/contexts/tomo.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo.py#L598

Added line #L598 was not covered by tests
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 @@ -658,6 +663,9 @@
mdoc_metadata["num_eer_frames"] = murfey.util.eer.num_frames(
metadata_file.parent / data_file
)
mdoc_metadata["frame_count"] = int(

Check warning on line 666 in src/murfey/client/contexts/tomo.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo.py#L666

Added line #L666 was not covered by tests
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
11 changes: 6 additions & 5 deletions src/murfey/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,11 +1954,7 @@
.where(db.DataCollectionGroup.session_id == session_id)
.where(db.DataCollectionGroup.tag == message["data_collection_group_tag"])
).first()
proc_params = murfey_db.exec(
select(db.TomographyPreprocessingParameters).where(
db.TomographyPreprocessingParameters.dcg_id == collected_ids.id
)
).one()
proc_params = get_tomo_preproc_params(collected_ids.id)

Check warning on line 1957 in src/murfey/server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/__init__.py#L1957

Added line #L1957 was not covered by tests
if not proc_params:
visit_name = message["visit_name"].replace("\r\n", "").replace("\n", "")
logger.warning(
Expand Down Expand Up @@ -2012,6 +2008,7 @@
"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 +2471,9 @@
"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 @@ -2832,6 +2832,7 @@
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 @@ -729,6 +729,9 @@
"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 @@ -1120,6 +1123,9 @@
/ 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")

Check warning on line 1127 in src/murfey/server/api/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/server/api/__init__.py#L1127

Added line #L1127 was not covered by tests

data_collection = db.exec(
select(DataCollectionGroup, DataCollection, ProcessingJob, AutoProcProgram)
.where(DataCollectionGroup.session_id == session_id)
Expand All @@ -1128,7 +1134,7 @@
.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 @@ -1143,7 +1149,7 @@
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 @@ -1158,6 +1164,7 @@
"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 @@ -349,6 +349,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