コード例 #1
0
def test_convert_the_banana(open_converted=False):

    pfo_study_in = os.path.join(root_dir, "test_data", "bru_banana")
    pfo_study_out = os.path.join(root_dir, "test_data", "nifti_banana")

    # delete study if already exists:
    target_folder = os.path.join(pfo_study_out, "banana")
    if os.path.exists(target_folder):
        os.system("rm -r {}".format(os.path.join(target_folder)))

    # instantiate the converter:
    bru = Bruker2Nifti(pfo_study_in, pfo_study_out, study_name="banana")

    bru.verbose = 2
    bru.correct_slope = True
    bru.get_acqp = False
    bru.get_method = False
    bru.get_reco = False

    bru.convert()

    if open_converted:

        if platform.system() == "Windows":
            os.startfile(pfo_study_out.encode("string-escape"))
        elif platform.system() == "Darwin":
            subprocess.Popen(["open", pfo_study_out])
        else:
            subprocess.Popen(["xdg-open", pfo_study_out])

    for ex in ["1", "2", "3"]:
        experiment_folder = os.path.join(pfo_study_out, "banana",
                                         "banana_{}".format(ex))
        assert os.path.exists(experiment_folder)
        assert os.path.exists(
            os.path.join(experiment_folder, "banana_{}.nii.gz".format(ex)))
コード例 #2
0
#!/bin/python

import os
from glob import glob
from bruker2nifti.converter import Bruker2Nifti

data_in = '/home/julia/projects/lc/20180808_162705_JH_lc_anatomy_02_1_2'
data_out = '/home/julia/projects/lc/20180808_162705_JH_lc_anatomy_02_1_2_nifti'

if not os.path.isdir(data_out):
    os.mkdir(data_out)

bru = Bruker2Nifti(data_in, data_out, study_name="")

print(bru.scans_list)
print(bru.list_new_name_each_scan)

