Exemple #1
0
def getdata(fname, maxv):

    print "Processing ", fname
    dat, attribs, cf = bu.getdata(os.path.join(path, fname))

    if (len(attribs) > 0):
        fsamp = attribs["Fsamp"]

    xdat = dat[:, data_columns[1]]

    lentrace = len(xdat)
    ## zero pad one cycle
    corr_full = bu.corr_func(dat[:, drive_column], xdat, fsamp, fdrive)

    return corr_full[0], np.max(corr_full)
def getdata(fname, maxv):

	print "Processing ", fname
        dat, attribs, cf = bu.getdata(os.path.join(path, fname))

        if( len(attribs) > 0 ):
            fsamp = attribs["Fsamp"]

        xdat = dat[:,data_columns[1]]

        lentrace = len(xdat)
        ## zero pad one cycle
        corr_full = bu.corr_func( dat[:,drive_column], xdat, fsamp, fdrive)
        

        return corr_full[0], np.max(corr_full) 
Exemple #3
0
def getdata(fname, maxv):

    print "Processing ", fname
    dat, attribs, cf = bu.getdata(os.path.join(path, fname))

    if (len(attribs) > 0):
        fsamp = attribs["Fsamp"]

    xdat = dat[:, data_columns[1]]

    lentrace = len(xdat)
    ## zero pad one cycle
    MinusDC = dat[:, drive_column]
    corr_full = bu.corr_func(MinusDC - np.median(MinusDC), xdat, fsamp, fdrive)

    #plt.figure()
    #plt.plot( xdat)
    #plt.plot(dat[:,drive_column])
    #plt.show()

    return corr_full[0], np.max(corr_full)
path = "/data/20140620/xtalk"

channels = np.array([1, 2, 3, 4, 5, 6])
drive_column = -1
dat, attribs, f = bu.getdata(os.path.join(path, fname))

corrs = []
corrmaxs = []

for i in range(7):
    if i != drive_column:

        corrmax = np.max(
            bu.corr_func(dat[:, drive_column],
                         dat[:, i],
                         attribs['Fsamp'],
                         attribs['drive_freq'],
                         filt=True))

        sub_corrs = bu.corr_blocks(dat[:, drive_column],
                                   dat[:, i],
                                   attribs['Fsamp'],
                                   attribs['drive_freq'],
                                   filt=True,
                                   N_blocks=3)

        corrs.append(sub_corrs)
        corrmaxs.append(corrmax)

plt.figure()
corrs = np.array(corrs)
        drive -= np.mean(drive)
        drive2 = drive**2
        drive2 -= np.mean(drive2)

        if (False):
            plt.figure()
            plt.plot(drive)
            #plt.plot(response)
            b, a = sig.butter(3, (2.0 * drive_freq + 5) / (Fs / 2.0))
            filt_resp = sig.filtfilt(b, a, response)
            plt.plot(filt_resp, 'c')
            plt.plot(drive2)
            plt.show()

        dummy_freq = 41  ## freq doesn't matter since we do 0 offset only
        corr_dr = bu.corr_func(drive, response, Fs, dummy_freq)[0]
        corr_dr2 = bu.corr_func(drive2, response, Fs, dummy_freq)[0]

        tot_corr_dr.append(corr_dr)
        tot_corr_dr2.append(corr_dr2)

    tot_dat[fidx, 0] = cpos
    tot_dat[fidx, 1] = np.mean(tot_corr_dr)
    tot_dat[fidx, 2] = np.mean(tot_corr_dr2)
    tot_dat[fidx, 3] = np.std(tot_corr_dr) / np.sqrt(len(tot_corr_dr))
    tot_dat[fidx, 4] = np.std(tot_corr_dr2) / np.sqrt(len(tot_corr_dr2))
    tot_dat_pts.append([cpos, tot_corr_dr, tot_corr_dr2])

    if (False and elec == 0):
        plt.figure()
        plt.plot(drive)

fname = r"allon_drive_pxi6259_chan0_10000mV_41Hz.h5"
path = "/data/20140620/xtalk"

channels = np.array([1, 2, 3, 4, 5, 6])
drive_column = -1
dat, attribs, f = bu.getdata(os.path.join(path, fname))

corrs = []
corrmaxs = []

for i in range(7):
    if i != drive_column:
        
        corrmax = np.max(bu.corr_func(dat[:, drive_column], dat[:, i], attribs['Fsamp'], attribs['drive_freq'], filt = True))
 
        sub_corrs = bu.corr_blocks(dat[:, drive_column], dat[:, i], attribs['Fsamp'], attribs['drive_freq'], filt = True, N_blocks = 3)

        corrs.append(sub_corrs)
        corrmaxs.append(corrmax)

        


