mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.69k stars 1.31k forks source link

API: simulation module #6119

Closed makkostya closed 5 years ago

makkostya commented 5 years ago

I create this issue to continue general discussion of a simulation module API, started in #5058. We need to design the API which should:

cc @sdeslauriers @ikojcic @ngayraud

@agramfort can you label this issue as "simulation" for codding sprint pls.

larsoner commented 5 years ago

Closing as dup of https://github.com/conda/conda/issues/8187

larsoner commented 5 years ago

Sorry wrong link, meant https://github.com/mne-tools/mne-python/issues/5924

larsoner commented 5 years ago

Ahh I thought #5924 was meant to cover all of these, but looking closer I guess not. Reopening

makkostya commented 5 years ago

Here is an example of a possible simulation script: https://gist.github.com/makkostya/4f783028bb1324dabb45388f91e2cb8f

Note: we suppose StcSimulator to be the subclass of SourceEstimate and thus it could be treated as an stc.

@ngayraud you created your own Simulator class? can you share the code pls to discuss.

ngayraud commented 5 years ago

Will do ASAP

Le mar. 9 avr. 2019 à 10:56, Maksymenko Kostiantyn notifications@github.com a écrit :

Here is an example of a possible simulation script: https://gist.github.com/makkostya/4f783028bb1324dabb45388f91e2cb8f

Note: we suppose StcSimulator to be the subclass of SourceEstimate and thus it could be treated as an stc.

@ngayraud https://github.com/ngayraud you created your own Simulator class? can you share the code pls to discuss.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mne-tools/mne-python/issues/6119#issuecomment-481164675, or mute the thread https://github.com/notifications/unsubscribe-auth/ARPD8yrfdB5-BhwB0jMaT9nFtcqekKEoks5vfFXQgaJpZM4cakZh .

ngayraud commented 5 years ago

Ok I am somewhat up to date with everything. Here is the API I created a while ago, which answers to mostly 2 and 3. https://gist.github.com/ngayraud/22f5d0360ba34e1873ae441b850253a1

The Simulation class saves the %basic" info on the experiment, such as, the forward model, the desired waveforms (for each dipole or for all dipoles). The get_events creates an mne.event based on the events (stimulations) on each dipole The simulate_raw_signal is similar to existing functions, with the difference that you can pass different stimulations for each dipole, thanks to the _get_propagation function which distributes the waveforms across time. Waveform lengths are given as time arrays, and another time array is given for the whole experiment.

wmvanvliet commented 5 years ago

Just wanted to leave a note that the beamformer team also wants to run simulations during the code sprint. So we're interested in the API design too!

larsoner commented 5 years ago

Great. First we need to decide on #6037, @agramfort is not convinced it's the best approach. Once that's done, we can work on the API of the SourceSimulator.

wmvanvliet commented 5 years ago

About the proposed SourceSimulator API, IMO it would be much simpler to not have to define all dipoles/sources at once with complicated lists/dics datastructures, but have something like:

sim = SourceSimulator(fwd)
sim.add_signal(name='signal1', location=..., waveform=...)
sim.add_signal(name='signal2', location=..., waveform=...)
sim.add_signal(name='signal3', location=..., waveform=...)
larsoner commented 5 years ago

Sounds good to me, except that it should take src not fwd in the constructor. Mapping source( time course)s to sensors is the domain of simulate_raw and should probably stay that way

larsoner commented 5 years ago

@ngayraud et al. here is the example of a naive API I wrote to do this sort of thing:

https://gist.github.com/larsoner/8566361d3e011c9ce34c1d321f0f4ef1

Feel free to reuse the code (not the simulator) to test out the eventual API/implementation. The result will hopefully produce images like this:

Screen Shot 2019-03-18 at 22 39 05 Screen Shot 2019-03-18 at 22 39 10
megazero1316 commented 5 years ago

hello i have a question, can the simulation API be used to simulated motor imagery EEG signal (or ERD/ERS pattern ) ?

ngayraud commented 5 years ago

Hi, I am interested in that too, and I think that it will be able to do that, as long as you provide it with the right parameters. If you can model the activity and provide the regions where it occurs, it should work.

Le mer. 24 avr. 2019 à 10:27, megazero1316 notifications@github.com a écrit :

hello i have a question, can the simulation API be used to simulated motor imagery EEG signal (or ERD/ERS pattern ) ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mne-tools/mne-python/issues/6119#issuecomment-486122471, or mute the thread https://github.com/notifications/unsubscribe-auth/AEJ4H446MCZGLBQAXGU6RCDPSAKVVANCNFSM4HDKIZQQ .

ngayraud commented 5 years ago

Now that we have #6243 merged into master, what else do we need to implement to close this issue? From what I remember, we discussed about providing template waveforms. I can provide templates for the following evoked responses: P300, N200, combination of P300+N200, and N400. For all these waveforms, two parameters can be tuned to set the amplitude and jitter of the peak. Before I do a PR, let me know if (1) you think it's a good idea and (2) if they should be on a separate .py file, maybe named waveforms.py Users can then create their own waveforms adding as much variability as they wand, and these can be passed to the SourceSimulator using the add_data function. An example should also be implemented - I can add one in the same PR.

agramfort commented 5 years ago

I would say priority is now to consolidate a narrative tutorial.

larsoner commented 5 years ago

Narrative in #6261, closing