bru.convert()
コード例 #3
0
ファイル: bruker2nii.py プロジェクト: portokalh/bruker2nifti
def main():
    """
    Parser from terminal with:
    $ python2 bruker2nifti -h
    $ python2 bruker2nifti -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # pfo_study_bruker_input
    parser.add_argument('-i',
                        '--input_study_folder',
                        dest='pfo_input',
                        type=str,
                        required=True,
                        help='Bruker study folder.')

    # pfo_study_nifti_output
    parser.add_argument('-o',
                        '--output_study_folder',
                        dest='pfo_output',
                        type=str,
                        required=True,
                        help='Output folder where the study will be saved.')

    # study_name = None,
    parser.add_argument('-study_name', dest='study_name', default=None)

    # scans_list = None
    parser.add_argument('-scans_list', dest='scans_list', default=None)

    # list_new_name_each_scan = None,
    parser.add_argument('-list_new_name_each_scan',
                        dest='list_new_name_each_scan',
                        default=None)

    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1)

    # qform = 2,
    parser.add_argument('-qform_code', dest='qform_code', type=int, default=1)

    # sform= 1,
    parser.add_argument('-sform_code', dest='sform_code', type=int, default=2)

    # do_not_save_npy = False,
    parser.add_argument('-do_not_save_npy',
                        dest='do_not_save_npy',
                        action='store_true')

    # do_not_save_human_readable = False,
    parser.add_argument('-do_not_save_human_readable',
                        dest='do_not_save_human_readable',
                        action='store_true')

    # correct_visu_slope = False,
    parser.add_argument('-correct_visu_slope',
                        dest='correct_visu_slope',
                        action='store_true')

    # correct_reco_slope = False,
    parser.add_argument('-correct_reco_slope',
                        dest='correct_reco_slope',
                        action='store_true')

    # user_matrix = None,
    parser.add_argument('-apply_matrix',
                        dest='user_matrix',
                        type=str,
                        default=None)

    # verbose = 1
    parser.add_argument('-verbose', '-v', dest='verbose', type=int, default=1)

    # Parse the input arguments
    args = parser.parse_args()

    # instantiate a converter:
    bruconv = Bruker2Nifti(args.pfo_input,
                           args.pfo_output,
                           study_name=args.study_name)

    if args.scans_list is not None:
        bruconv.scans_list = args.scans_list
    if args.list_new_name_each_scan is not None:
        bruconv.list_new_name_each_scan = args.list_new_name_each_scan
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_npy = not args.do_not_save_npy
    bruconv.save_human_readable = not args.do_not_save_human_readable
    bruconv.correct_visu_slope = args.correct_visu_slope
    bruconv.correct_reco_slope = args.correct_reco_slope
    bruconv.user_matrix = args.user_matrix
    bruconv.verbose = args.verbose

    if parser.add_argument > 0:
        print('\nConverter input parameters: ')
        print('-------------------------------------------------------- ')
        print('Study name             : {}'.format(bruconv.study_name))
        print('List of scans          : {}'.format(bruconv.scans_list))
        print('List of scans names    : {}'.format(
            bruconv.list_new_name_each_scan))
        print('Output NifTi version   : {}'.format(bruconv.nifti_version))
        print('Output NifTi q-form    : {}'.format(bruconv.qform_code))
        print('Output NifTi s-form    : {}'.format(bruconv.sform_code))
        print('Save npy               : {}'.format(bruconv.save_npy))
        print('Save human readable    : {}'.format(
            bruconv.save_human_readable))
        print('Correct the visu slope : {}'.format(bruconv.correct_visu_slope))
        print('Correct the reco slope : {}'.format(bruconv.correct_reco_slope))
        print('Apply matrix           : {}'.format(bruconv.user_matrix))
        print('-------------------------------------------------------- ')
    bruconv.convert()
コード例 #4
0
ファイル: a_bruker_convert.py プロジェクト: juhuntenburg/real
#!/bin/python

import os
from glob import glob
from bruker2nifti.converter import Bruker2Nifti

data_in = '/home/julia/projects/real_data/mouse_visual/CL181102fmrssouris9/raw/'
data_out = '/home/julia/projects/real_data/mouse_visual/CL181102fmrssouris9/raw/26/converted/'

if not os.path.isdir(data_out):
    os.mkdir(data_out)

bru = Bruker2Nifti(data_in, data_out)
bru.get_acqp = True
bru.get_method = True
bru.get_reco = True
bru.verbose = 0
bru.convert()
コード例 #5
0
def main_scan():
    """
    Parser from terminal with
    $ python2 bruker2nifti_scan -h
    $ python2 bruker2nifti_scan -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # pfo_input_scan
    parser.add_argument('-i',
                        '--input_scan_folder',
                        dest='pfo_input',
                        type=str,
                        required=True,
                        help='Bruker scan folder.')
    # pfo_output
    parser.add_argument('-o',
                        '--output_scan_folder',
                        dest='pfo_output',
                        type=str,
                        required=True,
                        help='Output folder where the study will be saved.')
    # fin_output = None
    parser.add_argument('--fin_output',
                        dest='fin_output',
                        type=str,
                        default=None)
    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1,
                        help='Filename of the nifti output.')
    # qform = 2,
    parser.add_argument('-qform_code', dest='qform_code', type=int, default=2)
    # sform = 1,
    parser.add_argument('-sform_code', dest='sform_code', type=int, default=1)

    # do_not_save_npy = False,
    parser.add_argument('-do_not_save_npy',
                        dest='do_not_save_npy',
                        action='store_true')

    # do_not_save_human_readable = False,
    parser.add_argument('-do_not_save_human_readable',
                        dest='do_not_save_human_readable',
                        action='store_true')

    # correct_visu_slope = False,
    parser.add_argument('-correct_visu_slope',
                        dest='correct_visu_slope',
                        action='store_true')

    # correct_reco_slope = False,
    parser.add_argument('-correct_reco_slope',
                        dest='correct_reco_slope',
                        action='store_true')

    # user_matrix = None,
    parser.add_argument('-apply_matrix',
                        dest='user_matrix',
                        type=str,
                        default=None)

    # verbose = 1
    parser.add_argument('-verbose', '-v', dest='verbose', type=int, default=1)

    args = parser.parse_args()

    # instantiate a converter:
    bruconv = Bruker2Nifti(os.path.dirname(args.pfo_input), args.pfo_output)
    # get the attributes
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_npy = not args.do_not_save_npy
    bruconv.save_human_readable = not args.do_not_save_human_readable
    bruconv.correct_visu_slope = args.correct_visu_slope
    bruconv.correct_reco_slope = args.correct_reco_slope
    bruconv.user_matrix = args.user_matrix
    bruconv.verbose = args.verbose

    if parser.add_argument > 0:
        print('\nConverter parameters: ')
        print('-------------------------------------------------------- ')
        print('Study Folder           : {}'.format(
            os.path.dirname(args.pfo_input)))
        print('Scan to convert        : {}'.format(
            os.path.basename(args.pfo_input)))
        print('List of scans          : {}'.format(bruconv.scans_list))
        print('Output NifTi version   : {}'.format(bruconv.nifti_version))
        print('Output NifTi q-form    : {}'.format(bruconv.qform_code))
        print('Output NifTi s-form    : {}'.format(bruconv.sform_code))
        print('Save npy               : {}'.format(bruconv.save_npy))
        print('Save human readable    : {}'.format(
            bruconv.save_human_readable))
        print('Correct the visu_slope : {}'.format(bruconv.correct_visu_slope))
        print('Correct the reco_slope : {}'.format(bruconv.correct_reco_slope))
        print('Apply matrix           : {}'.format(bruconv.user_matrix))
        print('-------------------------------------------------------- ')
    # convert the single:
    bruconv.convert_scan(args.pfo_input,
                         args.pfo_output,
                         nifti_file_name=args.fin_output,
                         create_output_folder_if_not_exists=True)
