Library
Misc
Tractography.Cone — Typestruct 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𝕊² — FunctionExp𝕊²(p, X, t)
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 — Functionspherical_to_euclidean(θ, ϕ)
Transform spherical to cartesian coordinates.
Recall that t∈[0, π] and p∈[0, 2π]
Tractography.euclidean_to_spherical — Functioneuclidean_to_spherical(x, y, z)
Transform cartesian to spherical coordinates. Assume that the vector has norm one.
Spherical harmonics evaluation strategy
Tractography.PlottingSH — Typestruct PlottingSH <: Tractography.AbstractSPHEvaluationSet up for plotting ODF.
Tractography.PreComputeAllODF — Typestruct PreComputeAllODF <: 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).
Models
Tractography.TMC — Typestruct TMC{𝒯, 𝒯alg<:Tractography.AbstractSPHEvaluation, 𝒯d, 𝒯C, 𝒯mol}Tractography Markov Chain (TMC).
Fields (with default values):
Δt::Any: Step size of the TMC. Default: 0.1evaluation_algo::Tractography.AbstractSPHEvaluation: Spherical harmonics evaluation algorithm. Can beFibonacciSH(), PreComputeAllODF(). Default: PreComputeAllODF()odfdata::Any: ODF data from nifti file. 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[i,j,k,angle]). Default: default_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 (use the 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 — Typestruct Deterministic <: Tractography.DeterministicSamplerTractography sampling performed with the argmax function. Can be used with FibonacciSH and PreComputeAllODF.
Tractography.Probabilistic — Typestruct Probabilistic <: Tractography.AbstractNotPureRejectionSamplerTractography sampling performed with the cumulative sum distribution. Can be used with FibonacciSH and PreComputeAllODF.
Constructor
Probabilistic()
Tractography.Diffusion — Typestruct Diffusion{Ta, T, Tk, Tmol, Tdmol} <: Tractography.AbstractSamplerTractography sampling performed with diffusive model. Basically, the streamlines (Xₜ)ₜ are solution of the SDE
dXₜ = γ * drift dt + γ_noise * √γ * dnoiseₜ
Arguments (with default values):
alg_sde::Any: SciML algorithm used to simulate the tractography diffusion process. Default: nothingγ::Any: γ parameter of the diffusion process. Default: 1.0γ_noise::Any: parameter of the diffusion process to scale the variance. Default: 1.0kw_sde::Any: keyword arguments passed to alg_sde. Default: nothingmollifier::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.Connectivity — Typestruct 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 — Functioninit(
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 — Functionsample(
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,
maxodf_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.maxodf_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! — Functionsample!(
streamlines,
streamlines_length,
model::TMC{𝒯},
cache::Tractography.AbstractCache,
alg,
seeds;
maxodf_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
maxodf_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! — Functionplot_streamlines!(ax, streamlines; k...)
Plot the streamlines.
The optional parameters are passed to lines!
Tractography.plot_odf! — Functionplot_odf!(ax, model; n_sphere, radius, st, I, J, K, c0min)
Plot the the ODF with glyphs.
See also
plot_odf(model; kwargs...)
Arguments
model::TMCI, J, Krange for displaying the ODF. Some of them can be a single element, likeK = 40:40.radiusradius of the glyph.st = 4stride, only show one overstglyph in each direction.
Optional arguments
Tractography.plot_slice — Functionplot_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.