Calibration of non-linear (logarithmic) function

Calibration of non-linear (logarithmic) function#

from pylab import *
%pylab inline
from io import StringIO
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
/home/user/miniforge3/envs/book/lib/python3.11/site-packages/IPython/core/magics/pylab.py:166: UserWarning: pylab import has clobbered these variables: ['round', 'cross', 'random', 'bool', 'min', 'tensordot', 'trace', 'matmul', 'fft', 'abs', 'diagonal', 'max', 'pow', 'vecdot', 'matrix_transpose', 'outer', 'power']
`%matplotlib` prevents importing * from pylab and numpy
  warn("pylab import has clobbered these variables: %s"  % clobbered +
# create two signals: concentration and temperature
c = StringIO("""
1.095406121 3.887032952 6.956500526 9.486921797 \
13.96944459 14.86018043 23.19810833 24.53008787 \
24.72311112 37.44113657 38.05523491 54.1881169""")


T = StringIO("""91.72763561 70.60278306 \
53.0039356 45.03419592 32.45847839 29.03763728 13.49252686 \
12.0641877 18.91647307 12.01351046 11.49379565 9.671537342 """)

c = loadtxt(c)
T = loadtxt(T)
plot(c,T,'o')
[<matplotlib.lines.Line2D at 0x7fd29aa0b6d0>]
../_images/7781e5e9252525b1348fd54aa6c0ed0422270a200835d4b6f9501c797b04f4bb.png
a = -np.log10(T)
plot(c,a,'o')
[<matplotlib.lines.Line2D at 0x7fd29aa378d0>]
../_images/656bbcfe39d8fd67eb81ed6417a10b5fbbc0a582c40160712af9aec714df4281.png

see the linear part and the “saturated part”, use only the linear one#

ind = c < 24
plot(c[ind],a[ind],':o')
[<matplotlib.lines.Line2D at 0x7fd29a74bc10>]
../_images/b8262526c80ec050d9daebed4e2e3654d1d489cac5f03ffaeed60640dd176d1d.png
polyfit(c[ind],a[ind],1)
array([ 0.03674248, -1.99891754])
plot(c,a,'o')
c1 = linspace(0,60,100)
a1 = 0.037*c1-2.0
plot(c1,a1,'--')
[<matplotlib.lines.Line2D at 0x7fd29a722210>]
../_images/03ba533d1af7ae698436b76352f987ba2876f2a8ad5a0795ed4c68aae57151e1.png
plot(c,T,'o')
a1 = 0.037*c1-2.0
plot(c1,10**(-a1),'--')
[<matplotlib.lines.Line2D at 0x7fd29a85be10>]
../_images/29e0e3ce4d786539cf4fa6db9c8e648ec23e08acb9865332b78a92a0bac69775.png
print(f'c = {c}')
print(f'T = {T}')
c = [ 1.09540612  3.88703295  6.95650053  9.4869218  13.96944459 14.86018043
 23.19810833 24.53008787 24.72311112 37.44113657 38.05523491 54.1881169 ]
T = [91.72763561 70.60278306 53.0039356  45.03419592 32.45847839 29.03763728
 13.49252686 12.0641877  18.91647307 12.01351046 11.49379565  9.67153734]
plot(c,T,'bo',c[6:8],T[6:8],'rs')
[<matplotlib.lines.Line2D at 0x7fd29a8ef710>,
 <matplotlib.lines.Line2D at 0x7fd29a8ef6d0>]
../_images/4e55a896836272402f3e28d51053d7fcfb85cc5171ac64986ba4c2291039f9a4.png
c2 = c.copy()
T2 = T.copy()
mask = ones(c2.shape[0],dtype=bool)
mask[[6,7]] = False
plot(c2[mask],T2[mask],'o')
[<matplotlib.lines.Line2D at 0x7fd298553f50>]
../_images/9b25eff7cf38539a73c5b0f07c8e1c9e8fdef1c319b18039930a2ceb96dcba9b.png
plot(c2[mask]-c2[0],T2[mask]-T2[0],'o')
[<matplotlib.lines.Line2D at 0x7fd2985befd0>]
../_images/a065583f461c1318ae607e3d20bc141fba1dc6a2046a7581dbb3df5122157f61.png
c3 = c2[mask] - c2[0]
T3 = T2[0] - T2[mask]
c3
array([ 0.        ,  2.79162683,  5.86109441,  8.39151568, 12.87403847,
       13.76477431, 23.627705  , 36.34573045, 36.95982879, 53.09271078])
loglog(c3,T3,'o')
[<matplotlib.lines.Line2D at 0x7fd298419d50>]
../_images/fc56d93b2eb03203c37a9676d23e614483060efe6e3a3054a854609034297550.png