コード例 #6
0
def main_scan():
    """
    Parser from terminal with
    $ python2 bruker2nifti_scan -h
    $ python2 bruker2nifti_scan -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # pfo_input_scan
    parser.add_argument(
        "-i",
        "--input_scan_folder",
        dest="pfo_input",
        type=str,
        required=True,
        help="Bruker scan folder.",
    )
    # pfo_output
    parser.add_argument(
        "-o",
        "--output_scan_folder",
        dest="pfo_output",
        type=str,
        required=True,
        help="Output folder where the study will be saved.",
    )
    # fin_output = None
    parser.add_argument("--fin_output", dest="fin_output", type=str, default=None)
    # nifti_version = 1,

    parser.add_argument("-nifti_version", dest="nifti_version", type=int, default=1)
    # qform = 1,
    parser.add_argument("-qform_code", dest="qform_code", type=int, default=1)
    # sform = 2,
    parser.add_argument("-sform_code", dest="sform_code", type=int, default=2)

    # do_not_save_human_readable = False,
    parser.add_argument(
        "-do_not_save_human_readable",
        dest="do_not_save_human_readable",
        action="store_true",
    )

    # correct_slope = False,

    parser.add_argument("-correct_slope", dest="correct_slope", action="store_true")

    # correct_offset = False,
    parser.add_argument("-correct_offset", dest="correct_offset", action="store_true")

    # sample_upside_down = False,
    parser.add_argument(
        "-sample_upside_down", dest="sample_upside_down", action="store_true"
    )

    # frame_body_as_frame_head = False,
    parser.add_argument(
        "-frame_body_as_frame_head",
        dest="frame_body_as_frame_head",
        action="store_true",
    )

    # verbose = 1
    parser.add_argument("-verbose", "-v", dest="verbose", type=int, default=1)

    args = parser.parse_args()

    # instantiate a converter:
    bruconv = Bruker2Nifti(os.path.dirname(args.pfo_input), args.pfo_output)
    # get the attributes
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_human_readable = not args.do_not_save_human_readable
    bruconv.correct_slope = args.correct_slope
    bruconv.correct_offset = args.correct_offset
    bruconv.verbose = args.verbose
    # Sample position
    bruconv.sample_upside_down = args.sample_upside_down
    bruconv.frame_body_as_frame_head = args.frame_body_as_frame_head

    if parser.add_argument > 0:

        print("\nConverter parameters: ")
        print("-------------------------------------------------------- ")
        print("Study Folder         : {}".format(os.path.dirname(args.pfo_input)))
        print("Scan to convert      : {}".format(os.path.basename(args.pfo_input)))
        print("List of scans        : {}".format(bruconv.scans_list))
        print("Output NifTi version : {}".format(bruconv.nifti_version))
        print("Output NifTi q-form  : {}".format(bruconv.qform_code))
        print("Output NifTi s-form  : {}".format(bruconv.sform_code))
        print("Save human readable  : {}".format(bruconv.save_human_readable))
        print("Correct the slope    : {}".format(bruconv.correct_slope))
        print("Correct the offset   : {}".format(bruconv.correct_offset))
        print("-------------------------------------------------------- ")
        print("Sample upside down         : {}".format(bruconv.sample_upside_down))
        print(
            "Frame body as frame head   : {}".format(bruconv.frame_body_as_frame_head)
        )
        print("-------------------------------------------------------- ")

    # convert the single:
    bruconv.convert_scan(
        args.pfo_input,
        args.pfo_output,
        nifti_file_name=args.fin_output,
        create_output_folder_if_not_exists=True,
    )

    # Print a warning message for paths with whitespace as it may interfere
    # with subsequent steps in an image analysis pipeline
    if utils.path_contains_whitespace(
        bruconv.pfo_study_nifti_output, bruconv.study_name
    ):
        print("INFO: Output path/filename contains whitespace")
コード例 #7
0
ファイル: bruker2nii.py プロジェクト: fgrelard/bruker2nifti
def main():
    """
    Parser from terminal with:
    $ python2 bruker2nifti -h
    $ python2 bruker2nifti -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # custom helper
    parser.add_argument('-what',
                        dest='what',
                        action='store_true',
                        required=False,
                        help='Get more information about the software')

    # pfo_study_bruker_input
    parser.add_argument('-i',
                        '--input_study_folder',
                        dest='pfo_input',
                        type=str,
                        required=False,
                        help='Bruker study folder.')

    # pfo_study_nifti_output
    parser.add_argument('-o',
                        '--output_study_folder',
                        dest='pfo_output',
                        type=str,
                        required=False,
                        help='Output folder where the study will be saved.')

    # study_name = None,
    parser.add_argument('-study_name', dest='study_name', default=None)

    # scans_list = None
    parser.add_argument('-scans_list', dest='scans_list', default=None)

    # list_new_name_each_scan = None,
    parser.add_argument('-list_new_name_each_scan',
                        dest='list_new_name_each_scan',
                        default=None)

    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1)

    # qform = 2,
    parser.add_argument('-qform_code', dest='qform_code', type=int, default=1)

    # sform= 1,
    parser.add_argument('-sform_code', dest='sform_code', type=int, default=2)

    # do_not_save_human_readable = False,
    parser.add_argument('-do_not_save_human_readable',
                        dest='do_not_save_human_readable',
                        action='store_true')

    # correct_slope = True,
    parser.add_argument('-correct_slope',
                        dest='correct_slope',
                        action='store_true')

    # correct_offset = True,
    parser.add_argument('-correct_offset',
                        dest='correct_offset',
                        action='store_true')

    # correct_offset = True,
    parser.add_argument('-sample_upside_down',
                        dest='sample_upside_down',
                        action='store_false')

    # correct_offset = True,
    parser.add_argument('-frame_body_as_frame_head',
                        dest='frame_body_as_frame_head',
                        action='store_false')

    # verbose = 1
    parser.add_argument('-verbose', '-v', dest='verbose', type=int, default=1)

    # ------ Parsing user's input ------ #

    args = parser.parse_args()

    # Check input:
    if args.what:
        msg = 'Code repository : {} \n' \
              'Documentation   : {}'.format('https://github.com/SebastianoF/bruker2nifti',
                                            'https://github.com/SebastianoF/bruker2nifti/wiki')
        sys.exit(msg)

    if not args.pfo_input or not args.pfo_output:
        sys.exit('Input bruker study [-i] and output folder [-o] required')

    # Instantiate a converter:
    bruconv = Bruker2Nifti(args.pfo_input,
                           args.pfo_output,
                           study_name=args.study_name)

    if args.scans_list is not None:
        bruconv.scans_list = args.scans_list
    if args.list_new_name_each_scan is not None:
        bruconv.list_new_name_each_scan = args.list_new_name_each_scan

    # Basics
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_human_readable = not args.do_not_save_human_readable
    bruconv.correct_slope = args.correct_slope
    bruconv.correct_offset = args.correct_offset
    bruconv.verbose = args.verbose
    # Sample position
    bruconv.sample_upside_down = args.sample_upside_down
    bruconv.frame_body_as_frame_head = args.frame_body_as_frame_head

    print('\nConverter input parameters: ')
    print('-------------------------------------------------------- ')
    print('Study name           : {}'.format(bruconv.study_name))
    print('List of scans        : {}'.format(bruconv.scans_list))
    print('List of scans names  : {}'.format(bruconv.list_new_name_each_scan))
    print('Output NifTi version : {}'.format(bruconv.nifti_version))
    print('Output NifTi q-form  : {}'.format(bruconv.qform_code))
    print('Output NifTi s-form  : {}'.format(bruconv.sform_code))
    print('Save human readable  : {}'.format(bruconv.save_human_readable))
    print('Correct the slope    : {}'.format(bruconv.correct_slope))
    print('Correct the offset   : {}'.format(bruconv.correct_offset))
    print('-------------------------------------------------------- ')
    print('Sample upside down         : {}'.format(bruconv.sample_upside_down))
    print('Frame body as frame head   : {}'.format(
        bruconv.frame_body_as_frame_head))
    print('-------------------------------------------------------- ')
    bruconv.convert()
