Compare commits
1 Commits
master
...
306-sigmoi
Author | SHA1 | Date | |
---|---|---|---|
66b56c9be6 |
@ -1,16 +0,0 @@
|
|||||||
/* integrands used in quadrature integration with scipy's LowLevelCallables */
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
double anistropicDiffusion(double x, void *user_data) {
|
|
||||||
double *c = (double *)user_data;
|
|
||||||
|
|
||||||
double q = c[0];
|
|
||||||
double t = c[1];
|
|
||||||
double d_perp = c[2];
|
|
||||||
double d_par = c[3];
|
|
||||||
|
|
||||||
double cos_theta = cos(x);
|
|
||||||
double sin_theta = sin(x);
|
|
||||||
|
|
||||||
return exp(-q * q * t * (d_par * cos_theta * cos_theta + d_perp * sin_theta * sin_theta)) * sin_theta;
|
|
||||||
}
|
|
Binary file not shown.
@ -5,17 +5,6 @@ from ctypes import CDLL, c_double, c_void_p
|
|||||||
from ..lib.logger import logger
|
from ..lib.logger import logger
|
||||||
|
|
||||||
|
|
||||||
diffusion_lib = None
|
|
||||||
try:
|
|
||||||
diffusion_lib = CDLL(str(Path(__file__).parents[1] / 'clib' / 'diffusion.so'))
|
|
||||||
|
|
||||||
diffusion_lib.anistropicDiffusion.restype = c_double
|
|
||||||
diffusion_lib.anistropicDiffusion.argtypes = (c_double, c_void_p)
|
|
||||||
|
|
||||||
HAS_C_FUNCS = True
|
|
||||||
except OSError:
|
|
||||||
HAS_C_FUNCS = False
|
|
||||||
|
|
||||||
lib = None
|
lib = None
|
||||||
try:
|
try:
|
||||||
lib = CDLL(str(Path(__file__).parents[1] / 'clib' / 'integrate.so'))
|
lib = CDLL(str(Path(__file__).parents[1] / 'clib' / 'integrate.so'))
|
||||||
@ -50,8 +39,10 @@ try:
|
|||||||
lib.energyDistSuscImag.restype = c_double
|
lib.energyDistSuscImag.restype = c_double
|
||||||
lib.energyDistSuscImag.argtypes = (c_double, c_void_p)
|
lib.energyDistSuscImag.argtypes = (c_double, c_void_p)
|
||||||
|
|
||||||
|
|
||||||
HAS_C_FUNCS = True
|
HAS_C_FUNCS = True
|
||||||
logger.info('Use C functions')
|
logger.info('Use C functions')
|
||||||
except OSError:
|
except OSError:
|
||||||
HAS_C_FUNCS = False
|
HAS_C_FUNCS = False
|
||||||
logger.info('Use python functions')
|
logger.info('Use python functions')
|
||||||
|
|
||||||
|
@ -302,26 +302,15 @@ class HdfReader(HdfNode):
|
|||||||
|
|
||||||
def make_signal(self, node, flag: str = 'fid', value: str = None, group: str = None):
|
def make_signal(self, node, flag: str = 'fid', value: str = None, group: str = None):
|
||||||
if value is None:
|
if value is None:
|
||||||
data_name = node.name
|
|
||||||
value = self._get_parameter_values(node, node.parameter)
|
value = self._get_parameter_values(node, node.parameter)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
data_name = f"{value}={node.parameter[value]}"
|
|
||||||
value = node.parameter[value]
|
value = node.parameter[value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(node.title_parameter)
|
|
||||||
try:
|
try:
|
||||||
temp = node
|
value = node.title_parameter[1][value]
|
||||||
while value != temp.title_parameter[0][0]:
|
|
||||||
if temp.parent is None:
|
|
||||||
break
|
|
||||||
temp = temp.parent
|
|
||||||
|
|
||||||
value = temp.title_parameter[0][1]
|
|
||||||
data_name = temp.name
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(f'{value} is not a valid key for {node.name}')
|
print(f'{value} is not a valid key for {node.name}')
|
||||||
data_name = node.name
|
|
||||||
value = None
|
value = None
|
||||||
|
|
||||||
if group is None:
|
if group is None:
|
||||||
@ -354,11 +343,11 @@ class HdfReader(HdfNode):
|
|||||||
dw = float(index['dwelltime'])
|
dw = float(index['dwelltime'])
|
||||||
if flag == 'fid':
|
if flag == 'fid':
|
||||||
x = np.arange(len(y)) * dw
|
x = np.arange(len(y)) * dw
|
||||||
ret = FID(x, y, name=data_name, value=value, group=group, filename=self.file.filename)
|
ret = FID(x, y, name=node.name, value=value, group=group, filename=self.file.filename)
|
||||||
|
|
||||||
elif flag == 'spectrum':
|
elif flag == 'spectrum':
|
||||||
x = np.linspace(-1/dw, 1/dw, num=len(y))
|
x = np.linspace(-1/dw, 1/dw, num=len(y))
|
||||||
ret = Spectrum(x, y, name=data_name, value=value, group=group, filename=self.file.filename)
|
ret = Spectrum(x, y, name=node.name, value=value, group=group, filename=self.file.filename)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'{flag} unknown, use `fid` or `spectrum`.')
|
raise ValueError(f'{flag} unknown, use `fid` or `spectrum`.')
|
||||||
|
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
from ctypes import c_double, cast, c_void_p, pointer
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy import special as special, LowLevelCallable
|
from scipy import special as special
|
||||||
from scipy.integrate import quad
|
|
||||||
|
|
||||||
from ..utils import gamma
|
from ..utils import gamma
|
||||||
from nmreval.distributions.helper import HAS_C_FUNCS, diffusion_lib
|
|
||||||
|
|
||||||
|
|
||||||
class Diffusion:
|
class Diffusion:
|
||||||
@ -107,29 +103,13 @@ class AnisotropicDiffusion(object):
|
|||||||
tp = x
|
tp = x
|
||||||
relax = np.exp(-(tp/trel)**brel)*np.exp(-(tp/trel)**brel)
|
relax = np.exp(-(tp/trel)**brel)*np.exp(-(tp/trel)**brel)
|
||||||
|
|
||||||
q = g * nucleus * tp
|
q_squared = np.power(g * nucleus * tp, 2)
|
||||||
t = 2 * tp / 3 + tm
|
t = 2 * tp / 3 + tm
|
||||||
|
z = np.sqrt(q_squared * (d_par - d_perp) * t)
|
||||||
# Callaghan eq (6.89)
|
# Callaghan eq (6.89)
|
||||||
if HAS_C_FUNCS:
|
diffs = np.exp(-q_squared*t*d_perp) * special.erf(z) / z
|
||||||
# divide by 2 to normalize by integral sin(x), x=0..pi
|
|
||||||
diffusion_decay = AnisotropicDiffusion._integrate_c(q, t, d_perp, d_par) / 2
|
|
||||||
else:
|
|
||||||
z = np.sqrt(q**2 * (d_par - d_perp) * t)
|
|
||||||
diffusion_decay = np.exp(-q**2 * t * d_perp) * special.erf(z) / z
|
|
||||||
|
|
||||||
return m0 * diffusion_decay * relax
|
return m0 * diffs * relax
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _integrate_c(q, t, d_perp, d_par) -> np.ndarray:
|
|
||||||
diffusion_decay = np.zeros_like(t)
|
|
||||||
|
|
||||||
for (i, t_i) in enumerate(t):
|
|
||||||
c = (c_double * 4)(q, t_i, d_perp, d_par)
|
|
||||||
user_data = cast(pointer(c), c_void_p)
|
|
||||||
|
|
||||||
diffusion_decay[i] = quad(LowLevelCallable(diffusion_lib.anistropicDiffusion, user_data), 0, np.pi, epsabs=1e-13)[0]
|
|
||||||
|
|
||||||
return diffusion_decay
|
|
||||||
|
|
||||||
|
|
||||||
class Peschier:
|
class Peschier:
|
||||||
|
Reference in New Issue
Block a user