-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatson-backup-to-data
71 lines (60 loc) · 3.42 KB
/
watson-backup-to-data
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
import logging
import os
import argparse
from fitting.watsonfit import WatsonResultModel
def main():
parser = argparse.ArgumentParser(
description='Helper script to compute outputs from backup data', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--infile',
help='Backup file', default=argparse.SUPPRESS)
parser.add_argument('-o', '--outfile',
help='5D output file with the approximation result (5,r,x,y,z), the first axis contains in place 0 '
'the kappa value, in place 1 the volume fraction and in the remaining places the unit direction.', default=argparse.SUPPRESS)
parser.add_argument('-op', '--outfilepeaks',
help='5D output file with the approximation result without kappa (4,r,x,y,z), the first axis contains in place 0 '
'the volume fraction and in the remaining places the unit direction.', default=argparse.SUPPRESS)
parser.add_argument('-of', '--outfilefodf',
help='If filename is set, Watson parameters are used to generate fodf data', default=argparse.SUPPRESS)
parser.add_argument('-ofn', '--outfilefodfpeaknumber',
help='Only export one distribution per voxel, 0 for principal direction, 1 and 2 for 2nd and 3rd.', default=None)
parser.add_argument('-vvi', '--vvicones',
help='If filename is set, r files are generated beginning with the given filename that contain data to visualize as cones with vvi.', default=argparse.SUPPRESS)
parser.add_argument('-v', '--verbose', default=True)
args = parser.parse_args()
print(args)
logging.basicConfig(filename=os.path.join("./", 'watson_backup_to_data.log'),
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%y-%m-%d %H:%M',
level=logging.INFO,
filemode='w')
if args.verbose:
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
# set a format which is simpler for console use
formatter = logging.Formatter(
'%(asctime)s: %(levelname)-8s %(message)s', datefmt='%y-%m-%d %H:%M')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
result_model = WatsonResultModel.load_from_file(args.infile)
if 'outfilebackup' in args:
logging.info(f"Saving backup to {args.outfilebackup}")
result_model.backup_to_file(args.outfilebackup)
if 'outfile' in args:
logging.info(f"Saving Watson output to {args.outfile}")
result_model.export_for_watson_tracking(args.outfile)
if 'outfilepeaks' in args:
logging.info(f"Saving Peak output to {args.outfilepeaks}")
result_model.export_for_peak_tracking(args.outfilepeaks)
if 'vvicones' in args:
logging.info(f"Saving vvi cones")
result_model.export_for_vvi_with_cones(args.vvicones)
if 'outfilefodf' in args:
logging.info(f"Saving fodf output to {args.outfilefodf}")
if args.outfilefodfpeaknumber is not None:
result_model.export_as_fodf_signal(args.outfilefodf, peak_number=int(args.outfilefodfpeaknumber))
else:
result_model.export_as_fodf_signal(args.outfilefodf)
if __name__=="__main__":
main()