Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS viz improvements #135

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions examples/eg004r__fitting_JR_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from whobpyt.models.JansenRit import RNNJANSEN, ParamsJR
from whobpyt.optimization.custom_cost_JR import CostsJR
from whobpyt.run import Model_fitting
import mne


# array and pd stuff
import numpy as np
Expand Down Expand Up @@ -160,12 +162,36 @@
plt.show()

# %%
# Plot the EEG
fig, ax = plt.subplots(1,3, figsize=(12,8))
ax[0].plot(F.lastRec['P'].npTS().T)
ax[0].set_title('Test: sourced EEG')
ax[1].plot(F.lastRec["eeg"].npTS().T)
ax[1].set_title('Test')
ax[2].plot(eeg_data.T)
ax[2].set_title('empirical')
plt.show()
# Plotting the timeseries of the fitted model and the empirical data using mne package

# import a 64 channel montage for visualization
montage = mne.channels.make_standard_montage('biosemi64')
# create info object based on the montage
info = mne.create_info(ch_names = montage.ch_names, sfreq = 1000, ch_types = 'eeg')

# create mne.evoked objects
evoked_emp = mne.EvokedArray(eeg_data, info)
evoked_emp.set_montage(montage)
evoked_fit = mne.EvokedArray(F.lastRec["eeg"].npTS()/1e6, info)
evoked_fit.set_montage(montage)

plt.plot(F.lastRec['P'].npTS().T, linewidth = 0.5)
# resize plot
plt.rcParams["figure.figsize"] = (8, 3)
plt.title('Simulated - Source Activity (200 Parcels)');
plt.ylim(-.3, .3);
# add x label
plt.xlabel('Time (ms)');
# add bar between 110 and 120 for stimulus
plt.axvspan(110, 120, alpha=0.5, color='red');
# add label for stimulus
plt.text(115, .25, 'Stimulation ON', color='black', fontsize=8, horizontalalignment='right', verticalalignment='center');

fig = evoked_emp.plot(gfp=True, time_unit='s', show=False, titles='Empirical - Channel EEG')
for ax in fig.axes:
ax.axvspan(0.11, 0.12, alpha=0.5, color='red');


fig = evoked_fit.plot(gfp=True, time_unit='s', show=False, titles='Simulated - Channel EEG');
for ax in fig.axes:
ax.axvspan(0.11, 0.12, alpha=0.5, color='red');
Loading