Example #1
0
def extract_amplitudes(index, r_min=0.7):
    t, rec, rec_filt = preprocess(index)

    i = 0
    amp = []
    for rec1_, rec_filt1_, rec2_, rec_filt2_ in zip(rec[0], rec_filt[0],
                                                    rec[1], rec_filt[1]):
        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt1_)
        # slope
        _, r, _, _ = epsp_slope(t, rec1_, ipk, yf=rec_filt1_, return_pos=True)
        if abs(r) < r_min:
            i += 1
            logger.warning("discarded new frame ({}), r={:.4f}, ".format(i, r))
        else:
            amp.append(rec1_[ipk])

        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt2_)
        # slope
        _, r, _, _ = epsp_slope(t, rec2_, ipk, yf=rec_filt2_, return_pos=True)
        if abs(r) < r_min:
            i += 1
            logger.warning("discarded new frame ({}), r={:.4f}, ".format(i, r))
        else:
            amp.append(rec2_[ipk])

    return amp
Example #2
0
def ppr(index, r_min=.7):
    t, rec, rec_filt = preprocess(index)

    i = 0
    ratio = []
    for rec1_, rec_filt1_, rec2_, rec_filt2_ in zip(rec[0], rec_filt[0],
                                                    rec[1], rec_filt[1]):
        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt1_)
        # slope
        _, r, _, _ = epsp_slope(t, rec1_, ipk, yf=rec_filt1_, return_pos=True)
        if abs(r) < r_min:
            i += 1
            logger.warning("discarded new frame ({}), r={:.4f}, ".format(i, r))
            continue
        amp1 = rec1_[ipk]

        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt2_)
        # slope
        _, r, _, _ = epsp_slope(t, rec2_, ipk, yf=rec_filt2_, return_pos=True)
        if abs(r) < r_min:
            i += 1
            logger.warning("discarded new frame ({}), r={:.4f}, ".format(i, r))
            continue
        amp2 = rec2_[ipk]

        ratio.append(amp2 / amp1)

    return np.array(ratio)
Example #3
0
def dual_pulse_plot(index, name="untitled"):
    plt.cla()

    ax.axhline(0, color="k", linestyle=":", linewidth=0.5)

    t, rec1, rec2 = preprocess(index)

    for rec, rec_filt, c, lbl in zip(rec1, rec2, ["r", "b"],
                                     ["1st pulse", "2nd pulse"]):
        # visualize data
        ax.plot(t, rec, c, label=lbl, linewidth=1)

        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt)
        ax.scatter(t[ipk],
                   rec[ipk],
                   marker="o",
                   edgecolors="k",
                   facecolor="none")

        # slope
        slope, r, dt, dy = epsp_slope(t,
                                      rec,
                                      ipk,
                                      yf=rec_filt,
                                      return_pos=True)
        ax.plot(dt, dy, "k:", linewidth=1)

    # final adjust
    ax.legend()
    # ax.set_xlim(coarse_crop)

    plt.savefig("{}.png".format(name), dpi=300)
    plt.waitforbuttonpress()
Example #4
0
def extract_amplitude(index, r_min=.7):
    t, rec, rec_filt = preprocess(index)

    data = []
    n_discard = 0
    for i, rec_, rec_filt_ in zip(range(index[0], index[1] + 1), rec,
                                  rec_filt):
        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt_)
        # slope
        try:
            slope, r, _, _ = epsp_slope(t,
                                        rec_,
                                        ipk,
                                        yf=rec_filt_,
                                        return_pos=True)
        except ValueError:
            n_discard += 1
            logger.warning("error ({})".format(n_discard))

        if abs(r) < r_min:
            n_discard += 1
            logger.warning("discarded new frame ({}), r={:.4f}, ".format(
                n_discard, r))

        data.append((i, rec_[ipk]))
    x, y = tuple(zip(*data))
    return np.array(x), np.array(y)
