1717logger = logging .getLogger (__name__ )
1818
1919
20- def check_file_is_correct_for_run_number (path : Path , run_number : str ) -> bool :
21- """
22- Check if a file matches the run number.
23-
24- :param path: The path to the file.
25- :param run_number: The run number to check for.
26- :return: True if it is a file and the run number is in the name.
27- """
28- return path .is_file () and run_number in path .name
29-
30-
3120def find_correct_tomo_dir (path : Path , run_number : str ) -> Path | None :
3221 """
3322 Check a directory for the IMAT image structure.
@@ -38,24 +27,15 @@ def find_correct_tomo_dir(path: Path, run_number: str) -> Path | None:
3827 :param run_number: The run number to check for.
3928 :return: The path to the Tomo directory if found, otherwise None.
4029 """
41- tomo = None
42- file_found = False
43- for child in path .iterdir ():
44- is_file = check_file_is_correct_for_run_number (child , run_number )
45- if is_file :
46- # File found
47- if tomo is not None :
48- # Tomo is already known
49- return tomo
50- if not file_found and tomo is None :
51- # Wait until we find the Tomo folder
52- file_found = True
53- if child .is_dir () and child .name == "Tomo" :
54- # Found a potential Tomo dir
55- tomo = path / child
56- if file_found :
57- # Tomo and file found, now return
58- return tomo
30+ for root , _ , files in path .walk (top_down = False ):
31+ for file in files :
32+ if run_number in file :
33+ # There are 2 known scenarios we are at the same level as Tomo, or in a directory one level lower.
34+ possible_tomo = root .parent / "Tomo"
35+ if root .parent .name == "Tomo" :
36+ return root .parent
37+ elif possible_tomo .exists ():
38+ return possible_tomo
5939 return None
6040
6141
@@ -76,16 +56,7 @@ def verify(self, job_request: JobRequest) -> None:
7656 imat_dir_path : Path | None = None
7757
7858 if exp_dir_path .exists () and exp_dir_path .is_dir ():
79- # Find file with run number in it, often ending with .csv, then search for a dir in the same directory as it
80- # called Tomo.
8159 imat_dir_path = find_correct_tomo_dir (exp_dir_path , str (job_request .run_number ))
82- if imat_dir_path is None :
83- # We haven't found it yet, search the expected path for the correct directory
84- for child in exp_dir_path .iterdir ():
85- if child .is_dir ():
86- imat_dir_path = find_correct_tomo_dir (child , str (job_request .run_number ))
87- if imat_dir_path is not None :
88- break
8960
9061 if imat_dir_path is not None and imat_dir_path .exists ():
9162 job_request .additional_values ["recon" ] = "true"
0 commit comments