Exemple #1
0
def plot_fake_strf(rast, stimparams):
	
	fig = plt.figure(figsize = (15, 10))
	ax1 = fig.add_axes([0.05, 0.2, 0.9, 0.75])
	ax2 = fig.add_axes([0.05, 0.05, 0.9, 0.15])
	
	fake_strf = calc_fake_strf(rast, stimparams)
	RF.plot_rf(fake_strf, ax = ax1, axes_on = False)
	psth = fake_strf.mean(0)
	psth_smoo = Spikes.hamming_smoo(psth, windlen = 5)
	ax2.plot(psth_smoo)
	ax2.set_xlim([0, rast.shape[1]])
	plt.draw(); plt.show();

	return fig
Exemple #2
0
def add_rf_analysis(frf, funit, stimparams):

	
	rast = frf['rast'].value
	# stimparams = frf['stimID'].value
	

	# calculate, smooth, threshold, and cluster RF
	rf = calc_rf(rast, stimparams, normed = True, smooth = False)
	rf[:, :5] = 0
	nan_ix = np.isnan(rf)
	if nan_ix.sum() > 0:
		print 'NaNs found in rf! Converting NaNs to zeros...'
		print nan_ix.sum()
		rf[np.isnan(rf)] = 0
	rf_smoo = gaussian_filter(rf, 0.5)
	rf_thresh = rf_smoo.copy()
	rf_mask = rf_thresh<0.25*rf_thresh.max()
	rf_thresh[rf_mask] = 0
	(rf_clust, max_clust_size) = findmaxcluster(rf_thresh)
	if max_clust_size < 10:
		print 'F*****G SMALL RF dude'
	
	# baseline_mean : mean firing rate 0-50ms for all trials	
	baseline_psth = 1000 * rast[:, :50].mean(0)
	baseline_mean = baseline_psth.mean()
	baseline_std = baseline_psth.std()
	fr_thresh = baseline_mean + 2*baseline_std

	# evoked and spontaneous psths
	ev_psth = calc_evoked_psth(rast, stimparams, rf_clust>0)
	ev_psth_smoo = Spikes.hamming_smoo(ev_psth, windlen = 5)
	spont_psth = calc_evoked_psth(rast, stimparams, rf_clust==0)
	

	# psth properties
	# peak firing rate
	resp_max = ev_psth_smoo.max()
	peak_time_ix = ev_psth_smoo.argmax()
	
	# first millisecond after the final sub-threshold millisecond
	resp_on_ix_ = (ev_psth_smoo[57:peak_time_ix]<fr_thresh).nonzero()[0]
	if not resp_on_ix_.any():
		resp_on_ix = peak_time_ix
	else:
		resp_on_ix = resp_on_ix_.max() + 58
	resp_off_ix = np.empty(3)
	resp_off_ix[0] = (ev_psth_smoo[peak_time_ix:]<resp_max/2).nonzero()[0].min() + peak_time_ix
	resp_off_ix[1] = (ev_psth_smoo[peak_time_ix:]<resp_max/4).nonzero()[0].min() + peak_time_ix
	resp_off_ix[2] = (ev_psth_smoo[peak_time_ix:]<fr_thresh).nonzero()[0].min() + peak_time_ix
	
	peak_time = peak_time_ix / 1000.
	resp_on = resp_on_ix / 1000.
	resp_off = resp_off_ix / 1000.
	
	# calculate a decay constant from the peak to the post-peak sub-threshold
	y = np.log(ev_psth[peak_time_ix:resp_off_ix[2]])
	tmp = linregress(np.arange(y.size), y)
	decay_const = tmp[0]
	
	# firing rate statistics on the rf
	rf_spont_mean = rf[rf_clust==0].mean()
	rf_resp_max = rf[rf_clust>0].max() - rf_spont_mean
	rf_resp_median = np.median(rf[rf_clust>0]) - rf_spont_mean
	rf_resp_mean = rf[rf_clust>0].mean() - rf_spont_mean
	rf_size = (rf_clust>0).sum()

	# automated CF measures (center-of-mass and auto)
	# automated BW measures
	cf_com = calc_rf_com(rf_clust)
	cf_auto = calc_cf(rf_clust)
	(bw, bw_lr, thresh) = calc_bw_thresh(rf_clust)

	# # PSTH for freq/attens in RF
	# fig = plt.figure()
	# ax = fig.add_subplot(111)
	# ax.plot(ev_psth_smoo, 'b.-')
	# ax.axhline(baseline_mean+3*baseline_std, color = 'r', ls = '--')
	# ax.axvline(resp_on_ix, color = 'r', ls = '--')
	# ax.axvline(resp_off_ix[0], color = 'r', ls = '--')
	# ax.axvline(resp_off_ix[1], color = 'r', ls = '--')
	# ax.axvline(resp_off_ix[2], color = 'r', ls = '--')
	
	rf_shape = rf.shape
	d = funit.require_dataset('rf', rf_shape, float)
	d.write_direct(rf)
	d = funit.require_dataset('rf_clust', rf_shape, float)
	d.write_direct(rf_clust)
	d = funit.require_dataset('rf_spont_mean', (), float)
	d.write_direct(np.array([rf_spont_mean]))
	d = funit.require_dataset('rf_resp_median', (), float)
	d.write_direct(np.array([rf_resp_median]))
	d = funit.require_dataset('rf_resp_mean', (), float)
	d.write_direct(np.array([rf_resp_mean]))
	d = funit.require_dataset('rf_resp_max', (), float)
	d.write_direct(np.array([rf_resp_max]))
	d = funit.require_dataset('resp_max', (), float)
	d.write_direct(np.array([resp_max]))
	d = funit.require_dataset('peak_time', (), float)
	d.write_direct(np.array([peak_time]))
	d = funit.require_dataset('resp_on', (), float)
	d.write_direct(np.array([resp_on]))
	d = funit.require_dataset('resp_off', (3,), float)
	d.write_direct(np.array([resp_off]))
	d = funit.require_dataset('decay_const', (), float)
	d.write_direct(np.array([decay_const]))	
	d = funit.require_dataset('rf_size', (), int)
	d.write_direct(np.array([rf_size]))
	d = funit.require_dataset('baseline_mean', (), float)
	d.write_direct(np.array([baseline_mean]))
	d = funit.require_dataset('cf_auto', (), float)
	d.write_direct(np.array([cf_auto]))
	d = funit.require_dataset('cf_com', (), float)
	d.write_direct(np.array([cf_com]))
	d = funit.require_dataset('bw', (8,), float)
	d.write_direct(bw)
	d = funit.require_dataset('bw_lr', (8,2), float)
	d.write_direct(bw_lr)
	d = funit.require_dataset('thresh', (), int)
	d.write_direct(np.array([thresh]))
	d = funit.require_dataset('ev_psth', (333,), float)
	d.write_direct(ev_psth[:333])