restructure of package DebyeFit

这个提交包含在:
majsylw
2021-08-06 10:15:43 +02:00
父节点 2d65a52d09
当前提交 6f33c8710f
共有 8 个文件被更改,包括 172 次插入486 次删除

查看文件

@@ -644,12 +644,28 @@ class Rawdata(Relaxation):
if __name__ == "__main__":
# | from Debye_Fit import HavriliakNegami, Jonscher, Rawdata, Crim |
# | |
# | |
# | Rawdata(3, "/data.txt",0.1, 1, 0.1, "M1", plot=True) |
# | |
# | HavriliakNegami(6, 1*10**12, 10**-3, 0.5, 1, 10, 5, 10**-6, 0.1, 1, 0, "M2", plot=True) |
# | |
# | Jonscher(4, 10**6, 10**-5, 50, 1, 10**5, 0.7, 0.1, 1, 0.1, "M3", plot=True) |
# | |
# | f = [0.5, 0.5] |
# | material1 = [3, 25, 10**6] |
# | material2 = [3 ,0, 10**3] |
# | materials = [material1, material2] |
# | Crim(2, 1*10**-1, 10**-9, 0.5, f, materials, 0.1, 1, 0, "M4", plot=True) |
# |
### Kelley et al. parameters
setup = HavriliakNegami(f_min=1e7, f_max=1e11,
alpha=0.91, beta=0.45,
e_inf=2.7, de=8.6-2.7, tau_0=9.4e-10,
sigma=0, mu=0, mu_sigma=0,
material_name="Kelley", f_n=100,
number_of_debye_poles=6,
plot=True, save=False,
optimizer_options={'swarmsize':30,
'maxiter':100,
@@ -662,38 +678,46 @@ if __name__ == "__main__":
'pflag': True})
setup.run()
setup = HavriliakNegami(f_min=1e7, f_max=1e11,
alpha=1-0.09, beta=0.45,
alpha=0.91, beta=0.45,
e_inf=2.7, de=8.6-2.7, tau_0=9.4e-10,
sigma=0, mu=0, mu_sigma=0,
material_name="Kelley", f_n=100,
number_of_debye_poles=6,
plot=True, save=False,
optimizer=DA,
optimizer_options={'seed': 111})
setup.run()
setup = HavriliakNegami(f_min=1e7, f_max=1e11,
alpha=1-0.09, beta=0.45,
alpha=0.91, beta=0.45,
e_inf=2.7, de=8.6-2.7, tau_0=9.4e-10,
sigma=0, mu=0, mu_sigma=0,
material_name="Kelley", f_n=100,
number_of_debye_poles=6,
plot=True, save=False,
optimizer=DE,
optimizer_options={'seed': 111})
setup.run()
### Testing setup
setup = Rawdata("Test.txt", 0.1, 1, 0.1, "M1", plot=True,
setup = Rawdata("examples/Test.txt", 0.1, 1, 0.1, "M1",
number_of_debye_poles=3, plot=True,
optimizer_options={'seed': 111})
setup.run()
np.random.seed(111)
setup = HavriliakNegami(1e12, 1e-3, 0.5, 1, 10, 5,
1e-6, 0.1, 1, 0, "M2", plot=True)
1e-6, 0.1, 1, 0, "M2",
number_of_debye_poles=6,
plot=True)
setup.run()
setup = Jonscher(1e6, 1e-5, 50, 1, 1e5, 0.7,
0.1, 1, 0.1, "M3", plot=True)
0.1, 1, 0.1, "M3",
number_of_debye_poles=4,
plot=True)
setup.run()
f = np.array([0.5, 0.5])
material1 = [3, 25, 1e6]
material2 = [3, 0, 1e3]
materials = np.array([material1, material2])
setup = Crim(1*1e-1, 1e-9, 0.5, f, materials, 0.1,
1, 0, "M4", plot=True)
1, 0, "M4", number_of_debye_poles=2,
plot=True)
setup.run()

查看文件

