File tree Expand file tree Collapse file tree
spimquant/workflow/scripts Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323
2424os .makedirs (posteriors_dir , exist_ok = True )
2525
26+ env = os .environ .copy ()
27+ env ["ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS" ] = str (threads )
28+
2629for k in range (init_k , min_k - 1 , - 1 ):
27- cmd = (
28- f"ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS={ threads } "
29- f"Atropos -v -d 3 --initialization KMeans[{ k } ] "
30- f" --intensity-image { downsampled } "
31- f" --output [{ dseg } ,{ posteriors_dir } /class-%02d.nii] "
32- f" --mask-image { mask } --mrf [{ mrf_smoothing } ,{ mrf_radius } ]"
33- )
34- result = subprocess .run (cmd , shell = True )
30+ cmd = [
31+ "Atropos" ,
32+ "-v" ,
33+ "-d" ,
34+ "3" ,
35+ "--initialization" ,
36+ f"KMeans[{ k } ]" ,
37+ "--intensity-image" ,
38+ downsampled ,
39+ "--output" ,
40+ f"[{ dseg } ,{ posteriors_dir } /class-%02d.nii]" ,
41+ "--mask-image" ,
42+ mask ,
43+ "--mrf" ,
44+ f"[{ mrf_smoothing } ,{ mrf_radius } ]" ,
45+ ]
46+ result = subprocess .run (cmd , env = env )
3547 if result .returncode == 0 :
3648 break
3749 elif k == min_k :
3850 raise subprocess .CalledProcessError (result .returncode , cmd )
3951 else :
52+ print (
53+ f"Atropos failed with k={ k } (exit code { result .returncode } ), "
54+ f"retrying with k={ k - 1 } "
55+ )
4056 # Clean up and retry with lower k
4157 if os .path .exists (dseg ):
4258 os .remove (dseg )
You can’t perform that action at this time.
0 commit comments