Skip to content

Commit 5930673

Browse files
authored
Merge branch 'master' into numpy-2-0
2 parents 7d83da0 + a21d2ef commit 5930673

File tree

7 files changed

+149
-24
lines changed

7 files changed

+149
-24
lines changed

.github/workflows/core-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ jobs:
2424
strategy:
2525
fail-fast: true
2626
matrix:
27-
os: ["ubuntu-latest", "windows-latest"]
28-
# "macos-latest",
27+
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
2928
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
3029
numpy-version: ['1.22.4', '1.23.5', '1.24.4', '1.25.1', '1.26.4', '2.0.2','2.1']
30+
# numpy 1.22: 3.10, 1.23: 3.11, 1.24: 3.11, 1.25: 3.11, 1.26: 3.12
3131
exclude:
3232
- python-version: '3.9'
3333
numpy-version: '2.1'
34+
- python-version: '3.11'
35+
numpy-version: '1.22.4'
3436
- python-version: '3.12'
3537
numpy-version: '1.22.4'
3638
- python-version: '3.12'

codemeta.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"license": "https://spdx.org/licenses/BSD-3-Clause",
55
"codeRepository": "https://github.com/NeuralEnsemble/python-neo",
66
"contIntegration": "https://github.com/NeuralEnsemble/python-neo/actions",
7-
"dateModified": "2024-08-28",
8-
"downloadUrl": "https://files.pythonhosted.org/packages/08/4b/c863c6bff783e94c92cb814f6ae821b35e6463c5a66e809b6864d0c66b4e/neo-0.13.3.tar.gz",
7+
"dateModified": "2024-10-14",
8+
"downloadUrl": null,
99
"issueTracker": "https://github.com/NeuralEnsemble/python-neo/issues",
1010
"name": "Neo",
11-
"version": "0.13.3",
11+
"version": "0.13.4",
1212
"identifier": "RRID:SCR_000634",
1313
"description": "Neo is a Python package for working with electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats, including Spike2, NeuroExplorer, AlphaOmega, Axon, Blackrock, Plexon, Tdt, and support for writing to a subset of these formats plus non-proprietary formats including HDF5.\n\nThe goal of Neo is to improve interoperability between Python tools for analyzing, visualizing and generating electrophysiology data by providing a common, shared object model. In order to be as lightweight a dependency as possible, Neo is deliberately limited to represention of data, with no functions for data analysis or visualization.\n\nNeo is used by a number of other software tools, including SpykeViewer (data analysis and visualization), Elephant (data analysis), the G-node suite (databasing), PyNN (simulations), tridesclous_ (spike sorting) and ephyviewer (data visualization).\n\nNeo implements a hierarchical data model well adapted to intracellular and extracellular electrophysiology and EEG data with support for multi-electrodes (for example tetrodes). Neo's data objects build on the quantities package, which in turn builds on NumPy by adding support for physical dimensions. Thus Neo objects behave just like normal NumPy arrays, but with additional metadata, checks for dimensional consistency and automatic unit conversion.",
1414
"applicationCategory": "neuroscience",
15-
"releaseNotes": "https://neo.readthedocs.io/en/stable/releases/0.13.3.html",
15+
"releaseNotes": null,
1616
"funding": "https://cordis.europa.eu/project/id/945539",
1717
"developmentStatus": "active",
1818
"referencePublication": "https://doi.org/10.3389/fninf.2014.00010",
@@ -23,7 +23,7 @@
2323
"programmingLanguage": ["Python"],
2424
"operatingSystem": ["Linux", "Windows", "macOS"],
2525
"softwareRequirements": [
26-
"Python (version 3.8+)",
26+
"Python (version 3.9+)",
2727
"see https://github.com/NeuralEnsemble/python-neo/blob/master/pyproject.toml"
2828
],
2929
"relatedLink": ["https://neo.readthedocs.io", "https://neuralensemble.org/community"],
@@ -112,6 +112,7 @@
112112
{ "@type": "Person", "givenName": "Kyu Hun", "familyName": "Lee"},
113113
{ "@type": "Person", "givenName": "Xin", "familyName": "Niu"},
114114
{ "@type": "Person", "givenName": "Anthony", "familyName": "Pinto"},
115-
{ "@type": "Person", "givenName": "Chris", "familyName": "Heydrick"}
115+
{ "@type": "Person", "givenName": "Chris", "familyName": "Heydrick"},
116+
{"@type": "Person", "givenName": "Nikhil", "familyName": "Chandra"}
116117
]
117118
}

