lfp_stim[channel_name] = np.ravel(sig)


	print "Finished loading TDT data."

	'''
	Process pupil and pulse data
	'''
	
	# Find IBIs and pupil data for all successful stress trials. 
	samples_pulse_successful_stress = ((BlockAB_behavior.state_time[BlockAB_behavior.ind_check_reward_states[BlockAB_stress_trial_inds]] - BlockAB_behavior.state_time[BlockAB_behavior.ind_check_reward_states[BlockAB_stress_trial_inds]-4])/60.)*pulse_samprate 	#number of samples in trial interval for pulse signal
	samples_pulse_successful_stress = np.array([int(val) for val in samples_pulse_successful_stress])
	samples_pupil_successful_stress = 0.1*pupil_samprate*np.ones(len(BlockAB_stress_trial_inds))  # look at first 100 ms
	samples_pupil_successful_stress = np.array([int(val) for val in samples_pulse_successful_stress])

	ibi_stress_mean, ibi_stress_std, pupil_stress_mean, pupil_stress_std, nbins_ibi_stress, ibi_stress_hist, nbins_pupil_stress, pupil_stress_hist = getIBIandPuilDilation(pulse_data, lfp_ind_hold_center_states_stress_trials,samples_pulse_successful_stress, pulse_samprate,pupil_data, lfp_ind_hold_center_states_stress_trials,samples_pupil_successful_stress,pupil_samprate)

	# Find IBIs and pupil data for all successful regular trials.
	samples_pulse_successful_reg = ((BlockAB_behavior.state_time[BlockAB_behavior.ind_check_reward_states[BlockAB_reg_trial_inds]] - BlockAB_behavior.state_time[BlockAB_behavior.ind_check_reward_states[BlockAB_reg_trial_inds]-4])/60.)*pulse_samprate 	#number of samples in trial interval for pulse signal
	samples_pulse_successful_reg = np.array([int(val) for val in samples_pulse_successful_reg])
	samples_pupil_successful_reg = 0.1*pupil_samprate*np.ones(len(BlockAB_reg_trial_inds))  # look at first 100 ms
	samples_pupil_successful_reg = np.array([int(val) for val in samples_pupil_successful_reg])


	ibi_reg_mean, ibi_reg_std, pupil_reg_mean, pupil_reg_std, nbins_ibi_reg, ibi_reg_hist, nbins_pupil_reg, pupil_reg_hist = getIBIandPuilDilation(pulse_data, lfp_ind_hold_center_states_reg_trials,samples_pulse_successful_reg, pulse_samprate,pupil_data, lfp_ind_hold_center_states_reg_trials,samples_pupil_successful_reg,pupil_samprate)


	# Find IBIs and pupil data for all successful stress trials with stimulation. 
	if hdf_filename_stim != '':
		samples_pulse_successful_stress_stim = ((BlockCB_behavior.state_time[BlockCB_behavior.ind_check_reward_states[BlockCB_stress_trial_inds]] - BlockCB_behavior.state_time[BlockCB_behavior.ind_check_reward_states[BlockCB_stress_trial_inds]-4])/60.)*pulse_samprate 	#number of samples in trial interval for pulse signal
		samples_pulse_successful_stress_stim = np.array([int(val) for val in samples_pulse_successful_stress_stim])
for i in range(0,len(row_ind_stress_stim)):
	hdf_index = np.argmin(np.abs(hdf_rows_stim - state_row_ind_stress_stim[i]))
	pulse_ind_stress_stim[i] = pulse_dio_sample_num_stim[hdf_index]
	pupil_ind_stress_stim[i] = pupil_dio_sample_num_stim[hdf_index]
	lfp_ind_stress_stim[i] = lfp_dio_sample_num_stim[hdf_index]

'''
Process pupil and pulse data
'''

# Find IBIs and pupil data for all successful stress trials. 
samples_pulse_successful_stress = np.floor(response_time_successful_stress*pulse_samprate) 	#number of samples in trial interval for pulse signal
samples_pupil_successful_stress = np.floor(response_time_successful_stress*pupil_samprate)
samples_lfp_successful_stress = np.floor(response_time_successful_stress*lfp_samprate)

