Skip to content

Commit 4550795

Browse files
Match dcgs for tomo multigrid (#819)
The data collection groups for atlas, metadata and fractions were not being matched up correctly for tomo multigrid. This is due to the metadata being in Supervisor/Sample and the data in Supervisor_Sample This resolves this issue by always using the metadata form with a slash. In the tomo context it checks the existence of the different metadata locations and determines the metadata_source and group_tag from this. Also catches errors from being unable to read grid squares on a tomo atlas, and not copying the batch positions list.
1 parent 5899043 commit 4550795

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

src/murfey/client/contexts/atlas.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def post_transfer_epu(
162162

163163
elif environment and transferred_file.name == "Atlas.dm":
164164
# Register all grid squares on this atlas
165-
gs_pix_positions = get_grid_square_atlas_positions(transferred_file)
165+
try:
166+
gs_pix_positions = get_grid_square_atlas_positions(transferred_file)
167+
except KeyError:
168+
logger.info("Unable to read grid square locations from Atlas.dm")
169+
return
166170
for gs, pos_data in gs_pix_positions.items():
167171
if pos_data:
168172
capture_post(

src/murfey/client/contexts/tomo.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
self._data_collection_stash: list = []
9494
self._processing_job_stash: dict = {}
9595
self._lock: RLock = RLock()
96+
self._group_tag: str = str(self._basepath)
9697

9798
def register_tomography_data_collections(
9899
self,
@@ -109,6 +110,20 @@ def register_tomography_data_collections(
109110
metadata_source = (
110111
self._basepath.parent / environment.visit / self._basepath.name
111112
)
113+
multigrid_metadata_source = (
114+
self._basepath.parent
115+
/ environment.visit
116+
/ "_".join(self._basepath.name.split("_")[:-1])
117+
/ self._basepath.name.split("_")[-1]
118+
)
119+
if not metadata_source.is_dir() and multigrid_metadata_source.is_dir():
120+
# If the multigrid path exists, tags need to replace the last _ with /
121+
metadata_source = multigrid_metadata_source
122+
self._group_tag = str(
123+
self._basepath.parent
124+
/ "_".join(self._basepath.name.split("_")[:-1])
125+
/ self._basepath.name.split("_")[-1]
126+
)
112127
ensure_dcg_exists(
113128
collection_type="tomo",
114129
metadata_source=metadata_source,
@@ -125,7 +140,7 @@ def register_tomography_data_collections(
125140
"acquisition_software": self._acquisition_software,
126141
"image_directory": image_directory,
127142
"data_collection_tag": tilt_series,
128-
"source": str(self._basepath),
143+
"source": self._group_tag,
129144
"tag": tilt_series,
130145
}
131146
if (
@@ -178,7 +193,7 @@ def register_tomography_data_collections(
178193
session_id=environment.murfey_session,
179194
data={
180195
"tag": tilt_series,
181-
"source": str(self._basepath),
196+
"source": self._group_tag,
182197
"recipe": recipe,
183198
"experiment_type": "tomography",
184199
},
@@ -390,7 +405,7 @@ def _add_tilt(
390405
"voltage": self.data_collection_parameters.get("voltage", 300),
391406
"eer_fractionation_file": eer_fractionation_file,
392407
"tag": tilt_series,
393-
"group_tag": str(self._basepath),
408+
"group_tag": self._group_tag,
394409
}
395410
capture_post(
396411
base_url=str(environment.url.geturl()),
@@ -607,7 +622,7 @@ def gather_metadata(
607622
environment.dose_per_frame if environment else None
608623
)
609624
mdoc_metadata["source"] = str(self._basepath)
610-
mdoc_metadata["tag"] = str(self._basepath)
625+
mdoc_metadata["tag"] = self._group_tag
611626
mdoc_metadata["tilt_series_tag"] = metadata_file.stem
612627
mdoc_metadata["exposure_time"] = float(mdoc_data_block["ExposureTime"])
613628
slit_width = mdoc_data_block["FilterSlitAndLoss"][0]

src/murfey/client/contexts/tomo_metadata.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,14 @@ def post_transfer(
226226

227227
elif transferred_file.name == "BatchPositionsList.xml":
228228
logger.info("Tomography session batch positions list found")
229-
shutil.copy(
230-
transferred_file,
231-
transferred_file.parent
232-
/ f"{transferred_file.stem}-{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}{transferred_file.suffix}",
233-
)
229+
try:
230+
shutil.copy(
231+
transferred_file,
232+
transferred_file.parent
233+
/ f"{transferred_file.stem}-{datetime.now().strftime('%Y-%m-%d-%H-%M-%S')}{transferred_file.suffix}",
234+
)
235+
except PermissionError:
236+
logger.warning("Unable to copy batch positions list")
234237
dcg_tag = ensure_dcg_exists(
235238
collection_type="tomo",
236239
metadata_source=metadata_source,

src/murfey/client/multigrid_control.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ def _start_dc(self, metadata_json):
520520
k: None if v == "None" else v for k, v in metadata_json.items()
521521
}
522522
if isinstance(context, TomographyContext):
523-
source = Path(metadata_json["source"])
524523
context.register_tomography_data_collections(
525524
file_extension=metadata_json["file_extension"],
526525
image_directory=str(self._environment.default_destinations[source]),
@@ -565,7 +564,7 @@ def _start_dc(self, metadata_json):
565564
instrument_name=self._environment.instrument_name,
566565
visit_name=self._environment.visit,
567566
session_id=self._environment.murfey_session,
568-
data={"rsync_source": str(source)},
567+
data={"rsync_source": metadata_json.get("tag", "")},
569568
)
570569
log.info("Tomography processing flushed")
571570

0 commit comments

Comments
 (0)