doc added; reading of isochronal bds

This commit is contained in:
dominik
2022-03-22 20:07:59 +01:00
parent a222072b28
commit 6cd630245c
89 changed files with 41178 additions and 973 deletions

9
doc/examples/README.rst Normal file
View File

@ -0,0 +1,9 @@
.. examples-index:
.. _gallery:
========
Examples
========
This page contains example plots. Click on any image to see the full image and source code.

View File

@ -0,0 +1,6 @@
.. _distribution_examples:
.. _distribution-examples-index:
Distribution of correlation times
=================================

View File

@ -0,0 +1,50 @@
"""
=========
Cole-Cole
=========
Example for Cole-Cole distributions
"""
import matplotlib.pyplot as plt
import numpy as np
from nmreval.distributions import ColeCole
x = np.logspace(-5, 5, num=101)
cc = ColeCole
alpha_CC = [0.3, 0.5, 0.7]
fig, axes = plt.subplots(2, 3, constrained_layout=True)
lines = []
for a in alpha_CC:
axes[0, 0].plot(np.log10(x), cc.correlation(x, 1, a))
axes[1, 0].plot(np.log10(x), np.log10(cc.specdens(x, 1, a)))
axes[0, 1].plot(np.log10(x), np.log10(cc.susceptibility(x, 1, a).real))
axes[1, 1].plot(np.log10(x), np.log10(cc.susceptibility(x, 1, a).imag))
l, = axes[0, 2].plot(np.log10(x), cc.distribution(x, 1, a),
label=rf'$\alpha={a}$')
lines.append(l)
fig_titles = ('Correlation function', 'Susceptibility (real)', 'Distribution',
'Spectral density', 'Susceptibility (imag)')
fig_xlabel = (r'$\log(t/\tau_\mathrm{HN})$', r'$\log(\omega\tau_\mathrm{HN})$',
r'$\log(\tau/\tau_\mathrm{HN})$', r'$\log(\omega\tau_\mathrm{HN})$',
r'$\log(\omega\tau_\mathrm{HN})$')
fig_ylabel = (r'$C(t)$', r"$\log(\chi'(\omega))$", r'$G(\ln\tau)$',
r'$\log(J(\omega))$', r"$\log(\chi''(\omega))$")
for title, xlabel, ylabel, ax in zip(fig_titles, fig_xlabel, fig_ylabel, axes.ravel()):
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
labels = [l.get_label() for l in lines]
leg = fig.legend(lines, labels, loc='center left', bbox_to_anchor=(1.05, 0.50),
bbox_transform=axes[1, 1].transAxes)
fig.delaxes(axes[1, 2])
plt.show()

View File

@ -0,0 +1,50 @@
"""
=============
Cole-Davidson
=============
Example for Cole-Davidson distributions
"""
import matplotlib.pyplot as plt
import numpy as np
from nmreval.distributions import ColeDavidson
x = np.logspace(-5, 5, num=101)
cd = ColeDavidson
gamma_CD = [0.3, 0.5, 0.7]
fig, axes = plt.subplots(2, 3, constrained_layout=True)
lines = []
for g in gamma_CD:
axes[0, 0].plot(np.log10(x), cd.correlation(x, 1, g))
axes[1, 0].plot(np.log10(x), np.log10(cd.specdens(x, 1, g)))
axes[0, 1].plot(np.log10(x), np.log10(cd.susceptibility(x, 1, g).real))
axes[1, 1].plot(np.log10(x), np.log10(cd.susceptibility(x, 1, g).imag))
l, = axes[0, 2].plot(np.log10(x), cd.distribution(x, 1, g),
label=rf'$\gamma={g}$')
lines.append(l)
fig_titles = ('Correlation function', 'Susceptibility (real)', 'Distribution',
'Spectral density', 'Susceptibility (imag)')
fig_xlabel = (r'$\log(t/\tau_\mathrm{CD})$', r'$\log(\omega\tau_\mathrm{CD})$',
r'$\log(\tau/\tau_\mathrm{CD})$', r'$\log(\omega\tau_\mathrm{CD})$',
r'$\log(\omega\tau_\mathrm{CD})$')
fig_ylabel = (r'$C(t)$', r"$\log(\chi'(\omega))$", r'$G(\ln\tau)$',
r'$\log(J(\omega))$', r"$\log(\chi''(\omega))$")
for title, xlabel, ylabel, ax in zip(fig_titles, fig_xlabel, fig_ylabel, axes.ravel()):
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
labels = [l.get_label() for l in lines]
leg = fig.legend(lines, labels, loc='center left', bbox_to_anchor=(1.05, 0.50),
bbox_transform=axes[1, 1].transAxes)
fig.delaxes(axes[1, 2])
plt.show()

