Skip to content

Commit 812ed39

Browse files
Merge branch 'NeuralEnsemble:master' into feature/newFilter
2 parents 4616987 + 454a564 commit 812ed39

File tree

18 files changed

+930
-33
lines changed

18 files changed

+930
-33
lines changed

.github/workflows/core-test.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
paths:
88
- 'neo/core/**'
99
- 'pyproject.toml'
10+
- '.github/workflows/*.yml'
1011

1112
# run checks on any change of master, including merge of PRs
1213
push:
@@ -26,14 +27,12 @@ jobs:
2627
os: ["ubuntu-latest", "windows-latest"]
2728
# "macos-latest",
2829
python-version: ['3.8', '3.9', '3.10', '3.11']
29-
numpy-version: ['1.19.5', '1.20.3', '1.21.6', '1.22.4', '1.23.5', '1.24.1']
30+
numpy-version: ['1.20.3', '1.21.6', '1.22.4', '1.23.5', '1.24.1', '1.25.1']
3031
exclude:
31-
- python-version: '3.10'
32-
numpy-version: '1.19.5'
32+
- python-version: '3.8'
33+
numpy-version: '1.25.1'
3334
- python-version: '3.10'
3435
numpy-version: '1.20.3'
35-
- python-version: '3.11'
36-
numpy-version: '1.19.5'
3736
- python-version: '3.11'
3837
numpy-version: '1.20.3'
3938
- python-version: '3.11'

doc/source/authors.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ and may not be the current affiliation of a contributor.
6363
* Oliver Kloss [13]
6464
* Heberto Mayorquin [24]
6565
* Thomas Perret [25]
66+
* Kyle Johnsen [26, 27]
6667

6768
1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Universite Claude Bernard Lyon 1
6869
2. Unité de Neuroscience, Information et Complexité, CNRS UPR 3293, Gif-sur-Yvette, France
@@ -89,6 +90,8 @@ and may not be the current affiliation of a contributor.
8990
23. Bio Engineering Laboratory, DBSSE, ETH, Basel, Switzerland
9091
24. CatalystNeuro
9192
25. Institut des Sciences Cognitives Marc Jeannerod, CNRS UMR5229, Lyon, France
93+
26. Georgia Institute of Technology
94+
27. Emory University
9295

9396
If we've somehow missed you off the list we're very sorry - please let us know.
9497

neo/core/container.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,39 @@ def size(self):
333333
return {name: len(getattr(self, name))
334334
for name in self._child_containers}
335335

336+
@property
337+
def _container_lookup(self):
338+
return {
339+
cls_name: getattr(self, container_name)
340+
for cls_name, container_name in zip(self._child_objects, self._child_containers)
341+
}
342+
343+
def _get_container(self, cls):
344+
if hasattr(cls, "proxy_for"):
345+
cls = cls.proxy_for
346+
return self._container_lookup[cls.__name__]
347+
348+
def add(self, *objects):
349+
"""Add a new Neo object to the Container"""
350+
for obj in objects:
351+
if (
352+
obj.__class__.__name__ in self._child_objects
353+
or (
354+
hasattr(obj, "proxy_for")
355+
and obj.proxy_for.__name__ in self._child_objects
356+
)
357+
):
358+
container = self._get_container(obj.__class__)
359+
container.append(obj)
360+
else:
361+
raise TypeError(
362+
f"Cannot add object of type {obj.__class__.__name__} "
363+
f"to a {self.__class__.__name__}, can only add objects of the "
364+
f"following types: {self._child_objects}"
365+
)
366+
367+
368+
336369
def filter(self, targdict=None, data=True, container=False, recursive=True,
337370
objects=None, **kwargs):
338371
"""

neo/core/group.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def __init__(self, objects=None, name=None, description=None, file_origin=None,
7676
self.allowed_types = None
7777
else:
7878
self.allowed_types = tuple(allowed_types)
79+
for type_ in self.allowed_types:
80+
if type_.__name__ not in self._child_objects:
81+
raise TypeError(f"Groups can not contain objects of type {type_.__name__}")
7982

8083
if objects:
8184
self.add(*objects)
@@ -134,26 +137,13 @@ def __init__(self, objects=None, name=None, description=None, file_origin=None,
134137
doc="list of Groups contained in this group"
135138
)
136139

137-
@property
138-
def _container_lookup(self):
139-
return {
140-
cls_name: getattr(self, container_name)
141-
for cls_name, container_name in zip(self._child_objects, self._child_containers)
142-
}
143-
144-
def _get_container(self, cls):
145-
if hasattr(cls, "proxy_for"):
146-
cls = cls.proxy_for
147-
return self._container_lookup[cls.__name__]
148-
149140
def add(self, *objects):
150141
"""Add a new Neo object to the Group"""
151142
for obj in objects:
152143
if self.allowed_types and not isinstance(obj, self.allowed_types):
153144
raise TypeError("This Group can only contain {}, but not {}"
154145
"".format(self.allowed_types, type(obj)))
155-
container = self._get_container(obj.__class__)
156-
container.append(obj)
146+
super().add(*objects)
157147

158148
def walk(self):
159149
"""

