def compute_mat_X(nbscans, lhrf, tr, tmax, onsets, durations=None): x = numpy.zeros((nbscans,lhrf),dtype=float) x_tmp = numpy.zeros(nbscans,dtype=float) x_tmp[xrange(0,tmax)] = restarize_events(onsets,numpy.zeros_like(onsets),tr,tmax) for i in xrange(0,lhrf): for j in xrange(0,len(x)): x[j,i] = x_tmp[j-i] return x
def compute_mat_X_2(nbscans, tr, lhrf, dt, onsets, durations=None): if durations is None: #assume spiked stimuli durations = numpy.zeros_like(onsets) osf = tr/dt # over-sampling factor assert( int(osf) == osf) #construction will only work if dt is a multiple of tr x = numpy.zeros((nbscans,lhrf),dtype=float) tmax = nbscans * tr #total session duration lgt = (nbscans + 2) * osf # nb of scans if tr=dt paradigm_bins = restarize_events(onsets, numpy.zeros_like(onsets), dt, tmax) firstcol = numpy.concatenate( (paradigm_bins, numpy.zeros(lgt-len(paradigm_bins))) ) firstrow = numpy.concatenate( ([paradigm_bins[0]], numpy.zeros(lhrf-1, dtype=int)) ) x_tmp = numpy.array(toeplitz( firstcol, firstrow), dtype=int) os_indexes = [(numpy.arange(nbscans)*osf).astype(int)] x = x_tmp[os_indexes] return x