def CompareRT_RegularVStress(stress_hdf_files, hdf_prefix): 

	all_reg_rt = []
	all_stress_rt = []

	avg_reg_rt = np.zeros(len(stress_hdf_files))
	avg_stress_rt = np.zeros(len(stress_hdf_files))

	for i, name in enumerate(stress_hdf_files):
		print 'File %i of %i' % (i+1, len(stress_hdf_files))
		# load stress data into class object StressBehavior
		hdf_location = hdf_prefix +name
		stress_data = StressBehavior(hdf_location)

		trial_times_percentage_session, num_times_per_session = stress_data.PlotTrialsCompleted(20)

		# find which trials are stress trials
		trial_type = np.ravel(stress_data.stress_type[stress_data.state_time[stress_data.ind_check_reward_states]])
		reg_trial_inds = np.array([ind for ind in range(len(trial_type)) if trial_type[ind] == 0])
		stress_trial_inds = np.array([ind for ind in range(len(trial_type)) if trial_type[ind] == 1])

		rt_reg, total_vel = stress_data.compute_rt_per_trial_FreeChoiceTask(reg_trial_inds)
		rt_stress, total_vel = stress_data.compute_rt_per_trial_FreeChoiceTask(stress_trial_inds)

		all_reg_rt.append(rt_reg.tolist())
		all_stress_rt.append(rt_stress.tolist())

		avg_reg_rt[i] = np.nanmean(rt_reg)
		avg_stress_rt[i] = np.nanmean(rt_stress)

		regular_times = trial_times_percentage_session[:num_times_per_session[0]]
		stress_times = trial_times_percentage_session[num_times_per_session[0]:num_times_per_session[0] + num_times_per_session[1]]
		
		# normalize to pecentage of session
		regular_times = regular_times/float(stress_times[-1])
		stress_times = stress_times/float(stress_times[-1])
		plt.figure(1)
		ax1 = plt.subplot(111)
		plt.plot(stress_times,np.ones(len(stress_times)) + i,'|', color='r')
		plt.plot(regular_times,np.ones(len(regular_times)) + i,'|', color = 'b')

	plt.xlim((0,1))
	plt.xlabel('Session (%)')
	ax1.get_yaxis().set_tick_params(direction='out')
	ax1.get_xaxis().set_tick_params(direction='out')
	ax1.get_xaxis().tick_bottom()
	ax1.get_yaxis().tick_left()
	plt.show()
	t, p = stats.ttest_ind(avg_reg_rt, avg_stress_rt)
	u_value, p_value = stats.mannwhitneyu(avg_reg_rt, avg_stress_rt)

	width = 0.5
	fig = plt.figure(2)
	ax = plt.subplot(111)
	plt.bar(0, [np.nanmean(avg_reg_rt)], width, color = 'b', ecolor = 'k', yerr = [np.nanstd(avg_reg_rt)/np.sqrt(len(avg_reg_rt) - 1.)])
	plt.bar(1, [np.nanmean(avg_stress_rt)], width, color = 'r', ecolor = 'k', yerr = [ np.nanstd(avg_stress_rt)/np.sqrt(len(avg_stress_rt) - 1.)])
	plt.ylabel('Reaction Time (s)')
	plt.xticks(np.arange(2)+width/2., ('Regular', 'Stress'))
	plt.title('Avg. RTs over %i Sessions: (t,p) = (%f,%f)' % (len(stress_hdf_files), t, p))
	plt.xlim((-0.1, 1 + width + 0.1))
	ax.text(0.6, 0.13, 'Regular: m = %f, Stress: m = %f' % (np.nanmean(avg_reg_rt), np.nanmean(avg_stress_rt)))
	plt.show()

	fig = plt.figure(3)
	ax = plt.subplot(111)
	plt.boxplot([avg_reg_rt, avg_stress_rt],0,'')
	plt.ylabel('Reaction Time (s)')
	plt.xticks(np.arange(2)+1., ('Regular', 'Stress'))
	plt.title('Avg. RTs over %i Sessions: (u,p) = (%f,%f)' % (len(stress_hdf_files), u_value, p_value))
	ax.text(0.6, 0.28, 'Regular: med = %f, Stress: med = %f' % (np.median(avg_reg_rt), np.median(avg_stress_rt)))
	
	plt.show()
	return avg_reg_rt, avg_stress_rt
phys_filename = pf_location + filename+'_b'+str(block_num)+'_PhysFeatures.mat'
phys_filename_stim = pf_location + filename+'_b'+str(block_num_stim)+'_PhysFeatures.mat'

lfp_channels = np.arange(1,161,dtype = int)					# channels 1 - 160
lfp_channels = np.delete(lfp_channels, [129, 131, 145])		# channels 129, 131, and 145 are open

bands = [[8,13],[13,30],[40,70],[70,200]]
# bands = [[8,18], [14-21],[101,298]]
'''
Load behavior data:
Note that FreeChoiceBehavior_withStressTrials has been updated so that the array ind_center_states contains the indices corresponding to when the center hold state begins.

state_time, ind_center_states, ind_check_reward_states, all_instructed_or_freechoice, all_stress_or_not, successful_stress_or_not,trial_success, target, reward = FreeChoiceBehavior_withStressTrials(hdf_location)
state_time_stim, ind_center_states_stim, ind_check_reward_states_stim, all_instructed_or_freechoice_stim, all_stress_or_not_stim, successful_stress_or_not_stim,trial_success_stim, target_stim, reward_stim = FreeChoiceBehavior_withStressTrials(hdf_location_stim)
'''
BlockAB_behavior = StressBehavior(hdf_location)
if hdf_filename_stim != '':
	BlockCB_behavior = StressBehavior(hdf_location_stim)

print "Behavior data loaded."

if os.path.exists(pf_filename)&os.path.exists(pf_filename_stim)&os.path.exists(phys_filename)&os.path.exists(phys_filename_stim):
	print "Power features previously computed. Loading now."
	lfp_features = dict()
	sp.io.loadmat(pf_filename,lfp_features)
	lfp_features_stim = dict()
	sp.io.loadmat(pf_filename_stim,lfp_features_stim)

	phys_features = dict()
	sp.io.loadmat(phys_filename,phys_features)
	ibi_reg_mean = np.ravel(phys_features['ibi_reg_mean'] )