doc/source/authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ and may not be the current affiliation of a contributor.
8888
* Téo Lohrer
8989
* Anthony Pinto [41]
9090
* Xin Niu
91+
* Nikhil Chandra [40]
9192

9293
1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Universite Claude Bernard Lyon 1
9394
2. Unité de Neuroscience, Information et Complexité, CNRS UPR 3293, Gif-sur-Yvette, France

doc/source/releases.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Release notes
66
.. toctree::
77
:maxdepth: 1
88

9+
releases/0.13.4.rst
910
releases/0.13.3.rst
1011
releases/0.13.2.rst
1112
releases/0.13.1.rst

doc/source/releases/0.13.4.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
========================
2+
Neo 0.13.4 release notes
3+
========================
4+
5+
21 October 2024
6+
7+
This release of Neo contains bug fixes across many IOs, a new IO for :code:`NeuroNexus`, drop of Python 3.8, NumPy 1.20 & 1.21, still with a focus on the planned 1.0 release.
8+
Additionally Neo now supports Quantities >=16.1 which brings us closer to support for NumPy 2.0 +. At the :code:`RawIO` level a new :code:`buffer api` has been introduced
9+
with the goal of better grouping streams of data together. This is an ongoing effort to provide better access to streams of data that are typically analyzed together without
10+
changes to the public API.
11+
12+
This point release will be the last release to not support Python 3.13 and NumPy > 2.0.
13+
14+
See all `pull requests`_ included in this release and the `list of closed issues`_.
15+
16+
17+
Updated dependencies
18+
--------------------
19+
20+
Neo has a limit of NumPy >= 1.22.4, < 2.0.0
21+
Neo now supports Python >= 3.9, <3.13
22+
Neo has a limit of Quantities >= 16.1
23+
Neo has a limit of dhn_med_py < 2.0.0 (for reading MED format)
24+
25+
Deprecations
26+
------------
27+
28+
As Quantities has dropped support for the :code:`copy` argument when making Quantities arrays to be NumPy 2.0 compatible, the :code:`copy` argument
29+
has also been deprecated in all Neo core objects (e.g. :code:`SpikeTrain`, etc.). For this version and the next version the default is now :code:`copy=None`.
30+
If :code:`copy=True` or :code:`copy=False` are used an error will be raised. This also means that some functionality for rescaling and dtype conversion, which
31+
required :code:`copy=True` are no longer possible. Appropriate errors are raised if the user tries these now impossible behaviors at construction.
32+
33+
Additional changes that occurred in Quantities can be viewed at their changelog:
34+
https://github.com/python-quantities/python-quantities/blob/master/CHANGES.txt
35+
36+
Currently acceptable construction patterns can be found in the Neo test folder:
37+
https://github.com/NeuralEnsemble/python-neo/blob/master/neo/test/coretest
38+
39+
Many previous behaviors can still be achieved by using additional lines of code, e.g.:
40+
41+
.. code-block:: python
42+
43+
>>> import quantities as pq
44+
>>> import neo
45+
46+
# if we want to get a spiketrain in seconds, but we entered our times in ms
47+
# we used to be able to autoconvert by specifying units. But now this will
48+
# raise an error!
49+
>>> times = [1,2,3] * 1 * pq.ms
50+
>>> t_stop = 1 * pq.s
51+
>>> spiketrain = neo.SpikeTrain(times, t_stop=t_stop, units='s')
52+
ValueError: cannot rescale and return view
53+
# so instead we need to rescale in a second step
54+
>>> spiketrain = neo.SpikeTrain(times, t_stop=t_stop)
55+
>>> spiketrain
56+
<SpikeTrain(array[1, 2, 3] * ms, [0.0 ms, 1000.0 ms])>
57+
>>> rescaled_spiketrain = spiketrain.rescale('s')
58+
>>> rescaled_spiketrain
59+
<SpikeTrain(array[0.001, 0.002, 0.003] * s, [0.0 s, 10.0 s])>
60+
61+
62+
CI Additions/Changes
63+
--------------------
64+
65+
Neo has sped up the testing suite by ~15% and added additional testing for IOs: :class:`NeuralynxIO` and
66+
:class:`Plexon2IO`.
67+
68+
Testing around :code:`copy` was removed from the core testing, since this argument is no longer possible.
69+
70+
71+
Addition of a New IO module
72+
---------------------------
73+
74+
Neo now has support for reading NeuroNexus :code:`.xdat` files with the new :class:`NeuroNexusIO`.
75+
76+
77+
Bug fixes and improvements in IO modules
78+
----------------------------------------
79+
80+
Bug fixes and/or improvements have been made to :class:`MaxwellIO`, :class:`NeuroNexusIO`,
81+
:class:`IntanIO`, :class:`Plexon2IO`, :class:`IgorIO`, :class:`SpikeGadgetsIO`, :class:`PlexonIO`,
82+
and :class:`BrainVisionRawIO`, and :class:`EDFIO`
83+
84+
Buffer API
85+
----------
86+
87+
The motivation for this :code:`RawIO` was that many IOs have buffers of data (memmaps/hdf5) files, which allow for multiple unrelated streams of data to be packaged
88+
together. This has led to some inconsistencies in how IOs access streams of data. For example, the :code:`PlexonIO` stores WideBand and Filtered versions of the same
89+
data, but the end user likely wouldn't want to analyze them both at the same time as that would be duplication of information. :code:`SpikeGLX` also makes use of a sync
90+
channel which is stored with the electrophysiological channels, but should not be analyzed as an ephys channel. The Buffer API will be an ongoing set of PRs at the
91+
:code:`RawIO` level to better clarify how data enters and is mapped in Neo versus how the end-user might request streams of data. We hope that this process will allow
92+
the end-user better access to the data they want without having unrelated data mixed in. Importantly the public API is not being affected by this process at all. The end-user
93+
will still request their desired stream using :code:`stream_index` argument when interacting with a :code:`RawIO`.
94+
95+
In this release, each IO was divided into whether it would fit with the buffer api requirements or not and the initial :code:`buffer_id` was applied to all IOs. This step
96+
has not changed any behavior in Neo. But the :code:`RawIO.header` information will now have an additional field that will be used in future releases of Neo under-the-hood.
97+
98+
We want to emphasize this is not a public API change and over the next version we hope to fully implement this new schema to allow for better interaction with data at the
99+
:code:`RawIO` and :code:`IO` levels of Neo.
100+
101+
This project has largely been spearheaded by Samuel Garcia and we thank him for his herculean efforts.
102+
103+
Acknowledgements
104+
----------------
105+
106+
Thanks to Zach McKenzie, Heberto Mayorquin, Samuel Garcia, Andrew Davison, Alessio Buccino, Nikhil Chandra, and Peter Steinmetz for their contributions to this release.
107+
108+
109+
.. _`pull requests`: https://github.com/NeuralEnsemble/python-neo/pulls?q=is%3Apr+is%3Aclosed+milestone%3A0.13.4
110+
111+
.. _`list of closed issues`: https://github.com/NeuralEnsemble/python-neo/issues?q=is%3Aissue+is%3Aclosed+milestone%3A0.13.4

