Skip to content

Examples

Sebastiano Ferraris edited this page Aug 14, 2017 · 24 revisions

Conversion Example

A dataset of MR Bruker images where to test the code can be found here (thanks to Mikaël Naveau).

In the following lines we will convert the images accessing bruker2nifti via

  • Python command shell,
  • Command Line Utility (CLI) to integrate it in a bash script,
  • Graphical User Interface (GUI).

All you need:

  • The dataset provided downloaded in a data_folder.
  • A python release with bruker2nifti installed

Converting via Python command shell

All in the same Python module:

import os

from bruker2nifti.converter import Bruker2Nifti

if __name__ == '__main__':
    root_dir = '/path/to/bruker2nifti/repo'
    pfo_study_in = os.path.join(root_dir, 'test_data', 'bru_banana')
    pfo_study_out = '/path/to/some/existing/folder/where/conversion/will/happen'

    # instantiate a converter - if you do not want to use the default study name in visu_pars set the study name here.
    bru = Bruker2Nifti(pfo_study_in, pfo_study_out, study_name='banana')
    # select the options (attributes) you may want to change - the one shown below are the default one:
    bru.verbose = 2
    bru.correct_slope = True
    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
    bru.correct_slope = False
    # Check that the list of scans and the scans names automatically selected makes some sense:
    print(bru.scans_list)
    print(bru.list_new_name_each_scan)
    print(bru.list_new_nifti_file_names)
    # call the function convert, to convert the study:
    bru.convert()

Converting via Graphical User Interface

Check the next wiki-page to convert the data_set examples with the GUI.

Type

python parsers/bruker2nii -h

for help and see the options.

You can convert a study from the parsers without any installation, with

python parsers/bruker2nii -i path/to/bruker/study -o path/to/output/folder

To convert a scan, to modify the code or to call the code with an import within other python module it is recommended to install the python package as a library following the next instructions.

In a python module

You can add the bruker2nifti folder in your PYTHONPATH, or you can install the converter as a library (next section more instructions on this).

To convert one of the test study, enter in an python or ipython session of a distribution with the required libraries installed the following lines: