-
Notifications
You must be signed in to change notification settings - Fork 1
Insert tomogram locations in SXT regions of interest #860
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
Changes from all commits
9faef0d
f03329e
8d258b8
616520b
87d6901
75ef736
f096412
36aaaac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import logging | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| from pydantic import BaseModel | ||
| from sqlmodel import select | ||
| from sqlmodel.orm.session import Session as SQLModelSession | ||
|
|
@@ -15,6 +16,7 @@ | |
| DataCollection, | ||
| DataCollectionGroup, | ||
| ProcessingJob, | ||
| SearchMap, | ||
| Session, | ||
| TiltSeries, | ||
| ) | ||
|
|
@@ -30,6 +32,8 @@ class SXTTiltSeriesInfo(BaseModel): | |
| pixel_size: float | ||
| tilt_offset: int | ||
| xrm_reference: str | None | ||
| x_stage_position: float | None = None | ||
| y_stage_position: float | None = None | ||
|
|
||
|
|
||
| def process_sxt_tilt_series( | ||
|
|
@@ -82,6 +86,63 @@ def process_sxt_tilt_series( | |
| instrument_name | ||
| ] | ||
|
|
||
| # Determine pixel location on a roi for display | ||
| min_distance: float | None = None | ||
| matching_roi: SearchMap | None = None | ||
| x_pixel_location: int | None = None | ||
| y_pixel_location: int | None = None | ||
| if tilt_series_info.x_stage_position and tilt_series_info.y_stage_position: | ||
| # Find all rois for this grid | ||
| dcg_rois = murfey_db.exec( | ||
| select(SearchMap) | ||
| .where(SearchMap.session_id == session_id) | ||
| .where(SearchMap.tag == tilt_series.rsync_source) | ||
| ).all() | ||
| for roi in dcg_rois: | ||
| if roi.x_stage_position is not None and roi.y_stage_position is not None: | ||
| # Determine the roi which is closest to this tomogram | ||
| roi_distance = np.sqrt( | ||
| (tilt_series_info.x_stage_position - roi.x_stage_position) ** 2 | ||
| + (tilt_series_info.y_stage_position - roi.y_stage_position) ** 2 | ||
| ) | ||
| if min_distance is None or roi_distance < min_distance: | ||
| min_distance = roi_distance | ||
| matching_roi = roi | ||
|
|
||
| # Calculate the position on the roi | ||
| if ( | ||
| matching_roi is not None | ||
| and matching_roi.x_stage_position is not None | ||
| and matching_roi.y_stage_position is not None | ||
| and matching_roi.height | ||
| and matching_roi.width | ||
| and matching_roi.pixel_size | ||
| ): | ||
| # Convert from stage position to pixel locations | ||
| # Stage position in microns, pixel size in metres | ||
| x_location_centered = ( | ||
| (tilt_series_info.x_stage_position - matching_roi.x_stage_position) | ||
| / matching_roi.pixel_size | ||
| / 1e6 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that on the client side, you have been converting the pixel size to metres, is the What are the units of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1e6 is needed as the stage position is microns and the pixel size is metres |
||
| ) | ||
| y_location_centered = ( | ||
| (tilt_series_info.y_stage_position - matching_roi.y_stage_position) | ||
| / matching_roi.pixel_size | ||
| / 1e6 | ||
| ) | ||
|
|
||
| # Scaling from different pixel size of atlas and roi, and atlas thumbnail size | ||
| x_pixel_location = int( | ||
| x_location_centered * 1024 / matching_roi.width + 512 | ||
| ) | ||
| y_pixel_location = int( | ||
| 512 - y_location_centered * 1024 / matching_roi.height | ||
| ) | ||
| else: | ||
| logger.warning( | ||
| f"Cannot match ROI {matching_roi.id if matching_roi else None} for {tilt_series_info.tag}" | ||
| ) | ||
|
|
||
| # Find the visit folder and any subfolders needed | ||
| parts = [secure_filename(p) for p in Path(tilt_series_info.txrm).parts] | ||
| visit_idx = parts.index(visit_name) | ||
|
|
@@ -119,6 +180,9 @@ def process_sxt_tilt_series( | |
| "pixel_size": tilt_series_info.pixel_size, | ||
| "manual_tilt_offset": -tilt_series_info.tilt_offset, | ||
| "node_creator_queue": machine_config.node_creator_queue, | ||
| "search_map_id": matching_roi.id if matching_roi else None, | ||
| "x_location": x_pixel_location, | ||
| "y_location": y_pixel_location, | ||
| }, | ||
| } | ||
| if _transport_object: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be iterated, but works as-is.