def test_hkernel(): """ test the hrf computation """ tr = 2.0 h = _hrf_kernel('spm', tr) assert_almost_equal(h[0], spm_hrf(tr)) assert_equal(len(h), 1) h = _hrf_kernel('spm + derivative', tr) assert_almost_equal(h[1], spm_time_derivative(tr)) assert_equal(len(h), 2) h = _hrf_kernel('spm + derivative + dispersion', tr) assert_almost_equal(h[2], spm_dispersion_derivative(tr)) assert_equal(len(h), 3) h = _hrf_kernel('glover', tr) assert_almost_equal(h[0], glover_hrf(tr)) assert_equal(len(h), 1) h = _hrf_kernel('glover + derivative', tr) assert_almost_equal(h[1], glover_time_derivative(tr)) assert_almost_equal(h[0], glover_hrf(tr)) assert_equal(len(h), 2) h = _hrf_kernel('fir', tr, fir_delays=np.arange(4)) assert_equal(len(h), 4) for dh in h: assert_equal(dh.sum(), 50.) # h = _hrf_kernel(None, tr) assert_equal(len(h), 1) assert_almost_equal(h[0], np.hstack((1, np.zeros(49))))
def test_hkernel(): """ test the hrf computation """ tr = 2.0 h = _hrf_kernel('spm', tr) assert_almost_equal(h[0], spm_hrf(tr)) assert_equal(len(h), 1) h = _hrf_kernel('spm_time', tr) assert_almost_equal(h[1], spm_time_derivative(tr)) assert_equal(len(h), 2) h = _hrf_kernel('spm_time_dispersion', tr) assert_almost_equal(h[2], spm_dispersion_derivative(tr)) assert_equal(len(h), 3) h = _hrf_kernel('canonical', tr) assert_almost_equal(h[0], glover_hrf(tr)) assert_equal(len(h), 1) h = _hrf_kernel('canonical with derivative', tr) assert_almost_equal(h[1], glover_time_derivative(tr)) assert_almost_equal(h[0], glover_hrf(tr)) assert_equal(len(h), 2) h = _hrf_kernel('fir', tr, fir_delays=np.arange(4)) assert_equal(len(h), 4) for dh in h: assert_equal(dh.sum(), 16.)
def test_hkernel(): """ test the hrf computation """ tr = 2.0 h = _hrf_kernel("spm", tr) assert_almost_equal(h[0], spm_hrf(tr)) assert_equal(len(h), 1) h = _hrf_kernel("spm + derivative", tr) assert_almost_equal(h[1], spm_time_derivative(tr)) assert_equal(len(h), 2) h = _hrf_kernel("spm + derivative + dispersion", tr) assert_almost_equal(h[2], spm_dispersion_derivative(tr)) assert_equal(len(h), 3) h = _hrf_kernel("glover", tr) assert_almost_equal(h[0], glover_hrf(tr)) assert_equal(len(h), 1) h = _hrf_kernel("glover + derivative", tr) assert_almost_equal(h[1], glover_time_derivative(tr)) assert_almost_equal(h[0], glover_hrf(tr)) assert_equal(len(h), 2) h = _hrf_kernel("fir", tr, fir_delays=np.arange(4)) assert_equal(len(h), 4) for dh in h: assert_equal(dh.sum(), 16.0)
def model_image_create_convolved_onsets(noise=False): """ """ general_settings() onsets1, onsets2, onsets3 = np.zeros((3, 100)) onsets1[[10, 40]] = 1 onsets2[[30, 60]] = 1 onsets3[[50, 80]] = 1 width = 10 fsize = 60 # Convolve the onsets hkernel = _hrf_kernel('spm', 1, oversampling=1) conv_onsets1 = np.array( [np.convolve(onsets1, h)[:onsets1.size] for h in hkernel])[0] conv_onsets2 = np.array( [np.convolve(onsets2, h)[:onsets2.size] for h in hkernel])[0] conv_onsets3 = np.array( [np.convolve(onsets3, h)[:onsets3.size] for h in hkernel])[0] # Normalize to same peak as onsets norm = np.max(conv_onsets1) conv_onsets1 /= (norm * 2) conv_onsets2 /= (norm * 2) conv_onsets3 /= (norm * 2) # Noise to simulate estimation if noise: conv_onsets1 += np.random.normal(0, .1, 100) conv_onsets2 += np.random.normal(0, .1, 100) conv_onsets3 += np.random.normal(0, .1, 100) # Offset for text h, v = -0.1 * 65, 0.1 # Colors cmap = sns.color_palette("colorblind", n_colors=3) tw_color = sns.color_palette("muted", 4)[3] # Plot f, ax = plt.subplots(1) ax.plot(conv_onsets1, color=cmap[0], linewidth=width) ax.text(10 + h, 0.5 + v, '1', rotation=90, fontsize=fsize) ax.text(40 + h, 0.5 + v, '4', rotation=90, fontsize=fsize) ax.plot(2 + conv_onsets2, color=cmap[1], linewidth=width) ax.text(30 + h, 2.5 + v, '2', rotation=90, fontsize=fsize) ax.text(60 + h, 2.5 + v, '5', rotation=90, fontsize=fsize) ax.plot(4 + conv_onsets3, color=cmap[2], linewidth=width) ax.text(50 + h, 4.5 + v, '3', rotation=90, fontsize=fsize) ax.text(80 + h, 4.5 + v, '6', rotation=90, fontsize=fsize) ax.set_ylim(-1.5, 5.5) ax.axis('off') # Add time windows visualization on the estimation mult = 1 if noise: ax.add_patch(patches.Rectangle((10, -1), 5, 6, fill=False, edgecolor=tw_color, linewidth=width*mult, linestyle='dashed')) ax.add_patch(patches.Rectangle((30, -1), 5, 6, fill=False, edgecolor=tw_color, linewidth=width*mult, linestyle='dashed')) ax.add_patch(patches.Rectangle((40, -1), 5, 6, fill=False, edgecolor=tw_color, linewidth=width*mult, linestyle='dashed')) ax.add_patch(patches.Rectangle((50, -1), 5, 6, fill=False, edgecolor=tw_color, linewidth=width*mult, linestyle='dashed')) ax.add_patch(patches.Rectangle((60, -1), 5, 6, fill=False, edgecolor=tw_color, linewidth=width*mult, linestyle='dashed')) ax.add_patch(patches.Rectangle((80, -1), 5, 6, fill=False, edgecolor=tw_color, linewidth=width*mult, linestyle='dashed')) print(ax.patches) plt.show()