Skip to content

Commit 22ed375

Browse files
authored
Merge pull request #1397 from zm711/docstrings
Add and unify many docstrings
2 parents e94a902 + 21efc0e commit 22ed375

34 files changed

+1145
-355
lines changed

neo/io/basefromrawio.py

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
55
BaseFromRaw implement a bridge between the new neo.rawio API
66
and the neo.io legacy that give neo.core object.
7-
The neo.rawio API is more restricted and limited and do not cover tricky
7+
The neo.rawio API is more restricted and limited and does not cover tricky
88
cases with asymetrical tree of neo object.
99
But if a format is done in neo.rawio the neo.io is done for free
1010
by inheritance of this class.
11-
Furthermore, IOs that inherits this BaseFromRaw also have the ability
12-
of the lazy load with proxy objects.
11+
Furthermore, IOs that inherit this BaseFromRaw also have the ability
12+
to lazy load with proxy objects.
1313
1414
1515
"""
@@ -80,26 +80,34 @@ def read_block(
8080
self, block_index=0, lazy=False, create_group_across_segment=None, signal_group_mode=None, load_waveforms=False
8181
):
8282
"""
83-
:param block_index: int default 0. In case of several block block_index can be specified.
84-
85-
:param lazy: False by default.
86-
87-
:param create_group_across_segment: bool or dict
83+
Reads one block of data from a file
84+
85+
Parameters
86+
----------
87+
block_index: int, default: 0
88+
In the case of multiple blocks, the block_index specifies which block to read
89+
lazy: bool, default: False
90+
Whether to read the block lazily (True) or load into memory (False)
91+
create_group_across_segment: bool | dict | None, default: None
8892
If True :
89-
* Create a neo.Group to group AnalogSignal segments
90-
* Create a neo.Group to group SpikeTrain across segments
91-
* Create a neo.Group to group Event across segments
92-
* Create a neo.Group to group Epoch across segments
93+
* Create a neo.Group to group AnalogSignal segments
94+
* Create a neo.Group to group SpikeTrain across segments
95+
* Create a neo.Group to group Event across segments
96+
* Create a neo.Group to group Epoch across segments
9397
With a dict the behavior can be controlled more finely
94-
create_group_across_segment = { 'AnalogSignal': True, 'SpikeTrain': False, ...}
95-
96-
:param signal_group_mode: 'split-all' or 'group-by-same-units' (default depend IO):
97-
This control behavior for grouping channels in AnalogSignal.
98-
* 'split-all': each channel will give an AnalogSignal
99-
* 'group-by-same-units' all channel sharing the same quantity units ar grouped in
100-
a 2D AnalogSignal
101-
102-
:param load_waveforms: False by default. Control SpikeTrains.waveforms is None or not.
98+
* for example: create_group_across_segment = { 'AnalogSignal': True, 'SpikeTrain': False, ...}
99+
signal_group_mode: 'split-all' | 'group-by-same-units' | None, default: None
100+
This control behavior for grouping channels in AnalogSignal.
101+
* 'split-all': each channel will be give an AnalogSignal
102+
* 'group-by-same-units' all channel sharing the same quantity units are grouped in a 2D AnalogSignal
103+
By default None since the default is dependant on the IO
104+
load_waveforms: bool, default: False
105+
Determines whether SpikeTrains.waveforms is created
106+
107+
Returns
108+
-------
109+
bl: neo.core.Block
110+
The block of data
103111
104112
"""
105113

@@ -200,31 +208,40 @@ def read_segment(
200208
strict_slicing=True,
201209
):
202210
"""
203-
:param block_index: int default 0. In case of several blocks block_index can be specified.
204-
205-
:param seg_index: int default 0. Index of segment.
206-
207-
:param lazy: False by default.
208-
209-
:param signal_group_mode: 'split-all' or 'group-by-same-units' (default depend IO):
210-
This control behavior for grouping channels in AnalogSignal.
211-
* 'split-all': each channel will give an AnalogSignal
212-
* 'group-by-same-units' all channel sharing the same quantity units ar grouped in
213-
a 2D AnalogSignal
214-
215-
:param load_waveforms: False by default. Control SpikeTrains.waveforms is None or not.
216-
217-
:param time_slice: None by default means no limit.
218-
A time slice is (t_start, t_stop) both are quantities.
219-
All object AnalogSignal, SpikeTrain, Event, Epoch will load only in the slice.
220-
221-
:param strict_slicing: True by default.
222-
Control if an error is raised or not when t_start or t_stop
223-
is outside the real time range of the segment.
211+
Reads one segment of the data file
212+
213+
Parameters
214+
----------
215+
block_index: int, default: 0
216+
In the case of a multiblock dataset, this specifies which block to read
217+
seg_index: int, default: 0
218+
In the case of a multisegment block, this specifies which segmeent to read
219+
lazy: bool, default: False
220+
Whether to lazily load the segment (True) or to load the segment into memory (False)
221+
signal_group_mode: 'split-all' | 'group-by-same-units' | None, default: None
222+
This control behavior for grouping channels in AnalogSignal.
223+
* 'split-all': each channel will be give an AnalogSignal
224+
* 'group-by-same-units' all channel sharing the same quantity units are grouped in a 2D AnalogSignal
225+
load_waveforms: bool, default: False
226+
Determines whether SpikeTrains.waveforms is created
227+
time_slice: tuple[quantity.Quantities | None] | None, default: None
228+
Whether to take a time slice of the data
229+
* None: indicates from beginning of the segment to the end of the segment
230+
* tuple: (t_start, t_stop) with t_start and t_stop being quantities in seconds
231+
* tuple: (None, t_stop) indicates the beginning of the segment to t_stop
232+
* tuple: (t_start, None) indicates from t_start to the end of the segment
233+
strict_slicing: bool, default: True
234+
Control if an error is raised or not when t_start or t_stop
235+
is outside of the real time range of the segment.
236+
237+
Returns
238+
-------
239+
seg: neo.core.Segment
240+
Returns the desired segment based on the parameters given
224241
"""
225242

226243
if lazy:
227-
assert time_slice is None, "For lazy=True you must specify time_slice when LazyObject.load(time_slice=...)"
244+
assert time_slice is None, "For lazy=True you must specify a time_slice when LazyObject.load(time_slice=...)"
228245

229246
assert (
230247
not load_waveforms
@@ -317,7 +334,7 @@ def get_sub_signal_streams(self, signal_group_mode="group-by-same-units"):
317334

318335
if len(all_units) == 1:
319336
# no substream
320-
#  None iwill be transform as slice later
337+
# None iwill be transform as slice later
321338
inner_stream_channels = None
322339
name = stream_name
323340
sub_stream = (stream_index, inner_stream_channels, name)

neo/io/baseio.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ def __init__(self, filename: str | Path = None, **kargs):
125125
def read(self, lazy: bool = False, **kargs):
126126
"""
127127
Return all data from the file as a list of Blocks
128+
129+
Parameters
130+
----------
131+
lazy: bool, default: False
132+
Whether to lazily load the data (True) or to load into memory (False)
133+
kargs: dict
134+
IO specific additional arguments
135+
136+
Returns
137+
------
138+
block_list: list[neo.core.Block]
139+
Returns all the data from the file as Blocks
128140
"""
129141
if lazy and not self.support_lazy:
130142
raise ValueError("This IO module does not support lazy loading")
@@ -142,6 +154,17 @@ def read(self, lazy: bool = False, **kargs):
142154
raise NotImplementedError
143155

144156
def write(self, bl, **kargs):
157+
"""
158+
Writes a given block if IO supports writing
159+
160+
Parameters
161+
----------
162+
bl: neo.core.Block
163+
The neo Block to be written
164+
kargs: dict
165+
IO specific additional arguments
166+
167+
"""
145168
if Block in self.writeable_objects:
146169
if isinstance(bl, Sequence):
147170
assert hasattr(self, "write_all_blocks"), (

neo/rawio/alphaomegarawio.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,21 @@
4747
class AlphaOmegaRawIO(BaseRawIO):
4848
"""
4949
AlphaOmega MPX file format 4 reader. Handles several segments.
50-
51-
A segment is a continuous record (when record starts/stops).
52-
50+
A segment is a continuous recording (when recording starts/stops).
5351
Only files in current `dirname` are loaded, subfolders are not explored.
5452
55-
:param dirname: folder from where to load the data
56-
:type dirname: str or Path-like
57-
:param lsx_files: list of lsx files in `dirname` referencing mpx files to
58-
load (optional). If None (default), read all mpx files in `dirname`
59-
:type lsx_files: list of strings or None
60-
:param prune_channels: if True removes the empty channels, defaults to True
61-
:type prune_channels: bool
62-
63-
.. warning::
53+
Parameters
54+
----------
55+
dirname: str | Path
56+
The folder from which the data will be loaded
57+
lsx_files: list[str] | None, default: None
58+
List of lsx files in `dirname` referencing mpx files to load (optional)
59+
If None all mpx files will be read
60+
prune_channels: bool, default: True
61+
If True removes the empty channels
62+
63+
Notes
64+
-----
6465
Because channels must be gathered into coherent streams, channels names
6566
**must** be the default channel names in AlphaRS or Alpha LAB SNR
6667
software.

