-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment_reader_factory.py
30 lines (24 loc) · 1.08 KB
/
experiment_reader_factory.py
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
from dials_reader import DIALSReader
from experiment_reader import ExperimentReader
from mantid_reader import MantidReader
def experiment_reader_factory(
file_path: str, file_path2: str = None
) -> ExperimentReader:
def is_dials_file(file_path: str, file_path2: str = None) -> bool:
if file_path.split(".")[1] == "expt" and file_path2 is None:
return True
elif file_path2 is not None:
if file_path.split(".")[1] == "expt" and file_path2.split(".")[1] == "refl":
return True
return False
def is_mantid_file(file_path: str, file_path2: str = None) -> bool:
if file_path2 is not None:
return False
if file_path.split(".")[1] == "nxs":
return True
return False
if is_dials_file(file_path=file_path, file_path2=file_path2):
return DIALSReader(expt_file_path=file_path, refl_file_path=file_path2)
elif is_mantid_file(file_path=file_path, file_path2=file_path2):
return MantidReader(nxs_file_path=file_path)
raise Exception("Cannot understand input files.")