Skip to content

Commit 08b9a0e

Browse files
SPA metadata source should include Images-Disc (#736)
Merging into main, needs running in test setup before live deployment The Images-Disc part of the source needs to be included as part of the tag, but this meant that the EpuSession.dm was being searched for in the wrong location. This PR makes sure the Images-Disc is always sent for ensure_dcg_exists in SPA, and then that searches for the dm file in the parent folder. Also ensures dcg exists for all images folders when metadata files are seen.
1 parent 0df33b0 commit 08b9a0e

File tree

3 files changed

+49
-52
lines changed

3 files changed

+49
-52
lines changed

src/murfey/client/context.py

Lines changed: 6 additions & 18 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,7 +93,6 @@ 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
)
@@ -120,28 +122,14 @@ def ensure_dcg_exists(
120122
atlas=Path(partial_path), sample=sample
121123
)
122124

123-
dcg_search_dir = (
125+
dcg_tag = (
124126
str(metadata_source).replace(f"/{environment.visit}", "").replace("//", "/")
125127
)
126-
if collection_type == "tomo":
127-
dcg_tag = dcg_search_dir
128-
else:
129-
dcg_images_dirs = sorted(
130-
Path(dcg_search_dir).glob("Images-Disc*"),
131-
key=lambda x: x.stat().st_ctime,
132-
)
133-
if not dcg_images_dirs:
134-
logger.warning(
135-
f"Cannot find Images-Disc* in {dcg_search_dir}, falling back to Images-Disc1"
136-
)
137-
dcg_images_dirs = [Path(dcg_search_dir) / "Images-Disc1"]
138-
dcg_tag = str(dcg_images_dirs[-1])
139-
140128
dcg_data = {
141129
"experiment_type_id": experiment_type_id,
142130
"tag": dcg_tag,
143131
"atlas": str(
144-
_atlas_destination(environment, metadata_source, token)
132+
_atlas_destination(environment, session_file.parent, token)
145133
/ environment.samples[metadata_source].atlas.parent
146134
/ atlas_xml_path.with_suffix(".jpg").name
147135
).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:

tests/client/test_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_ensure_dcg_exists_spa(mock_capture_post, tmp_path):
9999

100100
ensure_dcg_exists(
101101
collection_type="spa",
102-
metadata_source=metadata_source,
102+
metadata_source=metadata_source / "Images-Disc1",
103103
environment=env,
104104
token="token",
105105
)

0 commit comments

Comments
 (0)