neo/rawio/axographrawio.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -174,52 +174,50 @@ class AxographRawIO(BaseRawIO):
174174
"""
175175
RawIO class for reading AxoGraph files (.axgd, .axgx)
176176
177-
Args:
178-
filename (string):
179-
File name of the AxoGraph file to read.
180-
force_single_segment (bool):
181-
Episodic files are normally read as multi-Segment Neo objects. This
182-
parameter can force AxographRawIO to put all signals into a single
183-
Segment. Default: False.
184-
185-
Example:
177+
Parameters
178+
----------
179+
filename: str
180+
File name of the AxoGraph file to read.
181+
force_single_segment: bool, default: False
182+
Episodic files are normally read as multi-Segment Neo objects. This
183+
parameter can force AxographRawIO to put all signals into a single
184+
Segment.
185+
186+
Examples
187+
--------
186188
>>> import neo
187-
>>> r = neo.rawio.AxographRawIO(filename=filename)
188-
>>> r.parse_header()
189-
>>> print(r)
189+
>>> reader = neo.rawio.AxographRawIO(filename=filename)
190+
>>> reader.parse_header()
191+
>>> print(reader)
190192
191193
>>> # get signals
192-
>>> raw_chunk = r.get_analogsignal_chunk(
193-
... block_index=0, seg_index=0,
194-
... i_start=0, i_stop=1024,
195-
... channel_names=channel_names)
196-
>>> float_chunk = r.rescale_signal_raw_to_float(
197-
... raw_chunk,
198-
... dtype='float64',
199-
... channel_names=channel_names)
194+
>>> raw_chunk = reader.get_analogsignal_chunk(block_index=0,
195+
... seg_index=0,
196+
... i_start=0,
197+
... i_stop=1024,
198+
... channel_names=channel_names)
199+
200+
>>> float_chunk = r.rescale_signal_raw_to_float(raw_chunk,
201+
... dtype='float64',
202+
... channel_names=channel_names)
200203
>>> print(float_chunk)
201204
202205
>>> # get event markers
203-
>>> ev_raw_times, _, ev_labels = r.get_event_timestamps(
204-
... event_channel_index=0)
205-
>>> ev_times = r.rescale_event_timestamp(
206-
... ev_raw_times, dtype='float64')
206+
>>> ev_raw_times, _, ev_labels = reader.get_event_timestamps(event_channel_index=0)
207+
>>> ev_times = reader.rescale_event_timestamp(ev_raw_times, dtype='float64')
207208
>>> print([ev for ev in zip(ev_times, ev_labels)])
208209
209210
>>> # get interval bars
210-
>>> ep_raw_times, ep_raw_durations, ep_labels = r.get_event_timestamps(
211-
... event_channel_index=1)
212-
>>> ep_times = r.rescale_event_timestamp(
213-
... ep_raw_times, dtype='float64')
214-
>>> ep_durations = r.rescale_epoch_duration(
215-
... ep_raw_durations, dtype='float64')
211+
>>> ep_raw_times, ep_raw_durations, ep_labels = reader.get_event_timestamps(event_channel_index=1)
212+
>>> ep_times = reader.rescale_event_timestamp(ep_raw_times, dtype='float64')
213+
>>> ep_durations = reader.rescale_epoch_duration(ep_raw_durations, dtype='float64')
216214
>>> print([ep for ep in zip(ep_times, ep_durations, ep_labels)])
217215
218216
>>> # get notes
219-
>>> print(r.info['notes'])
217+
>>> print(reader.info['notes'])
220218
221219
>>> # get other miscellaneous info
222-
>>> print(r.info)
220+
>>> print(reader.info)
223221
"""
224222

