Exemple #1
0
    def test_plot_rdm(self):

        rdm = np.random.rand(8, 8)
        output = plot_rdm(rdm)
        self.assertEqual(output, 0)

        rdm = np.random.rand(7, 8)
        output = plot_rdm(rdm)
        self.assertEqual(output, "Invalid input!")
Exemple #2
0
plot_nps_hotmap(nps[:, :, 0], time_unit=[0, 0.01])

# Smooth the results and plot
plot_nps_hotmap(nps[:, :, 0], time_unit=[0, 0.01], smooth=True)

# 加上轮廓
rsa_plot.plot_stats_hotmap(nps, time_unit=[0, 0.01], smooth=True, outline=True)

#%%
"""**********       Section 4: Calculating single RDM and Plotting        **********"""

# Calculate the RDM based on the data during 190ms-210ms
rdm = eegRDM(megdata[:, :, :, :, 290:310])

# Plot this RDM
plot_rdm(rdm, rescale=True)

#%%
"""**********       Section 5: Calculating RDMs and Plotting       **********"""

# Calculate the RDMs by a 10ms time-window
# (raw sampling requency is 1000Hz, so here time_win=10ms/(1s/1000Hz)/1000=10)
rdms = eegRDM(megdata, time_opt=1, time_win=10, time_step=10)

# Plot the RDM of 0ms, 50ms, 100ms, 150ms, 200ms
times = [10, 20, 30, 40, 50]
for t in times:
    plot_rdm(rdms[t], rescale=True)

#%% 对比两个rdm之间的相似性,只有一个值出来(想到MVPA的那个图)
"""**********       Section 6: Calculating the Similarity between two RDMs     **********"""
Exemple #3
0
# Plot the NPS results
plot_nps_hotmap(nps[:, :, 0], time_unit=[0, 0.01], abs=True)

# Smooth the results and plot
plot_nps_hotmap(nps[:, :, 0], time_unit=[0, 0.01], abs=True, smooth=True)


# In[4]
"""**********       Section 4: Calculating single RDM and Plotting        **********"""

# Calculate the RDM based on the data during 190ms-210ms
rdm = eegRDM(megdata[:, :, :, :, 290:310], sub_opt=0)

# Plot this RDM
plot_rdm(rdm, percentile=True)


# In[5]
"""**********       Section 5: Calculating RDMs and Plotting       **********"""

# Calculate the RDMs by a 10ms time-window
# (raw sampling requency is 1000Hz, so here time_win=10ms/(1s/1000Hz)/1000=10)
rdms = eegRDM(megdata, time_opt=1, time_win=10, time_step=10, sub_opt=0)

# Plot the RDM of -100ms, 0ms, 100ms, 200ms, 30ms, 400ms
times = [0, 10, 20, 30, 40, 50]
for t in times:
    plot_rdm(rdms[t], percentile=True)

Exemple #4
0
for i in range(16):
    for j in range(16):
        diff = np.abs(i - j)
        if diff <= 8:
            model_RDM[i, j] = diff / 8
        else:
            model_RDM[i, j] = (16 - diff) / 8

conditions = [
    "0°", "22.5°", "45°", "67.5°", "90°", "112.5°", "135°", "157.5°", "180°",
    "202.5°", "225°", "247.5°", "270°", "292.5°", "315°", "337.5°"
]

# plot the Coding RDM
print("Coding RDM!")
plot_rdm(model_RDM, percentile=True, conditions=conditions)

# calculate the CTSimilarities between CTRDMs and Coding RDM
print("\nCalculate the Similarities of Orientation!")
Sim_ori_ERP = rdms_corr(model_RDM, RDM_ori_ERP)
print("\nCalculate the Similarities of Position!")
Sim_pos_ERP = rdms_corr(model_RDM, RDM_pos_ERP)
"""****** Section 5: Plot the RSA-based decoding results ******"""

# plot orientation decoding results
print("Orientation RSA-based Decoding Results!")
plot_tbytsim_withstats(Sim_ori_ERP,
                       start_time=-0.5,
                       end_time=1.5,
                       color='orange',
                       lim=[-0.1, 0.5])
