Python Forum
Error in running the Elliott Fitting function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in running the Elliott Fitting function
#1
Hi All,
I am new to the python and trying to do some curve fitting for my lab data. I have found an Elliott Fit code from Dr. Valerio D'Innocenzo's doctoral thesis and changed a bit to work for my data but it is not working. It was giving me errors like :

" RuntimeWarning: overflow encountered in cosh
return (1 / (abs(np.cosh((e-x))/ gamma)) * 2 * np.pi * np.sqrt(Eb) / (1 - np.exp(-2 * np.pi / (np.sqrt(D)))) * 1 / (1 - npc * (x - Eg)))
"

My experimental data is in 2nd column and energy values in 1st column.

Can anyone help me fix it?
Thanks,
Shashi
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
# ODEpack tool for differential equation integration
from numpy.distutils.fcompiler import none
from scipy.integrate import odeint, quad
# Optimization tool
import scipy.optimize as opt
#Interpolation tool
from scipy.interpolate import interp1d

def Elliots_fit (p, a_exp , e):
    Eb, Eg, gamma, npc, k = p
    #Descrete transitions to the excitonic states
    absex = np.zeros((e.size))
    n = np.linspace(1, 500, 500)
    for i in range(0, e.size):
        expr = 4*np.pi*(Eb**(3/2)) / (n**3)*(1/(np.cosh((e[i] - Eg + Eb/n**2) / gamma)))
        S = expr.cumsum(axis=0)
        absex[i] = S[-1]

    #Band to band absorption with Sommerfeld correction
    abseh = np.zeros((e.size))

    def fun_eh(x, e, gamma, Eb, Eg, npc):
        D = (x-Eg)/Eb
        return (1 / (abs(np.cosh((e-x))/ gamma)) * 2 * np.pi * np.sqrt(Eb) / (1 - np.exp(-2 * np.pi / (np.sqrt(D)))) * 1 / (1 - npc * (x - Eg)))

    for i in range(0, e.size):
        q = quad(fun_eh, Eg, np.inf, args=(e[i], gamma, Eb, Eg, npc))
        abseh[i] = q[0]
    #Complete Abs simulation (background added)
    abs_sim = np.zeros((e.size))
    for i in range(0, e.size):
        abs_sim[i] = (e[i] / Eb**(3/2))*(absex[i] + abseh[i])
    return (abs_sim*k-abs_exp_fit)

#Data loading
data = np.loadtxt('transmission_data.txt')
# plt.plot(e, data[:,2])
e_exp = data [:,0] # concerted from nm to eV
a_exp = data[:,1] # My data
#Intial Values
Eb = 0.030 # exciton binding energy (eV)
gamma = 0.029 # inhomogeneous line broadening (eV)
Eg = 2.402 # semiconductor bandgap (eV)
npc = -0.31 # non−parabolic coefficient
k = 0.0035
#Energy axis generation
# ix0 = np.searchsorted(e_exp ,1.58862)
# ix1 = np.searchsorted(e_exp ,1.42976)
# e = np.linspace(e_exp[ix1], e_exp[ix0-1], 500) # energy axes (eV)
e = np.linspace(e_exp[len(e_exp)-1], e_exp[0], 3440) # energy axes (eV)
p0 = np.array([Eb, Eg, gamma, npc, k],dtype=np.float64 )#b = np.array([[1,2,3,4,5],[6,7,8,9,10]],dtype=np.float64)
#Fit Calling
#Interpolating the simulated abs over the exp x−axis
f = interp1d(e_exp ,a_exp)
abs_exp_fit = f(e)
opt_out = opt.leastsq(Elliots_fit ,p0, args =( abs_exp_fit , e), full_output=1)
fitted_param = opt_out[0]
#Standard error evaluation

fitting = Elliots_fit(fitted_param, abs_exp_fit, e)

plt.plot(e, abs_exp_fit)
plt.plot(e, fitting)

if (len( abs_exp_fit ) > len(p0)) and opt_out [1] is not None:
    s_sq = (( fitting-abs_exp_fit )**2).sum()((len( abs_exp_fit )-len(p0)))
    pcov = opt_out[1] * s_sq
else:
    pcov = np.inf
error = []
for i in range(len(opt_out [0])):
    try:
        error.append( np.absolute(pcov[i][i])**0.5)
    except:
        error.append( 0.00 )
pfit_leastsq = opt_out [0]
perr_leastsq = np.array(error)
Reply


Messages In This Thread
Error in running the Elliott Fitting function - by shashisourabh - Jan-15-2020, 11:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sine fitting - extra modulation Pikano 2 1,015 Jan-04-2023, 07:41 AM
Last Post: Pikano
  Fitting transfer function model to FRF data ymohammadi 0 1,688 Feb-10-2022, 10:02 AM
Last Post: ymohammadi
  curve fitting matlotlib scipy Cjstarling 2 2,465 Sep-15-2020, 02:56 PM
Last Post: Cjstarling
  Fitting experimental data with differential equations : Optimization madoko 6 6,843 Jan-17-2019, 11:30 AM
Last Post: scidam
  panda, excel - script pauses and doesn't continue running, no error message william 1 2,678 Nov-24-2018, 01:24 AM
Last Post: ichabod801
  Newbie at using python and tensorflow getting error when running simple code FeatherineAu 0 3,989 Sep-28-2018, 02:09 PM
Last Post: FeatherineAu
  Fitting Lognormal Data Carolyn 3 16,073 May-21-2018, 12:10 AM
Last Post: scidam
  Error while running python script to get pixel points from google static map image python_newbee 3 4,838 Sep-15-2017, 06:25 AM
Last Post: python_newbee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020