@@ -265,5 +265,5 @@ Allows you to model dielectric properties obtained experimentally by fitting mul
* ``str1`` is an identifier for the material.
* ``i2`` is an optional parameter which controls the seeding of the random number generator used in stochastic global optimizator. By default (if you don't specify this parameter) the random number generator will be seeded by trying to read data from ``/dev/urandom`` (or the Windows analogue) if available or from the clock otherwise.
For example ``#Rawdata: user_libs/DebyeFit/Test.txt 0.1 1 0.1 3 M4`` creates a material called ``M4`` which ...
For example ``#Rawdata: user_libs/DebyeFit/examples/Test.txt 0.1 1 0.1 3 M4`` creates a material called ``M4`` which ...

文件差异因一行或多行过长而隐藏

查看文件

@@ -0,0 +1,123 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Multi-pole Debye model for biological tissues\r\n",
"\r\n",
"In the ``user_libs`` sub-package is a module called ``DebyeFit`` which can be used to to fit a multi-Debye expansion to dielectric data. As an adaptation of Debye model, the Cole-Cole model develops by introducing an exponent parameter $\\alpha$. By applying the variable ```alpha```, the Cole-Cole model not only can achieve broader dispersions but also it flats the relaxation spectra. Due to these advantages and improvements, the **Cole-Cole model** is widely used in characterizing the complex permittivity of biological materials under high frequencies. Cole-Cole media cannot be directly implemented to FDTD, that's why approximations of the model (in the script by a multi-Debye function) are employed. In the gprMax code the **Cole-Cole model** could be approximated by using a variation of Havriliak-Negami function with ```beta = 1```, and given as\r\n",
"\r\n",
"$$\r\n",
"\\epsilon(\\omega) = \\epsilon_{\\infty} + \\frac{\\Delta\\epsilon}{1+\\left(j\\omega t_{0}\\right)^{a}}\r\n",
"$$\r\n",
"where $\\epsilon(\\omega)$ is frequency dependent dielectric properties, $\\Delta\\epsilon$ - difference between the real permittivity at zero and infinity frequency.\r\n",
"$\\tau_{0}$ is relaxation time, $\\epsilon_{\\infty}$ - real part of relative permittivity at infinity frequency.\r\n",
"\r\n",
"In the notebook to model biological tissues in wide range of frequences we used data from Gabriel et al. [1,2] and the ```HavriliakNegami``` class has the following structure:\r\n",
"\r\n",
"```\r\n",
"HavriliakNegami(f_min, f_max,\r\n",
" alpha, beta, e_inf, de, tau_0,\r\n",
" sigma, mu, mu_sigma, material_name,\r\n",
" number_of_debye_poles=-1, f_n=50,\r\n",
" plot=False, save=True,\r\n",
" optimizer=PSO_DLS,\r\n",
" optimizer_options={})\r\n",
"```\r\n",
"\r\n",
"* ``f_min`` is first bound of the frequency range used to approximate the given function (Hz),\r\n",
"* ``f_max`` is second bound of the frequency range used to approximate the given function (Hz),\r\n",
"* ``alpha`` is real positive float number which varies 0 < $\\alpha$ < 1,\r\n",
"* ``beta`` is real positive float number which varies 0 < $\\beta$ < 1,\r\n",
"* ``e_inf`` is a real part of relative permittivity at infinity frequency,\r\n",
"* ```de``` is a difference between the real permittivity at zero and infinity frequency,\r\n",
"* ```tau_0``` is a relaxation time,\r\n",
"* ```sigma``` is a conductivity (Siemens/metre),\r\n",
"* ```mu``` is a relative permeability,\r\n",
"* ```mu_sigma``` is a magnetic loss,\r\n",
"* ```material_name``` is definition of material name,\r\n",
"* ```number_of_debye_poles``` is choosen number of Debye poles,\r\n",
"* ```f_n``` is choosen number of frequences,\r\n",
"* ```plot``` is a switch to turn on the plotting,\r\n",
"* ```save``` is a switch to turn on the saving final material properties,\r\n",
"* ```optimizer``` is a choosen optimizer to fit model to dielectric data,\r\n",
"* ```optimizer_options``` is a dict for options of choosen optimizer.\r\n",
"\r\n",
"[1] S Gabriel et al 1996 Phys. Med. Biol. 41 2271 <br>\r\n",
"[2] A Peyman and C Gabriel 2010 Phys. Med. Biol. 55 N413\r\n"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 6,
"source": [
"import timeit\r\n",
"import os, sys\r\n",
"sys.path.append(os.path.abspath(os.path.join('..')))\r\n",
"from Debye_Fit import HavriliakNegami\r\n",
"\r\n",
"tissues = { 'Bone': [2, 39.8, 8.42e-12, 0.72],\r\n",
" 'Fat': [2, 12.68, 10.49e-12, 0.85],\r\n",
" 'Skin': [3.0, 46.03, 7.80e-12, 0.66],\r\n",
" 'Tongue': [4.0, 53.00, 8.35e-12, 0.74],\r\n",
" 'Skull': [2.0, 42.42, 8.84e-12, 0.67]\r\n",
" }\r\n",
"results = []\r\n",
"for key, value in tissues.items():\r\n",
" print(f'Using {key}')\r\n",
"\r\n",
" start = timeit.default_timer()\r\n",
" setup = HavriliakNegami(f_min=1e1, f_max=1e11,\r\n",
" alpha=value[3], beta=1,\r\n",
" e_inf=value[0], de=value[1], tau_0=value[2],\r\n",
" sigma=0, mu=0, mu_sigma=0,\r\n",
" material_name=key,\r\n",
" number_of_debye_poles=5, f_n=100,\r\n",
" plot=True, save=False,\r\n",
" optimizer_options={'seed':111})\r\n",
" error, _ = setup.run()\r\n",
" stop = timeit.default_timer()\r\n",
"\r\n",
" print(f'Time for {key} tissue in aproximating {setup.name}: {stop - start}')\r\n",
" results.append({'tissue': key, 'duration': stop - start, 'average error': error})\r\n",
"\r\n",
"print(f\"{'Tissue':^70s}|{'Duration':^10s}|{'Average Error':^20s}\")\r\n",
"for v in results:\r\n",
" print(f\"{v['tissue']:^70s}|{v['duration']:^10.4f}|{v['average error']:^20.4f}\")\r\n"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"outputs": [],
"metadata": {}
}
],
"metadata": {
"interpreter": {
"hash": "270c35ebb5d97b81be8a17a9789409b50c2bbc598c3d7f78964280318b10e842"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.9.5 64-bit ('gprMax': conda)"
},
"language_info": {
"name": "python",
"version": "3.9.5",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

查看文件

@@ -2,7 +2,8 @@
# "Incorporating dispersive electrical properties in FDTD GPR models
# using a general Cole-Cole dispersion function,"
# 2012 14th International Conference on Ground Penetrating Radar (GPR), 2012, pp. 232-236
import os, sys
sys.path.append(os.path.abspath(os.path.join('..')))
from Debye_Fit import HavriliakNegami
if __name__ == "__main__":

查看文件

@@ -60,10 +60,19 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"source": [
"import timeit\r\n",
"\r\n",
"import os, sys\r\n",
"sys.path.append(os.path.abspath(os.path.join('..')))"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 1,
"source": [
"from Debye_Fit import HavriliakNegami\r\n",
"\r\n",
"start = timeit.default_timer()\r\n",
@@ -689,11 +698,11 @@
],
"metadata": {
"interpreter": {
"hash": "f2e147b290d62c5b3fc5a5ad175474efea81eef3972d419dbc01547d9ed603d6"
"hash": "270c35ebb5d97b81be8a17a9789409b50c2bbc598c3d7f78964280318b10e842"
},
"kernelspec": {
"display_name": "Python 3.7.4 64-bit (conda)",
"name": "python3"
"name": "python3",
"display_name": "Python 3.9.5 64-bit ('gprMax': conda)"
},
"language_info": {
"codemirror_mode": {
@@ -705,7 +714,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.5"
}
},
"nbformat": 4,