Library
Seeds
Tractography.from_fod — Function
from_fod(
model::TMC{𝒯},
n_seeds::Int64;
n_sphere,
maxfod_start
) -> Any
Generate seeds from orientation distribution functions.
Keyword arguments
maxfod_start = falseThe seeds are generated in voxels with non-zero average FOD with the orientations importance sampled.maxfod_start = trueThe seeds are generated in voxels with non-zero average FOD with the orientations corresponding to the maximum probability.
Tractography.from_mask — Function
from_mask(
model::TMC{𝒯},
mask::AbstractArray{Bool, 3},
n_seeds::Int64
) -> Any
Generate seeds from a 3D mask. The seeds are generated randomly inside voxels with non-zero values in the mask. The orientations are random.
fODF evaluation strategy
Tractography.PlottingSH — Type
struct PlottingSH <: Tractography.AbstractSPHEvaluationSet up for plotting ODF.
Tractography.PreComputeAllFOD — Type
struct PreComputeAllFOD <: Tractography.AbstractSPHEvaluationSpherical harmonics evaluation based on Fibonacci sampling. All ODF are pre-computed once and saved in a cache. Their positivity is enforced with a max(0,⋅) or a mollifier.
Details
If you have na angles for sampling the unit sphere and the data is of size (nx, ny, nz, nsph), it yields a matrix of dimensions (nx, ny, nz, na).
Tractography.DirectSH — Type
struct DirectSH <: Tractography.AbstractSPHEvaluationThe evaluation of spherical harmonics is done on the fly. Requires little memory.
See also PreComputeAllFOD
Models
Tractography.FODData — Type
struct FODData{𝒯, 𝒯d, 𝒯s, 𝒯t}Structure to hold FOD data.
Internal fields
filename::String: filename from which the (fod) data is read.data::Any: field which contains the FOD data.lmax::Int64: max l coordinate in of spherical harmonics.transform::Tractography.Transform: transform associated with data, seeTransform.normalized::Bool: Are the data normalized? In this casefod[i,j,l,1] ∈ {0,1}.
Methods
get_lmax(::FODData)returns the maxlcoordinate in of spherical harmonics.size(::FODData)returns the size of the data.get_range(::FODData)returns the range of the data in the real world coordinates.is_normalized(::FODData)return whether the data is normalized.
Constructors
In the following, data has shape nx x ny x nz x nt.
FODData(data::AbstractArray{𝒯, 4}, tranform::Transform, normalize_it::Bool; file_name = "None").FODData(data::AbstractArray{𝒯, 4}, S, T, normalize_it::Bool; file_name = "None").FODData(data::AbstractArray{𝒯, 4}, normalize_it::Bool)uses a trivial transform.FODData(file_name::String; normalize_it::Bool = true, k...)the transform is extracted from the nii file.
Tractography.TMC — Type
struct TMC{𝒯, 𝒯alg<:Tractography.AbstractSPHEvaluation, 𝒯d, 𝒯C, 𝒯mol}Tractography Markov Chain (TMC).
Internal fields (with default values):
Δt::Any: Step size of the TMC. Default: 0.1evaluation_algo::Tractography.AbstractSPHEvaluation: Spherical harmonics evaluation algorithm. Can beFibonacciSH(), PreComputeAllFOD(). Default: PreComputeAllFOD()foddata::Any: ODF data, typically from nifti file but can be passed as an Array. Must be the list of ODF in the base of spherical harmonics. Hence, it should be an (abstract) 4d array. Default: nothingcone::Any: Cone function to restrict angle diffusion. You can use aConeor a custom function(d1, d2) -> return_a_boolean. Default: Cone(90.0f0)proba_min::Any: Probability below which we stop tracking. Default: 0.0mollifier::Any: Mollifier, used to make the fodf non negative. During odf evaluation, we effectively usemollifier(fodf[angle,i,j,k]). Default: max_mollifier
Methods
_apply_mask!(model, mask)apply a mask to the raw SH tensor. See its doc string._getdata(model)return the fodf data associated with the TMC.size(model)returnnx, ny, nz, nt.eltype(model)return the scalar type of the data (default Float64).get_lmax(model)return the maxlcoordinate in of spherical harmonics.
Constructors (pass the internal fields!)
TMC()TMC(Δt = 0.1f0)for a Float32 TMCTMC(Δt = 0.1, proba_min = 0.)for a Float64 TMC. You need to specify both fieldsΔtandproba_minTMC(odfdata = rand(10,10,10,45))for custom ODF
Algorithms
Tractography.Deterministic — Type
struct Deterministic <: Tractography.DeterministicSamplerTractography sampling performed with the argmax function. Can be used with FibonacciSH and PreComputeAllFOD.
Tractography.Probabilistic — Type
struct Probabilistic <: Tractography.AbstractNotPureRejectionSamplerTractography sampling performed with the cumulative sum distribution. Can be used with FibonacciSH and PreComputeAllFOD.
Constructor
Probabilistic()
Tractography.Diffusion — Type
struct Diffusion{T, Tmol, Tdmol} <: Tractography.AbstractSDESampler{T}Tractography sampling performed with diffusive model. Basically, the streamlines (Xₜ)ₜ are solution of the SDE
dXₜ = γ⋅drift(Xₜ)⋅dt + √(2γ ⋅ γ_noise) ⋅ dnoiseₜ
where
drift(Xₜ) = (Xₜ², ∇log f(Xₜ))
Arguments (with default values):
γ::Any: γ parameter of the diffusion process. It is related to the curvature of the streamline. Default: 1.0γ_noise::Any: parameter of the diffusion process to scale the variance. Default: 1.0mollifier::Any: mollifier. Default: Base.Fix2(softplus, 10)d_mollifier::Any: differential of mollifier. Default: Base.Fix2(∂softplus, 10)adaptive::Bool: Fixed time step? Default: false
Constructor
Example for Float32: Diffusion(γ = 1f0). If you want Float64, you have to pass the two scalars
```Diffusion(γ = 1.0, γ_noise = 1.0)```Tractography.Transport — Type
Define a transport algorithm. Options are the same as for Diffusion.
Arguments (with default values):
γ::Any: γ parameter of the diffusion process. It is related to the curvature of the streamline. Default: 1.0mollifier::Any: mollifier. Default: Base.Fix2(softplus, 10)d_mollifier::Any: differential of mollifier. Default: Base.Fix2(∂softplus, 10)adaptive::Bool: Fixed time step? Default: false
Tractography.Connectivity — Type
struct Connectivity{Talg} <: Tractography.AbstractSamplerTractography based sampling of structural connectivity. Do not compute the full streamline but only return the first/last points and the streamlines lengths. This allows to compute many more streamlines on GPU where memory is limited.
Constructor example
Connectivity(Probabilistic())
Sampling
Tractography.init — Function
init(
model::TMC{𝒯},
alg;
n_sphere,
𝒯ₐ
) -> Tractography.ThreadedCache{_A, Nothing, _B, Nothing, Nothing} where {_A, _B}
Create a cache for computing streamlines in batches. This is interesting for use of memory limited environments (e.g. on GPU).
Arguments
algsampling algorithm,Deterministic, Probabilistic, Diffusion, etc.n_sphere::Int = 400number of points to discretize the sphere on which we evaluate the spherical harmonics.𝒯ₐ = Array{𝒯}specify the type of the arrays in the cache. If passed a GPU array type likeCuArrayfor CUDA, the sampling occurs on the GPU. Leave it for computing on CPU.
Tractography.sample — Function
sample(
model::TMC{𝒯},
alg::Tractography.AbstractSampler,
seeds::AbstractArray{𝒯, 2};
...
) -> Tuple{Any, Any}
sample(
model::TMC{𝒯},
alg::Tractography.AbstractSampler,
seeds::AbstractArray{𝒯, 2},
mask::Union{Nothing, AbstractArray{Bool}};
nt,
n_sphere,
maxfod_start,
reverse_direction,
nthreads,
gputhreads,
saveat
) -> Tuple{Any, Any}
Sample the TMC model.
Arguments
model::TMCalgsampling algorithm,Deterministic, Probabilistic, Diffusion, etc.seedsmatrix of size6 x NmcwhereNmcis the number of Monte-Carlo simulations to be performed.mask = nothingmatrix of boolean where to stop computation. See also_apply_mask.
Optional arguments
nt::Intmaximal number of steps to compute each streamline.n_sphere::Int = 400number of points to discretize the sphere on which we evaluate the spherical harmonics.maxfod_start::Boolfor each locations, use direction provided by the argmax of the ODF.reverse_direction::Boolreverse initial direction.nthreads::Int = 8number of threads on CPU.gputhreads::Int = 512number of threads on GPU.saveat::Intrecord the streamline everysaveatstep. Only available foralg <: Diffusion.
Output
streamlineswith shape3 x nt x Nmc
Tractography.sample! — Function
sample!(
streamlines,
streamlines_length,
model::TMC{𝒯},
cache::Tractography.AbstractCache,
alg,
seeds;
maxfod_start,
reverse_direction,
nthreads,
gputhreads,
nₜ,
saveat,
𝒯ₐ
) -> Any
Sample the TMC model inplace by overwriting result. This requires very little memory and can be run indefinitely on the GPU for example.
Arguments
streamlinesarray with shape3 x nt x Nmc.ntis maximal length of each streamline.Nmcis the number of Monte-Carlo simulations to be performed.streamlines_lengthlength of the streamlinesmodel::TMCalgsampling algorithm,Deterministic, Probabilistic, Diffusion, etc.seedsmatrix of size6 x NmcwhereNmcis the number of Monte-Carlo simulations to be performed.
Optional arguments
maxfod_start::Boolfor each locations, use direction provided by the argmax of the ODF.reverse_direction::Boolreverse initial direction.nthreads::Int = 8number of threads on CPU.gputhreads::Int = 512number of threads on GPU.
Plotting
Tractography.plot_streamlines! — Function
plot_streamlines!(ax, streamlines; k...)
Plot the streamlines with lines colored by local orientation.
The optional parameters are passed to lines!.
Tractography.plot_fod! — Function
plot_fod!(ax, model; n_sphere, radius, st, I, J, K, c0min)
Plot the the ODF with glyphs.
See also
plot_fod(model; kwargs...)for an out-of-place method with same parameters.
Arguments
axGLMakie scenemodel::TMC
Optional arguments
I, J, K: range for displaying the fODFs. Some of them can be a single element, likeK = 40:40.radius: radius of the glyph.st = 4: stride, only show one overstglyph in each direction.
Tractography.plot_slice — Function
plot_slice(model; k...)
Plot a slice of the data.
See also
plot_slice!
Arguments
model::TMC
Optional arguments
odf::Booldisplay the ODF with glyphs.slice::Booldisplay the brain slice from mean ODF value.interpolate::Boolinterpolate the brain slice (reduces pixelization).alphaalpha value for brain slice.I,J,Krange for displaying the ODF. One of them should be a single element, likeK = 40:40.st::Int = 2c0minminimum mean ODF value for plotting the glyph.n_theta::Intnumber of points for showing the glyphs.radius = 0.1radius of the glyphs.
Misc
Tractography.Cone — Type
struct Cone{𝒯<:Real}Structure to encode a cone to limit sampling the direction. This ensures that the angle in degrees between to consecutive streamline directions is less than angle.
The implemented condition is for cn = Cone(angle).
(cn::Cone)(d1, d2) = dot(d1, d2) > cosd(cn.alpha)Fields
alpha::Real: half section angle in degrees
Constructor
Cone(angle)
Tractography._apply_mask! — Function
_apply_mask!(model, mask)
Multiply the mask which is akin to a matrix of Bool with same size as the data stored in model. Basically, the mask mask[ix, iy, iz] ensures whether the voxel (ix, iy, iz) is discarded or not.
Arguments
model::TMC.maskcan be aAbstractArray{3, Bool}or aNIVolume.
Missing docstring for Tractography.save_streamlines. Check Documenter's build log for details.
Tractography.Exp𝕊² — Function
Exp𝕊²(p, X, t) -> Any
Exponential map on the sphere.
We assume that t > 0
See https://github.com/JuliaManifolds/ManifoldsBase.jl/blob/5c4a61ed3e5e44755a22f7872cb296a621905f87/test/ManifoldsBaseTestUtils.jl#L63
Tractography.spherical_to_euclidean — Function
spherical_to_euclidean(θ, ϕ) -> Tuple{Any, Any, Any}
Transform spherical to cartesian coordinates, the chart on the sphere minus the north/south poles.
Its coordinates are (sin(θ)cos(ϕ), sin(θ)sin(ϕ), cos(θ)).
Recall that θ ∈ [0, π] and ϕ ∈ [0, 2π].
Tractography.euclidean_to_spherical — Function
euclidean_to_spherical(x, y, z) -> Tuple{Any, Any}
Transform cartesian to spherical coordinates. Assume that the vector has norm one. Return (θ, ϕ) where θ ∈ [0, π] and ϕ ∈ [-π, π].