import numpy as np
import matplotlib.pyplot as plt
import scipy.stats
from scipy.stats import gamma
from stimuli import events2neural

def hrf(times):
    """ Return values for HRF at given times """
    # Gamma pdf for the peak
    peak_values = gamma.pdf(times, 6)
    # Gamma pdf for the undershoot
    undershoot_values = gamma.pdf(times, 12)
    # Combine them
    values = peak_values - 0.35 * undershoot_values
    # Scale max to 0.6
    return values / np.max(values) * 0.6

def constructing_convo(fname, n_volx):
	tr_times = np.arange(0, 30, 2.5)
	hrf_at_trs = hrf(tr_times)
	neural_prediction = events2neural(fname + '_cond.txt', 2.5, n_volx)
	all_tr_times = np.arange(n_volx) * 2.5
	convolved = np.convolve(neural_prediction, hrf_at_trs)
	convolved = convolved[:(len(convolved) - len(hrf_at_trs) + 1)]
	convolved = np.append(convolved, np.zeros(len(all_tr_times)-len(convolved)))

	plt.plot(all_tr_times, neural_prediction)
	plt.plot(all_tr_times, convolved)
	plt.show()

	np.savetxt(fname + '_conv.txt', convolved)

if __name__ == '__main__':
	from sys import argv

	filename = argv[1]
	if not filename:
		filename = 'ds114_sub009_t2r1'
	constructing_convo(filename, 173)
@@ -515,16 +515,71 @@
 _volx):%0A
+%09get_name = fname.replace('/', '_').replace('d', 'v')%0A%0A
 %09tr_time
@@ -667,16 +667,56 @@
 2neural(
+'.data/sub001/model/model001/onsets/' + 
 fname + 
@@ -720,13 +720,8 @@
  + '
-_cond
 .txt
@@ -1065,16 +1065,47 @@
 .show()%0A
+%09plt.savefig(get_name + '.png')
 %0A%09np.sav
@@ -1109,25 +1109,28 @@
 savetxt(
-f
+get_
 name + '
 _conv.tx
@@ -1121,21 +1121,16 @@
 name + '
-_conv
 .txt', c
@@ -1214,59 +1214,8 @@
 %5B1%5D%0A
-%09if not filename:%0A%09%09filename = 'ds114_sub009_t2r1'%0A
 %09con

update path, cond filename, saveimg