def responsive_shuffle_xcorr(cell, centre, whole): thresh = 2 rounds = 50 samples = len(centre) xcorr_c = corr_trial_to_trial(centre.T, 0) xcorr_w = corr_trial_to_trial(whole.T, 0) shuffles = [] for i in xrange(rounds): shift = np.random.randint(-samples, samples, 1) shift_xcorr_c = corr_trial_to_trial(centre.T, shift) shift_xcorr_w = corr_trial_to_trial(whole.T, shift) shuffles.append([shift_xcorr_c, shift_xcorr_w]) shuffles = np.array(shuffles) shift_xcorr_c = average_corrs(shuffles[:, 0]) shift_xcorr_w = average_corrs(shuffles[:, 1]) active = (xcorr_c > (shift_xcorr_c * thresh) or xcorr_w > (shift_xcorr_w * thresh)) vals = [cell, active, xcorr_c, xcorr_w, shift_xcorr_c, shift_xcorr_w] return vals
for cell in cell_idx: if cell in d: print 'active' else: continue print cell cell_res = [] for i, src in enumerate(['dat_raw_c', 'dat_raw_w']): dt = dat[src] if i == 0 and crr_c is None: try: crr_c = np.load('%s%s_%s.npy' % (target, exp, src)) except: crr_c = [] for c in cell_idx: crr_c.append(corr_trial_to_trial(dt[c].T)) crr_c = np.array(crr_c) np.save('%s%s_%s' % (target, exp, src), crr_c) elif i == 1 and crr_w is None: try: crr_w = np.load('%s%s_%s.npy' % (target, exp, src)) except: crr_w = [] for c in cell_idx: crr_w.append(corr_trial_to_trial(dt[c].T)) crr_w = np.array(crr_w) np.save('%s%s_%s' % (target, exp, src), crr_w) src_res = [] trials = np.arange(dt.shape[2]) ys = [] preds = []