Skip to content

Commit 8adb4da

Browse files
committed
Fixes for posting metadata in the right order
1 parent 6ef2ef6 commit 8adb4da

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

src/murfey/client/contexts/tomo_metadata.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def post_transfer(
5555
with open(transferred_file, "r") as session_xml:
5656
session_data = xmltodict.parse(session_xml.read())
5757

58-
windows_path = session_data["TomographySession"]["AtlasId"]["#text"]
58+
windows_path = session_data["TomographySession"]["AtlasId"]
5959
logger.info(f"Windows path to atlas metadata found: {windows_path}")
6060
visit_index = windows_path.split("\\").index(environment.visit)
6161
partial_path = "/".join(windows_path.split("\\")[visit_index + 1 :])
@@ -97,28 +97,27 @@ def post_transfer(
9797
else:
9898
logger.warning(f"Sample could not be identified for {transferred_file}")
9999
return
100-
if source:
101-
environment.samples[source] = SampleInfo(
102-
atlas=Path(partial_path), sample=sample
103-
)
104-
url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
105-
dcg_tag = "/".join(
106-
p for p in transferred_file.parent.parts if p != environment.visit
107-
)
108-
dcg_data = {
109-
"experiment_type": "tomo",
110-
"experiment_type_id": 36,
111-
"tag": dcg_tag,
112-
"atlas": str(
113-
_atlas_destination(environment, source, transferred_file)
114-
/ environment.samples[source].atlas.parent
115-
/ atlas_xml_path.with_suffix(".jpg").name
116-
),
117-
"sample": environment.samples[source].sample,
118-
"atlas_pixel_size": atlas_pixel_size,
119-
"atlas_binning": atlas_binning,
120-
}
121-
capture_post(url, json=dcg_data)
100+
environment.samples[source] = SampleInfo(
101+
atlas=Path(partial_path), sample=sample
102+
)
103+
url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
104+
dcg_tag = "/".join(
105+
p for p in transferred_file.parent.parts if p != environment.visit
106+
).replace("//", "/")
107+
dcg_data = {
108+
"experiment_type": "tomo",
109+
"experiment_type_id": 36,
110+
"tag": dcg_tag,
111+
"atlas": str(
112+
_atlas_destination(environment, source, transferred_file)
113+
/ environment.samples[source].atlas.parent
114+
/ atlas_xml_path.with_suffix(".jpg").name
115+
),
116+
"sample": environment.samples[source].sample,
117+
"atlas_pixel_size": atlas_pixel_size,
118+
"atlas_binning": atlas_binning,
119+
}
120+
capture_post(url, json=dcg_data)
122121

123122
elif transferred_file.name == "SearchMap.xml" and environment:
124123
logger.info("Tomography session search map xml found")

src/murfey/server/api/workflow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def register_dc_group(
108108
dcg_murfey[0].atlas_pixel_size = (
109109
dcg_params.atlas_pixel_size or dcg_murfey[0].atlas_pixel_size
110110
)
111+
dcg_murfey[0].atlas_binning = (
112+
dcg_params.atlas_binning or dcg_murfey[0].atlas_binning
113+
)
111114

112115
if _transport_object:
113116
if dcg_murfey[0].atlas_id is not None:
@@ -148,6 +151,7 @@ def register_dc_group(
148151
"atlas": dcg_params.atlas,
149152
"sample": dcg_params.sample,
150153
"atlas_pixel_size": dcg_params.atlas_pixel_size,
154+
"atlas_binning": dcg_params.atlas_binning,
151155
}
152156

153157
if _transport_object:

src/murfey/util/tomo_metadata.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def register_search_map_in_database(
9595
search_map.width = search_map_params.width or search_map.width
9696
if _transport_object:
9797
_transport_object.do_update_search_map(search_map.id, search_map_params)
98-
except Exception:
98+
except Exception as e:
99+
logger.info(f"Registering new search map due to {e}", exc_info=True)
99100
if _transport_object:
100101
sm_ispyb_response = _transport_object.do_insert_search_map(
101102
dcg.atlas_id, search_map_params
@@ -140,16 +141,13 @@ def register_search_map_in_database(
140141
height=search_map_params.height,
141142
width=search_map_params.width,
142143
)
143-
murfey_db.add(search_map)
144-
murfey_db.commit()
145144

146145
murfey_session = murfey_db.exec(
147146
select(MurfeySession).where(MurfeySession.id == session_id)
148147
).one()
149148
machine_config = get_machine_config(instrument_name=murfey_session.instrument_name)[
150149
murfey_session.instrument_name
151150
]
152-
153151
if all(
154152
[
155153
search_map.reference_matrix_m11,
@@ -209,15 +207,22 @@ def register_search_map_in_database(
209207
search_map_params.width_on_atlas = int(
210208
search_map.width * search_map.pixel_size / dcg.atlas_pixel_size
211209
)
212-
search_map_params.x_location = corrected_vector[0] / dcg.atlas_pixel_size + 2003
213-
search_map_params.y_location = corrected_vector[1] / dcg.atlas_pixel_size + 2003
210+
search_map_params.x_location = float(
211+
corrected_vector[0] / dcg.atlas_pixel_size + 2003
212+
)
213+
search_map_params.y_location = float(
214+
corrected_vector[1] / dcg.atlas_pixel_size + 2003
215+
)
214216
search_map.x_location = search_map_params.x_location
215217
search_map.y_location = search_map_params.y_location
216218
if _transport_object:
217219
_transport_object.do_update_search_map(search_map.id, search_map_params)
218220
else:
219221
logger.info(
220-
f"Unable to register search map {sanitise(search_map_name)} position yet"
222+
f"Unable to register search map {sanitise(search_map_name)} position yet: "
223+
f"stage {search_map_params.x_stage_position}, "
224+
f"width {search_map_params.width}, "
225+
f"atlas pixel size {dcg.atlas_pixel_size}"
221226
)
222227
murfey_db.add(search_map)
223228
murfey_db.commit()
@@ -327,16 +332,16 @@ def register_batch_position_in_database(
327332
search_map.height / 2,
328333
]
329334
tilt_series.x_location = (
330-
centre_batch_pixel[0]
331-
- BatchPositionParameters.x_beamshift / search_map.pixel_size
335+
centre_batch_pixel[0] - batch_parameters.x_beamshift / search_map.pixel_size
332336
)
333337
tilt_series.y_location = (
334-
centre_batch_pixel[1]
335-
- BatchPositionParameters.y_beamshift / search_map.pixel_size
338+
centre_batch_pixel[1] - batch_parameters.y_beamshift / search_map.pixel_size
336339
)
337340
else:
338341
logger.warning(
339-
f"No search map information available to register position of {sanitise(batch_name)}"
342+
f"Incomplete search map for position of {sanitise(batch_name)}: "
343+
f"stage {search_map.x_stage_position}, "
344+
f"width {search_map.width}, "
340345
)
341346
murfey_db.add(tilt_series)
342347
murfey_db.commit()

0 commit comments

Comments
 (0)