neo/rawio/edfrawio.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ def _parse_header(self):
8383
# or continuous EDF+ files ('EDF+C' in header)
8484
if ("EDF+" in file_version_header) and ("EDF+C" not in file_version_header):
8585
raise ValueError("Only continuous EDF+ files are currently supported.")
86-
87-
self.edf_reader = EdfReader(self.filename)
86+
self._open_reader()
8887
# load headers, signal information and
8988
self.edf_header = self.edf_reader.getHeader()
9089
self.signal_headers = self.edf_reader.getSignalHeaders()
9190

9291
# add annotations to header
93-
annotations = self.edf_reader.readAnnotations()
94-
self.signal_annotations = [[s, d, a] for s, d, a in zip(*annotations)]
92+
self._edf_annotations = self.edf_reader.readAnnotations()
93+
self.signal_annotations = [[s, d, a] for s, d, a in zip(*self._edf_annotations)]
9594

9695
# 1 stream = 1 sampling rate
9796
stream_characteristics = []
@@ -120,7 +119,7 @@ def _parse_header(self):
120119
signal_channels.append((ch_name, chan_id, sr, dtype, units, gain, offset, stream_id, buffer_id))
121120

122121
# convert channel index lists to arrays for indexing
123-
self.stream_idx_to_chidx = {k: np.array(v) for k, v in self.stream_idx_to_chidx.items()}
122+
self.stream_idx_to_chidx = {k: np.asarray(v) for k, v in self.stream_idx_to_chidx.items()}
124123

125124
signal_channels = np.array(signal_channels, dtype=_signal_channel_dtype)
126125

