kwneuro.resource ================ .. py:module:: kwneuro.resource Classes ------- .. autoapisummary:: kwneuro.resource.Resource kwneuro.resource.VolumeResource kwneuro.resource.InMemoryVolumeResource kwneuro.resource.BvalResource kwneuro.resource.InMemoryBvalResource kwneuro.resource.BvecResource kwneuro.resource.InMemoryBvecResource kwneuro.resource.ResponseFunctionResource kwneuro.resource.InMemoryResponseFunctionResource Module Contents --------------- .. py:class:: Resource Bases: :py:obj:`abc.ABC` Base class for all Resources. A Resource is a piece of data that could live in memory or on disk. .. py:attribute:: is_loaded :type: ClassVar[bool] :value: True Whether a resource corresponds to in-memory data, rather than for example on-disk data. .. py:method:: load() -> Resource :abstractmethod: 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. .. py:class:: VolumeResource Bases: :py:obj:`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. .. py:method:: get_array() -> numpy.typing.NDArray[numpy.number] :abstractmethod: Get the underlying volume data array .. py:method:: get_affine() -> numpy.typing.NDArray[numpy.floating] :abstractmethod: Get the 4x4 affine matrix that maps index space to patient/scanner space .. py:method:: get_metadata() -> dict[str, Any] :abstractmethod: Get the volume image metadata .. py:method:: load() -> InMemoryVolumeResource :abstractmethod: Load volume into memory .. py:class:: InMemoryVolumeResource Bases: :py:obj:`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. .. py:attribute:: is_loaded :type: ClassVar[bool] :value: True Whether a resource corresponds to in-memory data, rather than for example on-disk data. .. py:attribute:: array :type: numpy.typing.NDArray[numpy.number] .. py:attribute:: affine :type: numpy.typing.NDArray[numpy.floating] .. py:attribute:: metadata :type: dict[str, Any] .. py:method:: get_array() -> numpy.typing.NDArray[Any] Get the underlying volume data array .. py:method:: get_affine() -> numpy.typing.NDArray[numpy.floating] Get the 4x4 affine matrix that maps index space to patient/scanner space .. py:method:: get_metadata() -> dict[Any, Any] Get the volume image metadata .. py:method:: load() -> InMemoryVolumeResource Load volume into memory .. py:method:: 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. .. py:method:: from_ants_image(ants_image: ants.ANTsImage) -> InMemoryVolumeResource :staticmethod: Create an InMemoryVolumeResource from an ANTsImage. .. py:class:: BvalResource Bases: :py:obj:`Resource` Base class for resources representing a list of b-values associated with a 4D DWI volume stack. .. py:method:: get() -> numpy.typing.NDArray[numpy.floating] :abstractmethod: Get the underlying array of b-values .. py:method:: 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. .. py:class:: InMemoryBvalResource Bases: :py:obj:`BvalResource` A b-value list that is loaded into memory. .. py:attribute:: is_loaded :type: ClassVar[bool] :value: True Whether a resource corresponds to in-memory data, rather than for example on-disk data. .. py:attribute:: array :type: numpy.typing.NDArray[numpy.floating] The underlying array of b-values .. py:method:: get() -> numpy.typing.NDArray[numpy.floating] Get the underlying array of b-values .. py:class:: BvecResource Bases: :py:obj:`Resource` Base class for resources representing a list of b-vectors associated with a 4D DWI volume stack. .. py:method:: get() -> numpy.typing.NDArray[numpy.floating] :abstractmethod: Get the underlying array of b-vectors of shape (N,3) .. py:method:: 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. .. py:class:: InMemoryBvecResource Bases: :py:obj:`BvecResource` A b-vector list that is loaded into memory. .. py:attribute:: is_loaded :type: ClassVar[bool] :value: True Whether a resource corresponds to in-memory data, rather than for example on-disk data. .. py:attribute:: array :type: numpy.typing.NDArray[numpy.floating] The underlying array of b-vectors .. py:method:: get() -> numpy.typing.NDArray[numpy.floating] Get the underlying array of b-vectors of shape (N,3) .. py:class:: ResponseFunctionResource Bases: :py:obj:`Resource` Base class for resources representing a response function associated with a DWI. .. py:method:: get() -> tuple[numpy.typing.NDArray, numpy.floating] :abstractmethod: 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. .. py:method:: get_dipy_object() -> dipy.reconst.csdeconv.AxSymShResponse :abstractmethod: Get the underlying response function in a format compatible with Dipy .. py:method:: 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. .. py:class:: InMemoryResponseFunctionResource Bases: :py:obj:`ResponseFunctionResource` A response function that is loaded into memory. .. py:attribute:: is_loaded :type: ClassVar[bool] :value: True Whether a resource corresponds to in-memory data, rather than for example on-disk data. .. py:attribute:: sh_coeffs :type: 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. .. py:attribute:: avg_signal :type: numpy.floating The average non-diffusion weighted signal within the voxels used to calculate the response function .. py:method:: 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. .. py:method:: from_prolate_tensor(response: tuple[numpy.typing.NDArray, numpy.floating], gtab: dipy.core.gradients.GradientTable, sh_order_max: int = 8) -> InMemoryResponseFunctionResource :staticmethod: 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. :param response: Response function output by DIPY. :param gtab: Gradient table used to estimate response :param sh_order_max: Maximum spherical harmonic order to use for the basis model. Default is 8. Returns: InMemoryResponseFunctionResource .. py:method:: from_dipy_object(obj: dipy.reconst.csdeconv.AxSymShResponse) -> InMemoryResponseFunctionResource :staticmethod: Construct from a DIPY `AxSymShResponse` instance. .. py:method:: get_dipy_object() -> dipy.reconst.csdeconv.AxSymShResponse Return the stored response function as a DIPY `AxSymShResponse`.