Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions PyEIS/PyEIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@
from __future__ import division
import pandas as pd
import numpy as np
import mpmath as mp
import matplotlib as mpl
import seaborn as sns
from scipy.constants import codata
from pylab import *
from scipy.optimize import curve_fit
import mpmath as mp
from lmfit import minimize, Minimizer, Parameters, Parameter, report_fit
from lmfit import minimize, report_fit

#from scipy.optimize import leastsq
pd.options.mode.chained_assignment = None

#Plotting
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import seaborn as sns
import matplotlib.ticker as mtick
mpl.rc('mathtext', fontset='stixsans', default='regular')
mpl.rcParams.update({'axes.labelsize':22})
mpl.rc('xtick', labelsize=16)
mpl.rc('ytick', labelsize=16)
mpl.rc('legend',fontsize=14)

from scipy.constants import codata
F = codata.physical_constants['Faraday constant'][0]
Rg = codata.physical_constants['molar gas constant'][0]

Expand Down Expand Up @@ -57,7 +53,7 @@ def freq_gen(f_start, f_stop, pts_decade=7):
[1] = Angular frequency range [1/s]
'''
f_decades = np.log10(f_start) - np.log10(f_stop)
f_range = np.logspace(np.log10(f_start), np.log10(f_stop), num=np.around(pts_decade*f_decades), endpoint=True)
f_range = np.logspace(np.log10(f_start), np.log10(f_stop), num=np.around(pts_decade*f_decades).astype(int), endpoint=True)
w_range = 2 * np.pi * f_range
return f_range, w_range

Expand Down Expand Up @@ -2230,22 +2226,22 @@ class EIS_exp:
def __init__(self, path, data, cycle='off', mask=['none','none']):
self.df_raw0 = []
self.cycleno = []
for j in range(len(data)):
if data[j].find(".mpt") != -1: #file is a .mpt file
self.df_raw0.append(extract_mpt(path=path, EIS_name=data[j])) #reads all datafiles
elif data[j].find(".DTA") != -1: #file is a .dta file
self.df_raw0.append(extract_dta(path=path, EIS_name=data[j])) #reads all datafiles
elif data[j].find(".z") != -1: #file is a .z file
self.df_raw0.append(extract_solar(path=path, EIS_name=data[j])) #reads all datafiles
for j, f in enumerate(data, start=0):
if f.endswith('mpt'): #file is a .mpt file
self.df_raw0.append(extract_mpt(path=path, EIS_name=f)) #reads all datafiles
elif f.endswith('DTA'): #file is a .dta file
self.df_raw0.append(extract_dta(path=path, EIS_name=f)) #reads all datafiles
elif f.endswith('z'): #file is a .z file
self.df_raw0.append(extract_solar(path=path, EIS_name=f)) #reads all datafiles
elif f.endswith('txt'):
self.df_raw0.append(extract_csv(path=path, EIS_name=f))
else:
print('Data file(s) could not be identified')

self.cycleno.append(self.df_raw0[j].cycle_number)
if np.min(self.cycleno[j]) <= np.max(self.cycleno[j-1]):
if j > 0: #corrects cycle_number except for the first data file
self.df_raw0[j].update({'cycle_number': self.cycleno[j]+np.max(self.cycleno[j-1])}) #corrects cycle number
# else:
# print('__init__ Error (#1)')


#currently need to append a cycle_number coloumn to gamry files

Expand Down Expand Up @@ -4024,7 +4020,7 @@ def EIS_fit(self, params, circuit, weight_func='modulus', nan_policy='raise'):
self.circuit_fit = []
self.fit_E = []
for i in range(len(self.df)):
self.Fit.append(minimize(leastsq_errorfunc, params, method='leastsq', args=(self.df[i].w.values, self.df[i].re.values, self.df[i].im.values, circuit, weight_func), nan_policy=nan_policy, maxfev=9999990))
self.Fit.append(minimize(leastsq_errorfunc, params, method='leastsq', args=(self.df[i].w.values, self.df[i].re.values, self.df[i].im.values, circuit, weight_func), nan_policy=nan_policy, max_nfev=9999990))
print(report_fit(self.Fit[i]))

self.fit_E.append(np.average(self.df[i].E_avg))
Expand Down Expand Up @@ -4698,7 +4694,7 @@ def EIS_plot(self, bode='off', fitting='off', rr='off', nyq_xlim='none', nyq_yli
for i in range(len(self.df)):
ax.plot(self.df[i].re, self.df[i].im, marker='o', ms=4, lw=2, color=colors[i], ls='-', label=self.label_cycleno[i])
if fitting == 'on':
ax.plot(self.circuit_fit[i].real, -self.circuit_fit[i].imag, lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='')
ax.plot([i.real for i in self.circuit_fit[i]], [-i.imag for i in self.circuit_fit[i]], lw=0, marker='o', ms=8, mec='r', mew=1, mfc='none', label='')

### Bode Plot
if bode=='on':
Expand Down Expand Up @@ -6023,4 +6019,4 @@ def EIS_sim_fit(self, params, circuit, weight_func='modulus', nan_policy='raise'

#print()
#print('---> PyEIS Core Loaded (v. 0.5.7 - 02/01/19)')
#print()
#print()
24 changes: 20 additions & 4 deletions PyEIS/PyEIS_Data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from __future__ import division
import pandas as pd
import numpy as np
from scipy.constants import codata

#### Extracting .mpt files with PEIS or GEIS data
def correct_text_EIS(text_header):
Expand Down Expand Up @@ -142,6 +141,23 @@ def extract_solar(path, EIS_name):
data = data.assign(cycle_number = 1.0)
return data

#
#print()
#print('---> Data Extraction Script Loaded (v. 0.0.2 - 06/27/18)')

def extract_csv(path, EIS_name, sep='\t'):
'''
Extract data from simple csv style file.

