Skip to content

Commit 9975f24

Browse files
authored
Pass machine config from Analyser and MultigridController to Context and related functions (#761)
* Pass machine config from the Analyser to the Context * Pass 'rsync_basepath' directly to the '_file_transferred_to' and '_atlas_destination' functions * Pass machine config directly to the 'ensure_dcg_exists' function * Fixed broken tests
1 parent b78c905 commit 9975f24

16 files changed

Lines changed: 235 additions & 122 deletions

File tree

src/murfey/client/analyser.py

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ def _find_context(self, file_path: Path) -> bool:
145145
)
146146
)
147147
):
148-
self._context = CLEMContext("leica", self._basepath, self._token)
148+
self._context = CLEMContext(
149+
"leica",
150+
self._basepath,
151+
self._murfey_config,
152+
self._token,
153+
)
149154
return True
150155

151156
# -----------------------------------------------------------------------------
@@ -161,7 +166,12 @@ def _find_context(self, file_path: Path) -> bool:
161166
and "Sites" in file_path.parts
162167
)
163168
):
164-
self._context = FIBContext("autotem", self._basepath, self._token)
169+
self._context = FIBContext(
170+
"autotem",
171+
self._basepath,
172+
self._murfey_config,
173+
self._token,
174+
)
165175
return True
166176

167177
# Determine if it's from Maps
@@ -173,35 +183,58 @@ def _find_context(self, file_path: Path) -> bool:
173183
all(path in file_path.parts for path in ("LayersData", "Layer"))
174184
)
175185
):
176-
self._context = FIBContext("maps", self._basepath, self._token)
186+
self._context = FIBContext(
187+
"maps",
188+
self._basepath,
189+
self._murfey_config,
190+
self._token,
191+
)
177192
return True
178193

179194
# Determine if it's from Meteor
180195
if (
181196
# Image metadata stored in "features.json" file
182197
file_path.name == "features.json" or ()
183198
):
184-
self._context = FIBContext("meteor", self._basepath, self._token)
199+
self._context = FIBContext(
200+
"meteor",
201+
self._basepath,
202+
self._murfey_config,
203+
self._token,
204+
)
185205
return True
186206

187207
# -----------------------------------------------------------------------------
188208
# SXT workflow checks
189209
# -----------------------------------------------------------------------------
190210
if file_path.suffix in (".txrm", ".xrm"):
191-
self._context = SXTContext("zeiss", self._basepath, self._token)
211+
self._context = SXTContext(
212+
"zeiss",
213+
self._basepath,
214+
self._murfey_config,
215+
self._token,
216+
)
192217
return True
193218

194219
# -----------------------------------------------------------------------------
195220
# Tomography and SPA workflow checks
196221
# -----------------------------------------------------------------------------
197222
if "atlas" in file_path.parts:
198223
self._context = AtlasContext(
199-
"serialem" if self._serialem else "epu", self._basepath, self._token
224+
"serialem" if self._serialem else "epu",
225+
self._basepath,
226+
self._murfey_config,
227+
self._token,
200228
)
201229
return True
202230

203231
if "Metadata" in file_path.parts or file_path.name == "EpuSession.dm":
204-
self._context = SPAMetadataContext("epu", self._basepath, self._token)
232+
self._context = SPAMetadataContext(
233+
"epu",
234+
self._basepath,
235+
self._murfey_config,
236+
self._token,
237+
)
205238
return True
206239
elif (
207240
"Batch" in file_path.parts
@@ -210,7 +243,10 @@ def _find_context(self, file_path: Path) -> bool:
210243
or file_path.name == "Session.dm"
211244
):
212245
self._context = TomographyMetadataContext(
213-
"tomo", self._basepath, self._token
246+
"tomo",
247+
self._basepath,
248+
self._murfey_config,
249+
self._token,
214250
)
215251
return True
216252

