Skip to content

Commit 32f8ef7

Browse files
Remove the client-side stashing for tomography (#473)
The client still stores a stash of data collection and processing job calls for tomography before the first mdoc is seen. However, the server already has a preprocess stash for tomography, so the client one is not needed any more. This removes the client stash, and just sends all requests on to the server.
1 parent c1cbe82 commit 32f8ef7

File tree

4 files changed

+17
-161
lines changed

4 files changed

+17
-161
lines changed

src/murfey/client/contexts/tomo.py

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

96-
def _flush_data_collections(self):
97-
logger.info(
98-
f"Flushing {len(self._data_collection_stash)} data collection API calls"
99-
)
100-
for dc_data in self._data_collection_stash:
101-
data = {
102-
**dc_data[2],
103-
**{
104-
k: v
105-
for k, v in dc_data[1].data_collection_parameters.items()
106-
if k != "tag"
107-
},
108-
}
109-
capture_post(dc_data[0], json=data)
110-
self._data_collection_stash = []
111-
112-
def _flush_processing_jobs(self):
113-
logger.info(
114-
f"Flushing {len(self._processing_job_stash.keys())} processing job API calls"
115-
)
116-
for v in self._processing_job_stash.values():
117-
for pd in v:
118-
requests.post(pd[0], json=pd[1])
119-
self._processing_job_stash = {}
120-
12196
def _file_transferred_to(
12297
self, environment: MurfeyInstanceEnvironment, source: Path, file_path: Path
12398
):
@@ -228,8 +203,18 @@ def _add_tilt(
228203
self._tilt_series_sizes[tilt_series] = 0
229204
try:
230205
if environment:
231-
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
232-
data = {
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 = {
233218
"experiment_type": "tomography",
234219
"file_extension": file_path.suffix,
235220
"acquisition_software": self._acquisition_software,
@@ -246,7 +231,7 @@ def _add_tilt(
246231
environment.data_collection_parameters
247232
and environment.data_collection_parameters.get("voltage")
248233
):
249-
data.update(
234+
dc_data.update(
250235
{
251236
"voltage": environment.data_collection_parameters[
252237
"voltage"
@@ -265,51 +250,16 @@ def _add_tilt(
265250
],
266251
}
267252
)
253+
capture_post(dc_url, json=dc_data)
254+
268255
proc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_processing_job"
269-
if (
270-
environment.data_collection_group_ids.get(str(self._basepath))
271-
is None
272-
):
273-
self._data_collection_stash.append((url, environment, data))
274-
self._processing_job_stash[tilt_series] = [
275-
(
276-
proc_url,
277-
{
278-
"tag": tilt_series,
279-
"source": str(self._basepath),
280-
"recipe": "em-tomo-preprocess",
281-
"experiment_type": "tomography",
282-
},
283-
)
284-
]
285-
self._processing_job_stash[tilt_series].append(
286-
(
287-
proc_url,
288-
{
289-
"tag": tilt_series,
290-
"source": str(self._basepath),
291-
"recipe": "em-tomo-align",
292-
"experiment_type": "tomography",
293-
},
294-
)
295-
)
296-
else:
297-
capture_post(url, json=data)
298-
capture_post(
299-
proc_url,
300-
json={
301-
"tag": tilt_series,
302-
"source": str(self._basepath),
303-
"recipe": "em-tomo-preprocess",
304-
"experiment_type": "tomography",
305-
},
306-
)
256+
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
307257
capture_post(
308258
proc_url,
309259
json={
310260
"tag": tilt_series,
311261
"source": str(self._basepath),
312-
"recipe": "em-tomo-align",
262+
"recipe": recipe,
313263
"experiment_type": "tomography",
314264
},
315265
)

src/murfey/client/instance_environment.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class MurfeyInstanceEnvironment(BaseModel):
4141
destination_registry: Dict[str, str] = {}
4242
watchers: Dict[Path, DirWatcher] = {}
4343
demo: bool = False
44-
data_collection_group_ids: Dict[str, int] = {}
4544
data_collection_parameters: dict = {}
4645
movies: Dict[Path, MovieTracker] = {}
4746
movie_tilt_pair: Dict[Path, str] = {}
@@ -64,7 +63,6 @@ def clear(self):
6463
for w in self.watchers.values():
6564
w.stop()
6665
self.watchers = {}
67-
self.data_collection_group_ids = {}
6866
self.data_collection_parameters = {}
6967
self.movies = {}
7068
self.movie_tilt_pair = {}

src/murfey/client/multigrid_control.py

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

379379
source = Path(json["source"])
380-
381-
url = f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self.session_id}/register_data_collection_group"
382-
dcg_data = {
383-
"experiment_type": "tomo",
384-
"experiment_type_id": 36,
385-
"tag": str(source),
386-
}
387-
requests.post(url, json=dcg_data)
388-
389-
data = {
390-
"voltage": json["voltage"],
391-
"pixel_size_on_image": json["pixel_size_on_image"],
392-
"experiment_type": json["experiment_type"],
393-
"image_size_x": json["image_size_x"],
394-
"image_size_y": json["image_size_y"],
395-
"file_extension": json["file_extension"],
396-
"acquisition_software": json["acquisition_software"],
397-
"image_directory": str(self._environment.default_destinations[source]),
398-
"tag": json["tilt_series_tag"],
399-
"source": str(source),
400-
"magnification": json["magnification"],
401-
"total_exposed_dose": json.get("total_exposed_dose"),
402-
"c2aperture": json.get("c2aperture"),
403-
"exposure_time": json.get("exposure_time"),
404-
"slit_width": json.get("slit_width"),
405-
"phase_plate": json.get("phase_plate", False),
406-
}
407-
capture_post(
408-
f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self._environment.murfey_session}/start_data_collection",
409-
json=data,
410-
)
411-
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
412-
capture_post(
413-
f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self._environment.murfey_session}/register_processing_job",
414-
json={
415-
"tag": json["tilt_series_tag"],
416-
"source": str(source),
417-
"recipe": recipe,
418-
},
419-
)
420380
log.info("Registering tomography processing parameters")
421381
if self._environment.data_collection_parameters.get("num_eer_frames"):
422382
eer_response = requests.post(
@@ -440,8 +400,6 @@ def _start_dc(self, json, from_form: bool = False):
440400
f"{self._environment.url.geturl()}/sessions/{self._environment.murfey_session}/tomography_preprocessing_parameters",
441401
json=json,
442402
)
443-
context._flush_data_collections()
444-
context._flush_processing_jobs()
445403
capture_post(
446404
f"{self._environment.url.geturl()}/visits/{self._environment.visit}/{self._environment.murfey_session}/flush_tomography_processing",
447405
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
@@ -475,54 +475,6 @@ def _start_dc(self, json, from_form: bool = False):
475475
context = self.analysers[source]._context
476476
if isinstance(context, TomographyContext):
477477
source = Path(json["source"])
478-
url = f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_data_collection_group"
479-
dcg_data = {
480-
"experiment_type": "tomo",
481-
"experiment_type_id": 36,
482-
"tag": str(source),
483-
"atlas": (
484-
str(self._environment.samples[source].atlas)
485-
if self._environment.samples.get(source)
486-
else ""
487-
),
488-
"sample": (
489-
self._environment.samples[source].sample
490-
if self._environment.samples.get(source)
491-
else None
492-
),
493-
}
494-
capture_post(url, json=dcg_data)
495-
data = {
496-
"voltage": json["voltage"],
497-
"pixel_size_on_image": json["pixel_size_on_image"],
498-
"experiment_type": json["experiment_type"],
499-
"image_size_x": json["image_size_x"],
500-
"image_size_y": json["image_size_y"],
501-
"file_extension": json["file_extension"],
502-
"acquisition_software": json["acquisition_software"],
503-
"image_directory": str(self._environment.default_destinations[source]),
504-
"tag": json["tilt_series_tag"],
505-
"source": str(source),
506-
"magnification": json["magnification"],
507-
"total_exposed_dose": json.get("total_exposed_dose"),
508-
"c2aperture": json.get("c2aperture"),
509-
"exposure_time": json.get("exposure_time"),
510-
"slit_width": json.get("slit_width"),
511-
"phase_plate": json.get("phase_plate", False),
512-
}
513-
capture_post(
514-
f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/start_data_collection",
515-
json=data,
516-
)
517-
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
518-
capture_post(
519-
f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_processing_job",
520-
json={
521-
"tag": json["tilt_series_tag"],
522-
"source": str(source),
523-
"recipe": recipe,
524-
},
525-
)
526478
log.info("Registering tomography processing parameters")
527479
if self.app._environment.data_collection_parameters.get("num_eer_frames"):
528480
eer_response = requests.post(
@@ -546,8 +498,6 @@ def _start_dc(self, json, from_form: bool = False):
546498
f"{self.app._environment.url.geturl()}/sessions/{self.app._environment.murfey_session}/tomography_preprocessing_parameters",
547499
json=json,
548500
)
549-
context._flush_data_collections()
550-
context._flush_processing_jobs()
551501
capture_post(
552502
f"{self.app._environment.url.geturl()}/visits/{self._visit}/{self.app._environment.murfey_session}/flush_tomography_processing",
553503
json={"rsync_source": str(source)},

0 commit comments

Comments
 (0)