neo/io/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* :attr:`KlustaKwikIO`
4040
* :attr:`KwikIO`
4141
* :attr:`MaxwellIO`
42+
* :attr:`MedIO`
4243
* :attr:`MicromedIO`
4344
* :attr:`NeoMatlabIO`
4445
* :attr:`NestIO`
@@ -165,6 +166,10 @@
165166
.. autoclass:: neo.io.MaxwellIO
166167
167168
.. autoattribute:: extensions
169+
170+
.. autoclass:: neo.io.MedIO
171+
172+
.. autoattribute:: extensions
168173
169174
.. autoclass:: neo.io.MicromedIO
170175
@@ -313,6 +318,7 @@
313318
from neo.io.kwikio import KwikIO
314319
from neo.io.mearecio import MEArecIO
315320
from neo.io.maxwellio import MaxwellIO
321+
from neo.io.medio import MedIO
316322
from neo.io.micromedio import MicromedIO
317323
from neo.io.neomatlabio import NeoMatlabIO
318324
from neo.io.nestio import NestIO
@@ -366,6 +372,7 @@
366372
KwikIO,
367373
MEArecIO,
368374
MaxwellIO,
375+
MedIO,
369376
MicromedIO,
370377
NixIO,
371378
NixIOFr,

neo/io/medio.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
IO for reading MED datasets using dhn-med-py library.
3+
4+
dhn-med-py
5+
https://medformat.org
6+
https://pypi.org/project/dhn-med-py/
7+
8+
MED Format Specifications: https://medformat.org
9+
10+
Author: Dan Crepeau, Matt Stead
11+
"""
12+
13+
from neo.io.basefromrawio import BaseFromRaw
14+
from neo.rawio.medrawio import MedRawIO
15+
16+
17+
class MedIO(MedRawIO, BaseFromRaw):
18+
"""
19+
IO for reading MED datasets.
20+
"""
21+
name = 'MED IO'
22+
description = "IO for reading MED datasets"
23+
24+
_prefered_signal_group_mode = 'group-by-same-units'
25+
mode = 'dir'
26+
27+
def __init__(self, dirname=None, password=None, keep_original_times=False):
28+
MedRawIO.__init__(self, dirname=dirname, password=password,
29+
keep_original_times=keep_original_times)
30+
"""
31+
Initialise IO instance
32+
33+
Parameters
34+
----------
35+
dirname : str
36+
Directory containing data files
37+
password : str
38+
MED sessions can be optionally encrypted with a password.
39+
Default: None
40+
keep_original_times : bool
41+
Preserve original time stamps as in data files. By default datasets are
42+
shifted to begin at t_start = 0. When set to True, timestamps will be
43+
returned as UTC (seconds since midnight 1 Jan 1970).
44+
Default: False
45+
"""
46+
BaseFromRaw.__init__(self, dirname)
47+
48+
def close(self):
49+
MedRawIO.close(self)
50+
51+
def __del__(self):
52+
MedRawIO.__del__(self)

neo/rawio/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* :attr:`ElanRawIO`
2525
* :attr:`IntanRawIO`
2626
* :attr:`MaxwellRawIO`
27+
* :attr:`MedRawIO`
2728
* :attr:`MEArecRawIO`
2829
* :attr:`MicromedRawIO`
2930
* :attr:`NeuralynxRawIO`
@@ -93,6 +94,10 @@
9394
9495
.. autoattribute:: extensions
9596
97+
.. autoclass:: neo.rawio.MedRawIO
98+
99+
.. autoattribute:: extensions
100+
96101
.. autoclass:: neo.rawio.MEArecRawIO
97102
98103
.. autoattribute:: extensions
@@ -186,6 +191,7 @@
186191
from neo.rawio.intanrawio import IntanRawIO
187192
from neo.rawio.maxwellrawio import MaxwellRawIO
188193
from neo.rawio.mearecrawio import MEArecRawIO
194+
from neo.rawio.medrawio import MedRawIO
189195
from neo.rawio.micromedrawio import MicromedRawIO
190196
from neo.rawio.neuralynxrawio import NeuralynxRawIO
191197
from neo.rawio.neuroexplorerrawio import NeuroExplorerRawIO
@@ -220,6 +226,7 @@
220226
MicromedRawIO,
221227
MaxwellRawIO,
222228
MEArecRawIO,
229+
MedRawIO,
223230
NeuralynxRawIO,
224231
NeuroExplorerRawIO,
225232
NeuroScopeRawIO,

neo/rawio/maxwellrawio.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop,
183183
if np.array(channel_indexes).size > 1 and np.any(np.diff(channel_indexes) < 0):
184184
# get around h5py constraint that it does not allow datasets
185185
# to be indexed out of order
186-
sorted_channel_indexes = np.sort(channel_indexes)
187-
resorted_indexes = np.array(
188-
[list(channel_indexes).index(ch) for ch in sorted_channel_indexes])
186+
order_f = np.argsort(channel_indexes)
187+
sorted_channel_indexes = channel_indexes[order_f]
188+
# use argsort again on order_f to obtain resorted_indexes
189+
resorted_indexes = np.argsort(order_f)
189190

190191
try:
191192
if resorted_indexes is None:

0 commit comments

Comments
 (0)