kwneuro.resource module

class kwneuro.resource.BvalResource

Bases: Resource

Base class for resources representing a list of b-values associated with a 4D DWI volume stack.

abstractmethod get()

Get the underlying array of b-values

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

load()

Load a Resource. Specific functionality depends on the Resource subclass, but if the resource is considered to be ‘loaded’ then this should be a no-op, returning the same Resource back.

Return type:

BvalResource

class kwneuro.resource.BvecResource

Bases: Resource

Base class for resources representing a list of b-vectors associated with a 4D DWI volume stack.

abstractmethod get()

Get the underlying array of b-vectors of shape (N,3)

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

load()

Load a Resource. Specific functionality depends on the Resource subclass, but if the resource is considered to be ‘loaded’ then this should be a no-op, returning the same Resource back.

Return type:

BvecResource

class kwneuro.resource.InMemoryBvalResource(array)

Bases: BvalResource

A b-value list that is loaded into memory.

Parameters:

array (ndarray[tuple[Any, ...], dtype[floating]])

array: ndarray[tuple[Any, ...], dtype[floating]]

The underlying array of b-values

get()

Get the underlying array of b-values

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

is_loaded: ClassVar[bool] = True

Whether a resource corresponds to in-memory data, rather than for example on-disk data.

class kwneuro.resource.InMemoryBvecResource(array)

Bases: BvecResource

A b-vector list that is loaded into memory.

Parameters:

array (ndarray[tuple[Any, ...], dtype[floating]])

array: ndarray[tuple[Any, ...], dtype[floating]]

The underlying array of b-vectors

get()

Get the underlying array of b-vectors of shape (N,3)

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

is_loaded: ClassVar[bool] = True

Whether a resource corresponds to in-memory data, rather than for example on-disk data.

class kwneuro.resource.InMemoryResponseFunctionResource(sh_coeffs, avg_signal)

Bases: ResponseFunctionResource

A response function that is loaded into memory.

Parameters:
  • sh_coeffs (ndarray[tuple[Any, ...], dtype[floating]])

  • avg_signal (floating)

avg_signal: floating

The average non-diffusion weighted signal within the voxels used to calculate the response function

static from_dipy_object(obj)

Construct from a DIPY AxSymShResponse instance.

Parameters:

obj (AxSymShResponse)

Return type:

InMemoryResponseFunctionResource

static from_prolate_tensor(response, gtab, sh_order_max=8)

Convert a legacy DIPY prolate-tensor response (evals, S0) into spherical harmonic coefficients using the approach from DIPY’s csdeconv module: https://github.com/dipy/dipy/blob/f7b863f1485cd3fa6329c8e8f3388d8f58863f0d/dipy/reconst/csdeconv.py#L168. :type response: tuple[ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], floating] :param response: Response function output by DIPY. :type gtab: GradientTable :param gtab: Gradient table used to estimate response :type sh_order_max: int :param sh_order_max: Maximum spherical harmonic order to use for the basis model. Default is 8.

Returns: InMemoryResponseFunctionResource

Return type:

InMemoryResponseFunctionResource

get()

Returns the underlying response function components as (sh_coeffs, avg_signal) :returns: An array of m=0 coefficients for even degrees l = [0, 2, …, sh_order].

The array length is ((sh_order / 2) + 1,), where sh_order is the maximal spherical harmonics order.

avg_signal: The mean signal intensity across the sphere, equivalent to the m=0, l=0 component.

Return type:

sh_coeffs

get_dipy_object()

Return the stored response function as a DIPY AxSymShResponse.

Return type:

AxSymShResponse

is_loaded: ClassVar[bool] = True

Whether a resource corresponds to in-memory data, rather than for example on-disk data.

sh_coeffs: ndarray[tuple[Any, ...], dtype[floating]]

Spherical harmonic coefficients of the response function for an axially symmetric, even-degree model. Following the Dipy convention for symmetric signals, only even degrees (l = 0, 2, 4, …, sh_order) are included. Under the assumption of axial symmetry, only the m = 0 coefficients are included. The coefficients are ordered by increasing degree l:

Index 0: l=0, m=0 (proportional to the average signal or avg_signal) Index 1: l=2, m=0 Index 2: l=4, m=0 … Index M-1: l=sh_order, m=0

The total number of coefficients M is (sh_order / 2) + 1.

class kwneuro.resource.InMemoryVolumeResource(array, affine=<factory>, metadata=<factory>)

Bases: VolumeResource

A volume resource that is loaded into memory. An n-D array where n >= 3 and where three of the dimensions are spatial and have associated header information describing a patient coordinate system.

Parameters:
affine: ndarray[tuple[Any, ...], dtype[floating]]
array: ndarray[tuple[Any, ...], dtype[number]]
static from_ants_image(ants_image)

Create an InMemoryVolumeResource from an ANTsImage.

Parameters:

ants_image (ANTsImage)

Return type:

InMemoryVolumeResource

get_affine()

Get the 4x4 affine matrix that maps index space to patient/scanner space

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

get_array()

Get the underlying volume data array

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

get_metadata()

Get the volume image metadata

Return type:

dict[Any, Any]

is_loaded: ClassVar[bool] = True

Whether a resource corresponds to in-memory data, rather than for example on-disk data.

load()

Load volume into memory

Return type:

InMemoryVolumeResource

metadata: dict[str, Any]
to_ants_image()

Convert to an ANTsImage. This conversion creates a deep copy of the underlying data. The coordinate system is also converted from Nibabel’s RAS+ to ANTs/ LPS+ orientation.

Return type:

ANTsImage

class kwneuro.resource.Resource

Bases: ABC

Base class for all Resources. A Resource is a piece of data that could live in memory or on disk.

is_loaded: ClassVar[bool] = True

Whether a resource corresponds to in-memory data, rather than for example on-disk data.

abstractmethod load()

Load a Resource. Specific functionality depends on the Resource subclass, but if the resource is considered to be ‘loaded’ then this should be a no-op, returning the same Resource back.

Return type:

Resource

class kwneuro.resource.ResponseFunctionResource

Bases: Resource

Base class for resources representing a response function associated with a DWI.

abstractmethod get()

Returns the underlying response function components as (sh_coeffs, avg_signal) :returns: An array of m=0 coefficients for even degrees l = [0, 2, …, sh_order].

The array length is ((sh_order / 2) + 1,), where sh_order is the maximal spherical harmonics order.

avg_signal: The mean signal intensity across the sphere, equivalent to the m=0, l=0 component.

Return type:

sh_coeffs

abstractmethod get_dipy_object()

Get the underlying response function in a format compatible with Dipy

Return type:

AxSymShResponse

load()

Load a Resource. Specific functionality depends on the Resource subclass, but if the resource is considered to be ‘loaded’ then this should be a no-op, returning the same Resource back.

Return type:

ResponseFunctionResource

class kwneuro.resource.VolumeResource

Bases: Resource

Base class for resources representing a volume or volume stack. An n-D array where n >= 3 and where three of the dimensions are spatial and have associated header information describing a patient coordinate system.

abstractmethod get_affine()

Get the 4x4 affine matrix that maps index space to patient/scanner space

Return type:

ndarray[tuple[Any, ...], dtype[floating]]

abstractmethod get_array()

Get the underlying volume data array

Return type:

ndarray[tuple[Any, ...], dtype[number]]

abstractmethod get_metadata()

Get the volume image metadata

Return type:

dict[str, Any]

abstractmethod load()

Load volume into memory

Return type:

InMemoryVolumeResource