Skip to content

Commit f2cfc5d

Browse files
committed
Merge branch 'main' into safe-atlas-xml-search and fix conflicts
2 parents a501c5e + 8739a6c commit f2cfc5d

10 files changed

Lines changed: 121 additions & 189 deletions

File tree

src/murfey/client/analyser.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,7 @@ def _analyse(self):
308308
dc_metadata["acquisition_software"] = (
309309
self._context._acquisition_software
310310
)
311-
self.notify(
312-
{
313-
"form": dc_metadata,
314-
}
315-
)
311+
self.notify(dc_metadata)
316312

317313
# If a file with a CLEM context is identified, immediately post it
318314
elif isinstance(self._context, CLEMContext):
@@ -366,11 +362,7 @@ def _analyse(self):
366362
dc_metadata["acquisition_software"] = (
367363
self._context._acquisition_software
368364
)
369-
self.notify(
370-
{
371-
"form": dc_metadata,
372-
}
373-
)
365+
self.notify(dc_metadata)
374366
elif isinstance(
375367
self._context,
376368
(

src/murfey/client/context.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ def ensure_dcg_exists(
4545
if collection_type == "tomo":
4646
experiment_type_id = 36
4747
session_file = metadata_source / "Session.dm"
48+
source_visit_dir = metadata_source.parent
4849
elif collection_type == "spa":
4950
experiment_type_id = 37
50-
session_file = metadata_source / "EpuSession.dm"
51+
# For SPA the metadata source sent should include the Images-Disc
52+
session_file = metadata_source.parent / "EpuSession.dm"
53+
source_visit_dir = metadata_source.parent.parent
5154
for h in entry_points(group="murfey.hooks"):
5255
try:
5356
if h.name == "get_epu_session_metadata":
@@ -90,27 +93,13 @@ def ensure_dcg_exists(
9093
partial_path = "/".join(windows_path.split("\\")[visit_index + 1 :])
9194
logger.info("Partial Linux path successfully constructed from Windows path")
9295

93-
source_visit_dir = metadata_source.parent
9496
logger.info(
9597
f"Looking for atlas XML file in metadata directory {str((source_visit_dir / partial_path).parent)}"
9698
)
9799

98-
dcg_search_dir = (
100+
dcg_tag = (
99101
str(metadata_source).replace(f"/{environment.visit}", "").replace("//", "/")
100102
)
101-
if collection_type == "tomo":
102-
dcg_tag = dcg_search_dir
103-
else:
104-
dcg_images_dirs = sorted(
105-
Path(dcg_search_dir).glob("Images-Disc*"),
106-
key=lambda x: x.stat().st_ctime,
107-
)
108-
if not dcg_images_dirs:
109-
logger.warning(
110-
f"Cannot find Images-Disc* in {dcg_search_dir}, falling back to Images-Disc1"
111-
)
112-
dcg_images_dirs = [Path(dcg_search_dir) / "Images-Disc1"]
113-
dcg_tag = str(dcg_images_dirs[-1])
114103

115104
for p in partial_path.split("/"):
116105
if p.startswith("Sample"):
@@ -143,7 +132,7 @@ def ensure_dcg_exists(
143132
"experiment_type_id": experiment_type_id,
144133
"tag": dcg_tag,
145134
"atlas": str(
146-
_atlas_destination(environment, metadata_source, token)
135+
_atlas_destination(environment, session_file.parent, token)
147136
/ environment.samples[metadata_source].atlas.parent
148137
/ atlas_xml_path.with_suffix(".jpg").name
149138
).replace("//", "/"),

src/murfey/client/contexts/spa_metadata.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -106,35 +106,39 @@ def post_transfer(
106106
return
107107

108108
if source:
109-
dcg_tag = ensure_dcg_exists(
110-
collection_type="spa",
111-
metadata_source=source,
112-
environment=environment,
113-
token=self._token,
114-
)
115109
gs_pix_positions = get_grid_square_atlas_positions(
116110
source.parent / partial_path
117111
)
118-
for gs, pos_data in gs_pix_positions.items():
119-
if pos_data:
120-
capture_post(
121-
base_url=str(environment.url.geturl()),
122-
router_name="session_control.spa_router",
123-
function_name="register_grid_square",
124-
token=self._token,
125-
session_id=environment.murfey_session,
126-
gsid=int(gs),
127-
data={
128-
"tag": dcg_tag,
129-
"x_location": pos_data[0],
130-
"y_location": pos_data[1],
131-
"x_stage_position": pos_data[2],
132-
"y_stage_position": pos_data[3],
133-
"width": pos_data[4],
134-
"height": pos_data[5],
135-
"angle": pos_data[6],
136-
},
137-
)
112+
for images_disc in list(source.glob("Images-Disc*")) or [
113+
source / "Images-Disc1"
114+
]:
115+
# Do the dcg registration for every Images-Disc with this session file
116+
dcg_tag = ensure_dcg_exists(
117+
collection_type="spa",
118+
metadata_source=images_disc,
119+
environment=environment,
120+
token=self._token,
121+
)
122+
for gs, pos_data in gs_pix_positions.items():
123+
if pos_data:
124+
capture_post(
125+
base_url=str(environment.url.geturl()),
126+
router_name="session_control.spa_router",
127+
function_name="register_grid_square",
128+
token=self._token,
129+
session_id=environment.murfey_session,
130+
gsid=int(gs),
131+
data={
132+
"tag": dcg_tag,
133+
"x_location": pos_data[0],
134+
"y_location": pos_data[1],
135+
"x_stage_position": pos_data[2],
136+
"y_stage_position": pos_data[3],
137+
"width": pos_data[4],
138+
"height": pos_data[5],
139+
"angle": pos_data[6],
140+
},
141+
)
138142

139143
elif (
140144
transferred_file.suffix == ".dm"
@@ -145,12 +149,15 @@ def post_transfer(
145149
source = _get_source(transferred_file, environment=environment)
146150
if source is None:
147151
return None
148-
ensure_dcg_exists(
149-
collection_type="spa",
150-
metadata_source=source,
151-
environment=environment,
152-
token=self._token,
153-
)
152+
for images_disc in list(source.glob("Images-Disc*")) or [
153+
source / "Images-Disc1"
154+
]:
155+
ensure_dcg_exists(
156+
collection_type="spa",
157+
metadata_source=images_disc,
158+
environment=environment,
159+
token=self._token,
160+
)
154161

155162
gs_name = int(transferred_file.stem.split("_")[1])
156163
logger.info(
@@ -168,7 +175,9 @@ def post_transfer(
168175
logger.warning(
169176
f"Cannot find Images-Disc* in {visitless_source_search_dir}"
170177
)
171-
return
178+
visitless_source_images_dirs = [
179+
Path(visitless_source_search_dir) / "Images-Disc1"
180+
]
172181
visitless_source = str(visitless_source_images_dirs[-1])
173182

174183
if fh_positions:

0 commit comments

Comments
 (0)