@@ -228,7 +264,10 @@ def _find_context(self, file_path: Path) -> bool:
228264
if not self._context:
229265
logger.info("Acquisition software: EPU")
230266
self._context = SPAModularContext(
231-
"epu", self._basepath, self._token
267+
"epu",
268+
self._basepath,
269+
self._murfey_config,
270+
self._token,
232271
)
233272
self.parameters_model = ProcessingParametersSPA
234273
return True
@@ -244,7 +283,10 @@ def _find_context(self, file_path: Path) -> bool:
244283
if not self._context:
245284
logger.info("Acquisition software: tomo")
246285
self._context = TomographyContext(
247-
"tomo", self._basepath, self._token
286+
"tomo",
287+
self._basepath,
288+
self._murfey_config,
289+
self._token,
248290
)
249291
self.parameters_model = ProcessingParametersTomo
250292
return True
@@ -281,7 +323,10 @@ def _analyse(self):
281323
and not self._context
282324
):
283325
self._context = SPAMetadataContext(
284-
"epu", self._basepath, self._token
326+
"epu",
327+
self._basepath,
328+
self._murfey_config,
329+
self._token,
285330
)
286331
elif (
287332
"Batch" in transferred_file.parts
@@ -290,7 +335,10 @@ def _analyse(self):
290335
and not self._context
291336
):
292337
self._context = TomographyMetadataContext(
293-
"tomo", self._basepath, self._token
338+
"tomo",
339+
self._basepath,
340+
self._murfey_config,
341+
self._token,
294342
)
295343
self.post_transfer(transferred_file)
296344
else:

src/murfey/client/context.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@
88
import xmltodict
99

1010
from murfey.client.instance_environment import MurfeyInstanceEnvironment, SampleInfo
11-
from murfey.util.client import capture_post, get_machine_config_client
11+
from murfey.util.client import capture_post
1212

1313
logger = logging.getLogger("murfey.client.context")
1414

1515