ibi_stress_mean, ibi_stress_std, pupil_stress_mean, pupil_stress_std, nbins_ibi_stress, ibi_stress_hist, nbins_pupil_stress, pupil_stress_hist = getIBIandPuilDilation(pulse_data, pulse_ind_successful_stress,samples_pulse_successful_stress, pulse_samprate,pupil_data, pupil_ind_successful_stress,samples_pupil_successful_stress,pupil_samprate)


# Find IBIs and pupil data for all stress trials
samples_pulse_stress = np.floor(response_time_stress*pulse_samprate) 	#number of samples in trial interval for pulse signal
samples_pupil_stress = np.floor(response_time_stress*pupil_samprate)
samples_lfp_stress = np.floor(response_time_stress*lfp_samprate)

ibi_all_stress_mean, ibi_all_stress_std, pupil_all_stress_mean, pupil_all_stress_std, nbins_ibi_all_stress, ibi_all_stress_hist, nbins_pupil_all_stress, pupil_all_stress_hist = getIBIandPuilDilation(pulse_data, pulse_ind_stress,samples_pulse_stress, pulse_samprate,pupil_data, pupil_ind_stress,samples_pupil_stress,pupil_samprate)

# Find IBIs and pupil data for successful and all regular trials. 
samples_pulse_successful_reg = np.floor(response_time_successful_reg*pulse_samprate)
samples_pupil_successful_reg = np.floor(response_time_successful_reg*pupil_samprate)
samples_lfp_successful_reg = np.floor(response_time_successful_reg*lfp_samprate)

ibi_reg_mean, ibi_reg_std, pupil_reg_mean, pupil_reg_std, nbins_ibi_reg, ibi_reg_hist, nbins_pupil_reg, pupil_reg_hist = getIBIandPuilDilation(pulse_data, pulse_ind_successful_reg,samples_pulse_successful_reg, pulse_samprate,pupil_data, pupil_ind_successful_reg,samples_pupil_successful_reg,pupil_samprate)
		hdf_index = np.argmin(np.abs(hdf_rows - state_row_ind_reg[i]))
		pulse_ind_reg_after.append(pulse_dio_sample_num[hdf_index])
		pupil_ind_reg_after.append(pupil_dio_sample_num[hdf_index])
		hdeeg_ind_reg_after.append(hdeeg_dio_sample_num[hdf_index])

'''
Process pupil and pulse data
'''

# Find IBIs and pupil data for all successful stress trials. 
samples_pulse_successful_stress = np.floor(response_time_successful_stress*pulse_samprate) 	#number of samples in trial interval for pulse signal
samples_pupil_successful_stress = np.floor(response_time_successful_stress*pupil_samprate)
samples_hdeeg_successful_stress = np.floor(response_time_successful_stress*hdeeg_samprate)
samples_hdeeg_successful_reg = np.floor(response_time_successful_reg*hdeeg_samprate)

ibi_stress_mean, ibi_stress_std, pupil_stress_mean, pupil_stress_std, nbins_ibi_stress, ibi_stress_hist, nbins_pupil_stress, pupil_stress_hist = getIBIandPuilDilation(pulse_data, pulse_ind_successful_stress,samples_pulse_successful_stress, pulse_samprate,pupil_data, pupil_ind_successful_stress,samples_pupil_successful_stress,pupil_samprate)


# Find IBIs and pupil data for all stress trials
samples_pulse_stress = np.floor(response_time_stress*pulse_samprate) 	#number of samples in trial interval for pulse signal
samples_pupil_stress = np.floor(response_time_stress*pupil_samprate)
samples_hdeeg_stress = np.floor(response_time_stress*hdeeg_samprate)

ibi_all_stress_mean, ibi_all_stress_std, pupil_all_stress_mean, pupil_all_stress_std, nbins_ibi_all_stress, ibi_all_stress_hist, nbins_pupil_all_stress, pupil_all_stress_hist = getIBIandPuilDilation(pulse_data, pulse_ind_stress,samples_pulse_stress, pulse_samprate,pupil_data, pupil_ind_stress,samples_pupil_stress,pupil_samprate)

# Find IBIs and pupil data for successful and all regular trials. 
samples_pulse_successful_reg = np.floor(response_time_successful_reg*pulse_samprate)
samples_pupil_successful_reg = np.floor(response_time_successful_reg*pupil_samprate)
samples_pulse_reg = np.floor(response_time_reg*pulse_samprate)
samples_pupil_reg = np.floor(response_time_reg*pupil_samprate)