Example #1
0
def proto_0101(theABF):
    abf = ABF(theABF)
    abf.log.info("analyzing as an IC tau")
    #plot=ABFplot(abf)

    plt.figure(figsize=(SQUARESIZE / 2, SQUARESIZE / 2))
    plt.grid()
    plt.ylabel("relative potential (mV)")
    plt.xlabel("time (sec)")
    m1, m2 = [.05, .1]
    for sweep in range(abf.sweeps):
        abf.setsweep(sweep)
        plt.plot(abf.sweepX2,
                 abf.sweepY - abf.average(m1, m2),
                 alpha=.2,
                 color='#AAAAFF')
    average = abf.averageSweep()
    average -= np.average(
        average[int(m1**abf.pointsPerSec):int(m2 * abf.pointsPerSec)])
    plt.plot(abf.sweepX2, average, color='b', lw=2, alpha=.5)
    plt.axvspan(m1, m2, color='r', ec=None, alpha=.1)
    plt.axhline(0, color='r', ls="--", alpha=.5, lw=2)
    plt.margins(0, .1)

    # save it
    plt.tight_layout()
    frameAndSave(abf, "IC tau")
    plt.close('all')
Example #2
0
def proto_0314(theABF):
    abf = ABF(theABF)
    abf.log.info("analyzing a cosine + ramp protocol")

    if len(abf.comment_sweeps > 0):
        # comments exist, so graph the average sweep before/after the first comment
        sweepsToAverage = 10
        baselineSweep1 = max(0, abf.comment_sweeps[0] - sweepsToAverage)
        baselineSweep2 = abf.comment_sweeps[0]
        drugSweep1 = abf.comment_sweeps[0] + 1
        drugSweep2 = min(abf.sweeps - 1,
                         abf.comment_sweeps[0] + 1 + sweepsToAverage)

        plt.figure(figsize=(16, 4))
        plt.grid(ls='--', alpha=.5)
        plt.plot(abf.sweepX2,
                 abf.averageSweep(baselineSweep1, baselineSweep2),
                 label="baseline (%d-%d)" % (baselineSweep1, baselineSweep2),
                 alpha=.8)
        plt.plot(abf.sweepX2,
                 abf.averageSweep(drugSweep1, drugSweep2),
                 label="drug (%d-%d)" % (drugSweep1, drugSweep2),
                 alpha=.8)
        plt.margins(0, .05)
        plt.legend()
        plt.tight_layout()
        frameAndSave(abf, "cos ramp avg", closeWhenDone=False)
        plt.axis([2.25, 4.5, None, None])
        frameAndSave(abf, "cos ramp avgSine", closeWhenDone=False)
        plt.axis([9, 12.5, None, None])
        frameAndSave(abf, "cos ramp avgRamp")

    # prepare for AP analysis
    ap = AP(abf)

    # calculate rest potential
    avgVoltagePerSweep = []
    times = []
    for sweep in abf.setsweeps():
        avgVoltagePerSweep.append(abf.average(0, 2.25))
        times.append(abf.sweepStart / 60)

    # detect only cos APs
    M1, M2 = 2.25, 4.5
    ap.detect_time1, ap.detect_time2 = M1, M2
    ap.detect()
    apsPerSweepCos = [len(x) for x in ap.get_bySweep()]

    # detect only ramp APs
    M1, M2 = 9, 12.5
    ap.detect_time1, ap.detect_time2 = M1, M2
    ap.detect()
    apsPerSweepRamp = [len(x) for x in ap.get_bySweep()]

    # make the plot of APs and stuff
    plt.figure(figsize=(8, 8))

    plt.subplot(311)
    plt.grid(ls='--', alpha=.5)
    plt.plot(times, avgVoltagePerSweep, '.-')
    plt.ylabel("Rest Potential (mV)")
    comment_lines(abf)

    plt.subplot(312)
    plt.grid(ls='--', alpha=.5)
    plt.plot(times, apsPerSweepCos, '.-')
    plt.ylabel("APs in Cos (#)")
    comment_lines(abf)

    plt.subplot(313)
    plt.grid(ls='--', alpha=.5)
    plt.plot(times, apsPerSweepRamp, '.-')
    plt.ylabel("APs in Ramp (#)")
    comment_lines(abf)

    plt.tight_layout()

    frameAndSave(abf, "cos ramp")
    plt.close('all')