The standard seperator is TAB and one row with column names. We want the columns
to named in a unified way: f, re, im, Z_mag, Y_phase.
'''

raw = pd.read_csv(path+EIS_name, sep='\t')
data = raw.rename(columns={'Frequency': 'f',
'Z_re': 're',
'Z_img': 'im',
'Z_E': 'Z_mag',
'Phase_E': 'Y_phase'})

data = data.assign(cycle_number = 1.0)

return data

21 changes: 21 additions & 0 deletions Tutorials/data/ex3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Frequency Z_E Phase_E Z_re Z_img
9.99999974737875E-5 100583.6953125 -0.279304325580597 27.0720300383251 7.764292820412
2.64000002061948E-4 94564.09375 -0.30045759677887 25.2917649727993 7.83634239799212
6.94999995175749E-4 74765.84375 -0.277011215686798 20.1363550823005 5.72519214566868
0.00182999996468425 60787.3515625 -0.291797459125519 16.3009754118168 4.89634619343949
0.00482999999076128 50841.2578125 -0.292887330055237 13.6293204344493 4.11005724755008
0.012699999846518 41034.671875 -0.373376429080963 10.6980794680164 4.19100089402257
0.0335999988019466 32260.626953125 -0.488816767930985 7.97511565518254 4.24171869846458
0.0886000022292137 23141.171875 -0.673698782920837 5.06387704288688 4.04245395981071
0.233999997377396 14394.5966796875 -0.830590903759003 2.71832007079357 2.97582963502232
0.61599999666214 8027.01171875 -0.968166828155518 1.27394300153653 1.85165059664597
1.62000000476837 4135.037109375 -1.06667029857636 0.559271484191949 1.01377527470784
4.28000020980835 2047.56225585938 -1.12656533718109 0.246390984067987 0.517672058733144
11.3000001907349 1010.5595703125 -1.14149475097656 0.117776716105174 0.257280251327722
29.7999992370605 493.506958007813 -1.1841938495636 0.0521006506280274 0.127983487310445
78.5544738769531 229.480880737305 -1.19812071323395 0.0233956747070571 0.0598439806122616
207.120727539063 104.836708068848 -1.12022435665131 0.012783215532553 0.0264246675054082
546.105041503906 52.2368049621582 -0.889707863330841 0.00920929245798327 0.0113629988017006
1439.88830566406 33.1943054199219 -0.550724923610687 0.00792018481248082 0.00486380987101006
3796.48291015625 27.5287494659424 -0.273702025413513 0.00742113193798794 0.0020834666438922
10010 25.8860626220703 -0.116779141128063 0.00719873118873418 8.44504077744677E-4