-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
102 lines (87 loc) · 3.31 KB
/
main.py
File metadata and controls
102 lines (87 loc) · 3.31 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Scripts to run oscillation mapping pipeline."""
import logging
import pdb
from absl import app, flags
from ml_collections import config_flags
from config import base_config
from subject_classmap import Subject
FLAGS = flags.FLAGS
_CONFIG = config_flags.DEFINE_config_file("config", None, "config file.")
flags.DEFINE_boolean("force_recon", False, "force reconstruction for the subject")
flags.DEFINE_boolean("force_readin", False, "force read in .mat for the subject")
flags.DEFINE_bool("force_segmentation", False, "run segmentation again.")
def oscillation_mapping_reconstruction(config: base_config.Config):
"""Run the oscillation mapping pipeline with reconstruction.
Args:
config (config_dict.ConfigDict): config dict
"""
subject = Subject(config=config)
try:
subject.read_twix_files()
except:
subject.read_mrd_files()
logging.info("Getting RBC:M ratio from static spectroscopy.")
subject.calculate_rbc_m_ratio()
logging.info("Reconstructing images")
subject.preprocess()
if config.recon.recon_proton:
subject.reconstruction_ute()
subject.reconstruction_gas()
subject.reconstruction_dissolved()
subject.reconstruction_rbc_oscillation()
logging.info("Segmenting Proton Mask")
subject.segmentation()
subject.save_subject_to_mat()
subject.dixon_decomposition()
subject.dissolved_analysis()
subject.dissolved_binning()
subject.oscillation_analysis()
subject.oscillation_binning()
subject.get_statistics()
subject.write_stats_to_csv()
subject.generate_figures()
subject.generate_pdf()
subject.save_files()
logging.info("Complete")
def oscillation_mapping_readin(config: base_config.Config):
"""Run the oscillation imaging pipeline by reading in .mat file.
Args:
config (config_dict.ConfigDict): config dict
"""
subject = Subject(config=config)
subject.read_mat_file()
if FLAGS.force_segmentation:
logging.info("Segmenting Proton Mask")
subject.segmentation()
subject.save_subject_to_mat()
subject.dixon_decomposition()
subject.dissolved_analysis()
subject.dissolved_binning()
subject.oscillation_analysis()
subject.oscillation_binning()
subject.get_statistics()
subject.write_stats_to_csv()
subject.generate_figures()
subject.generate_pdf()
logging.info("Complete")
def main(argv):
"""Run the oscillation imaging pipeline.
Either run the reconstruction or read in the .mat file.
"""
config = _CONFIG.value
if FLAGS.force_recon:
logging.info("Oscillation imaging mapping with reconstruction.")
oscillation_mapping_reconstruction(config)
elif FLAGS.force_readin:
logging.info("Oscillation imaging mapping with reconstruction.")
oscillation_mapping_readin(config)
elif config.processes.oscillation_mapping_recon:
logging.info("Oscillation imaging mapping with reconstruction.")
oscillation_mapping_reconstruction(config)
elif config.processes.oscillation_mapping_readin:
logging.info("Oscillation imaging mapping with reconstruction.")
oscillation_mapping_readin(config)
else:
pass
if __name__ == "__main__":
app.run(main)