Exemplo n.º 1
0
def sakakibara_iv_sum_stats(data):
    output = []
    for d in data.split_periodic(11000, adjust=True):
        d = d.trim_left(10000, adjust=True)
        current = d['ina.i_Na']
        output = output+[max(current, key=abs)]
    return output
Exemplo n.º 2
0
def sakakibara_rec_sum_stats(data, fast=True, slow=True):
    def double_exp(t, tau_r1, tau_r2, A0, A1, A2):
        return A0-A1*np.exp(-t/tau_r1)-A2*np.exp(-t/tau_r2)
    output1 = []
    output2 = []
    timename = 'engine.time'
    for i, d in enumerate(data.split_periodic(tsplit_rec, adjust=True, closed_intervals=False)):
        recov = []
        for t in tsplits_rec:
            d_, d = d.split(t)
            step1 = d_.trim(d_[timename][0]+10000,
                            d_[timename][0]+10000+1000,
                            adjust=True)
            step2 = d_.trim_left(t-1000, adjust=True)
            try:
                max1 = max(step1['ina.i_Na'], key=abs)
                max2 = max(step2['ina.i_Na'], key=abs)
                recov = recov + [max2/max1]
            except:
                recov = recov + [float('inf')]

        # Now fit output to double exponential
        with warnings.catch_warnings():
            warnings.simplefilter('error', so.OptimizeWarning)
            warnings.simplefilter('error', RuntimeWarning)
            try:
                popt, _ = so.curve_fit(double_exp,
                                       twaits_rec,
                                       recov,
                                       p0=[1.,10.,0.9,0.1,0.],
                                       bounds=(0.,
                                               [100,1000,1.0,1.0,1.0]),
                                       max_nfev=1000)

                fit = [double_exp(t,popt[0],popt[1],popt[2],popt[3],popt[4])
                       for t in twaits_rec]

                # Calculate r2
                ss_res = np.sum((np.array(recov)-np.array(fit))**2)
                ss_tot = np.sum((np.array(recov)-np.mean(np.array(recov)))**2)
                r2 = 1 - (ss_res / ss_tot)

                tauf = min(popt[0],popt[1])
                taus = max(popt[0],popt[1])
                if r2 > fit_threshold:
                    if fast:
                        output1 = output1+[tauf]
                    if slow:
                        output2 = output2+[taus]
                else:
                    raise RuntimeWarning('scipy.optimize.curve_fit found a poor fit')
            except:
                if fast:
                    output1 = output1+[float('inf')]
                if slow:
                    output2 = output2+[float('inf')]
    output = output1+output2
    return output
Exemplo n.º 3
0
def sakakibara_inact_kin_sum_stats(data, fast=True, slow=True):
    def double_exp(t, tauh, taus, Ah, As, A0):
        return Ah*np.exp(-t/tauh) + As*np.exp(-t/taus) + A0

    output_fast = []
    output_slow =  []
    for d in data.split_periodic(10100, adjust=True):
        d = d.trim_left(10000, adjust=True)

        current = d['ina.i_Na'][:-1]
        time = d['engine.time'][:-1]
        index = np.argmax(np.abs(current))

        # Set time zero to peak current
        current = current[index:]
        time = time[index:]
        t0 = time[0]
        time = [t-t0 for t in time]

        with warnings.catch_warnings():
            warnings.simplefilter('error', OptimizeWarning)
            warnings.simplefilter('error', RuntimeWarning)
            try:
                current = [c/current[0] for c in current]
                if len(time)<=1 or len(current)<=1:
                    raise Exception('Failed simulation')
                popt, _ = so.curve_fit(double_exp,
                                       time,
                                       current,
                                       p0=[2,20,0.9,0.1,0],
                                       bounds=(0.,
                                               [np.inf, np.inf, 1.0, 1.0, 1.0]),
                                       max_nfev=1000)
                fit = [double_exp(t,popt[0],popt[1],popt[2],popt[3],popt[4]) for t in time]
                # Calculate r2
                ss_res = np.sum((np.array(current)-np.array(fit))**2)
                ss_tot = np.sum((np.array(current)-np.mean(np.array(current)))**2)
                r2 = 1 - (ss_res / ss_tot)

                tauh = min(popt[0],popt[1])
                taus = max(popt[0],popt[1])

                if r2 > fit_threshold:
                    if fast:
                        output_fast = output_fast+[tauh]
                    if slow:
                        output_slow = output_slow+[taus]
                else:
                    raise RuntimeWarning('scipy.optimize.curve_fit found a poor fit')
            except:
                if fast:
                    output_fast = output_slow+[float('inf')]
                if slow:
                    output_slow = output_slow+[float('inf')]
    output = output_fast+output_slow
    return output
Exemplo n.º 4
0
def sakakibara_act_sum_stats(data):
    output = []
    for d in data.split_periodic(11000, adjust=True):
        d = d.trim_left(10000, adjust=True)
        act_gate = d['ina.g']
        output = output+[max(act_gate, key=abs)]
    norm = max(output)
    for i in range(len(output)):
        output[i] /= norm
    return output
Exemplo n.º 5
0
def sakakibara_inact_sum_stats(data):
    output = []
    for d in data.split_periodic(11030, adjust=True):
        d = d.trim_left(11000, adjust = True)
        inact_gate = d['ina.g']
        output = output+[max(inact_gate, key=abs)]
    norm = max(output)
    try:
        for i in range(len(output)):
            output[i] /= norm
    except:
        for i in range(len(output)):
            output[i] = float('inf')
    return output