View File

@ -0,0 +1,53 @@
"""
================
Havriliak-Negami
================
Example for Havriliak-Negami distributions
"""
from itertools import product
import matplotlib.pyplot as plt
import numpy as np
from nmreval.distributions import HavriliakNegami
x = np.logspace(-5, 5, num=101)
hn = HavriliakNegami
alpha_CC = [0.4, 0.8]
gamma_CD = [0.3, 0.7]
fig, axes = plt.subplots(2, 3, constrained_layout=True)
lines = []
for a, g in product(alpha_CC, gamma_CD):
axes[0, 0].plot(np.log10(x), hn.correlation(x, 1, a, g))
axes[1, 0].plot(np.log10(x), np.log10(hn.specdens(x, 1, a, g)))
axes[0, 1].plot(np.log10(x), np.log10(hn.susceptibility(x, 1, a, g).real))
axes[1, 1].plot(np.log10(x), np.log10(hn.susceptibility(x, 1, a, g).imag))
l, = axes[0, 2].plot(np.log10(x), hn.distribution(x, 1, a, g),
label=rf'$\alpha={a}, \gamma={g}$')
lines.append(l)
fig_titles = ('Correlation function', 'Susceptibility (real)', 'Distribution',
'Spectral density', 'Susceptibility (imag)')
fig_xlabel = (r'$\log(t/\tau_\mathrm{HN})$', r'$\log(\omega\tau_\mathrm{HN})$',
r'$\log(\tau/\tau_\mathrm{HN})$', r'$\log(\omega\tau_\mathrm{HN})$',
r'$\log(\omega\tau_\mathrm{HN})$')
fig_ylabel = (r'$C(t)$', r"$\log(\chi'(\omega))$", r'$G(\ln\tau)$',
r'$\log(J(\omega))$', r"$\log(\chi''(\omega))$")
for title, xlabel, ylabel, ax in zip(fig_titles, fig_xlabel, fig_ylabel, axes.ravel()):
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
labels = [l.get_label() for l in lines]
leg = fig.legend(lines, labels, loc='center left', bbox_to_anchor=(1.05, 0.50),
bbox_transform=axes[1, 1].transAxes)
fig.delaxes(axes[1, 2])
plt.show()

View File

@ -0,0 +1,50 @@
"""
=========================
Kohlrausch-Williams-Watts
=========================
Example for KWW distributions
"""
import matplotlib.pyplot as plt
import numpy as np
from nmreval.distributions import KWW
x = np.logspace(-5, 5, num=101)
kww = KWW
beta_KWW = [0.3, 0.5, 0.7]
fig, axes = plt.subplots(2, 3, constrained_layout=True)
lines = []
for b in beta_KWW:
axes[0, 0].plot(np.log10(x), kww.correlation(x, 1, b))
axes[1, 0].plot(np.log10(x), np.log10(kww.specdens(x, 1, b)))
axes[0, 1].plot(np.log10(x), np.log10(kww.susceptibility(x, 1, b).real))
axes[1, 1].plot(np.log10(x), np.log10(kww.susceptibility(x, 1, b).imag))
l, = axes[0, 2].plot(np.log10(x), kww.distribution(x, 1, b),
label=rf'$\beta={b}$')
lines.append(l)
fig_titles = ('Correlation function', 'Susceptibility (real)', 'Distribution',
'Spectral density', 'Susceptibility (imag)')
fig_xlabel = (r'$\log(t/\tau_\mathrm{KWW})$', r'$\log(\omega\tau_\mathrm{KWW})$',
r'$\log(\tau/\tau_\mathrm{KWW})$', r'$\log(\omega\tau_\mathrm{KWW})$',
r'$\log(\omega\tau_\mathrm{KWW})$')
fig_ylabel = (r'$C(t)$', r"$\log(\chi'(\omega))$", r'$G(\ln\tau)$',
r'$\log(J(\omega))$', r"$\log(\chi''(\omega))$")
for title, xlabel, ylabel, ax in zip(fig_titles, fig_xlabel, fig_ylabel, axes.ravel()):
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
labels = [l.get_label() for l in lines]
leg = fig.legend(lines, labels, loc='center left', bbox_to_anchor=(1.05, 0.50),
bbox_transform=axes[1, 1].transAxes)
fig.delaxes(axes[1, 2])
plt.show()

View File

