kwneuro.resource

Classes

Resource

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

VolumeResource

Base class for resources representing a volume or volume stack.

InMemoryVolumeResource

A volume resource that is loaded into memory.

BvalResource

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

InMemoryBvalResource

A b-value list that is loaded into memory.

BvecResource

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

InMemoryBvecResource

A b-vector list that is loaded into memory.

ResponseFunctionResource

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

InMemoryResponseFunctionResource

A response function that is loaded into memory.

Module Contents

class kwneuro.resource.Resource

Bases: abc.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() Resource

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.

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_array() numpy.typing.NDArray[numpy.number]

Get the underlying volume data array

abstractmethod get_affine() numpy.typing.NDArray[numpy.floating]

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

abstractmethod get_metadata() dict[str, Any]

Get the volume image metadata

abstractmethod load() InMemoryVolumeResource

Load volume into memory

class kwneuro.resource.InMemoryVolumeResource

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.

is_loaded: ClassVar[bool] = True

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

array: numpy.typing.NDArray[numpy.number]
affine: numpy.typing.NDArray[numpy.floating]
metadata: dict[str, Any]
get_array() numpy.typing.NDArray[Any]

Get the underlying volume data array

get_affine() numpy.typing.NDArray[numpy.floating]

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

get_metadata() dict[Any, Any]

Get the volume image metadata

load() InMemoryVolumeResource

Load volume into memory

to_ants_image() ants.ANTsImage

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.

static from_ants_image(ants_image: ants.ANTsImage) InMemoryVolumeResource

Create an InMemoryVolumeResource from an ANTsImage.

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() numpy.typing.NDArray[numpy.floating]

Get the underlying array of b-values

load() BvalResource

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.

class kwneuro.resource.InMemoryBvalResource

Bases: BvalResource

A b-value list that is loaded into memory.

is_loaded: ClassVar[bool] = True

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

array: numpy.typing.NDArray[numpy.floating]

The underlying array of b-values

get() numpy.typing.NDArray[numpy.floating]

Get the underlying array of b-values

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() numpy.typing.NDArray[numpy.floating]

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

load() BvecResource

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.

class kwneuro.resource.InMemoryBvecResource

Bases: BvecResource

A b-vector list that is loaded into memory.

is_loaded: ClassVar[bool] = True

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

array: numpy.typing.NDArray[numpy.floating]

The underlying array of b-vectors

get() numpy.typing.NDArray[numpy.floating]

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

class kwneuro.resource.ResponseFunctionResource

Bases: Resource

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

abstractmethod get() tuple[numpy.typing.NDArray, numpy.floating]

Returns the underlying response function components as (sh_coeffs, avg_signal).

Returns:

A tuple of (sh_coeffs, avg_signal) where sh_coeffs is an array of m=0 coefficients for even degrees l = [0, 2, …, sh_order] with length (sh_order / 2) + 1, and avg_signal is the mean signal intensity across the sphere.

abstractmethod get_dipy_object() dipy.reconst.csdeconv.AxSymShResponse

Get the underlying response function in a format compatible with Dipy

load() ResponseFunctionResource

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.

class kwneuro.resource.InMemoryResponseFunctionResource

Bases: ResponseFunctionResource

A response function that is loaded into memory.

is_loaded: ClassVar[bool] = True

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

sh_coeffs: numpy.typing.NDArray[numpy.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.

avg_signal: numpy.floating

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

get() tuple[numpy.typing.NDArray, numpy.floating]

Returns the underlying response function components as (sh_coeffs, avg_signal).

Returns:

A tuple of (sh_coeffs, avg_signal) where sh_coeffs is an array of m=0 coefficients for even degrees l = [0, 2, …, sh_order] with length (sh_order / 2) + 1, and avg_signal is the mean signal intensity across the sphere.

static from_prolate_tensor(response: tuple[numpy.typing.NDArray, numpy.floating], gtab: dipy.core.gradients.GradientTable, sh_order_max: int = 8) InMemoryResponseFunctionResource

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.

Parameters:
  • response – Response function output by DIPY.

  • gtab – Gradient table used to estimate response

  • sh_order_max – Maximum spherical harmonic order to use for the basis model. Default is 8.

Returns: InMemoryResponseFunctionResource

static from_dipy_object(obj: dipy.reconst.csdeconv.AxSymShResponse) InMemoryResponseFunctionResource

Construct from a DIPY AxSymShResponse instance.

get_dipy_object() dipy.reconst.csdeconv.AxSymShResponse

Return the stored response function as a DIPY AxSymShResponse.