Skip to content

Commit

Permalink
FIX: ensure that simulations can be performed multiple times (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrltz authored Oct 22, 2024
1 parent c441d17 commit 05d65df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/meegsim/coupling_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,13 @@ def _set_coupling(sources, coupling_graph, times, random_state):
# Get the corresponding coupling parameters
coupling_params = coupling_graph.get_edge_data(name1, name2)

# Extract the coupling method
coupling_fn = coupling_params.pop('method')
# Extract the coupling method temporarily
tmp_coupling_params = coupling_params.copy()
coupling_fn = tmp_coupling_params.pop('method')

# Adjust the waveform of s2 to be coupled with s1
s2.waveform = coupling_fn(s1.waveform, get_sfreq(times),
**coupling_params,
**tmp_coupling_params,
random_state=random_state)

return sources
13 changes: 11 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,14 @@ def test_builtin_methods():
sc = sim.simulate(sfreq, duration, fwd, random_state=seed)

# SourceConfiguration methods
sc.to_stc()
sc.to_raw(fwd, info)
stc = sc.to_stc()
raw = sc.to_raw(fwd, info)

# Check that it is possible to simulate data multiple times
sc_new = sim.simulate(sfreq, duration, fwd, random_state=seed)
stc_new = sc_new.to_stc()
raw_new = sc_new.to_raw(fwd, info)

# Check that the result is reproducible
assert np.allclose(stc.data, stc_new.data)
assert np.allclose(raw.get_data(), raw_new.get_data())

0 comments on commit 05d65df

Please sign in to comment.