2022/04/28-2022/06/18处理数据(jxy)

import csv,sys,os
import matplotlib.pyplot as plt

filename = 'IEC6M01-#20-C03-Eng_Sweep_CgVg_hf_r1_220419_151711.csv'
csv_reader = csv.reader(open(filename))

### input the area
area = 2.64e-5
# print('The area is {}'.format(area))

n = 0
ls,tmp = [],[]
for row in csv_reader:
    cv = [row[-2],row[-1]]
    tmp.append(cv)
    if n %241 == 0:
        ls.append(tmp)
        tmp = []
    n += 1


fig_path = "figs"
if not os.path.exists(fig_path):
    os.mkdir(fig_path)


index = 1
for i in ls[1:]:
    Cg,Vg = [], []
    f =  open('figs/Die-{}_Cgs.dat'.format(index),'w')
    f.write('Cg Vg\n')
    for j in i:
        Cg.append(float(j[0]))
        Vg.append(float(j[1]))
        f.write('{} {}\n'.format(float(j[0])/area,float(j[1])))
    f.close()

    plt.plot(Vg,Cg)
    plt.title('Cg-Vg curve_{}'.format(index))
    plt.xlabel('Vg')
    plt.ylabel('Cg')
    plt.savefig('figs/Die-{}_Cgs.jpg'.format(index))
    plt.clf()
    index += 1

with open('CV.csv','w',encoding='gbk',newline="") as f:
    csv_writer = csv.writer(f)
    for j in range(len(ls[1])):
        tmp = []
        for i in range(1,len(ls)):
            tmp += [ls[i][j][1],float(ls[i][j][0])/area]
        csv_writer.writerow(tmp)
    f.close()
import csv,sys,os
import matplotlib.pyplot as plt

filename = 'IEC6M01-#20-T01-Eng_Sweep_IdVg_220331_091507.csv'
csv_reader = csv.reader(open(filename))