コード例 #8
0
ファイル: bruker2nii.py プロジェクト: dzhoshkun/bruker2nifti
def main():
    """
    Parser from terminal with:
    $ python2 bruker2nifti_study -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # pfo_study_bruker_input
    parser.add_argument('-i', '--input_study_folder',
                        dest='pfo_input',
                        type=str,
                        required=True,
                        help='Bruker study folder.')

    # pfo_study_nifti_output
    parser.add_argument('-o', '--output_study_folder',
                        dest='pfo_output',
                        type=str,
                        required=True,
                        help='Output folder where the study will be saved.')

    # study_name = None,
    parser.add_argument('-study_name',
                        dest='study_name',
                        default=None)

    # scans_list = None
    parser.add_argument('-scans_list',
                        dest='scans_list',
                        default=None)

    # list_new_name_each_scan = None,
    parser.add_argument('-list_new_name_each_scan',
                        dest='list_new_name_each_scan',
                        default=None)

    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1)

    # qform = 2,
    parser.add_argument('-qform_code',
                        dest='qform_code',
                        type=int,
                        default=2)

    # sform= 1,
    parser.add_argument('-sform_code',
                        dest='sform_code',
                        type=int,
                        default=1)

    # save_human_readable = True,
    parser.add_argument('-save_human_readable',
                        dest='save_human_readable',
                        action='store_true')

    # correct_slope = False,
    parser.add_argument('-correct_slope',
                        dest='correct_slope',
                        action='store_false')
    # verbose = 1
    parser.add_argument('-verbose', '-v',
                        dest='verbose',
                        action='store_true')

    # Parse the input arguments
    args = parser.parse_args()

    # instantiate a converter:
    bruconv = Bruker2Nifti(args.pfo_input,
                           args.pfo_output,
                           study_name=args.study_name)

    if args.scans_list is not None:
        bruconv.scans_list = args.scans_list
    if args.list_new_name_each_scan is not None:
        bruconv.list_new_name_each_scan = args.list_new_name_each_scan
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_human_readable = args.save_human_readable
    bruconv.correct_slope = args.correct_slope
    bruconv.verbose = args.verbose

    bruconv.convert()
コード例 #9
0
def main_scan():
    """
    Parser from terminal with
    $ python2 bruker2nifti_scan -h
    $ python2 bruker2nifti_scan -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # pfo_input_scan
    parser.add_argument('-i',
                        '--input_scan_folder',
                        dest='pfo_input',
                        type=str,
                        required=True,
                        help='Bruker scan folder.')
    # pfo_output
    parser.add_argument('-o',
                        '--output_scan_folder',
                        dest='pfo_output',
                        type=str,
                        required=True,
                        help='Output folder where the study will be saved.')
    # fin_output = None
    parser.add_argument('--fin_output',
                        dest='fin_output',
                        type=str,
                        default=None)
    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1,
                        help='Filename of the nifti output.')
    # qform = 2,
    parser.add_argument('-qform_code', dest='qform_code', type=int, default=2)
    # sform = 1,
    parser.add_argument('-sform_code', dest='sform_code', type=int, default=1)

    # do_not_save_human_readable = False,
    parser.add_argument('-do_not_save_human_readable',
                        dest='do_not_save_human_readable',
                        action='store_true')

    # correct_slope = False,
    parser.add_argument('-correct_slope',
                        dest='correct_slope',
                        action='store_true')
    # verbose = 1
    parser.add_argument('-verbose', '-v', dest='verbose', type=int, default=1)

    args = parser.parse_args()

    # instantiate a converter:
    bruconv = Bruker2Nifti(os.path.dirname(args.pfo_input), args.pfo_output)
    # get the attributes
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_human_readable = not args.do_not_save_human_readable
    bruconv.correct_slope = args.correct_slope
    bruconv.verbose = args.verbose

    if parser.add_argument > 0:
        print('\nConverter parameters: ')
        print('-------------------------------------------------------- ')
        print('Study Folder         : {}'.format(
            os.path.dirname(args.pfo_input)))
        print('Scan to convert      : {}'.format(
            os.path.basename(args.pfo_input)))
        print('List of scans        : {}'.format(bruconv.scans_list))
        print('Output NifTi version : {}'.format(bruconv.nifti_version))
        print('Output NifTi q-form  : {}'.format(bruconv.qform_code))
        print('Output NifTi s-form  : {}'.format(bruconv.sform_code))
        print('Save human readable  : {}'.format(bruconv.save_human_readable))
        print('Correct the slope    : {}'.format(bruconv.correct_slope))
        print('-------------------------------------------------------- ')
    # convert the single:
    bruconv.convert_scan(args.pfo_input,
                         args.pfo_output,
                         nifti_file_name=args.fin_output,
                         create_output_folder_if_not_exists=True)

    # Print a warning message for paths with whitespace as it may interfere
    # with subsequent steps in an image analysis pipeline
    if utils.path_contains_whitespace(bruconv.pfo_study_nifti_output,
                                      bruconv.study_name):
        print("INFO: Output path/filename contains whitespace")
