Skip to content

Commit

Permalink
added stejskal tanner plane model and test
Browse files Browse the repository at this point in the history
  • Loading branch information
rutgerfick committed Feb 22, 2018
1 parent 2a65e42 commit 8590e3e
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
61 changes: 61 additions & 0 deletions dmipy/signal_models/plane_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,67 @@
]


class P2PlaneStejskalTannerApproximation(ModelProperties):
r""" Stejskal-Tanner approximation of diffusion between two infinitely
large parallel planes. Assumes short-gradient pulse (SGP) approximation
(pulse length towards zero) and the long diffusion time limit (pulse
separation towards infinity). We follow the notation of Balinov [1]_.
References
----------
.. [1] Balinov, Balin, et al. "The NMR self-diffusion method applied to
restricted diffusion. Simulation of echo attenuation from molecules in
spheres and between planes." Journal of Magnetic Resonance, Series A
104.1 (1993): 17-25.
"""
_parameter_ranges = {
'diameter': (1e-2, 20)
}

_parameter_scales = {
'diameter': DIAMETER_SCALING
}

_parameter_types = {
'diameter': 'plane'
}
_model_type = 'NMRModel'

def __init__(self, diameter=None):
self.diameter = diameter

def plane_attenuation(self, q, diameter):
"Equation 6 in Balinov et al. (1993)."
q_argument = 2 * np.pi * q * diameter
return 2 * (1 - np.cos(q_argument)) / q_argument ** 2

def __call__(self, acquisition_scheme, **kwargs):
r'''
Calculates the signal attenuation.
Parameters
----------
acquisition_scheme : DmipyAcquisitionScheme instance,
An acquisition scheme that has been instantiated using dMipy.
kwargs: keyword arguments to the model parameter values,
Is internally given as **parameter_dictionary.
Returns
-------
attenuation : float or array, shape(N),
signal attenuation
'''
q = acquisition_scheme.qvalues
diameter = kwargs.get('diameter', self.diameter)

E_plane = np.ones_like(q)
q_nonzero = q > 0
E_plane[q_nonzero] = self.plane_attenuation(
q[q_nonzero], diameter
)
return E_plane


class P3PlaneCallaghanApproximation(ModelProperties):
r"""
The Callaghan model [1]_ of diffusion between two parallel infinite plates.
Expand Down
28 changes: 27 additions & 1 deletion dmipy/signal_models/tests/test_soderman.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
from numpy.testing import assert_almost_equal
import numpy as np
from dmipy.signal_models import cylinder_models, sphere_models
from dmipy.signal_models import plane_models, cylinder_models, sphere_models
from dmipy.core.acquisition_scheme import (
acquisition_scheme_from_qvalues,)


def test_RTPP_to_diameter_soderman(samples=1000):
"""This tests if the RTPP of the plane relates correctly to the diameter
of the plane."""
diameter = 10e-6

delta = np.tile(1e-10, samples) # delta towards zero
Delta = np.tile(1e10, samples) # Delta towards infinity
qvals_perp = np.linspace(0, 10e6, samples)
n_perp = np.tile(np.r_[1., 0., 0.], (samples, 1))
scheme = acquisition_scheme_from_qvalues(
qvals_perp, n_perp, delta, Delta)

soderman = plane_models.P2PlaneStejskalTannerApproximation(
diameter=diameter)

E_soderman = soderman(scheme)

rtpp_soderman = 2 * np.trapz(
E_soderman, x=qvals_perp
)

diameter_soderman = 1 / rtpp_soderman

assert_almost_equal(diameter_soderman, diameter, 7)


def test_RTAP_to_diameter_soderman(samples=1000):
"""This tests if the RTAP of the cylinder relates correctly to the diameter
of the cylinder."""
Expand Down

0 comments on commit 8590e3e

Please sign in to comment.