Example #5
0
def extract_peak_info(t, rec, rec_filt, r_min=0.7):
    i = 0
    amp, slope = [], []
    for rec_, rec_filt_ in zip(rec, rec_filt):
        # using filtered signal to extract slope
        ipk, _ = find_epsp_peak(t, rec_filt_)

        # slope
        slope_, r, _, _ = epsp_slope(t,
                                     rec_,
                                     ipk,
                                     yf=rec_filt_,
                                     return_pos=True)
        if abs(r) < r_min:
            i += 1
            logger.warning("discarded new frame ({}), r={:.4f}, ".format(i, r))
            continue

        # save datapoint
        amp.append(rec_[ipk])
        slope.append(slope_)
    amp = np.array(amp)
    slope = np.array(slope)

    return len(amp), amp, slope
Example #6
0
def compare_plot(indice, labels, name="untitled", **kwargs):
    plt.cla()

    coarse_crop = (0.1, 0.15)
    ax.axhline(0, color="k", linestyle=":", linewidth=0.5)

    for index, label, c in zip(indice, labels, ["r", "b", "k"]):
        t, rec, rec_filt = preprocess(index, coarse_crop)

        # visualize data
        ax.plot(t, rec, c, label=label, linewidth=1)

        try:
            # using filtered signal to extract slope
            ipk, _ = find_epsp_peak(t, rec_filt)
            ax.scatter(t[ipk],
                       rec[ipk],
                       marker="o",
                       edgecolors="k",
                       facecolor="none")

            # slope
            slope, r, dt, dy = epsp_slope(t,
                                          rec,
                                          ipk,
                                          yf=rec_filt,
                                          return_pos=True)
            ax.plot(dt, dy, "k:", linewidth=1)
        except ValueError:
            logger.error("unable to determine slope")

    # labels
    plt.xlabel("Time (s)")
    plt.ylabel("Intensity (mV)")
    ax.legend()

    plt.savefig("{}.png".format(name), dpi=300)
    plt.waitforbuttonpress()
Example #7
0
def main(index, name="filter_demo_sink"):
    plt.cla()

    # load data
    t, stim, rec = load_frame_group(path, index=index, stacked=False)
    # apply filter
    rec_filt = []
    for rec_ in rec:
        rec_ = butter_lpf(rec_, lo_cutoff, fs)
        rec_filt.append(rec_)
    # mean
    rec = np.stack(rec, axis=0).mean(axis=0)
    rec = subtract_baseline(t, rec)

    # visualize raw data
    crop = (0.1, 0.15)

    t_, rec = t_crop(t, rec, crop)
    ax.plot(t_, rec, "r", label="raw", linewidth=1)

    ax.axhline(0, color="k", linestyle=":", linewidth=0.5)

    # using filtered signal to extract slope
    rec_filt = np.stack(rec_filt, axis=0).mean(axis=0)
    rec_filt = subtract_baseline(t, rec_filt)

    t_, rec_filt = t_crop(t, rec_filt, crop)

    ipk, _ = find_epsp_peak(t_, rec_filt)

    ax.scatter(
        t_[ipk],
        rec_filt[ipk],
        marker="o",
        edgecolors="b",
        facecolor="none",
        label="EPSP peak",
    )

    # slope
    slope, r, dt, dy = epsp_slope(t_, rec, ipk, yf=rec_filt, return_pos=True)

    ax.plot(dt, dy, "b:", label="EPSP slope", linewidth=1)

    # labels
    ax.legend()
    plt.xlabel("Time (s)")
    plt.ylabel("Intensity (mV)")

    # create inset
    axin = inset_axes(ax, width="30%", height="50%", loc=4, borderpad=3)

    t_in, rec_in = t_crop(t_, rec, (0.1025, 0.1100))
    axin.plot(t_in, rec_in, "r", label="raw", linewidth=1)

    axin.scatter(
        t_[ipk],
        rec_filt[ipk],
        marker="o",
        edgecolors="b",
        facecolor="none",
        label="EPSP peak",
    )

    axin.plot(dt, dy, "b:", linewidth=2)

    axin.set_xlim((0.1025, 0.1100))

    # final adjust
    ax.set_xlim(crop)

    plt.savefig("{}_slope-{:.3f}_r-{:.3f}.png".format(name, slope, r), dpi=300)

    plt.waitforbuttonpress()