コード例 #10
0
ファイル: bruker2nii.py プロジェクト: jathpala/bruker2nifti
def main():
    """
    Parser from terminal with:
    $ python2 bruker2nifti -h
    $ python2 bruker2nifti -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # The action to be taken
    #  'convert': Convert images to nifti format (default)
    #  'list': List scans without converting
    parser.add_argument('command',
                        type=str,
                        nargs='?',
                        default='convert',
                        choices=['convert', 'list'],
                        help='Action to take: ' +
                        'convert - convert to nifti, ' +
                        'list - list studies and exit')

    # custom helper
    parser.add_argument('-what',
                        dest='what',
                        action='store_true',
                        required=False,
                        help='Get more information about the software')

    # pfo_study_bruker_input
    parser.add_argument('-i',
                        '--input_study_folder',
                        dest='pfo_input',
                        type=str,
                        required=False,
                        help='Bruker study folder.')

    # pfo_study_nifti_output
    parser.add_argument('-o',
                        '--output_study_folder',
                        dest='pfo_output',
                        type=str,
                        required=False,
                        help='Output folder where the study will be saved.')

    # study_name = None,
    parser.add_argument('-study_name', dest='study_name', default=None)

    # scans_list = None
    # Accepts a list of single digit numbers without any separators. Unable to
    # specify multi-digit scan numbers this way. The --scans argument specified
    # below supersedes this but --scans_list is left in for backwards
    # compatibility. If --scans is also supplied, this paramater is ignored.
    parser.add_argument('-scans_list', dest='scans_list', default=None)

    # A comma or space/tab separated list of scans to operate on
    parser.add_argument('--scans', dest='scans', default=None)

    # list_new_name_each_scan = None,
    parser.add_argument('-list_new_name_each_scan',
                        dest='list_new_name_each_scan',
                        default=None)

    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1)

    # qform = 2,
    parser.add_argument('-qform_code', dest='qform_code', type=int, default=1)

    # sform= 1,
    parser.add_argument('-sform_code', dest='sform_code', type=int, default=2)

    # do_not_save_human_readable = False,
    parser.add_argument('-do_not_save_human_readable',
                        dest='do_not_save_human_readable',
                        action='store_true')

    # correct_slope = True,
    parser.add_argument('-correct_slope',
                        dest='correct_slope',
                        action='store_true')

    # correct_offset = True,
    parser.add_argument('-correct_offset',
                        dest='correct_offset',
                        action='store_true')

    # correct_offset = True,
    parser.add_argument('-sample_upside_down',
                        dest='sample_upside_down',
                        action='store_false')

    # correct_offset = True,
    parser.add_argument('-frame_body_as_frame_head',
                        dest='frame_body_as_frame_head',
                        action='store_false')

    # verbose = 1
    parser.add_argument('-verbose', '-v', dest='verbose', type=int, default=1)

    # ------ Parsing user's input ------ #

    args = parser.parse_args()

    if args.scans:
        scan_list = re.split(r"[^\d]+", args.scans)
    elif args.scans_list:
        scan_list = list(args.scans_list)
    else:
        scan_list = None

    # Check input:
    if args.command == 'list':
        list_scans(args.pfo_input)
        sys.exit(0)

    if args.what:
        msg = 'Code repository : {} \n' \
              'Documentation   : {}'.format('https://github.com/SebastianoF/bruker2nifti',
                                            'https://github.com/SebastianoF/bruker2nifti/wiki')
        sys.exit(msg)

    if not args.pfo_input or not args.pfo_output:
        sys.exit('Input bruker study [-i] and output folder [-o] required')

    # Instantiate a converter:
    bruconv = Bruker2Nifti(args.pfo_input,
                           args.pfo_output,
                           study_name=args.study_name)

    if scan_list is not None:
        bruconv.scans_list = scan_list
    if args.list_new_name_each_scan is not None:
        bruconv.list_new_name_each_scan = args.list_new_name_each_scan
    elif scan_list is not None:
        # This list of output scan names is populated during object instantiation
        # which causes problems when updating the list of scans to convert after
        # object instantiation (the only way to do it). The following work-around
        # replaces the list of output file names if a list is not explicitly provided.
        # TODO: Restructure the Bruker2Nifti class so that this is not necessary.
        bruconv.list_new_name_each_scan = [
            bruconv.study_name + '_' + ls for ls in scan_list
        ]

    # Basics
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_human_readable = not args.do_not_save_human_readable
    bruconv.correct_slope = args.correct_slope
    bruconv.correct_offset = args.correct_offset
    bruconv.verbose = args.verbose
    # Sample position
    bruconv.sample_upside_down = args.sample_upside_down
    bruconv.frame_body_as_frame_head = args.frame_body_as_frame_head

    print('\nConverter input parameters: ')
    print('-------------------------------------------------------- ')
    print('Study name           : {}'.format(bruconv.study_name))
    print('List of scans        : {}'.format(bruconv.scans_list))
    print('List of scans names  : {}'.format(bruconv.list_new_name_each_scan))
    print('Output NifTi version : {}'.format(bruconv.nifti_version))
    print('Output NifTi q-form  : {}'.format(bruconv.qform_code))
    print('Output NifTi s-form  : {}'.format(bruconv.sform_code))
    print('Save human readable  : {}'.format(bruconv.save_human_readable))
    print('Correct the slope    : {}'.format(bruconv.correct_slope))
    print('Correct the offset   : {}'.format(bruconv.correct_offset))
    print('-------------------------------------------------------- ')
    print('Sample upside down         : {}'.format(bruconv.sample_upside_down))
    print('Frame body as frame head   : {}'.format(
        bruconv.frame_body_as_frame_head))
    print('-------------------------------------------------------- ')
    bruconv.convert()

    # Print a warning message for paths with whitespace as it may interfere
    # with subsequent steps in an image analysis pipeline
    if utils.path_contains_whitespace(bruconv.pfo_study_nifti_output,
                                      bruconv.study_name):
        print("INFO: Output path/filename contains whitespace")
コード例 #11
0
def main():
    """
    Parser from terminal with
    $ python2 bruker2nifti_study -i input_file_path -o output_file_path
    """

    parser = argparse.ArgumentParser()

    # pfo_input_scan
    parser.add_argument('-i',
                        '--input_scan_folder',
                        dest='pfo_input',
                        type=str,
                        required=True,
                        help='Bruker scan folder.')
    # pfo_output
    parser.add_argument('-o',
                        '--output_scan_folder',
                        dest='pfo_output',
                        type=str,
                        required=True,
                        help='Output folder where the study will be saved.')
    # fin_output = None
    parser.add_argument('--fin_output',
                        dest='fin_output',
                        type=str,
                        default=None)
    # nifti_version = 1,
    parser.add_argument('-nifti_version',
                        dest='nifti_version',
                        type=int,
                        default=1,
                        help='Filename of the nifti output.')
    # qform = 2,
    parser.add_argument('-qform_code', dest='qform_code', type=int, default=2)
    # sform = 1,
    parser.add_argument('-sform_code', dest='sform_code', type=int, default=1)

    # save_human_readable = True,
    parser.add_argument('-save_human_readable',
                        dest='save_human_readable',
                        action='store_true')
    # normalise_b_vectors_if_dwi = True,
    parser.add_argument('-normalise_b_vectors_if_dwi',
                        dest='normalise_b_vectors_if_dwi',
                        action='store_true')
    # correct_slope = False,
    parser.add_argument('-correct_slope',
                        dest='correct_slope',
                        action='store_false')
    # verbose = 1
    parser.add_argument('-verbose', dest='verbose', action='store_true')
    # -info_only
    parser.add_argument('-info_only', dest='info_only', action='store_false')
    # -nifti_only
    parser.add_argument('-nifti_only', dest='nifti_only', action='store_false')

    args = parser.parse_args()

    # instantiate a converter:
    bruconv = Bruker2Nifti(os.path.dirname(args.pfo_input), args.pfo_output)
    # get the attributes
    bruconv.nifti_version = args.nifti_version
    bruconv.qform_code = args.qform_code
    bruconv.sform_code = args.sform_code
    bruconv.save_human_readable = args.save_human_readable
    bruconv.correct_slope = args.correct_slope
    bruconv.verbose = args.verbose
    # convert the single:
    bruconv.convert_scan(args.pfo_input,
                         args.pfo_output,
                         nifti_file_name=args.fin_output,
                         create_output_folder_if_not_exists=True)
コード例 #12
0
import os
from bruker2nifti.converter import Bruker2Nifti

data_folder = '/Users/alex/jacques/Testing_Scans_zone/FA_catch/N57433_m00'
pfo_study_in = os.path.join(data_folder, 'raw', 'McGill_Orientation',
                            'a20130329_APM_DEV_Orient.j71')
pfo_study_in = data_folder
destination_folder = '/Users/alex/jacques/Testing_Scans_zone/FA_catch/'
pfo_study_out = destination_folder

bru = Bruker2Nifti(pfo_study_in, pfo_study_out, study_name='my_study')

bru.verbose = 2
bru.correct_slope = False
bru.get_acqp = False
bru.get_method = False
bru.get_reco = False
bru.nifti_version = 1
bru.qform_code = 1
bru.sform_code = 2
bru.save_human_readable = True
bru.save_b0_if_dwi = True

print(bru.scans_list)
print(bru.list_new_name_each_scan)

bru.convert()