Skip to content

Commit f9991a9

Browse files
Restore code to register tomo data collections post mdoc (#498)
1 parent ab7af90 commit f9991a9

File tree

3 files changed

+100
-64
lines changed

3 files changed

+100
-64
lines changed

src/murfey/client/contexts/tomo.py

Lines changed: 88 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,84 @@ def __init__(self, acquisition_software: str, basepath: Path):
9393
self._processing_job_stash: dict = {}
9494
self._lock: RLock = RLock()
9595

96+
def register_tomography_data_collections(
97+
self,
98+
file_extension: str,
99+
image_directory: str,
100+
environment: MurfeyInstanceEnvironment | None = None,
101+
):
102+
if not environment:
103+
logger.error(
104+
"No environment passed to register tomography data collections"
105+
)
106+
return
107+
try:
108+
dcg_url = f"{str(environment.url.geturl())}/visits/{str(environment.visit)}/{environment.murfey_session}/register_data_collection_group"
109+
dcg_data = {
110+
"experiment_type": "tomo",
111+
"experiment_type_id": 36,
112+
"tag": str(self._basepath),
113+
"atlas": "",
114+
"sample": None,
115+
}
116+
capture_post(dcg_url, json=dcg_data)
117+
118+
for tilt_series in self._tilt_series.keys():
119+
dc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
120+
dc_data = {
121+
"experiment_type": "tomography",
122+
"file_extension": file_extension,
123+
"acquisition_software": self._acquisition_software,
124+
"image_directory": image_directory,
125+
"data_collection_tag": tilt_series,
126+
"source": str(self._basepath),
127+
"tag": tilt_series,
128+
}
129+
if (
130+
environment.data_collection_parameters
131+
and environment.data_collection_parameters.get("voltage")
132+
):
133+
# Once mdoc parameters are known register processing jobs
134+
dc_data.update(
135+
{
136+
"voltage": environment.data_collection_parameters[
137+
"voltage"
138+
],
139+
"pixel_size_on_image": environment.data_collection_parameters[
140+
"pixel_size_on_image"
141+
],
142+
"image_size_x": environment.data_collection_parameters[
143+
"image_size_x"
144+
],
145+
"image_size_y": environment.data_collection_parameters[
146+
"image_size_y"
147+
],
148+
"magnification": environment.data_collection_parameters[
149+
"magnification"
150+
],
151+
}
152+
)
153+
capture_post(dc_url, json=dc_data)
154+
155+
proc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_processing_job"
156+
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
157+
capture_post(
158+
proc_url,
159+
json={
160+
"tag": tilt_series,
161+
"source": str(self._basepath),
162+
"recipe": recipe,
163+
"experiment_type": "tomography",
164+
},
165+
)
166+
else:
167+
logger.info(
168+
"Cannot register data collection yet as no values from mdoc"
169+
)
170+
171+
except Exception as e:
172+
logger.error(f"ERROR {e}, {environment.data_collection_parameters}")
173+
96174
def _file_transferred_to(
97175
self, environment: MurfeyInstanceEnvironment, source: Path, file_path: Path
98176
):
@@ -201,71 +279,17 @@ def _add_tilt(
201279
capture_post(ts_url, json=ts_data)
202280
if not self._tilt_series_sizes.get(tilt_series):
203281
self._tilt_series_sizes[tilt_series] = 0
204-
try:
205-
if environment:
206-
dcg_url = f"{str(environment.url.geturl())}/visits/{str(environment.visit)}/{environment.murfey_session}/register_data_collection_group"
207-
dcg_data = {
208-
"experiment_type": "tomo",
209-
"experiment_type_id": 36,
210-
"tag": str(self._basepath),
211-
"atlas": "",
212-
"sample": None,
213-
}
214-
capture_post(dcg_url, json=dcg_data)
215-
216-
dc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
217-
dc_data = {
218-
"experiment_type": "tomography",
219-
"file_extension": file_path.suffix,
220-
"acquisition_software": self._acquisition_software,
221-
"image_directory": str(
222-
environment.default_destinations.get(
223-
file_path.parent, file_path.parent
224-
)
225-
),
226-
"data_collection_tag": tilt_series,
227-
"source": str(self._basepath),
228-
"tag": tilt_series,
229-
}
230-
if (
231-
environment.data_collection_parameters
232-
and environment.data_collection_parameters.get("voltage")
233-
):
234-
dc_data.update(
235-
{
236-
"voltage": environment.data_collection_parameters[
237-
"voltage"
238-
],
239-
"pixel_size_on_image": environment.data_collection_parameters[
240-
"pixel_size_on_image"
241-
],
242-
"image_size_x": environment.data_collection_parameters[
243-
"image_size_x"
244-
],
245-
"image_size_y": environment.data_collection_parameters[
246-
"image_size_y"
247-
],
248-
"magnification": environment.data_collection_parameters[
249-
"magnification"
250-
],
251-
}
252-
)
253-
capture_post(dc_url, json=dc_data)
254-
255-
proc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_processing_job"
256-
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
257-
capture_post(
258-
proc_url,
259-
json={
260-
"tag": tilt_series,
261-
"source": str(self._basepath),
262-
"recipe": recipe,
263-
"experiment_type": "tomography",
264-
},
265-
)
266282

267-
except Exception as e:
268-
logger.error(f"ERROR {e}, {environment.data_collection_parameters}")
283+
# Will register processing jobs for all tilt series except the first one
284+
self.register_tomography_data_collections(
285+
file_extension=file_path.suffix,
286+
image_directory=str(
287+
environment.default_destinations.get(
288+
file_path.parent, file_path.parent
289+
)
290+
),
291+
environment=environment,
292+
)
269293
else:
270294
if file_path not in self._tilt_series[tilt_series]:
271295
for p in self._tilt_series[tilt_series]:

src/murfey/client/multigrid_control.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ def _start_dc(self, json, from_form: bool = False):
377377
)
378378

379379
source = Path(json["source"])
380+
context.register_tomography_data_collections(
381+
file_extension=json["file_extension"],
382+
image_directory=str(self._environment.default_destinations[source]),
383+
environment=self._environment,
384+
)
385+
380386
log.info("Registering tomography processing parameters")
381387
if self._environment.data_collection_parameters.get("num_eer_frames"):
382388
eer_response = requests.post(

src/murfey/client/tui/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ def _start_dc(self, json, from_form: bool = False):
478478
context = self.analysers[source]._context
479479
if isinstance(context, TomographyContext):
480480
source = Path(json["source"])
481+
context.register_tomography_data_collections(
482+
file_extension=json["file_extension"],
483+
image_directory=str(self._environment.default_destinations[source]),
484+
environment=self._environment,
485+
)
486+
481487
log.info("Registering tomography processing parameters")
482488
if self.app._environment.data_collection_parameters.get("num_eer_frames"):
483489
eer_response = requests.post(

0 commit comments

Comments
 (0)