spike2io 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spike2io-0.1.0/LICENSE +21 -0
- spike2io-0.1.0/MANIFEST.in +23 -0
- spike2io-0.1.0/PKG-INFO +361 -0
- spike2io-0.1.0/README.md +313 -0
- spike2io-0.1.0/ced/__init__.py +3 -0
- spike2io-0.1.0/ced/_ceds64_cffi.c +5178 -0
- spike2io-0.1.0/ced/_ceds64_cffi.cp310-win_amd64.pyd +0 -0
- spike2io-0.1.0/ced/_ceds64_cffi.cp311-win_amd64.pyd +0 -0
- spike2io-0.1.0/ced/_ceds64_cffi.cp312-win_amd64.pyd +0 -0
- spike2io-0.1.0/ced/_ceds64_cffi.cp313-win_amd64.pyd +0 -0
- spike2io-0.1.0/ced/_ceds64_cffi.cp314-win_amd64.pyd +0 -0
- spike2io-0.1.0/ced/_ceds64_cffi.cp39-win_amd64.pyd +0 -0
- spike2io-0.1.0/ced/cffi_build.py +172 -0
- spike2io-0.1.0/ced/ffi_ceds64.py +1206 -0
- spike2io-0.1.0/ced/ffi_sonpy.py +986 -0
- spike2io-0.1.0/ced/main.py +1514 -0
- spike2io-0.1.0/ced/s2rx.py +415 -0
- spike2io-0.1.0/ced/son_types.py +80 -0
- spike2io-0.1.0/ced/utils.py +123 -0
- spike2io-0.1.0/ced/x64/ceds64Prot.m +170 -0
- spike2io-0.1.0/ced/x64/ceds64Thunk.dll +0 -0
- spike2io-0.1.0/ced/x64/ceds64Thunk.lib +0 -0
- spike2io-0.1.0/ced/x64/ceds64int.dll +0 -0
- spike2io-0.1.0/ced/x64/ceds64int.h +1095 -0
- spike2io-0.1.0/ced/x64/ceds64int.lib +0 -0
- spike2io-0.1.0/ced/x64/son64.dll +0 -0
- spike2io-0.1.0/ced/x64/son64.lib +0 -0
- spike2io-0.1.0/ced/x64/son64Interface.dll +0 -0
- spike2io-0.1.0/pyproject.toml +8 -0
- spike2io-0.1.0/setup.cfg +4 -0
- spike2io-0.1.0/setup.py +177 -0
- spike2io-0.1.0/spike2io.egg-info/PKG-INFO +361 -0
- spike2io-0.1.0/spike2io.egg-info/SOURCES.txt +35 -0
- spike2io-0.1.0/spike2io.egg-info/dependency_links.txt +1 -0
- spike2io-0.1.0/spike2io.egg-info/not-zip-safe +1 -0
- spike2io-0.1.0/spike2io.egg-info/requires.txt +10 -0
- spike2io-0.1.0/spike2io.egg-info/top_level.txt +1 -0
spike2io-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NeuralDataFormats
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Files to include in the source distribution (sdist).
|
|
2
|
+
# (package_data in setup.py governs the wheel; this governs the sdist.)
|
|
3
|
+
|
|
4
|
+
include README.md
|
|
5
|
+
include LICENSE
|
|
6
|
+
|
|
7
|
+
# Prebuilt CFFI extensions and generated C source
|
|
8
|
+
recursive-include ced *.pyd
|
|
9
|
+
recursive-include ced *.c
|
|
10
|
+
|
|
11
|
+
# Native libraries, headers, and MATLAB prototype references.
|
|
12
|
+
# NOTE: ced/x86 is deliberately excluded. Every prebuilt extension is
|
|
13
|
+
# win_amd64, so a 32-bit interpreter could never load those DLLs; they stay
|
|
14
|
+
# in the repository but are not distributed.
|
|
15
|
+
recursive-include ced/x64 *.dll *.h *.lib *.m
|
|
16
|
+
|
|
17
|
+
# Do not ship intermediate build artifacts.
|
|
18
|
+
# NOTE: do NOT use the usual "*.py[cod]" pattern here -- the [cod] class also
|
|
19
|
+
# matches ".pyd", which would wrongly drop our prebuilt Windows extensions.
|
|
20
|
+
prune ced/Release
|
|
21
|
+
global-exclude *.obj *.exp
|
|
22
|
+
global-exclude *.pyc *.pyo
|
|
23
|
+
global-exclude __pycache__
|
spike2io-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spike2io
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Read CED Spike2 (.smr/.smrx) data files in Python via the native SON64 library.
|
|
5
|
+
Home-page: https://github.com/JimHokanson/python_spike2
|
|
6
|
+
Author: Jim Hokanson
|
|
7
|
+
Author-email: jim.hokanson@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source, https://github.com/JimHokanson/python_spike2
|
|
10
|
+
Project-URL: Issues, https://github.com/JimHokanson/python_spike2/issues
|
|
11
|
+
Keywords: spike2,ced,son64,smrx,electrophysiology,neuroscience
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: numpy
|
|
29
|
+
Requires-Dist: cffi>=1.0.0; platform_system == "Windows"
|
|
30
|
+
Provides-Extra: sonpy
|
|
31
|
+
Requires-Dist: sonpy; extra == "sonpy"
|
|
32
|
+
Provides-Extra: plot
|
|
33
|
+
Requires-Dist: matplotlib; extra == "plot"
|
|
34
|
+
Dynamic: author
|
|
35
|
+
Dynamic: author-email
|
|
36
|
+
Dynamic: classifier
|
|
37
|
+
Dynamic: description
|
|
38
|
+
Dynamic: description-content-type
|
|
39
|
+
Dynamic: home-page
|
|
40
|
+
Dynamic: keywords
|
|
41
|
+
Dynamic: license
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
Dynamic: project-url
|
|
44
|
+
Dynamic: provides-extra
|
|
45
|
+
Dynamic: requires-dist
|
|
46
|
+
Dynamic: requires-python
|
|
47
|
+
Dynamic: summary
|
|
48
|
+
|
|
49
|
+
# spike2io — Spike2 Files in Python
|
|
50
|
+
|
|
51
|
+
A Python library for loading [Spike2](https://ced.co.uk/products/spike2) `.smr` / `.smrx` files. It reads a file and exposes its channels as typed Python objects returning NumPy arrays.
|
|
52
|
+
|
|
53
|
+
Work on this code was supported by a grant from the NIH NIDDK ([grant: R21DK140694](https://reporter.nih.gov/project-details/11232104)).
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Why this library?
|
|
58
|
+
|
|
59
|
+
CED provides an official Python package, [sonpy](https://pypi.org/project/sonpy/), but on its own it has limitations:
|
|
60
|
+
|
|
61
|
+
- Narrow platform/version coverage — as of 1.9.12 (June 2026) the macOS and Linux wheels are built for CPython 3.14 only
|
|
62
|
+
- Older versions of sonpy may appear to have better coverage but were buggy
|
|
63
|
+
|
|
64
|
+
`spike2io` provides a consistent, NumPy-based interface on top of *two* interchangeable backends, so you get the same API whichever one is available:
|
|
65
|
+
|
|
66
|
+
| Backend | What it uses | Platforms | Python |
|
|
67
|
+
|---------|--------------|-----------|--------|
|
|
68
|
+
| `ceds64` | Bundled CFFI extension + CED's SON64 DLLs | Windows x64 | 3.9 – 3.14 |
|
|
69
|
+
| `sonpy` | CED's own [sonpy](https://pypi.org/project/sonpy/) package | Windows / macOS / Linux | 3.9 – 3.14 on Windows, **3.14 only** on macOS/Linux |
|
|
70
|
+
|
|
71
|
+
The `ceds64` backend is bundled — on Windows there is nothing else to install. It is also the default when both are present, because it can return WaveMark/RealMark sample payloads, which sonpy cannot.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install spike2io
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Windows (64-bit)** — the CED libraries ship with the package, so no other Python
|
|
82
|
+
dependency is needed. They do require Microsoft's
|
|
83
|
+
[Visual C++ 2012 Redistributable (x64)](https://www.microsoft.com/en-us/download/details.aspx?id=30679),
|
|
84
|
+
which many systems already have; install it if importing `ced` reports that the
|
|
85
|
+
`ceds64` backend failed to load.
|
|
86
|
+
|
|
87
|
+
**macOS / Linux** — reading goes through CED's `sonpy`, which currently publishes macOS/Linux wheels for CPython 3.14 only:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install spike2io[sonpy]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Optional plotting helpers (`.plot()` methods) need matplotlib:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install spike2io[plot]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Requirements:** Python >= 3.9 on Windows, >= 3.14 on macOS/Linux. NumPy.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Example Files
|
|
104
|
+
|
|
105
|
+
A repository of example `.smr` / `.smrx` files is available for testing:
|
|
106
|
+
|
|
107
|
+
<https://github.com/JimHokanson/spike2_example_files>
|
|
108
|
+
|
|
109
|
+
The examples below use files from that repository.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Usage
|
|
114
|
+
|
|
115
|
+
### Reading a file
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import ced
|
|
119
|
+
|
|
120
|
+
f = ced.read_file("my_recording.smr")
|
|
121
|
+
# ... work with f ...
|
|
122
|
+
f.close()
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Files can also be used as context managers, which closes them even if an error is raised:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
import ced
|
|
129
|
+
|
|
130
|
+
with ced.read_file("my_recording.smr") as f:
|
|
131
|
+
w = f.waveforms[0]
|
|
132
|
+
segments = w.get_data()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
By default the first available backend is used, preferring `ceds64`. Pass `backend=` to force one:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
import ced
|
|
139
|
+
|
|
140
|
+
f = ced.read_file("my_recording.smr", backend="sonpy")
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If you pass a `.s2rx` resource file, the matching `.smrx` / `.smr` recording is opened instead.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### Waveform channels
|
|
148
|
+
|
|
149
|
+
Waveform channels hold continuous analog signals (e.g. pressure, EMG, voltage). Both Spike2 waveform types appear here — `Adc` (scaled 16-bit) and `RealWave` (32-bit float).
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import ced
|
|
153
|
+
from matplotlib import pyplot as plt
|
|
154
|
+
|
|
155
|
+
with ced.read_file("Demo1.smr") as f:
|
|
156
|
+
# First waveform channel (not necessarily channel number 1)
|
|
157
|
+
w = f.waveforms[0]
|
|
158
|
+
|
|
159
|
+
print(w.name) # Data
|
|
160
|
+
print(w.units) # volt
|
|
161
|
+
print(w.fs) # 2000.0 — samples per second
|
|
162
|
+
|
|
163
|
+
# get_data() returns a list of segments, one per contiguous
|
|
164
|
+
# recording run. Demo1.smr was paused 5 times, so it has 6.
|
|
165
|
+
segments = w.get_data()
|
|
166
|
+
|
|
167
|
+
plt.figure()
|
|
168
|
+
for seg in segments:
|
|
169
|
+
seg.plot() # convenience method: seg.time vs seg.data
|
|
170
|
+
plt.ylabel(f"{w.name} ({w.units})")
|
|
171
|
+
plt.xlabel("Time (s)")
|
|
172
|
+
plt.show()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
A recording with no pauses returns a single-element list. Each segment has:
|
|
176
|
+
|
|
177
|
+
| Attribute | Description |
|
|
178
|
+
|-----------|-------------|
|
|
179
|
+
| `seg.time` | NumPy array of sample times (seconds) |
|
|
180
|
+
| `seg.data` | NumPy array of sample values (physical units) |
|
|
181
|
+
| `seg.n_samples` | Number of samples in this segment |
|
|
182
|
+
| `seg.start_time` | Time in seconds of the first sample |
|
|
183
|
+
| `seg.start_tick` | Time in file ticks of the first sample |
|
|
184
|
+
|
|
185
|
+
Sample times come from the file's own clock, so channels stay aligned with each other and with event times. A channel does not necessarily start at time zero — Spike2 staggers waveform channels across the sampling multiplexer, and a channel can also start well into a recording. `Demo1.smr` above starts at 17.76225 s.
|
|
186
|
+
|
|
187
|
+
To read part of a channel, give either a time range (seconds, inclusive) or a sample range (1-based, inclusive):
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
import ced
|
|
191
|
+
|
|
192
|
+
with ced.read_file("Demo1.smr") as f:
|
|
193
|
+
w = f.waveforms[0]
|
|
194
|
+
segments = w.get_data(time_range=(20.0, 25.0))
|
|
195
|
+
segments = w.get_data(sample_range=(1, 1000))
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`get_data()` with no arguments returns everything and never raises. A range reaching past the end of the file raises `ValueError`; pass `out_of_range='clamp'` (or `'warning'`) to return what exists instead.
|
|
199
|
+
|
|
200
|
+
Data is returned as float64 by default. Use `return_format='single'` for float32, or `'int16'` for the raw stored values of an `Adc` channel.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### Event channels
|
|
205
|
+
|
|
206
|
+
Spike2 distinguishes rising-edge, falling-edge, and both-edge (level) event channels. Which lists are populated depends on the file — `Demo_Jim.smrx` has two falling-edge channels and one both-edge channel, and no rising-edge channels.
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
import ced
|
|
210
|
+
|
|
211
|
+
with ced.read_file("Demo_Jim.smrx") as f:
|
|
212
|
+
print([c.name for c in f.event_falls]) # ['Stimulus', 'Response']
|
|
213
|
+
print([c.name for c in f.event_both]) # ['Memory']
|
|
214
|
+
|
|
215
|
+
fall = f.event_falls[0]
|
|
216
|
+
d = fall.get_data()
|
|
217
|
+
print(d.n_events) # 752
|
|
218
|
+
print(d.times[:3]) # [0.06286 0.85558 1.97999] — seconds
|
|
219
|
+
d.plot() # event times as tick marks
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Both-edge channels also report the signal level in force before the first transition:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
import ced
|
|
226
|
+
|
|
227
|
+
with ced.read_file("Demo_Jim.smrx") as f:
|
|
228
|
+
both = f.event_both[0]
|
|
229
|
+
d = both.get_data()
|
|
230
|
+
|
|
231
|
+
print(d.n_events) # 752
|
|
232
|
+
print(d.start_level) # 1 (0 = low, 1 = high)
|
|
233
|
+
print(d.times[:3]) # transition times in seconds
|
|
234
|
+
d.plot() # square wave
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`get_data()` accepts the same `time_range` and `out_of_range` arguments as waveform channels. `get_times()` is the same method under a clearer name.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### Marker channels
|
|
242
|
+
|
|
243
|
+
Marker channels carry a timestamp plus four 8-bit codes. The `Keyboard` channel records keys pressed during acquisition, and its codes are decoded to characters automatically.
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
import ced
|
|
247
|
+
|
|
248
|
+
with ced.read_file("Demo_Jim.smrx") as f:
|
|
249
|
+
mk = f.markers[0]
|
|
250
|
+
d = mk.get_data()
|
|
251
|
+
|
|
252
|
+
print(mk.name) # Keyboard
|
|
253
|
+
print(d.n_events) # 38
|
|
254
|
+
print(d.times[:3]) # marker times in seconds
|
|
255
|
+
print("".join(d.c1[:5])) # thisi
|
|
256
|
+
|
|
257
|
+
d.plot() # vertical lines, labelled with c1
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Codes are available as `d.c1` through `d.c4`. Pass `to_char=False` to keep them as raw `uint8`.
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
### Listing all channels
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
import ced
|
|
268
|
+
|
|
269
|
+
with ced.read_file("my_recording.smrx") as f:
|
|
270
|
+
print("Waveform channels :", len(f.waveforms))
|
|
271
|
+
print("Event-rise channels:", len(f.event_rises))
|
|
272
|
+
print("Event-fall channels:", len(f.event_falls))
|
|
273
|
+
print("Event-both channels:", len(f.event_both))
|
|
274
|
+
print("Marker channels :", len(f.markers))
|
|
275
|
+
|
|
276
|
+
for w in f.waveforms:
|
|
277
|
+
print(f" {w.name} ({w.units})")
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
`f.all_chan_objects` holds every channel in file order, and `f.chan_info` is a table of `[id, index, name, type]` rows.
|
|
281
|
+
|
|
282
|
+
Channels can also be looked up by name:
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
import ced
|
|
286
|
+
|
|
287
|
+
with ced.read_file("my_recording.smrx") as f:
|
|
288
|
+
w = f.get_channels("nerve") # partial match, case-insensitive
|
|
289
|
+
chans = f.get_channels(["nerve", "signal"]) # several at once
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
### Cursor positions
|
|
295
|
+
|
|
296
|
+
Spike2 stores cursor positions in a `.s2rx` sidecar file next to the recording. When one is present it is parsed automatically and exposed as `f.meta_file`:
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
import ced
|
|
300
|
+
|
|
301
|
+
with ced.read_file("Demo_Jim.smrx") as f:
|
|
302
|
+
print(f.meta_file.get_vertical_cursor_positions()) # [115.68]
|
|
303
|
+
print(f.meta_file.get_horizontal_cursor_positions()) # []
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Positions are in seconds. A cursor that was never moved has no stored position and is omitted, so a file whose cursors are all untouched returns an empty list. `f.meta_file` is `None` when there is no `.s2rx` file.
|
|
307
|
+
|
|
308
|
+
**Note, this functionality is undocumented by CED. The .s2rx file is a XML file, so it is easy to read. However, the behavior of the components is not documented** There may be other features that could be extracted from this file ....
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Low-Level API
|
|
313
|
+
|
|
314
|
+
`ced.ffi_ceds64` is a thin wrapper over the CED DLL, and `ced.ffi_sonpy` presents the same function names on top of sonpy. Use these if you need direct access to file, channel and marker primitives. Channel numbers are 1-based and times are in file ticks.
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
from ced import ffi_ceds64 as ffi
|
|
318
|
+
|
|
319
|
+
fhand = ffi.open("Demo.smr")
|
|
320
|
+
|
|
321
|
+
print(ffi.chan_title(fhand, 1)) # Sinewave
|
|
322
|
+
print(ffi.chan_units(fhand, 1)) # Volts
|
|
323
|
+
print(ffi.chan_type(fhand, 1)) # 1 — ChanType.ADC
|
|
324
|
+
print(ffi.time_base(fhand)) # 9.999999999999999e-06 — seconds per tick
|
|
325
|
+
|
|
326
|
+
# n_read, int16 samples, tick of the first sample
|
|
327
|
+
n_read, data, t_first = ffi.read_wave_s(fhand, chan=1, n_max=5000, t_from=0)
|
|
328
|
+
|
|
329
|
+
ffi.close(fhand)
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Both modules are documented inline; see their docstrings for the full set of calls. Note they are interchangeable only for reading — `edit_marker`, `write_ext_marks`, `extra_data` and the `mask_*` functions exist in `ffi_ceds64` only.
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Relationship to the MATLAB library
|
|
337
|
+
|
|
338
|
+
This package is the Python counterpart of [matlab_spike2](https://github.com/NeuralDataFormats/matlab_spike2). The high-level API mirrors the MATLAB interface:
|
|
339
|
+
|
|
340
|
+
| MATLAB | Python |
|
|
341
|
+
|--------|--------|
|
|
342
|
+
| `file = ced.file(path)` | `f = ced.read_file(path)` |
|
|
343
|
+
| `w = file.waveforms(1)` | `w = f.waveforms[0]` |
|
|
344
|
+
| `d = w.getData()` | `data = w.get_data()` |
|
|
345
|
+
| `plot(d(i).time, d(i).data)` | `seg.plot()` |
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## Known Limitations
|
|
350
|
+
|
|
351
|
+
- **WaveMark / RealMark / TextMark** channels are read, but on the `sonpy` backend the numeric sample payload is unavailable — sonpy 1.9.12 exposes no attribute for it, so `.data` comes back empty. Timestamps and codes are correct on both backends.
|
|
352
|
+
- **MATLAB's `return_format` options** for both-edge event channels (`'time_series1'`, `'time_series2'`, `'switch_times'`, `'starts_and_stops'`) are not yet ported. Python returns transition times and a starting level, equivalent to MATLAB's default `'times'`.
|
|
353
|
+
- **Writing files** is available through the backend modules but is not covered by the high-level API.
|
|
354
|
+
- Some example files (`example1.smr`, `example2.smr`) cannot be opened by the bundled `ceds64` backend, which returns error −13. They read correctly with `backend="sonpy"`. Unfortunately I have no idea why this is :/
|
|
355
|
+
- There are limited error checks on low-level DLL return codes.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## License
|
|
360
|
+
|
|
361
|
+
MIT — see [LICENSE](LICENSE) for details.
|