plt.figure()
corrs = np.array(corrs)
plt.errorbar(range(len(corrs[:, 0])), corrs[:, 0], yerr = corrs[:, 1], fmt = 'o')
plt.errorbar(range(len(corrs[:, 0])), np.array(corrmaxs), yerr = corrs[:, 1], fmt = 'o' )

plt.show()
        ## take correlation with drive and drive^2

        response = cdat[skip_dat:-skip_dat, dcol]
        response -= np.mean(response)
        if (elec < 3):
            drive = cdat[skip_dat:-skip_dat, elec + 8]
        else:
            drive = cdat[skip_dat:-skip_dat, elec + 9]
        if (cpos < 0 and gain == 0.2): drive *= -1
        drive -= np.mean(drive)
        drive2 = drive**2
        drive2 -= np.mean(drive2)

        dummy_freq = 38  ## freq doesn't matter since we do 0 offset only
        corr_dr = bu.corr_func(drive, response, Fs, dummy_freq)[0]
        corr_dr2 = bu.corr_func(drive2, response, Fs, dummy_freq)[0]

        ## find the error on the correlation from a few dummy frequencies
        tvec = np.linspace(0, (len(response) - 1.0) / Fs, len(response))
        rand_phase = np.random.rand() * 2. * np.pi
        s_m5 = np.sin(2 * np.pi * tvec * (drive_freq - 5.0) + rand_phase)
        s_p5 = np.sin(2 * np.pi * tvec * (drive_freq + 5.0) + rand_phase)
        corr_dr_m5 = bu.corr_func(s_m5, response, Fs, dummy_freq)[0]
        corr_dr_p5 = bu.corr_func(s_p5, response, Fs, dummy_freq)[0]
        ## upper bound on the error

        if (False and elec == 3):
            plt.figure()
            plt.plot(drive)
            #plt.plot(response)
def getdata(fname, maxv, ang, gain):

	print "Processing ", fname
        dat, attribs, cf = bu.getdata(os.path.join(path, fname))

        ## make sure file opened correctly
        if( len(dat) == 0 ):
            return {}

        dat[:, drive_column] *= gain
        if( len(attribs) > 0 ):
            fsamp = attribs["Fsamp"]
            drive_amplitude = attribs["drive_amplitude"]

            
        xdat, ydat = rotate_data(dat[:,data_columns[0]], dat[:,data_columns[1]], ang)

        drive_amp = np.sqrt(2)*np.std(dat[:,drive_column])

        if( remove_laser_noise ):
            laser_good = bu.laser_reject(dat[:, laser_column], 60., 90., 4e-6, 100, fsamp, False)
        else:
            laser_good = np.ones_like(dat[:, laser_column]) > 0

        corr_full = bu.corr_func(dat[:,drive_column], xdat, fsamp, fdrive, good_pts=laser_good)

        corr = corr_full[ maxv ]
        corr_max = np.max(corr_full)
        corr_max_pos = np.argmax(corr_full)
        xpsd, freqs = matplotlib.mlab.psd(xdat, Fs = fsamp, NFFT = NFFT) 
        #ypsd, freqs = matplotlib.mlab.psd(ydat, Fs = fsamp, NFFT = NFFT) 
        max_bin = np.argmin( np.abs( freqs - fdrive ) )
        ref_bin = np.argmin( np.abs( freqs - fref ) )

        ## also correlate signal with drive squared
        dsq = dat[:,drive_column]**2
        dsq -= np.mean(dsq)
        sq_amp = np.sqrt(2)*np.std( dsq )
        ## only normalize by one factor of the squared amplitude
        corr_sq_full = bu.corr_func(dsq*sq_amp, xdat, fsamp, fdrive)
        corr_sq_max = np.max(corr_sq_full)
        corr_sq_max_pos = np.argmax(corr_sq_full)

        xoff = sp.filtfilt(boff, aoff, xdat)

        if(False):
            plt.figure()
            plt.plot( xdat )
            plt.plot( dat[:, drive_column] )

            plt.figure()
            plt.plot( corr_full )
            plt.show()

        ctime = attribs["time"]

        ## is this a calibration file?
        cdir,_ = os.path.split(fname)
        is_cal = cdir == cal_path

        curr_scale = 1.0
        ## make a dictionary containing the various calculations
        out_dict = {"corr_t0": corr,
                    "max_corr": [corr_max, corr_max_pos],
                    "max_corr_sq": [corr_sq_max, corr_sq_max_pos],
                    "psd": np.sqrt(xpsd[max_bin]),
                    "ref_psd": np.sqrt(xpsd[ref_bin]),
                    "temps": attribs["temps"],
                    "time": bu.labview_time_to_datetime(ctime),
                    "num_flashes": attribs["num_flashes"],
                    "is_cal": is_cal,
                    "drive_amp": drive_amp}

        cf.close()
        return out_dict
