-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstance_environment.py
More file actions
126 lines (107 loc) · 4.08 KB
/
Copy pathinstance_environment.py
File metadata and controls
126 lines (107 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from __future__ import annotations
import itertools
import logging
from itertools import count
from pathlib import Path
from threading import RLock
from typing import Callable, Dict, List, NamedTuple, Optional, Set
from urllib.parse import ParseResult
from pydantic import BaseModel, ConfigDict, field_validator
from pydantic_core.core_schema import ValidationInfo
from murfey.client.watchdir import DirWatcher
logger = logging.getLogger("murfey.client.instance_environment")
MurfeyID = count(1)
MovieID = count(1)
class MovieTracker(NamedTuple):
movie_number: int
motion_correction_uuid: int
class SampleInfo(NamedTuple):
atlas: Path
sample: int
global_env_lock = RLock()
class MurfeyInstanceEnvironment(BaseModel):
url: ParseResult
client_id: int
instrument_name: str
software_versions: Dict[str, str] = {}
sources: List[Path] = []
default_destinations: Dict[Path, str] = {}
destination_registry: Dict[str, str] = {}
watchers: Dict[Path, DirWatcher] = {}
demo: bool = False
id_tag_registry: Dict[str, List[str]] = {
"data_collection_group": [],
"data_collection": [],
"processing_job": [],
"auto_proc_program": [],
}
listeners: Dict[str, Set[Callable]] = {}
data_collection_group_ids: Dict[str, int] = {}
data_collection_ids: Dict[str, int] = {}
processing_job_ids: Dict[str, Dict[str, int]] = {}
autoproc_program_ids: Dict[str, Dict[str, int]] = {}
data_collection_parameters: dict = {}
movies: Dict[Path, MovieTracker] = {}
motion_corrected_movies: Dict[Path, List[str]] = {}
movie_tilt_pair: Dict[Path, str] = {}
tilt_angles: Dict[str, List[List[str]]] = {}
movie_counters: Dict[str, itertools.count] = {}
visit: str = ""
processing_only_mode: bool = False
gain_ref: Optional[Path] = None
superres: bool = True
murfey_session: Optional[int] = None
samples: Dict[Path, SampleInfo] = {}
model_config = ConfigDict(arbitrary_types_allowed=True)
@field_validator("data_collection_group_ids")
def dcg_callback(cls, v, info: ValidationInfo):
with global_env_lock:
for l in info.data.get("listeners", {}).get(
"data_collection_group_ids", []
):
for k in v.keys():
if k not in info.data["id_tag_registry"]["data_collection"]:
l(k)
return v
@field_validator("data_collection_ids")
def dc_callback(cls, v, info: ValidationInfo):
with global_env_lock:
for l in info.data.get("listeners", {}).get("data_collection_ids", []):
for k in v.keys():
if k not in info.data["id_tag_registry"]["processing_job"]:
l(k)
return v
@field_validator("processing_job_ids")
def job_callback(cls, v, info: ValidationInfo):
with global_env_lock:
for l in info.data.get("listeners", {}).get("processing_job_ids", []):
for k in v.keys():
if k not in info.data["id_tag_registry"]["auto_proc_program"]:
l(k, v[k]["ispyb-relion"])
return v
@field_validator("autoproc_program_ids")
def app_callback(cls, v, info: ValidationInfo):
with global_env_lock:
for l in info.data.get("listeners", {}).get("autoproc_program_ids", []):
for k in v.keys():
if v[k].get("em-tomo-preprocess"):
l(k, v[k]["em-tomo-preprocess"])
return v
def clear(self):
self.sources = []
self.default_destinations = {}
for w in self.watchers.values():
w.stop()
self.watchers = {}
self.data_collection_group_ids = {}
self.data_collection_ids = {}
self.processing_job_ids = {}
self.autoproc_program_ids = {}
self.data_collection_parameters = {}
self.movies = {}
self.motion_corrected_movies = {}
self.listeners = {}
self.movie_tilt_pair = {}
self.tilt_angles = {}
self.visit = ""
self.gain_ref = None