|
3 | 3 | from cryoemservices. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +from __future__ import annotations |
6 | 7 |
|
7 | | -def submit_cluster_request(): |
| 8 | +from pathlib import Path |
| 9 | +from typing import Literal, Optional |
| 10 | + |
| 11 | +from murfey.util.config import get_machine_config |
| 12 | + |
| 13 | +try: |
| 14 | + from murfey.server.ispyb import TransportManager # Session |
| 15 | +except AttributeError: |
| 16 | + pass # Ignore if ISPyB credentials environment variable not set |
| 17 | + |
| 18 | + |
| 19 | +def submit_cluster_request( |
| 20 | + # Session parameters |
| 21 | + session_id: int, |
| 22 | + instrument_name: str, |
| 23 | + # Processing parameters |
| 24 | + series_name: str, |
| 25 | + images: list[Path], |
| 26 | + metadata: Path, |
| 27 | + # Optional processing parameters |
| 28 | + align_self: Optional[str] = None, |
| 29 | + flatten: Optional[Literal["min", "max", "mean"]] = "mean", |
| 30 | + align_across: Optional[str] = None, |
| 31 | + # Optional session parameters |
| 32 | + messenger: Optional[TransportManager] = None, |
| 33 | +): |
| 34 | + if not messenger: |
| 35 | + raise Exception("Unable to find transport manager") |
| 36 | + |
| 37 | + # Load feedback queue |
| 38 | + machine_config = get_machine_config()[instrument_name] |
| 39 | + feedback_queue: str = machine_config.feedback_queue |
| 40 | + |
| 41 | + # Work out session directory from file path |
| 42 | + processed_folder = machine_config.processed_directory_name |
| 43 | + if not images: |
| 44 | + raise ValueError(f"No image files have been provided for {series_name!r}") |
| 45 | + reference_file = images[0] |
| 46 | + path_parts = list(reference_file.parts) |
| 47 | + path_parts[0] = "" if path_parts[0] == "/" else path_parts[0] |
| 48 | + try: |
| 49 | + root_index = path_parts.index(processed_folder) |
| 50 | + except ValueError: |
| 51 | + raise ValueError( |
| 52 | + f"The processed directory {processed_folder!r} could not be found in the " |
| 53 | + f"file path for {str(reference_file)!r}" |
| 54 | + ) |
| 55 | + session_dir = Path("/".join(path_parts[:root_index])) |
| 56 | + |
| 57 | + # Submit message to cryoemservices |
| 58 | + messenger.send( |
| 59 | + "processing_recipe", |
| 60 | + { |
| 61 | + "recipes": ["clem-align-and-merge"], |
| 62 | + "parameters": { |
| 63 | + # Job parameters |
| 64 | + "series_name": series_name, |
| 65 | + "images": [str(file) for file in images], |
| 66 | + "metadata": str(metadata), |
| 67 | + "align_self": ("null" if align_self is None else align_self), |
| 68 | + "flatten": ("null" if flatten is None else flatten), |
| 69 | + "align_across": ("null" if align_across is None else align_across), |
| 70 | + # Other recipe parameters |
| 71 | + "session_dir": str(session_dir), |
| 72 | + "session_id": session_id, |
| 73 | + "job_name": series_name, |
| 74 | + "feedback_queue": feedback_queue, |
| 75 | + }, |
| 76 | + }, |
| 77 | + new_connection=True, |
| 78 | + ) |
8 | 79 | return True |
0 commit comments