<commit_before># -*- coding: utf-8 -*-

import numpy as np
import linecache
import math

#Constants
eps0 = 8.854187817e-14 #F*cm^-1
q = 1.602176462e-19 #C

def cv_read(cv_file, model):
    """ Read Capacitance-Voltage data from *.CV file
    
    Parameters
    ----------
    cv_file : srt, path to the CV file
    model : str, 'Cp' or 'Cs' - model for calculation capacitance
    
    Returns
    -------
    Cp, Cs : float, capacitance in uF/cm^2
    voltage : float, voltage in V
    
    """
    
    #get area, size and frequency from line 12 of CV file
    #example: 0 0.106 2327.1 443.02 0
    #(?) (area) (first frequency in rad) (second freq) (?)
    cv_properties = linecache.getline(cv_file, 12)
    cv_properties = cv_properties.split()
    area = float(cv_properties[1])
    freq = float(cv_properties[2])

    #build voltage array from values in line 15
    #example: -0.64142 0.008 19 100
    #(start voltage) (step) (number of negative steps) (total number of steps)
    voltage_range = linecache.getline(cv_file, 15)
    voltage_range = voltage_range.split()
    vstart = float(voltage_range[0])
    vstep = float(voltage_range[1])
    nneg = float(voltage_range[2])
    npos = float(voltage_range[3]) - nneg
    voltage = np.concatenate((
                              np.linspace(vstart, vstart-vstep*nneg, nneg+1),
                              np.linspace(vstart, vstart+vstep*npos, npos,
                                          endpoint=False)
                              ),
                             axis = 0)

    # Y is complex admittance (Gp+Bp*i)
    cnv = dict.fromkeys([0], lambda x: complex(*eval(x)))
    Y = np.genfromtxt(cv_file, converters=cnv, 
                      delimiter=25, skip_header=15)
    #sort array
    array = np.vstack((voltage, Y.real, Y.imag)).T
    array = array[array[:,0].argsort(0)]
    voltage = array[:,0]
    Y.real = array[:,1]
    Y.imag = array[:,2]

    Diss = Y.real/Y.imag
    Cp = 1e6*Y.imag/(freq*area)
    Cs = Cp*(1+Diss**2)

    if model == 'Cp':
        return Cp, voltage
    if model == 'Cs':
        return Cs, voltage

def iv_read(iv_file):
    """ Read Current-Voltage data from *.IV file
    
    Parameters
    ----------
    cv_file : srt, path to the IV file
    
    Returns
    -------
    current : float, current in mA/cm^2
    voltage : float, voltage in V
    
    """
    
    #build voltage array from values in line 15
    #example: -0.64142 0.008 19 100
    #(start voltage) (step) (number of negative steps) (total number of steps)
    voltage_range = linecache.getline(iv_file, 15)
    voltage_range = voltage_range.split()
    vstart = float(voltage_range[0])
    vstep = float(voltage_range[1])
    nneg = float(voltage_range[2])
    npos = float(voltage_range[3]) - nneg
    voltage = np.concatenate((
                              np.linspace(vstart, vstart-vstep*nneg, nneg+1),
                              np.linspace(vstart, vstart+vstep*npos, npos,
                                          endpoint=False)
                              ),
                             axis = 0)

    # read current 
    current = np.genfromtxt(iv_file, skip_header=15)
    
    #sort array
    array = np.vstack((voltage, current)).T
    array = array[array[:,0].argsort(0)]
    voltage = array[:,0]
    current = array[:,1]

    return current, voltage
        
