Skip to content

Commit 8daaa4f

Browse files
committed
Remove the client-side data collection stash
1 parent 51fd6ad commit 8daaa4f

File tree

3 files changed

+33
-167
lines changed

3 files changed

+33
-167
lines changed

src/murfey/client/contexts/tomo.py

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,6 @@ def __init__(self, acquisition_software: str, basepath: Path):
9292
self._processing_job_stash: dict = {}
9393
self._lock: RLock = RLock()
9494

95-
def _flush_data_collections(self):
96-
logger.info(
97-
f"Flushing {len(self._data_collection_stash)} data collection API calls"
98-
)
99-
for dc_data in self._data_collection_stash:
100-
data = {
101-
**dc_data[2],
102-
**{
103-
k: v
104-
for k, v in dc_data[1].data_collection_parameters.items()
105-
if k != "tag"
106-
},
107-
}
108-
capture_post(dc_data[0], json=data)
109-
self._data_collection_stash = []
110-
111-
def _flush_processing_jobs(self):
112-
logger.info(
113-
f"Flushing {len(self._processing_job_stash.keys())} processing job API calls"
114-
)
115-
for v in self._processing_job_stash.values():
116-
for pd in v:
117-
requests.post(pd[0], json=pd[1])
118-
self._processing_job_stash = {}
119-
12095
def _file_transferred_to(
12196
self, environment: MurfeyInstanceEnvironment, source: Path, file_path: Path
12297
):
@@ -227,8 +202,18 @@ def _add_tilt(
227202
self._tilt_series_sizes[tilt_series] = 0
228203
try:
229204
if environment:
230-
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
231-
data = {
205+
dcg_url = f"{str(environment.url.geturl())}/visits/{str(environment.visit)}/{environment.murfey_session}/register_data_collection_group"
206+
dcg_data = {
207+
"experiment_type": "tomo",
208+
"experiment_type_id": 36,
209+
"tag": str(self._basepath),
210+
"atlas": "",
211+
"sample": None,
212+
}
213+
capture_post(dcg_url, json=dcg_data)
214+
215+
dc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
216+
dc_data = {
232217
"experiment_type": "tomography",
233218
"file_extension": file_path.suffix,
234219
"acquisition_software": self._acquisition_software,
@@ -245,7 +230,7 @@ def _add_tilt(
245230
environment.data_collection_parameters
246231
and environment.data_collection_parameters.get("voltage")
247232
):
248-
data.update(
233+
dc_data.update(
249234
{
250235
"voltage": environment.data_collection_parameters[
251236
"voltage"
@@ -264,54 +249,27 @@ def _add_tilt(
264249
],
265250
}
266251
)
252+
capture_post(dc_url, json=dc_data)
253+
267254
proc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_processing_job"
268-
if (
269-
environment.data_collection_group_ids.get(str(self._basepath))
270-
is None
271-
):
272-
self._data_collection_stash.append((url, environment, data))
273-
self._processing_job_stash[tilt_series] = [
274-
(
275-
proc_url,
276-
{
277-
"tag": tilt_series,
278-
"source": str(self._basepath),
279-
"recipe": "em-tomo-preprocess",
280-
"experiment_type": "tomography",
281-
},
282-
)
283-
]
284-
self._processing_job_stash[tilt_series].append(
285-
(
286-
proc_url,
287-
{
288-
"tag": tilt_series,
289-
"source": str(self._basepath),
290-
"recipe": "em-tomo-align",
291-
"experiment_type": "tomography",
292-
},
293-
)
294-
)
295-
else:
296-
capture_post(url, json=data)
297-
capture_post(
298-
proc_url,
299-
json={
300-
"tag": tilt_series,
301-
"source": str(self._basepath),
302-
"recipe": "em-tomo-preprocess",
303-
"experiment_type": "tomography",
304-
},
305-
)
306-
capture_post(
307-
proc_url,
308-
json={
309-
"tag": tilt_series,
310-
"source": str(self._basepath),
311-
"recipe": "em-tomo-align",
312-
"experiment_type": "tomography",
313-
},
314-
)
255+
capture_post(
256+
proc_url,
257+
json={
258+
"tag": tilt_series,
259+
"source": str(self._basepath),
260+
"recipe": "em-tomo-preprocess",
261+
"experiment_type": "tomography",
262+
},
263+
)
264+
capture_post(
265+
proc_url,
266+
json={
267+
"tag": tilt_series,
268+
"source": str(self._basepath),
269+
"recipe": "em-tomo-align",
270+
"experiment_type": "tomography",
271+
},
272+
)
315273

316274
except Exception as e:
317275
logger.error(f"ERROR {e}, {environment.data_collection_parameters}")

src/murfey/client/multigrid_control.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -369,46 +369,6 @@ def _start_dc(self, json, from_form: bool = False):
369369
)
370370

371371
source = Path(json["source"])
372-
373-
url = f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self.session_id}/register_data_collection_group"
374-
dcg_data = {
375-
"experiment_type": "tomo",
376-
"experiment_type_id": 36,
377-
"tag": str(source),
378-
}
379-
requests.post(url, json=dcg_data)
380-
381-
data = {
382-
"voltage": json["voltage"],
383-
"pixel_size_on_image": json["pixel_size_on_image"],
384-
"experiment_type": json["experiment_type"],
385-
"image_size_x": json["image_size_x"],
386-
"image_size_y": json["image_size_y"],
387-
"file_extension": json["file_extension"],
388-
"acquisition_software": json["acquisition_software"],
389-
"image_directory": str(self._environment.default_destinations[source]),
390-
"tag": json["tilt_series_tag"],
391-
"source": str(source),
392-
"magnification": json["magnification"],
393-
"total_exposed_dose": json.get("total_exposed_dose"),
394-
"c2aperture": json.get("c2aperture"),
395-
"exposure_time": json.get("exposure_time"),
396-
"slit_width": json.get("slit_width"),
397-
"phase_plate": json.get("phase_plate", False),
398-
}
399-
capture_post(
400-
f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self._environment.murfey_session}/start_data_collection",
401-
json=data,
402-
)
403-
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
404-
capture_post(
405-
f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self._environment.murfey_session}/register_processing_job",
406-
json={
407-
"tag": json["tilt_series_tag"],
408-
"source": str(source),
409-
"recipe": recipe,
410-
},
411-
)
412372
log.info("Registering tomography processing parameters")
413373
if self._environment.data_collection_parameters.get("num_eer_frames"):
414374
eer_response = requests.post(
@@ -432,8 +392,6 @@ def _start_dc(self, json, from_form: bool = False):
432392
f"{self._environment.url.geturl()}/sessions/{self._environment.murfey_session}/tomography_preprocessing_parameters",
433393
json=json,
434394
)
435-
context._flush_data_collections()
436-
context._flush_processing_jobs()
437395
capture_post(
438396
f"{self._environment.url.geturl()}/visits/{self._environment.visit}/{self._environment.murfey_session}/flush_tomography_processing",
439397
json={"rsync_source": str(source)},

src/murfey/client/tui/app.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -474,54 +474,6 @@ def _start_dc(self, json, from_form: bool = False):
474474
context = self.analysers[source]._context
475475
if isinstance(context, TomographyContext):
476476
source = Path(json["source"])
477-
url = f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_data_collection_group"
478-
dcg_data = {
479-
"experiment_type": "tomo",
480-
"experiment_type_id": 36,
481-
"tag": str(source),
482-
"atlas": (
483-
str(self._environment.samples[source].atlas)
484-
if self._environment.samples.get(source)
485-
else ""
486-
),
487-
"sample": (
488-
self._environment.samples[source].sample
489-
if self._environment.samples.get(source)
490-
else None
491-
),
492-
}
493-
capture_post(url, json=dcg_data)
494-
data = {
495-
"voltage": json["voltage"],
496-
"pixel_size_on_image": json["pixel_size_on_image"],
497-
"experiment_type": json["experiment_type"],
498-
"image_size_x": json["image_size_x"],
499-
"image_size_y": json["image_size_y"],
500-
"file_extension": json["file_extension"],
501-
"acquisition_software": json["acquisition_software"],
502-
"image_directory": str(self._environment.default_destinations[source]),
503-
"tag": json["tilt_series_tag"],
504-
"source": str(source),
505-
"magnification": json["magnification"],
506-
"total_exposed_dose": json.get("total_exposed_dose"),
507-
"c2aperture": json.get("c2aperture"),
508-
"exposure_time": json.get("exposure_time"),
509-
"slit_width": json.get("slit_width"),
510-
"phase_plate": json.get("phase_plate", False),
511-
}
512-
capture_post(
513-
f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/start_data_collection",
514-
json=data,
515-
)
516-
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
517-
capture_post(
518-
f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_processing_job",
519-
json={
520-
"tag": json["tilt_series_tag"],
521-
"source": str(source),
522-
"recipe": recipe,
523-
},
524-
)
525477
log.info("Registering tomography processing parameters")
526478
if self.app._environment.data_collection_parameters.get("num_eer_frames"):
527479
eer_response = requests.post(
@@ -545,8 +497,6 @@ def _start_dc(self, json, from_form: bool = False):
545497
f"{self.app._environment.url.geturl()}/sessions/{self.app._environment.murfey_session}/tomography_preprocessing_parameters",
546498
json=json,
547499
)
548-
context._flush_data_collections()
549-
context._flush_processing_jobs()
550500
capture_post(
551501
f"{self.app._environment.url.geturl()}/visits/{self._visit}/{self.app._environment.murfey_session}/flush_tomography_processing",
552502
json={"rsync_source": str(source)},

0 commit comments

Comments
 (0)