Skip to content

Commit

Permalink
Fixed after merge, reduced nesting, note to the changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrltz committed Aug 10, 2024
1 parent 36b2fa5 commit fe771d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Waveforms of white noise, narrowband oscillation (white noise filtered in a narrow frequency band) and 1/f noise with adjustable slope ([#8](https://github.com/ctrltz/meegsim/pull/8))
- Selector of random vertices in the whole source space or in a subset of vertices ([#10](https://github.com/ctrltz/meegsim/pull/8))
16 changes: 6 additions & 10 deletions src/meegsim/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Many options are already covered by mne.simulation.select_source_in_label so we can reuse the functionality under the hood.
"""
import numpy as np
import mne

from meegsim.utils import unpack_vertices

Expand Down Expand Up @@ -49,19 +48,16 @@ def select_random(src, *, n=1, vertices=None, sort_output=False, random_state=No

src_unpacked = unpack_vertices([s['vertno'] for s in src])

if vertices is None:
vertices = src_unpacked
else:
vertices = unpack_vertices(vertices)
if not all(vert in set(src_unpacked) for vert in vertices):
raise ValueError("Some vertices are not contained in the src.")
vertices = unpack_vertices(vertices) if vertices else src_unpacked
vertices_not_in_src = set(vertices) - set(src_unpacked)
if vertices_not_in_src:
raise ValueError("Some vertices are not contained in the src.")

if n > len(vertices):
raise ValueError("Number of vertices to select exceeds available vertices.")

selected_vertno = rng.choice(vertices, size=n, replace=False)
if sort_output:
selected_vertno = np.sort(rng.choice(vertices, size=n, replace=False))
else:
selected_vertno = rng.choice(vertices, size=n, replace=False)
selected_vertno = np.sort(selected_vertno)

return [(vert[0], vert[1]) for vert in selected_vertno]
3 changes: 2 additions & 1 deletion src/meegsim/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np

import warnings


def combine_stcs(stc1, stc2):
"""
Expand Down

0 comments on commit fe771d0

Please sign in to comment.