def lin_fit(capacitance, voltage, vmin=None, vmax=None, eps=15.15):
    """ Returns linear fit for measured 1/C^2 and calculated Doping level 
    
    Parameters
    ----------
    capacitance : float, capacitance in uF/cm^2
    voltage : float, voltage in V
    vmin, vmax : float, range for linear fitting
    eps : float, dielectric constant (default is for InAs)<commit_msg>ep_read function added<commit_after># -*- coding: utf-8 -*-

import numpy as np
import linecache
import math

#Constants
eps0 = 8.854187817e-14 #F*cm^-1
q = 1.602176462e-19 #C

def cv_read(cv_file, model):
    """ Read Capacitance-Voltage data from *.CV file
    
    Parameters
    ----------
    cv_file : srt, path to the CV file
    model : str, 'Cp' or 'Cs' - model for calculation capacitance
    
    Returns
    -------
    Cp, Cs : float, capacitance in uF/cm^2
    voltage : float, voltage in V
    
    """
    
    #get area, size and frequency from line 12 of CV file
    #example: 0 0.106 2327.1 443.02 0
    #(?) (area) (first frequency in rad) (second freq) (?)
    cv_properties = linecache.getline(cv_file, 12)
    cv_properties = cv_properties.split()
    area = float(cv_properties[1])
    freq = float(cv_properties[2])

    #build voltage array from values in line 15
    #example: -0.64142 0.008 19 100
    #(start voltage) (step) (number of negative steps) (total number of steps)
    voltage_range = linecache.getline(cv_file, 15)
    voltage_range = voltage_range.split()
    vstart = float(voltage_range[0])
    vstep = float(voltage_range[1])
    nneg = float(voltage_range[2])
    npos = float(voltage_range[3]) - nneg
    voltage = np.concatenate((
                              np.linspace(vstart, vstart-vstep*nneg, nneg+1),
                              np.linspace(vstart, vstart+vstep*npos, npos,
                                          endpoint=False)
                              ),
                             axis = 0)

    # Y is complex admittance (Gp+Bp*i)
    cnv = dict.fromkeys([0], lambda x: complex(*eval(x)))
    Y = np.genfromtxt(cv_file, converters=cnv, 
                      delimiter=25, skip_header=15)
    #sort array
    array = np.vstack((voltage, Y.real, Y.imag)).T
    array = array[array[:,0].argsort(0)]
    voltage = array[:,0]
    Y.real = array[:,1]
    Y.imag = array[:,2]

    Diss = Y.real/Y.imag
    Cp = 1e6*Y.imag/(freq*area)
    Cs = Cp*(1+Diss**2)

    if model == 'Cp':
        return Cp, voltage
    if model == 'Cs':
        return Cs, voltage

def iv_read(iv_file):
    """ Read Current-Voltage data from *.IV file
    
    Parameters
    ----------
    cv_file : srt, path to the IV file
    
    Returns
    -------
    current : float, current in mA/cm^2
    voltage : float, voltage in V
    
    """
    
    #build voltage array from values in line 15
    #example: -0.64142 0.008 19 100
    #(start voltage) (step) (number of negative steps) (total number of steps)
    voltage_range = linecache.getline(iv_file, 15)
    voltage_range = voltage_range.split()
    vstart = float(voltage_range[0])
    vstep = float(voltage_range[1])
    nneg = float(voltage_range[2])
    npos = float(voltage_range[3]) - nneg
    voltage = np.concatenate((
                              np.linspace(vstart, vstart-vstep*nneg, nneg+1),
                              np.linspace(vstart, vstart+vstep*npos, npos,
                                          endpoint=False)
                              ),
                             axis = 0)

    # read current 
    current = np.genfromtxt(iv_file, skip_header=15)
    
    #sort array
    array = np.vstack((voltage, current)).T
    array = array[array[:,0].argsort(0)]
    voltage = array[:,0]
    current = array[:,1]

    return current, voltage

def ep_read(ep_file):
    """ Read measured doping profile from *.EP file
    
    Parameters
    ----------
    ep_file : srt, path to the EP file

    Returns
    -------
    doping : float, doping level in cm^-3
    width : float, depletion width + etched with in um
    
    """
    data=np.genfromtxt(ep_file, skip_header=13, names=['width', 'doping'])
    
    doping=data['doping']
    width=data['width']
    
    return doping, width
        
def lin_fit(capacitance, voltage, vmin=None, vmax=None, eps=15.15):
    """ Returns linear fit for measured 1/C^2 and calculated Doping level 
    
    Parameters
    ----------
    capacitance : float, capacitance in uF/cm^2
    voltage : float, voltage in V
    vmin, vmax : float, range for linear fitting
    eps : float, dielectric constant (default is for InAs)
{'fraction_non_alphanumeric': 0.12429022082018927, 'fraction_numerical': 0.032681388012618294, 'mean_word_length': 2.039110429447853, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '762897', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2539, 'n_words': 686}