external
Calls to external packages
test |
Run tests for module using nose. |
external.fsl
FSL IO
Dpy (fname[, mode, compression]) |
Methods |
FSLError |
Class signals error in FSL processing |
InTemporaryDirectory ([suffix, prefix, dir]) |
Create, return, and change directory to a temporary directory |
Popen (args[, bufsize, executable, stdin, …]) |
Execute a child program in a new process. |
affine_transform (input, matrix[, offset, …]) |
Apply an affine transformation. |
apply_warp (in_nii, affine_mat, nonlin_nii, …) |
|
bet (in_nii, out_nii[, options]) |
|
create_displacements (fin, fmat, fnonlin, …) |
Create displacements using FSL’s FLIRT and FNIRT tools |
dcm2nii (dname, outdir[, filt, options]) |
|
eddy_correct (in_nii, out_nii[, ref]) |
|
flirt2aff (mat, in_img, ref_img) |
Transform from in_img voxels to ref_img voxels given mat |
flirt2aff_files (matfile, in_fname, ref_fname) |
Map from in_fname image voxels to ref_fname voxels given matfile |
have_flirt () |
Return True if we can call flirt without error |
mc (input, coordinates[, output, order, …]) |
Map the input array to new coordinates by interpolation. |
pipe (cmd[, print_sto, print_ste]) |
A tine pipeline system to run external tools. |
pjoin (a, *p) |
Join two or more pathname components, inserting ‘/’ as needed. |
run_flirt_imgs (in_img, ref_img[, dof, flags]) |
Run flirt on nibabel images, returning affine |
warp_displacements (ffa, flaff, fdis, fref, ffaw) |
Warp an image using fsl displacements |
warp_displacements_tracks (fdpy, ffa, fmat, …) |
Warp tracks from native space to the FMRIB58/MNI space |
write_bvals_bvecs (bvals, bvecs[, outpath, …]) |
Write FSL FDT bvals and bvecs files |
dipy.external.
test
(label='fast', verbose=1, extra_argv=None, doctests=False, coverage=False, raise_warnings=None, timer=False)Run tests for module using nose.
Parameters: |
|
---|---|
Returns: |
|
Notes
Each NumPy module exposes test in its namespace to run all tests for it. For example, to run all tests for numpy.lib:
>>> np.lib.test()
Examples
>>> result = np.lib.test()
Running unit tests for numpy.lib
...
Ran 976 tests in 3.933s
OK
>>> result.errors
[]
>>> result.knownfail
[]
Dpy
dipy.external.fsl.
Dpy
(fname, mode='r', compression=0)Bases: object
Methods
read_track () |
read one track each time |
read_tracks () |
read the entire tractography |
read_tracksi (indices) |
read tracks with specific indices |
write_track (track) |
write on track each time |
write_tracks (tracks) |
write many tracks together |
close | |
version |
__init__
(fname, mode='r', compression=0)Advanced storage system for tractography based on HDF5
Parameters: |
|
---|
Examples
>>> import os
>>> from tempfile import mkstemp #temp file
>>> from dipy.io.dpy import Dpy
>>> def dpy_example():
... fd,fname = mkstemp()
... fname += '.dpy'#add correct extension
... dpw = Dpy(fname,'w')
... A=np.ones((5,3))
... B=2*A.copy()
... C=3*A.copy()
... dpw.write_track(A)
... dpw.write_track(B)
... dpw.write_track(C)
... dpw.close()
... dpr = Dpy(fname,'r')
... dpr.read_track()
... dpr.read_track()
... dpr.read_tracksi([0, 1, 2, 0, 0, 2])
... dpr.close()
... os.remove(fname) #delete file from disk
>>> dpy_example()
FSLError
dipy.external.fsl.
FSLError
Bases: Exception
Class signals error in FSL processing
Attributes: |
|
---|
Methods
with_traceback |
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self. |
InTemporaryDirectory
dipy.external.fsl.
InTemporaryDirectory
(suffix='', prefix='tmp', dir=None)Bases: nibabel.tmpdirs.TemporaryDirectory
Create, return, and change directory to a temporary directory
Examples
>>> import os
>>> my_cwd = os.getcwd()
>>> with InTemporaryDirectory() as tmpdir:
... _ = open('test.txt', 'wt').write('some text')
... assert os.path.isfile('test.txt')
... assert os.path.isfile(os.path.join(tmpdir, 'test.txt'))
>>> os.path.exists(tmpdir)
False
>>> os.getcwd() == my_cwd
True
Methods
cleanup |
Popen
dipy.external.fsl.
Popen
(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=<object object>, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, encoding=None, errors=None)Bases: object
Execute a child program in a new process.
For a complete description of the arguments see the Python documentation.
args: A string, or a sequence of program arguments.
executable: A replacement program to execute.
close_fds: Controls closing or inheriting of file descriptors.
shell: If true, the command will be executed through the shell.
cwd: Sets the current directory before the child is executed.
env: Defines the environment variables for the new process.
startupinfo and creationflags (Windows only)
restore_signals (POSIX only)
start_new_session (POSIX only)
pass_fds (POSIX only)
Methods
communicate ([input, timeout]) |
Interact with process: Send data to stdin. |
kill () |
Kill the process with SIGKILL |
poll () |
Check if child process has terminated. |
send_signal (sig) |
Send a signal to the process. |
terminate () |
Terminate the process with SIGTERM |
wait ([timeout, endtime]) |
Wait for child process to terminate. |
__init__
(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=<object object>, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, encoding=None, errors=None)Create new Popen instance.
communicate
(input=None, timeout=None)Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate.
The optional “input” argument should be data to be sent to the child process (if self.universal_newlines is True, this should be a string; if it is False, “input” should be bytes), or None, if no data should be sent to the child.
communicate() returns a tuple (stdout, stderr). These will be bytes or, if self.universal_newlines was True, a string.
dipy.external.fsl.
affine_transform
(input, matrix, offset=0.0, output_shape=None, output=None, order=3, mode='constant', cval=0.0, prefilter=True)Apply an affine transformation.
Given an output image pixel index vector o
, the pixel value
is determined from the input image at position
np.dot(matrix, o) + offset
.
Parameters: |
|
---|---|
Returns: |
|
Notes
The given matrix and offset are used to find for each point in the output the corresponding coordinates in the input by an affine transformation. The value of the input at those coordinates is determined by spline interpolation of the requested order. Points outside the boundaries of the input are filled according to the given mode.
Changed in version 0.18.0: Previously, the exact interpretation of the affine transformation
depended on whether the matrix was supplied as a one-dimensional or
two-dimensional array. If a one-dimensional array was supplied
to the matrix parameter, the output pixel value at index o
was determined from the input image at position
matrix * (o + offset)
.
References
[1] | (1, 2) https://en.wikipedia.org/wiki/Homogeneous_coordinates |
dipy.external.fsl.
create_displacements
(fin, fmat, fnonlin, finvw, fdisp, fdispa, fref)Create displacements using FSL’s FLIRT and FNIRT tools
Parameters: |
|
---|
dipy.external.fsl.
flirt2aff
(mat, in_img, ref_img)Transform from in_img voxels to ref_img voxels given mat
Parameters: |
|
---|---|
Returns: |
|
Notes
Thanks to Mark Jenkinson and Jesper Andersson for the correct statements here, apologies for any errors we’ve added.
flirt
registers an in
image to a ref
image. It can produce
(with the -omat
option) - a 4 x 4 affine matrix giving the mapping from
inspace to refspace.
The rest of this note is to specify what inspace and refspace are.
In what follows, a voxtrans for an image is the 4 by 4 affine
np.diag([vox_i, vox_j, vox_k, 1])
where vox_i
etc are the voxel
sizes for the first second and third voxel dimension. vox_i
etc are
always positive.
If the input image has an affine with a negative determinant, then the mapping from voxel coordinates in the input image to inspace is simply voxtrans for the input image. If the reference image has a negative determinant, the mapping from voxel space in the reference image to refspace is simply voxtrans for the reference image.
A negative determinant for the image affine is the common case, of an image with a x voxel flip. Analyze images don’t store affines and flirt assumes a negative determinant in these cases.
For positive determinant affines, flirt starts inspace and / or refspace with an x voxel flip. The mapping implied for an x voxel flip for image with shape (N_i, N_j, N_k) is:
- [[-1, 0, 0, N_i - 1],
- [ 0, 1, 0, 0], [ 0, 0, 1, 0], [ 0, 0, 0, 1]]
If the input image has an affine with a positive determinant, then mapping
from input image voxel coordinates to inspace is np.dot(input_voxtrans,
input_x_flip)
- where input_x_flip
is the matrix above with N_i
given by the input image first axis length. Similarly the mapping from
reference voxel coordinates to refspace, if the reference image has a
positive determinant, is np.dot(ref_voxtrans, ref_x_flip)
- where
ref_x_flip
is the matrix above with N_i
given by the reference
image first axis length.
dipy.external.fsl.
flirt2aff_files
(matfile, in_fname, ref_fname)Map from in_fname image voxels to ref_fname voxels given matfile
See flirt2aff()
docstring for details.
Parameters: |
|
---|---|
Returns: |
|
dipy.external.fsl.
mc
(input, coordinates, output=None, order=3, mode='constant', cval=0.0, prefilter=True)Map the input array to new coordinates by interpolation.
The array of coordinates is used to find, for each point in the output, the corresponding coordinates in the input. The value of the input at those coordinates is determined by spline interpolation of the requested order.
The shape of the output is derived from that of the coordinate array by dropping the first axis. The values of the array along the first axis are the coordinates in the input array at which the output value is found.
Parameters: |
|
---|---|
Returns: |
|
See also
spline_filter
, geometric_transform
, scipy.interpolate
Examples
>>> from scipy import ndimage
>>> a = np.arange(12.).reshape((4, 3))
>>> a
array([[ 0., 1., 2.],
[ 3., 4., 5.],
[ 6., 7., 8.],
[ 9., 10., 11.]])
>>> ndimage.map_coordinates(a, [[0.5, 2], [0.5, 1]], order=1)
array([ 2., 7.])
Above, the interpolated value of a[0.5, 0.5] gives output[0], while a[2, 1] is output[1].
>>> inds = np.array([[0.5, 2], [0.5, 4]])
>>> ndimage.map_coordinates(a, inds, order=1, cval=-33.3)
array([ 2. , -33.3])
>>> ndimage.map_coordinates(a, inds, order=1, mode='nearest')
array([ 2., 8.])
>>> ndimage.map_coordinates(a, inds, order=1, cval=0, output=bool)
array([ True, False], dtype=bool)
dipy.external.fsl.
pipe
(cmd, print_sto=True, print_ste=True)A tine pipeline system to run external tools.
For more advanced pipelining use nipype http://www.nipy.org/nipype
dipy.external.fsl.
run_flirt_imgs
(in_img, ref_img, dof=6, flags='')Run flirt on nibabel images, returning affine
Parameters: |
|
---|---|
Returns: |
|
dipy.external.fsl.
warp_displacements
(ffa, flaff, fdis, fref, ffaw, order=1)Warp an image using fsl displacements
Parameters: |
|
---|
dipy.external.fsl.
warp_displacements_tracks
(fdpy, ffa, fmat, finv, fdis, fdisa, fref, fdpyw)Warp tracks from native space to the FMRIB58/MNI space
We use here the fsl displacements. Have a look at create_displacements to see an example of how to use these displacements.
Parameters: |
|
---|
dipy.external.fsl.
write_bvals_bvecs
(bvals, bvecs, outpath=None, prefix='')Write FSL FDT bvals and bvecs files
Parameters: |
|
---|