Exemple #9
0
def getdata(fname, maxv, ang, gain):

    print "Processing ", fname
    dat, attribs, cf = bu.getdata(os.path.join(path, fname))

    ## make sure file opened correctly
    if (len(dat) == 0):
        return {}

    dat[:, drive_column] *= gain
    if (len(attribs) > 0):
        fsamp = attribs["Fsamp"]
        drive_amplitude = attribs["drive_amplitude"]

    xdat, ydat = rotate_data(dat[:, data_columns[0]], dat[:, data_columns[1]],
                             ang)

    drive_amp = np.sqrt(2) * np.std(dat[:, drive_column])

    if (remove_laser_noise):
        laser_good = bu.laser_reject(dat[:, laser_column], 60., 90., 4e-6, 100,
                                     fsamp, False)
    else:
        laser_good = np.ones_like(dat[:, laser_column]) > 0

    corr_full = bu.corr_func(dat[:, drive_column],
                             xdat,
                             fsamp,
                             fdrive,
                             good_pts=laser_good)

    corr = corr_full[maxv]
    corr_max = np.max(corr_full)
    corr_max_pos = np.argmax(corr_full)
    xpsd, freqs = matplotlib.mlab.psd(xdat, Fs=fsamp, NFFT=NFFT)
    #ypsd, freqs = matplotlib.mlab.psd(ydat, Fs = fsamp, NFFT = NFFT)
    max_bin = np.argmin(np.abs(freqs - fdrive))
    ref_bin = np.argmin(np.abs(freqs - fref))

    ## also correlate signal with drive squared
    dsq = dat[:, drive_column]**2
    dsq -= np.mean(dsq)
    sq_amp = np.sqrt(2) * np.std(dsq)
    ## only normalize by one factor of the squared amplitude
    corr_sq_full = bu.corr_func(dsq * sq_amp, xdat, fsamp, fdrive)
    corr_sq_max = np.max(corr_sq_full)
    corr_sq_max_pos = np.argmax(corr_sq_full)

    xoff = sp.filtfilt(boff, aoff, xdat)

    if (False):
        plt.figure()
        plt.plot(xdat)
        plt.plot(dat[:, drive_column])

        plt.figure()
        plt.plot(corr_full)
        plt.show()

    ctime = attribs["time"]

    ## is this a calibration file?
    cdir, _ = os.path.split(fname)
    is_cal = cdir == cal_path

    curr_scale = 1.0
    ## make a dictionary containing the various calculations
    out_dict = {
        "corr_t0": corr,
        "max_corr": [corr_max, corr_max_pos],
        "max_corr_sq": [corr_sq_max, corr_sq_max_pos],
        "psd": np.sqrt(xpsd[max_bin]),
        "ref_psd": np.sqrt(xpsd[ref_bin]),
        "temps": attribs["temps"],
        "time": bu.labview_time_to_datetime(ctime),
        "num_flashes": attribs["num_flashes"],
        "is_cal": is_cal,
        "drive_amp": drive_amp
    }

    cf.close()
    return out_dict
                plt.loglog(cfreqs, cpsd, color=col_list[j])
                plt.plot(cfreqs[cidx],
                         cpsd[cidx],
                         'o',
                         color=col_list[j],
                         linewidth=1.5)

        if (plot_freqs): plt.show()
        drive_freq_list = np.array(drive_freq_list)

        print "Drive freqs are:  ", drive_freq_list[:, 0]

    for didx, dcol in enumerate(data_cols):
        for eidx, ecol in enumerate(electrode_cols):

            corr_full = bu.corr_func(dat[:, ecol], dat[:, dcol], fsamp,
                                     drive_freq_list[eidx][0])
            dc_val = np.mean(dat[:, ecol])

            corr_mat[fidx, didx, eidx, :] = [dc_val, corr_full[0]]

## now plot total correlation
for eidx, ecol in enumerate(electrode_cols):

    plt.figure()
    plt.subplot(3, 1, 1)
    plt.plot(corr_mat[:, 0, eidx, 0],
             corr_mat[:, 0, eidx, 1],
             color=col_list[eidx])
    plt.title("Electrode %d, X" % eidx)

    plt.subplot(3, 1, 2)