@ -0,0 +1,50 @@
"""
============
Log-Gaussian
============
Example for Log-Gaussian distributions
"""
import matplotlib.pyplot as plt
import numpy as np
from nmreval.distributions import LogGaussian
x = np.logspace(-5, 5, num=101)
lg = LogGaussian
sigma_lg = [1, 3, 5]
fig, axes = plt.subplots(2, 3, constrained_layout=True)
lines = []
for s in sigma_lg:
axes[0, 0].plot(np.log10(x), lg.correlation(x, 1, s))
axes[1, 0].plot(np.log10(x), np.log10(lg.specdens(x, 1, s)))
axes[0, 1].plot(np.log10(x), np.log10(lg.susceptibility(x, 1, s).real))
axes[1, 1].plot(np.log10(x), np.log10(lg.susceptibility(x, 1, s).imag))
l, = axes[0, 2].plot(np.log10(x), lg.distribution(x, 1, s),
label=rf'$\sigma={s}$')
lines.append(l)
fig_titles = ('Correlation function', 'Susceptibility (real)', 'Distribution',
'Spectral density', 'Susceptibility (imag)')
fig_xlabel = (r'$\log(t/\tau_\mathrm{LG})$', r'$\log(\omega\tau_\mathrm{LG})$',
r'$\log(\tau/\tau_\mathrm{LG})$', r'$\log(\omega\tau_\mathrm{LG})$',
r'$\log(\omega\tau_\mathrm{LG})$')
fig_ylabel = (r'$C(t)$', r"$\log(\chi'(\omega))$", r'$G(\ln\tau)$',
r'$\log(J(\omega))$', r"$\log(\chi''(\omega))$")
for title, xlabel, ylabel, ax in zip(fig_titles, fig_xlabel, fig_ylabel, axes.ravel()):
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
labels = [l.get_label() for l in lines]
leg = fig.legend(lines, labels, loc='center left', bbox_to_anchor=(1.05, 0.50),
bbox_transform=axes[1, 1].transAxes)
fig.delaxes(axes[1, 2])
plt.show()

View File

@ -0,0 +1,6 @@
.. _nmr_examples:
.. _nmr-examples-index:
NMR specifics
=============

View File

@ -0,0 +1,67 @@
"""
=======================
Spin-lattice relaxation
=======================
Example for
"""
import numpy as np
from matplotlib import pyplot as plt
from nmreval.distributions import ColeDavidson
from nmreval.nmr import Relaxation, RelaxationEvaluation
from nmreval.nmr.coupling import Quadrupolar
from nmreval.utils.constants import kB
# Define temperature range
inv_temp = np.linspace(3, 9, num=30)
temperature = 1000/inv_temp
# spectral density parameter
ea = 0.45
tau = 1e-21 * np.exp(ea / kB / temperature)
gamma_cd = 0.1
# interaction parameter
omega = 2*np.pi*46e6
delta = 120e3
eta = 0
r = Relaxation()
r.set_distribution(ColeDavidson) # the only parameter that has to be set beforehand
t1_values = r.t1(omega, tau, gamma_cd, mode='bpp',
prefactor=Quadrupolar.relax(delta, eta))
# add noise
rng = np.random.default_rng(123456789)
noisy = (rng.random(t1_values.size)-0.5) * 0.5 * t1_values + t1_values
# set parameter and data
r_eval = RelaxationEvaluation()
r_eval.set_distribution(ColeDavidson)
r_eval.set_coupling(Quadrupolar, (delta, eta))
r_eval.data(temperature, noisy)
r_eval.omega = omega
t1_min_data, _ = r_eval.calculate_t1_min() # second argument is None
t1_min_inter, line = r_eval.calculate_t1_min(interpolate=1, trange=(160, 195), use_log=True)
fig, ax = plt.subplots()
ax.semilogy(1000/t1_min_data[0], t1_min_data[1], 'rx', label='Data minimum')
ax.semilogy(1000/t1_min_inter[0], t1_min_inter[1], 'r+', label='Parabola')
ax.semilogy(1000/line[0], line[1])
found_gamma, found_height = r_eval.get_increase(t1_min_inter[1], idx=0, mode='distribution')
print(found_gamma)
plt.axhline(found_height)
plt.show()
#%%
# Now we found temperature and height of the minimum we can calculate the correlation time
plt.semilogy(1000/temperature, tau)
tau_from_t1, opts = r_eval.correlation_from_t1()
print(opts)
plt.semilogy(1000/tau_from_t1[:, 0], tau_from_t1[:, 1], 'o')
plt.show()