n = 0
ls,tmp = [],[]
ls1,tmp1 = [],[]
for row in csv_reader:
    if n <= 65*(2*(n//130+1)-1) and n%130!=0:
        tmp.append([row[-3],row[-1]])
    else:
        tmp1.append([row[-3]])
    if n %130 == 0:
        ls.append(tmp)
        tmp = []
        ls1.append(tmp1)
        tmp1 = []
    n += 1

fig_path = "figs"
if not os.path.exists(fig_path):
    os.mkdir(fig_path)
for i in range(1,len(ls)):
    Id, Id1, Vg = [], [], []
    f =  open('figs/Die-{}_IdVg.dat'.format(i),'w')
    f.write('Id Id1 Vg\n')
    for j in range(len(ls[1])):
        Id.append(float(ls[i][j][0]))
        Id1.append(float(ls1[i][j][0]))
        Vg.append(float(ls[i][j][1]))
        f.write('{} {} {}\n'.format(float(ls[i][j][0]),float(ls1[i][j][0]),float(ls[i][j][1])))
    f.close()
    # plt.rcParams.update({'figure.max_open_warning':0})
    # plt.figure()
    plt.plot(Vg,Id)
    plt.yscale('log')
    plt.plot(Vg,Id1)
    plt.yscale('log')
    plt.title('Id-Vg curve_{}'.format(i))
    plt.xlabel('Vg')
    plt.ylabel('Id')
    plt.savefig('figs/Die-{}_IdVg.jpg'.format(i))
    plt.clf()

 

 

import csv,sys,os
import matplotlib.pyplot as plt
from scipy import integrate
import numpy as np
# https://blog.csdn.net/github_15549139/article/details/47146279

def filter(filename1,filename2):
    with open(filename1,'r') as f1:
        content1 = f1.readlines()
    with open(filename2,'r') as f2:
        content2 = f2.readlines()

    Id_raw, Vg_raw1 = [], []
    for i in content1[1:]:
        tmp = i.split()
        Id_raw.append(float(tmp[0]))
        Vg_raw1.append(float(tmp[-1]))

    Cg_raw, Vg_raw2 = [], []
    for j in content2[1:]:
        tmp = j.split()
        Cg_raw.append(float(tmp[0]))
        Vg_raw2.append(float(tmp[1]))
    return Id_raw,Vg_raw1,Cg_raw,Vg_raw2


def mobility_old(Id_raw,Vg_raw1,Cg_raw,Vg_raw2,dat_i):
    f1 = np.polyfit(Vg_raw1,Id_raw,15)
    yvals1 = np.polyval(f1,Vg_raw1)
    f2 = np.polyfit(Vg_raw2,Cg_raw,15)
    yvals2 = np.polyval(f2,Vg_raw2)

    ## Selected the Voltage windows
    Vg_min = max(min(Vg_raw1),min(Vg_raw2))
    Vg_max = min(max(Vg_raw1),max(Vg_raw2))
    Vg = np.linspace(Vg_min,Vg_max,num=2000)
    Id = np.polyval(f1, Vg)
    Cg = np.polyval(f2, Vg)

    plt.plot(Vg_raw1,Id_raw,'.',label='raw')
    plt.plot(Vg,Id,label='fit')
    plt.xlabel('$V_g$')
    plt.ylabel('$I_d$')
    plt.yscale('log')
    plt.title('$I_d$-$V_g$_{}-curve'.format(dat_i))
    plt.legend()
    plt.savefig('mobs/Die-{}_IdVg_fit.jpg'.format(dat_i))
    plt.clf()

    plt.plot(Vg_raw2,Cg_raw,'.',label='raw')
    plt.plot(Vg,Cg,label='fit')
    plt.xlabel('$V_g$')
    plt.ylabel('$C_g$')
    plt.title('$C_g$-$V_g$_{}-curve'.format(dat_i))
    plt.legend()
    plt.savefig('mobs/Die-{}_Cgs_fit.jpg'.format(dat_i))
    plt.clf()

    minCg = min(Cg)
    Cgc = [i-minCg for i in Cg]
    ## integrate.cumtrapz: integral function. 
    ## Q is charge which capacitance to volatge integration.
    Q = abs(integrate.cumtrapz(Cgc,Vg))
    ## mob: mobility. equal to (L/W)*(Id/Vd/Q)
    mob = [(L/W)*(Id[i]/Vd/Q[i-1]) for i in range(1,len(Id))]
    ## Ns = Q/q
    Ns = [i/e0 for i in Q]

    plt.plot(Vg[1:],Ns,'b')
    plt.xlabel('$V_g$')
    plt.ylabel('$N$')
    plt.title('$N$-$V_g$_{}-curve'.format(dat_i))
    plt.savefig('mobs/Die-{}_NV.jpg'.format(dat_i))
    plt.clf()

    plt.plot(Ns[1000:],mob[1000:],'r')
    plt.xlabel('$N$')
    plt.ylabel('$\mu$')
    plt.title('Mobility {}'.format(dat_i))
    plt.savefig('mobs/Die-{}_mobility.jpg'.format(dat_i))
    plt.clf()


def mobility(Id_raw,Vg_raw1,Cg_raw,Vg_raw2,dat_i,vfb):
    ## Id_raw, Vg_raw1 must be the same dimension
    ## Cg_raw, Vg_raw2 must be the same dimension

    ## 'np.polyfit' return a list of polynomial coefficient
    poly1 = np.polyfit(Vg_raw1,Id_raw,15)
    ## yvals1: fitted data of Id-Vg curve
    yvals1 = np.polyval(poly1,Vg_raw1)

    ## 'np.polyfit' return a list of polynomial coefficient
    poly2 = np.polyfit(Vg_raw2,Cg_raw,15)
    ## yvals2: fitted data of Cg-Vg curve
    yvals2 = np.polyval(poly2,Vg_raw2)

    ## Selected the Voltage windows
    Vg_min = max(min(Vg_raw1),min(Vg_raw2))
    Vg_max = min(max(Vg_raw1),max(Vg_raw2))

    if vfb > Vg_max or vfb < Vg_min:
        sys.exit()

    if np.polyval(poly2,vfb) < np.polyval(poly2,Vg_max):
        # print('This is n-type!')
        ## Voltage grid points 2000 (default)
        Vg = np.linspace(vfb,Vg_max,num=2000)
        Id = np.polyval(poly1, Vg)
        Cg = np.polyval(poly2, Vg)
    else:
        # print('This is p-type!')
        Vg = np.linspace(vfb,Vg_min,num=2000)
        Id = np.polyval(poly1, Vg)
        Cg = np.polyval(poly2, Vg)

    plt.plot(Vg_raw1,Id_raw,'.',label='raw')
    plt.plot(Vg,Id,label='fit')
    plt.xlabel('$V_g$')
    plt.ylabel('$I_d$')
    plt.yscale('log')
    plt.title('$I_d$-$V_g$_{}-curve'.format(dat_i))
    plt.legend()
    plt.savefig('mobs/Die-{}_IdVg_fit.jpg'.format(dat_i))
    plt.clf()

    plt.plot(Vg_raw2,Cg_raw,'.',label='raw')
    plt.plot(Vg,Cg,label='fit')
    plt.xlabel('$V_g$')
    plt.ylabel('$C_g$')
    plt.title('$C_g$-$V_g$_{}-curve'.format(dat_i))
    plt.legend()
    plt.savefig('mobs/Die-{}_Cgs_fit.jpg'.format(dat_i))
    plt.clf()

    ## integrate.cumtrapz: integral function. 
    ## Q is charge which capacitance to volatge integration.
    Q = abs(integrate.cumtrapz(Cg,Vg))
    ## mob: mobility. equal to (L/W)*(Id/Vd/Q)
    mob = [(L/W)*(Id[i]/Vd/Q[i-1]) for i in range(1,len(Id))]
    ## Ns = Q/q
    Ns = [i/e0 for i in Q]

    plt.plot(Vg[1:],Ns,'b')
    plt.xlabel('$V_g$')
    plt.ylabel('$N$')
    plt.title('$N$-$V_g$_{}-curve'.format(dat_i))
    plt.savefig('mobs/Die-{}_NV.jpg'.format(dat_i))
    plt.clf()

    plt.plot(Ns[1000:],mob[1000:],'r')
    plt.xlabel('$N$')
    plt.ylabel('$\mu$')
    plt.title('Mobility_{}'.format(dat_i))
    plt.savefig('mobs/Die-{}_mobility.jpg'.format(dat_i))
    plt.clf()

def readVfb(filename):
    with open(filename,'r') as f:
        content = f.readlines()
    res = content[0].split()
    res = [float(i) for i in res]
    return res

def main():
    fig_path = "figs"
    if not os.path.exists(fig_path):
        print('No "figs" filefold!\n**No CV/IV data!**')
        sys.exit()
    mob_path = "mobs"
    if not os.path.exists(mob_path):
        os.mkdir(mob_path)

    num = 0
    for i in os.listdir(fig_path):
        if i[-8:] == '_Cgs.dat':
            num += 1
    if num == 0:
        print('Please check the name of "*_Cgs.dat')
        sys.exit()

    vfb_path = 'vfb.txt'
    if not os.path.exists(vfb_path):
        print('Warning! there is no "vfb.txt".\n***We will use the minimum of Voltage***')
        flag = False
    else:
        Vfb = readVfb(vfb_path)
        flag = True
        if num != len(Vfb):
            print('The numbers of CV.dat-{} and Vfb.txt-{} mismatch'.format(num,len(Vfb)))
            sys.exit()

    ## Start,end denote the sequence of CV/IV.dat you want to do with.
    start, end = 1, num
    for dat_i in range(start,end+1):
        filename1 = 'figs/Die-{}_IdVg.dat'.format(dat_i)
        filename2 = 'figs/Die-{}_Cgs.dat'.format(dat_i)
        Id_raw, Vg_raw1, Cg_raw, Vg_raw2 = filter(filename1,filename2)
        if flag:
            vfb = Vfb[dat_i-1]
            mobility(Id_raw,Vg_raw1,Cg_raw,Vg_raw2,dat_i,vfb)
        else:
            mobility_old(Id_raw,Vg_raw1,Cg_raw,Vg_raw2,dat_i)
        print('Die-{} is done.'.format(dat_i))
    print('Congratulation!')

if __name__ == '__main__':
    ### constant Parameter
    W=0.198*1e-4 #cm
    L=0.5e-4 #cm
    e0=1.602e-19
    ### Control Parameter
    Vd = 0.9
    main()

 

posted @ 2022-06-18 14:04  ghzphy  阅读(27)  评论(0编辑  收藏  举报