forked from bunkerhillhealth/bunkerhill-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnifti_to_modelrunner_input.py
49 lines (40 loc) · 1.42 KB
/
nifti_to_modelrunner_input.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Command to convert 3D NifTi arrays to input files compatible with Bunkerhill's ModelRunner.
Example usage:
python nifti_to_modelrunner_input.py \
--nifti_filename=/path/to/hippocampus_009_0000.nii.gz \
--data_dirname=/tmp \
--study_uuid=77d1b303-f8b2-4aca-a84c-6c102d3625e1 \
--series_uuid=e57ac58e-c0e8-44ab-be7e-4d17b32f6a8f
"""
import argparse
import pickle
import nibabel as nib
from bunkerhill import shared_file_utils
def main(args: argparse.Namespace) -> None:
input_array = nib.load(args.nifti_filename).get_data()
pixel_array = {'pixel_array': {args.series_uuid: input_array}}
input_filename = shared_file_utils.get_model_arguments_filename(
args.data_dirname, args.study_uuid
)
with open(input_filename, 'wb') as f:
pickle.dump(pixel_array, f)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--nifti_filename', help='Path to NifTi file', required=True, type=str)
parser.add_argument(
'--data_dirname', help='Directory where input file will be written.', required=True, type=str
)
parser.add_argument(
'--study_uuid',
help=('UUID identifier of study. Inputs will be encoded as '
'{study_uuid}_input.pkl.'),
required=True,
type=str
)
parser.add_argument(
'--series_uuid',
help='UUID identifier of series from which pixel array input originates.',
required=True,
type=str
)
main(parser.parse_args())