1616
def _file_transferred_to(
17-
environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str
17+
environment: MurfeyInstanceEnvironment,
18+
source: Path,
19+
file_path: Path,
20+
rsync_basepath: Path,
1821
):
19-
machine_config = get_machine_config_client(
20-
str(environment.url.geturl()),
21-
token,
22-
instrument_name=environment.instrument_name,
23-
)
2422
if environment.visit in environment.default_destinations[source]:
2523
return (
26-
Path(machine_config.get("rsync_basepath", ""))
24+
rsync_basepath
2725
/ Path(environment.default_destinations[source])
2826
/ file_path.relative_to(source) # need to strip out the rsync_module name
2927
)
3028
return (
31-
Path(machine_config.get("rsync_basepath", ""))
29+
rsync_basepath
3230
/ Path(environment.default_destinations[source])
3331
/ environment.visit
3432
/ file_path.relative_to(source)
@@ -52,22 +50,19 @@ def _get_source(file_path: Path, environment: MurfeyInstanceEnvironment) -> Path
5250

5351

5452
def _atlas_destination(
55-
environment: MurfeyInstanceEnvironment, source: Path, token: str
53+
environment: MurfeyInstanceEnvironment,
54+
source: Path,
55+
rsync_basepath: Path,
5656
) -> Path:
57-
machine_config = get_machine_config_client(
58-
str(environment.url.geturl()),
59-
token,
60-
instrument_name=environment.instrument_name,
61-
)
6257
for i, destination_part in enumerate(
6358
Path(environment.default_destinations[source]).parts
6459
):
6560
if destination_part == environment.visit:
66-
return Path(machine_config.get("rsync_basepath", "")) / "/".join(
61+
return rsync_basepath / "/".join(
6762
Path(environment.default_destinations[source]).parent.parts[: i + 1]
6863
)
6964
return (
70-
Path(machine_config.get("rsync_basepath", ""))
65+
rsync_basepath
7166
/ Path(environment.default_destinations[source]).parent
7267
/ environment.visit
7368
)
@@ -77,6 +72,7 @@ def ensure_dcg_exists(
7772
collection_type: str,
7873
metadata_source: Path,
7974
environment: MurfeyInstanceEnvironment,
75+
machine_config: dict,
8076
token: str,
8177
) -> str | None:
8278
"""Create a data collection group"""
@@ -183,7 +179,11 @@ def ensure_dcg_exists(
183179
"experiment_type_id": experiment_type_id,
184180
"tag": dcg_tag,
185181
"atlas": str(
186-
_atlas_destination(environment, session_file.parent, token)
182+
_atlas_destination(
183+
environment,
184+
session_file.parent,
185+
Path(machine_config.get("rsync_basepath", "")),
186+
)
187187
/ environment.samples[metadata_source].atlas.parent
188188
/ atlas_xml_path.with_suffix(".jpg").name
189189
).replace("//", "/"),

src/murfey/client/contexts/atlas.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212

1313

1414
class AtlasContext(Context):
15-
def __init__(self, acquisition_software: str, basepath: Path, token: str):
15+
def __init__(
16+
self,
17+
acquisition_software: str,
18+
basepath: Path,
19+
machine_config: dict,
20+
token: str,
21+
):
1622
super().__init__("Atlas", acquisition_software, token)
1723
self._basepath = basepath
24+
self._machine_config = machine_config
1825

1926
def post_transfer(
2027
self,
@@ -69,7 +76,9 @@ def post_transfer_epu(
6976
source = _get_source(transferred_file, environment)
7077
if source:
7178
transferred_atlas_name = _atlas_destination(
72-
environment, source, self._token
79+
environment,
80+
source,
81+
Path(self._machine_config.get("rsync_basepath", "")),
7382
) / transferred_file.relative_to(source.parent)
7483
capture_post(
7584
base_url=str(environment.url.geturl()),
@@ -91,7 +100,9 @@ def post_transfer_epu(
91100
if source:
92101
atlas_mrc = transferred_file.with_suffix(".mrc")
93102
transferred_atlas_jpg = _atlas_destination(
94-
environment, source, self._token
103+
environment,
104+
source,
105+
Path(self._machine_config.get("rsync_basepath", "")),
95106
) / atlas_mrc.relative_to(source.parent).with_suffix(".jpg")
96107

97108
with open(transferred_file, "rb") as atlas_xml:

src/murfey/client/contexts/clem.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@
1212

1313
from murfey.client.context import Context
1414
from murfey.client.instance_environment import MurfeyInstanceEnvironment
15-
from murfey.util.client import capture_post, get_machine_config_client
15+
from murfey.util.client import capture_post
1616

1717
# Create logger object
1818
logger = logging.getLogger("murfey.client.contexts.clem")
1919

2020

2121
def _file_transferred_to(
22-
environment: MurfeyInstanceEnvironment, source: Path, file_path: Path, token: str
22+
environment: MurfeyInstanceEnvironment,
23+
source: Path,
24+
file_path: Path,
25+
rsync_basepath: Path,
2326
) -> Optional[Path]:
2427
"""
2528
Returns the Path of the transferred file on the DLS file system.
2629
"""
27-
machine_config = get_machine_config_client(
28-
str(environment.url.geturl()),
29-
token,
30-
instrument_name=environment.instrument_name,
31-
)
32-
3330
# Construct destination path
34-
base_destination = Path(machine_config.get("rsync_basepath", "")) / Path(
35-
environment.default_destinations[source]
36-
)
31+
base_destination = rsync_basepath / Path(environment.default_destinations[source])
3732
# Add visit number to the path if it's not present in default destination
3833
if environment.visit not in environment.default_destinations[source]:
3934
base_destination = base_destination / environment.visit
@@ -87,9 +82,16 @@ def _find_elements_recursively(
8782

8883

8984
class CLEMContext(Context):
90-
def __init__(self, acquisition_software: str, basepath: Path, token: str):
85+
def __init__(
86+
self,
87+
acquisition_software: str,
88+
basepath: Path,
89+
machine_config: dict,
90+
token: str,
91+
):
9192
super().__init__("CLEM", acquisition_software, token)
9293
self._basepath = basepath
94+
self._machine_config = machine_config
9395
# CLEM contexts for "auto-save" acquisition mode
9496
self._tiff_series: Dict[str, List[str]] = {} # {Series name : TIFF path list}
9597
self._series_metadata: Dict[str, str] = {} # {Series name : Metadata file path}
@@ -125,7 +127,7 @@ def post_transfer(
125127
environment=environment,
126128
source=source,
127129
file_path=transferred_file,
128-
token=self._token,
130+
rsync_basepath=Path(self._machine_config.get("rsync_basepath", "")),
129131
)
130132
if not destination_file:
131133
logger.warning(
@@ -301,7 +303,7 @@ def post_transfer(
301303
environment=environment,
302304
source=source,
303305
file_path=transferred_file,
304-
token=self._token,
306+
rsync_basepath=Path(self._machine_config.get("rsync_basepath", "")),
305307
)
306308
if not destination_file:
307309
logger.warning(

0 commit comments

Comments
 (0)