@@ -174,6 +173,15 @@ def _parse_header(self):
174173
for array_key in array_keys:
175174
array_anno = {array_key: [h[array_key] for h in self.signal_headers]}
176175
seg_ann["signals"].append({"__array_annotations__": array_anno})
176+
177+
# We store the following attributes for rapid access without needing the reader
178+
179+
self._t_stop = self.edf_reader.datarecord_duration * self.edf_reader.datarecords_in_file
180+
# use sample count of first signal in stream
181+
self._stream_index_samples = {stream_index : self.edf_reader.getNSamples()[chidx][0] for stream_index, chidx in self.stream_idx_to_chidx.items()}
182+
self._number_of_events = len(self.edf_reader.readAnnotations()[0])
183+
184+
self.close()
177185

178186
def _get_stream_channels(self, stream_index):
179187
return self.header["signal_channels"][self.stream_idx_to_chidx[stream_index]]
@@ -183,14 +191,11 @@ def _segment_t_start(self, block_index, seg_index):
183191
return 0.0 # in seconds
184192

185193
def _segment_t_stop(self, block_index, seg_index):
186-
t_stop = self.edf_reader.datarecord_duration * self.edf_reader.datarecords_in_file
187194
# this must return an float scale in second
188-
return t_stop
195+
return self._t_stop
189196

190197
def _get_signal_size(self, block_index, seg_index, stream_index):
191-
chidx = self.stream_idx_to_chidx[stream_index][0]
192-
# use sample count of first signal in stream
193-
return self.edf_reader.getNSamples()[chidx]
198+
return self._stream_index_samples[stream_index]
194199

195200
def _get_signal_t_start(self, block_index, seg_index, stream_index):
196201
return 0.0 # EDF does not provide temporal offset information
@@ -219,12 +224,13 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
219224

220225
# load data into numpy array buffer
221226
data = []
227+
self._open_reader()
222228
for i, channel_idx in enumerate(selected_channel_idxs):
223229
# use int32 for compatibility with pyedflib
224230
buffer = np.empty(n, dtype=np.int32)
225231
self.edf_reader.read_digital_signal(channel_idx, i_start, n, buffer)
226232
data.append(buffer)
227-
233+
self._close_reader()
228234
# downgrade to int16 as this is what is used in the edf file format
229235
# use fortran (column major) order to be more efficient after transposing
230236
data = np.asarray(data, dtype=np.int16, order="F")
@@ -247,11 +253,11 @@ def _get_spike_raw_waveforms(self, block_index, seg_index, spike_channel_index,
247253
return None
248254

249255
def _event_count(self, block_index, seg_index, event_channel_index):
250-
return len(self.edf_reader.readAnnotations()[0])
256+
return self._number_of_events
251257

252258
def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_start, t_stop):
253259
# these time should be already in seconds
254-
timestamps, durations, labels = self.edf_reader.readAnnotations()
260+
timestamps, durations, labels = self._edf_annotations
255261
if t_start is None:
256262
t_start = self.segment_t_start(block_index, seg_index)
257263
if t_stop is None:
@@ -281,6 +287,9 @@ def _rescale_event_timestamp(self, event_timestamps, dtype, event_channel_index)
281287
def _rescale_epoch_duration(self, raw_duration, dtype, event_channel_index):
282288
return np.asarray(raw_duration, dtype=dtype)
283289

290+
def _open_reader(self):
291+
self.edf_reader = EdfReader(self.filename)
292+
284293
def __enter__(self):
285294
return self
286295

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[project]
22
name = "neo"
3-
version = "0.14.0.dev0"
3+
version = "0.13.4"
44
authors = [{name = "Neo authors and contributors"}]
55
description = "Neo is a package for representing electrophysiology data in Python, together with support for reading a wide range of neurophysiology file formats"
66
readme = "README.rst"
7-
requires-python = ">=3.9"
7+
requires-python = ">=3.9,<3.13" # 3.13 will require NumPy > 2.0 (Windows issue in CI)
88
license = {text = "BSD 3-Clause License"}
99
classifiers = [
1010
"Development Status :: 4 - Beta",
@@ -14,10 +14,10 @@ classifiers = [
1414
"Natural Language :: English",
1515
"Topic :: Scientific/Engineering",
1616
"License :: OSI Approved :: BSD License",
17-
"Programming Language :: Python :: 3.8",
1817
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
2121
"Programming Language :: Python :: 3 :: Only",
2222
]
2323

0 commit comments

Comments
 (0)