我有一个参数列表:
i = 120
a = 122
n_epochs = 120
sfreq, duration = 1000., 1000
times = np.arange(0, duration, 1 / sfreq)
amp , amp2 , nse_amp = 1., 1., 0.5
nfft = 512
nse1 = np.random.rand(times.size) * nse_amp
nse2 = np.random.rand(times.size) * nse_amp
x = amp * np.sin(2 * np.pi * 200 * times) + nse1
y = amp * np.sin(2 * np.pi * 200 * times + np.pi/5) + nse2
n_freqs = nfft/2 + 1
还有一堆函数(工作正常),它们是计算上一个函数所需要的。你知道吗
此函数取决于多个参数。只要i
达到a
,我就想在循环中运行我的函数,并绘制所有结果。你知道吗
我的职能:
def my_con(x, y, n_epochs, nfft, sfreq, con_name='coh'):
'''Computes connectivity measure mentioned on provided signal pair and its surrogates.'''
freqs, Rxy, Rxy_mean, Rxx_mean, Ryy_mean = compute_mean_psd_csd(x, y, n_epochs, nfft, sfreq)
# compute surrogates
x_surr = x.copy()
y_surr = y.copy()
np.random.shuffle(x_surr)
np.random.shuffle(y_surr)
freqs_surro, Rxy_s, Rxy_s_mean, Rxx_s_mean, Ryy_s_mean = compute_mean_psd_csd(x_surr, y_surr, n_epochs, nfft, sfreq)
if con_name == 'coh':
coh = my_coherence(n_freqs, Rxy_mean, Rxx_mean, Ryy_mean)
coh_surro = my_coherence(n_freqs, Rxy_s_mean, Rxx_s_mean, Ryy_s_mean)
return coh, coh_surro, freqs, freqs_surro
现在要做的任务是: 我希望这个函数在一个循环中工作。我在这两方面都做过,但都没有成功。你知道吗
con, con_surro, freqs, freqs_surro = my_con(x, y, n_epochs, nfft, sfreq, con_name) # for doing every con_surro calc. too add [i]
同时我的绘图设置:
pl.figure('Connectivity')
pl.plot(freqs, con)
pl.plot(freqs_surro, con_surro)
pl.legend(['Con', 'Surrogates'])
pl.tight_layout()
pl.show(True)
那也许能解决我自己的问题。有人想提些建议?!你知道吗
相关问题 更多 >
编程相关推荐