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/Documents/repos/engineering_experiments_measurements_course/.conda/lib/python3.12/site-packages/IPython/core/magics/pylab.py:166: UserWarning: pylab import has clobbered these variables: ['max', 'abs', 'random', 'outer', 'diagonal', 'bool', 'min', 'round', 'trace', 'power', 'matmul', 'tensordot', 'fft', 'matrix_transpose', 'pow', 'vecdot', 'cross']
`%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 0x7f26860fa630>]
../_images/626c2649e56f73405d1ab7c83f978c65623d010ef7d2b8368a14a6d229e20b52.png
a = -np.log10(T)
plot(c,a,'o')
[<matplotlib.lines.Line2D at 0x7f2683e1ade0>]
../_images/4fcfcc28c075403ebe9057471ab51a6a18f82186745a7362fca8c848196d5104.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 0x7f2683e76f60>]
../_images/a003aaa010e929c80378735fa6c7465e2006a1185ced5875e4034612951ff611.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 0x7f2685f169f0>]
../_images/f9daf7b39b59f0585dc5ae1adcb04589c75824a50cd4c23c495908fac5d24dda.png
plot(c,T,'o')
a1 = 0.037*c1-2.0
plot(c1,10**(-a1),'--')
[<matplotlib.lines.Line2D at 0x7f2685f8e660>]
../_images/adce6c24037af9c696cf5d5489a10872e2b98457f16f73357e8bb60830d3935e.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 0x7f2683ccb3e0>,
 <matplotlib.lines.Line2D at 0x7f2683ccb290>]
../_images/5912dc8eec1b95a3585668797e51de4db5b6ad2b8c153c4c199320da0f000c03.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 0x7f2683d3a360>]
../_images/75e64dc42ab483f15f8ec11d3425e4de84e1ddb97a2d79f42767ea5a95fc7b0c.png
plot(c2[mask]-c2[0],T2[mask]-T2[0],'o')
[<matplotlib.lines.Line2D at 0x7f2683bb9010>]
../_images/71e5f0873b3b4fd8ee43003dd2f89b3decc801210e788384d635c9d4f0692345.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 0x7f2683bf0290>]
../_images/02e29fda744e7c3e063c9e692b78663aa4d17485d2ea825073392f5669b2c54a.png