save fit parameter and agr; more doc
This commit is contained in:
		| @@ -5,8 +5,8 @@ | ||||
| # from the environment for the first two. | ||||
| SPHINXOPTS    ?= | ||||
| SPHINXBUILD   ?= /autohome/dominik/miniconda3/bin/sphinx-build | ||||
| SOURCEDIR     = /autohome/dominik/nmreval/docs/source | ||||
| BUILDDIR      = /autohome/dominik/nmreval/docs/build | ||||
| SOURCEDIR     = /autohome/dominik/nmreval/doc/source | ||||
| BUILDDIR      = /autohome/dominik/nmreval/doc/_build | ||||
|  | ||||
| # Put it first so that "make" without argument is like "make help". | ||||
| help: | ||||
|   | ||||
| @@ -1,12 +1,19 @@ | ||||
| """ | ||||
| ======================= | ||||
| Spin-lattice relaxation | ||||
| ======================= | ||||
| ========== | ||||
| T1 minimum | ||||
| ========== | ||||
|  | ||||
| Example for | ||||
| ``RelaxationEvaluation`` is used to get width parameter from a T1 minimum. | ||||
| As a subclass of ``Relaxation`` it can also be used to calculate Relaxation times. | ||||
| The basic steps are: | ||||
|  | ||||
| * Determine a T1 minimum with `nmreval.nmr.RelaxationEvaluation.calculate_t1_min` | ||||
| * Calculate width parameter of a spectral density/coupling constants/... with | ||||
|   ``RelaxationEvaluation.get_increase`` | ||||
| * Calculate correlation times from these values with ``RelaxationEvaluation.correlation_from_t1`` | ||||
| """ | ||||
| import numpy as np | ||||
| from matplotlib import pyplot as plt | ||||
| import matplotlib.pyplot as plt | ||||
|  | ||||
| from nmreval.distributions import ColeDavidson | ||||
| from nmreval.nmr import Relaxation, RelaxationEvaluation | ||||
| @@ -20,7 +27,7 @@ temperature = 1000/inv_temp | ||||
| # spectral density parameter | ||||
| ea = 0.45 | ||||
| tau = 1e-21 * np.exp(ea / kB / temperature) | ||||
| gamma_cd = 0.1 | ||||
| gamma_cd = 0.4 | ||||
|  | ||||
| # interaction parameter | ||||
| omega = 2*np.pi*46e6 | ||||
| @@ -28,40 +35,57 @@ delta = 120e3 | ||||
| eta = 0 | ||||
|  | ||||
| r = Relaxation() | ||||
| r.set_distribution(ColeDavidson)  # the only parameter that has to be set beforehand | ||||
| r.set_distribution(ColeDavidson)  # the only parameter that 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) | ||||
| rng = np.random.default_rng() | ||||
| noisy = (rng.random(t1_values.size)-0.5) * 0.5 * t1_values + t1_values | ||||
|  | ||||
| # set parameter and data | ||||
| ax_t1 = plt.figure().add_subplot() | ||||
| ax_t1.semilogy(inv_temp, t1_values, label='Calculated T1') | ||||
| ax_t1.semilogy(inv_temp, noisy, 'o', label='Noise') | ||||
| ax_t1.legend() | ||||
|  | ||||
| plt.show() | ||||
|  | ||||
|  | ||||
| # Actual evaluation starts here | ||||
| # setting necessary parameter | ||||
| r_eval = RelaxationEvaluation() | ||||
| r_eval.set_distribution(ColeDavidson) | ||||
| r_eval.set_coupling(Quadrupolar, (delta, eta)) | ||||
| r_eval.data(temperature, noisy) | ||||
| r_eval.set_data(temperature, noisy) | ||||
| r_eval.omega = omega | ||||
|  | ||||
| # Find a T1 minumum | ||||
| 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]) | ||||
| ax_min = plt.figure().add_subplot() | ||||
| ax_min.semilogy(inv_temp, noisy, 'o', label='Data') | ||||
| ax_min.semilogy(1000/line[0], line[1], '--') | ||||
| ax_min.semilogy(1000/t1_min_data[0], t1_min_data[1], 'C2X',label='Data minimum') | ||||
| ax_min.semilogy(1000/t1_min_inter[0], t1_min_inter[1], 'C3P',label='Parabola') | ||||
| ax_min.set_xlim(4.5, 7) | ||||
| ax_min.set_ylim(1e-3, 1e-1) | ||||
| ax_min.legend() | ||||
|  | ||||
| # Vary the first (and for Cole-Davidson, only) parameter of the spectral density | ||||
| found_gamma, found_height = r_eval.get_increase(t1_min_inter[1], idx=0, mode='distribution') | ||||
| print(found_gamma) | ||||
|  | ||||
| plt.axhline(found_height) | ||||
| print(f'Minimum at {found_height} for {found_gamma}; input is {gamma_cd}') | ||||
| plt.show() | ||||
|  | ||||
| #%% | ||||
| # Now we found temperature and height of the minimum we can calculate the correlation time | ||||
| ################################################################################## | ||||
| # Calculation of correlation times uses previously parameter for spectral density | ||||
| # and prefactor | ||||
|  | ||||
| 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') | ||||
| tau_from_t1, opts = r_eval.correlation_from_t1(mode='mean') | ||||
| print(f'Used options: {opts}') | ||||
|  | ||||
| ax_tau = plt.figure().add_subplot() | ||||
| ax_tau.semilogy(inv_temp, tau*gamma_cd, label='Original input') | ||||
| ax_tau.semilogy(1000/tau_from_t1[:, 0], tau_from_t1[:, 1], 'o', label='Calculated') | ||||
| ax_tau.legend() | ||||
| plt.show() | ||||
|   | ||||
| @@ -1,179 +0,0 @@ | ||||
| :orphan: | ||||
|  | ||||
|  | ||||
|  | ||||
| .. _sphx_glr_gallery: | ||||
|  | ||||
| .. examples-index: | ||||
|  | ||||
| .. _gallery: | ||||
|  | ||||
| ======== | ||||
| Examples | ||||
| ======== | ||||
|  | ||||
| This page contains example plots. Click on any image to see the full image and source code. | ||||
|  | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-clear"></div> | ||||
|  | ||||
|  | ||||
|  | ||||
| .. _sphx_glr_gallery_distribution: | ||||
|  | ||||
|  .. _distribution_examples: | ||||
|  | ||||
| .. _distribution-examples-index: | ||||
|  | ||||
| Distribution of correlation times | ||||
| ================================= | ||||
|  | ||||
|  | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-thumbcontainer" tooltip="Example for KWW distributions"> | ||||
|  | ||||
| .. only:: html | ||||
|  | ||||
|  .. figure:: /gallery/distribution/images/thumb/sphx_glr_plot_KWW_thumb.png | ||||
|      :alt: Kohlrausch-Williams-Watts | ||||
|  | ||||
|      :ref:`sphx_glr_gallery_distribution_plot_KWW.py` | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     </div> | ||||
|  | ||||
|  | ||||
| .. toctree:: | ||||
|    :hidden: | ||||
|  | ||||
|    /gallery/distribution/plot_KWW | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-thumbcontainer" tooltip="Example for Cole-Cole distributions"> | ||||
|  | ||||
| .. only:: html | ||||
|  | ||||
|  .. figure:: /gallery/distribution/images/thumb/sphx_glr_plot_ColeCole_thumb.png | ||||
|      :alt: Cole-Cole | ||||
|  | ||||
|      :ref:`sphx_glr_gallery_distribution_plot_ColeCole.py` | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     </div> | ||||
|  | ||||
|  | ||||
| .. toctree:: | ||||
|    :hidden: | ||||
|  | ||||
|    /gallery/distribution/plot_ColeCole | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-thumbcontainer" tooltip="Example for Log-Gaussian distributions"> | ||||
|  | ||||
| .. only:: html | ||||
|  | ||||
|  .. figure:: /gallery/distribution/images/thumb/sphx_glr_plot_LogGaussian_thumb.png | ||||
|      :alt: Log-Gaussian | ||||
|  | ||||
|      :ref:`sphx_glr_gallery_distribution_plot_LogGaussian.py` | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     </div> | ||||
|  | ||||
|  | ||||
| .. toctree:: | ||||
|    :hidden: | ||||
|  | ||||
|    /gallery/distribution/plot_LogGaussian | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-thumbcontainer" tooltip="Example for Cole-Davidson distributions"> | ||||
|  | ||||
| .. only:: html | ||||
|  | ||||
|  .. figure:: /gallery/distribution/images/thumb/sphx_glr_plot_ColeDavidson_thumb.png | ||||
|      :alt: Cole-Davidson | ||||
|  | ||||
|      :ref:`sphx_glr_gallery_distribution_plot_ColeDavidson.py` | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     </div> | ||||
|  | ||||
|  | ||||
| .. toctree:: | ||||
|    :hidden: | ||||
|  | ||||
|    /gallery/distribution/plot_ColeDavidson | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-thumbcontainer" tooltip="Example for Havriliak-Negami distributions"> | ||||
|  | ||||
| .. only:: html | ||||
|  | ||||
|  .. figure:: /gallery/distribution/images/thumb/sphx_glr_plot_HavriliakNegami_thumb.png | ||||
|      :alt: Havriliak-Negami | ||||
|  | ||||
|      :ref:`sphx_glr_gallery_distribution_plot_HavriliakNegami.py` | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     </div> | ||||
|  | ||||
|  | ||||
| .. toctree:: | ||||
|    :hidden: | ||||
|  | ||||
|    /gallery/distribution/plot_HavriliakNegami | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-clear"></div> | ||||
|  | ||||
|  | ||||
|  | ||||
| .. _sphx_glr_gallery_nmr: | ||||
|  | ||||
| .. _nmr_examples: | ||||
|  | ||||
| .. _nmr-examples-index: | ||||
|  | ||||
| NMR specifics | ||||
| ============= | ||||
|  | ||||
|  | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-thumbcontainer" tooltip="Example for"> | ||||
|  | ||||
| .. only:: html | ||||
|  | ||||
|  .. figure:: /gallery/nmr/images/thumb/sphx_glr_plot_RelaxationEvaluation_thumb.png | ||||
|      :alt: Spin-lattice relaxation | ||||
|  | ||||
|      :ref:`sphx_glr_gallery_nmr_plot_RelaxationEvaluation.py` | ||||
|  | ||||
| .. raw:: html | ||||
|  | ||||
|     </div> | ||||
|  | ||||
|  | ||||
| .. toctree:: | ||||
|    :hidden: | ||||
|  | ||||
|    /gallery/nmr/plot_RelaxationEvaluation | ||||
| .. raw:: html | ||||
|  | ||||
|     <div class="sphx-glr-clear"></div> | ||||
|  | ||||
| @@ -1,3 +0,0 @@ | ||||
| '/autohome/dominik/nmreval/doc/_build/html/index.html', (0, 6969) | ||||
| '/autohome/dominik/nmreval/doc/_build/html/_static/documentation_options.js', (7168, 364) | ||||
| '/autohome/dominik/nmreval/doc/_build/html/searchindex.js', (7680, 29280) | ||||
										
											Binary file not shown.
										
									
								
							| @@ -1,3 +0,0 @@ | ||||
| '/autohome/dominik/nmreval/doc/_build/html/index.html', (0, 6969) | ||||
| '/autohome/dominik/nmreval/doc/_build/html/_static/documentation_options.js', (7168, 364) | ||||
| '/autohome/dominik/nmreval/doc/_build/html/searchindex.js', (7680, 29280) | ||||
		Reference in New Issue
	
	Block a user