225223
name = "AxographRawIO"

neo/rawio/axonarawio.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,36 @@
3232

3333
class AxonaRawIO(BaseRawIO):
3434
"""
35-
Class for reading raw, continuous data from the Axona dacqUSB system:
35+
Class for reading raw, continuous data from the Axona dacqUSB system
36+
37+
Parameters
38+
----------
39+
filename: str
40+
The name of the *.bin file containing the data
41+
42+
Notes
43+
-----
44+
3645
http://space-memory-navigation.org/DacqUSBFileFormats.pdf
3746
3847
The raw data is saved in .bin binary files with an accompanying .set
3948
file about the recording setup (see the above manual for details).
4049
41-
Usage::
42-
43-
import neo.rawio
44-
r = neo.rawio.AxonaRawIO(filename=os.path.join(dir_name, base_filename))
45-
r.parse_header()
46-
print(r)
47-
raw_chunk = r.get_analogsignal_chunk(block_index=0, seg_index=0,
48-
i_start=0, i_stop=1024,
49-
channel_names=channel_names)
50-
float_chunk = reader.rescale_signal_raw_to_float(
51-
raw_chunk, dtype='float64',
52-
channel_indexes=[0, 3, 6]
53-
)
50+
Examples
51+
--------
52+
53+
>>> import neo.rawio
54+
>>> r = neo.rawio.AxonaRawIO(filename=os.path.join(dir_name, base_filename))
55+
>>> r.parse_header()
56+
>>> print(r)
57+
>>> raw_chunk = r.get_analogsignal_chunk(block_index=0,
58+
seg_index=0,
59+
i_start=0,
60+
i_stop=1024,
61+
channel_names=channel_names)
62+
>>> float_chunk = reader.rescale_signal_raw_to_float(raw_chunk,
63+
dtype='float64',
64+
channel_indexes=[0, 3, 6])
5465
5566
"""
5667

neo/rawio/axonrawio.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@
5353

5454

5555
class AxonRawIO(BaseRawIO):
56+
"""
57+
Class for Class for reading data from pCLAMP and AxoScope files (.abf version 1 and 2)
58+
59+
Parameters
60+
----------
61+
filename: str, default: ''
62+
The *.abf file to be read
63+
64+
Notes
65+
-----
66+
This code is a port of abfload and abf2load written in Matlab (BSD-2-Clause licence) by
67+
Copyright (c) 2009, Forrest Collman, [email protected]
68+
Copyright (c) 2004, Harald Hentschke
69+
70+
Examples
71+
--------
72+
73+
>>> import neo.rawio
74+
>>> reader = neo.rawio.AxonRawIO(filename='mydata.abf')
75+
>>> reader.parse_header()
76+
>>> print(reader)
77+
78+
"""
5679
extensions = ["abf"]
5780
rawmode = "one-file"
5881

0 commit comments

Comments
 (0)