-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.py
More file actions
68 lines (52 loc) · 1.98 KB
/
Copy pathcontext.py
File metadata and controls
68 lines (52 loc) · 1.98 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
from __future__ import annotations
import logging
from pathlib import Path
from typing import Any, Dict, List, NamedTuple
from backports.entry_points_selectable import entry_points
from murfey.client.instance_environment import MurfeyInstanceEnvironment
logger = logging.getLogger("murfey.client.context")
class FutureRequest(NamedTuple):
url: str
message: Dict[str, Any]
class ProcessingParameter(NamedTuple):
name: str
label: str
default: Any = None
def detect_acquisition_software(dir_for_transfer: Path) -> str:
glob = dir_for_transfer.glob("*")
for f in glob:
if f.name.startswith("EPU") or f.name.startswith("GridSquare"):
return "epu"
if f.name.startswith("Position") or f.suffix == ".mdoc":
return "tomo"
return ""
class Context:
user_params: List[ProcessingParameter] = []
metadata_params: List[ProcessingParameter] = []
def __init__(self, name: str, acquisition_software: str):
self._acquisition_software = acquisition_software
self.name = name
self.data_collection_parameters: dict = {}
def post_transfer(
self,
transferred_file: Path,
environment: MurfeyInstanceEnvironment | None = None,
**kwargs,
):
# Search external packages for additional hooks to include in Murfey
for h in entry_points(group="murfey.post_transfer_hooks"):
if h.name == self.name:
h.load()(transferred_file, environment=environment, **kwargs)
def post_first_transfer(
self,
transferred_file: Path,
environment: MurfeyInstanceEnvironment | None = None,
**kwargs,
):
self.post_transfer(transferred_file, environment=environment, **kwargs)
def gather_metadata(
self, metadata_file: Path, environment: MurfeyInstanceEnvironment | None = None
):
raise NotImplementedError(
f"gather_metadata must be declared in derived class to be used: {self}"
)