Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 17 additions & 67 deletions src/murfey/client/contexts/tomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,6 @@ def __init__(self, acquisition_software: str, basepath: Path):
self._processing_job_stash: dict = {}
self._lock: RLock = RLock()

def _flush_data_collections(self):
logger.info(
f"Flushing {len(self._data_collection_stash)} data collection API calls"
)
for dc_data in self._data_collection_stash:
data = {
**dc_data[2],
**{
k: v
for k, v in dc_data[1].data_collection_parameters.items()
if k != "tag"
},
}
capture_post(dc_data[0], json=data)
self._data_collection_stash = []

def _flush_processing_jobs(self):
logger.info(
f"Flushing {len(self._processing_job_stash.keys())} processing job API calls"
)
for v in self._processing_job_stash.values():
for pd in v:
requests.post(pd[0], json=pd[1])
self._processing_job_stash = {}

def _file_transferred_to(
self, environment: MurfeyInstanceEnvironment, source: Path, file_path: Path
):
Expand Down Expand Up @@ -227,8 +202,18 @@ def _add_tilt(
self._tilt_series_sizes[tilt_series] = 0
try:
if environment:
url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
data = {
dcg_url = f"{str(environment.url.geturl())}/visits/{str(environment.visit)}/{environment.murfey_session}/register_data_collection_group"
dcg_data = {
"experiment_type": "tomo",
"experiment_type_id": 36,
"tag": str(self._basepath),
"atlas": "",
"sample": None,
}
capture_post(dcg_url, json=dcg_data)

dc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/start_data_collection"
dc_data = {
"experiment_type": "tomography",
"file_extension": file_path.suffix,
"acquisition_software": self._acquisition_software,
Expand All @@ -245,7 +230,7 @@ def _add_tilt(
environment.data_collection_parameters
and environment.data_collection_parameters.get("voltage")
):
data.update(
dc_data.update(
{
"voltage": environment.data_collection_parameters[
"voltage"
Expand All @@ -264,51 +249,16 @@ def _add_tilt(
],
}
)
capture_post(dc_url, json=dc_data)

proc_url = f"{str(environment.url.geturl())}/visits/{environment.visit}/{environment.murfey_session}/register_processing_job"
if (
environment.data_collection_group_ids.get(str(self._basepath))
is None
):
self._data_collection_stash.append((url, environment, data))
self._processing_job_stash[tilt_series] = [
(
proc_url,
{
"tag": tilt_series,
"source": str(self._basepath),
"recipe": "em-tomo-preprocess",
"experiment_type": "tomography",
},
)
]
self._processing_job_stash[tilt_series].append(
(
proc_url,
{
"tag": tilt_series,
"source": str(self._basepath),
"recipe": "em-tomo-align",
"experiment_type": "tomography",
},
)
)
else:
capture_post(url, json=data)
capture_post(
proc_url,
json={
"tag": tilt_series,
"source": str(self._basepath),
"recipe": "em-tomo-preprocess",
"experiment_type": "tomography",
},
)
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
capture_post(
proc_url,
json={
"tag": tilt_series,
"source": str(self._basepath),
"recipe": "em-tomo-align",
"recipe": recipe,
"experiment_type": "tomography",
},
)
Expand Down
2 changes: 0 additions & 2 deletions src/murfey/client/instance_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class MurfeyInstanceEnvironment(BaseModel):
destination_registry: Dict[str, str] = {}
watchers: Dict[Path, DirWatcher] = {}
demo: bool = False
data_collection_group_ids: Dict[str, int] = {}
data_collection_parameters: dict = {}
movies: Dict[Path, MovieTracker] = {}
movie_tilt_pair: Dict[Path, str] = {}
Expand All @@ -64,7 +63,6 @@ def clear(self):
for w in self.watchers.values():
w.stop()
self.watchers = {}
self.data_collection_group_ids = {}
self.data_collection_parameters = {}
self.movies = {}
self.movie_tilt_pair = {}
Expand Down
42 changes: 0 additions & 42 deletions src/murfey/client/multigrid_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,46 +369,6 @@ def _start_dc(self, json, from_form: bool = False):
)

source = Path(json["source"])

url = f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self.session_id}/register_data_collection_group"
dcg_data = {
"experiment_type": "tomo",
"experiment_type_id": 36,
"tag": str(source),
}
requests.post(url, json=dcg_data)

data = {
"voltage": json["voltage"],
"pixel_size_on_image": json["pixel_size_on_image"],
"experiment_type": json["experiment_type"],
"image_size_x": json["image_size_x"],
"image_size_y": json["image_size_y"],
"file_extension": json["file_extension"],
"acquisition_software": json["acquisition_software"],
"image_directory": str(self._environment.default_destinations[source]),
"tag": json["tilt_series_tag"],
"source": str(source),
"magnification": json["magnification"],
"total_exposed_dose": json.get("total_exposed_dose"),
"c2aperture": json.get("c2aperture"),
"exposure_time": json.get("exposure_time"),
"slit_width": json.get("slit_width"),
"phase_plate": json.get("phase_plate", False),
}
capture_post(
f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self._environment.murfey_session}/start_data_collection",
json=data,
)
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
capture_post(
f"{str(self._environment.url.geturl())}/visits/{str(self._environment.visit)}/{self._environment.murfey_session}/register_processing_job",
json={
"tag": json["tilt_series_tag"],
"source": str(source),
"recipe": recipe,
},
)
log.info("Registering tomography processing parameters")
if self._environment.data_collection_parameters.get("num_eer_frames"):
eer_response = requests.post(
Expand All @@ -432,8 +392,6 @@ def _start_dc(self, json, from_form: bool = False):
f"{self._environment.url.geturl()}/sessions/{self._environment.murfey_session}/tomography_preprocessing_parameters",
json=json,
)
context._flush_data_collections()
context._flush_processing_jobs()
capture_post(
f"{self._environment.url.geturl()}/visits/{self._environment.visit}/{self._environment.murfey_session}/flush_tomography_processing",
json={"rsync_source": str(source)},
Expand Down
50 changes: 0 additions & 50 deletions src/murfey/client/tui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,54 +474,6 @@ def _start_dc(self, json, from_form: bool = False):
context = self.analysers[source]._context
if isinstance(context, TomographyContext):
source = Path(json["source"])
url = f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_data_collection_group"
dcg_data = {
"experiment_type": "tomo",
"experiment_type_id": 36,
"tag": str(source),
"atlas": (
str(self._environment.samples[source].atlas)
if self._environment.samples.get(source)
else ""
),
"sample": (
self._environment.samples[source].sample
if self._environment.samples.get(source)
else None
),
}
capture_post(url, json=dcg_data)
data = {
"voltage": json["voltage"],
"pixel_size_on_image": json["pixel_size_on_image"],
"experiment_type": json["experiment_type"],
"image_size_x": json["image_size_x"],
"image_size_y": json["image_size_y"],
"file_extension": json["file_extension"],
"acquisition_software": json["acquisition_software"],
"image_directory": str(self._environment.default_destinations[source]),
"tag": json["tilt_series_tag"],
"source": str(source),
"magnification": json["magnification"],
"total_exposed_dose": json.get("total_exposed_dose"),
"c2aperture": json.get("c2aperture"),
"exposure_time": json.get("exposure_time"),
"slit_width": json.get("slit_width"),
"phase_plate": json.get("phase_plate", False),
}
capture_post(
f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/start_data_collection",
json=data,
)
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
capture_post(
f"{str(self._url.geturl())}/visits/{str(self._visit)}/{self._environment.murfey_session}/register_processing_job",
json={
"tag": json["tilt_series_tag"],
"source": str(source),
"recipe": recipe,
},
)
log.info("Registering tomography processing parameters")
if self.app._environment.data_collection_parameters.get("num_eer_frames"):
eer_response = requests.post(
Expand All @@ -545,8 +497,6 @@ def _start_dc(self, json, from_form: bool = False):
f"{self.app._environment.url.geturl()}/sessions/{self.app._environment.murfey_session}/tomography_preprocessing_parameters",
json=json,
)
context._flush_data_collections()
context._flush_processing_jobs()
capture_post(
f"{self.app._environment.url.geturl()}/visits/{self._visit}/{self.app._environment.murfey_session}/flush_tomography_processing",
json={"rsync_source": str(source)},
Expand Down