Exemple #5
0
plotting.plot_epi(savefilename+".nii")
plotting.show()



"""**********       Section 5: Calculating the RDM for ROI and Plotting        **********"""

# get mask of "mask_vt" in the dataset
mask_vt_filename = haxby_dataset.mask_face[0]
mask_vt_data = nib.load(mask_vt_filename).get_fdata()

# calculate the RDM for ROI
rdm_roi = fmriRDM_roi(fmri_data, mask_vt_data)

# plot the RDM
plot_rdm(rdm_roi, rescale=True, conditions=categories)



"""**********       Section 6: Calculating the RDM by Searchlight and Plotting        **********"""

# calculate the RDMs by Searchlight
fmri_RDMs = fmriRDM(fmri_data, sub_opt=0)

# plot one of the RDMs
plot_rdm(fmri_RDMs[20, 30, 30], rescale=True, conditions=categories)



"""**********       Section 7: Calculating the representational similarities       **********"""
"""**********             between a coding model and neural activities           **********"""
labels = [
    "left 10°", "left 30°", "left 50°", "left 70°", "left 90°", "left 110°",
    "left 130°", "left 150°", "left 170°", "right 10°", "right 30°",
    "right 50°", "right 70°", "right 90°", "right 110°", "right 130°",
    "right 150°", "right 170°"
]

ori_codingrdm = np.ones([18, 18], dtype=np.float)

for i in range(9):
    for j in range(9):
        ori_codingrdm[i, j] = np.abs(i - j) / 8
ori_codingrdm[9:, 9:] = ori_codingrdm[:9, :9]
ori_codingrdm[:9, 9:] = ori_codingrdm[:9, :9]
ori_codingrdm[9:, :9] = ori_codingrdm[:9, :9]

plot_rdm(ori_codingrdm, conditions=labels, con_fontsize=10)

np.savetxt("ori_rdm.txt", ori_codingrdm)

pos_codingrdm = np.ones([18, 18], dtype=np.int)

for i in range(9):
    for j in range(9):
        pos_codingrdm[i, j] = 0
        pos_codingrdm[i + 9, j + 9] = 0

plot_rdm(pos_codingrdm, conditions=labels, con_fontsize=10)

np.savetxt("pos_rdm.txt", pos_codingrdm)
Exemple #7
0
# the shape of MEG data: megdata is [3, 92, 306, 1101]
# n_subs = 3, n_conditions = 92, n_channels = 306, n_timepoints = 1101 (-100ms to 1000ms)
"""**********       Section 2: Calculating single RDM and Plotting        **********"""

# shape of megdata: [n_subs, n_cons, n_chls, n_ts] -> [n_cons, n_subs, n_chls, n_ts]
megdata = np.transpose(megdata, (1, 0, 2, 3))

# shape of megdata: [n_cons, n_subs, n_chls, n_ts] -> [n_cons, n_subs, n_trials, n_chls, n_ts]
# here data is averaged, so set n_trials = 1
megdata = np.reshape(megdata, [92, 3, 1, 306, 1101])

# Calculate the RDM based on the data during 190ms-210ms
rdm = eegRDM(megdata[:, :, :, :, 290:310])

# Plot this RDM
plot_rdm(rdm, rescale=True)
"""**********       Section 3: Calculating RDMs and Plotting       **********"""

# Calculate the RDMs by a 10ms time-window
# (raw sampling requency is 1000Hz, so here time_win=10ms/(1s/1000Hz)/1000=10)
rdms = eegRDM(megdata, time_win=10, time_opt=1)

# Plot the RDM of 0ms, 50ms, 100ms, 150ms, 200ms
times = [0, 10, 20, 30, 40, 50]
for t in times:
    plot_rdm(rdms[t], rescale=True)
"""**********       Section 4: Calculating the Similarity between two RDMs     **********"""

# RDM of 200ms
rdm_sample1 = rdms[30]
# RDM of 800ms