Skip to content

Commit

Permalink
add more docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
zm711 committed Feb 7, 2024
1 parent e121ed9 commit 727d4f2
Show file tree
Hide file tree
Showing 25 changed files with 497 additions and 236 deletions.
20 changes: 9 additions & 11 deletions neo/io/basefromrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def read_block(
block_index: int, default: 0
In the case of multiple blocks, the block_index specifies which block to read
lazy: bool, default: False
Whether to read the block lazily (True) or load into memory (false)
Whether to read the block lazily (True) or load into memory (False)
create_group_across_segment: bool | dict | None, default: None
If True :
* Create a neo.Group to group AnalogSignal segments
Expand All @@ -98,9 +98,8 @@ def read_block(
* for example: create_group_across_segment = { 'AnalogSignal': True, 'SpikeTrain': False, ...}
signal_group_mode: 'split-all' | 'group-by-same-units' | None, default: None
This control behavior for grouping channels in AnalogSignal.
* 'split-all': each channel will give an AnalogSignal
* 'group-by-same-units' all channel sharing the same quantity units ar grouped in
a 2D AnalogSignal
* 'split-all': each channel will be give an AnalogSignal
* 'group-by-same-units' all channel sharing the same quantity units are grouped in a 2D AnalogSignal
By default None since the default is dependant on the IO
load_waveforms: bool, default: False
Determines whether SpikeTrains.waveforms is created
Expand Down Expand Up @@ -221,20 +220,19 @@ def read_segment(
Whether to lazily load the segment (True) or to load the segment into memory (False)
signal_group_mode: 'split-all' | 'group-by-same-units' | None, default: None
This control behavior for grouping channels in AnalogSignal.
* 'split-all': each channel will give an AnalogSignal
* 'group-by-same-units' all channel sharing the same quantity units ar grouped in
a 2D AnalogSignal
* 'split-all': each channel will be give an AnalogSignal
* 'group-by-same-units' all channel sharing the same quantity units are grouped in a 2D AnalogSignal
load_waveforms: bool, default: False
Determines whether SpikeTrains.waveforms is created
time_slice: tuple[float | None] | None, default: None
time_slice: tuple[quantity.Quantities | None] | None, default: None
Whether to take a time slice of the data
* None: indicates from beginning of segment to the end of the segment
* None: indicates from beginning of the segment to the end of the segment
* tuple: (t_start, t_stop) with t_start and t_stop being quantities in seconds
* tuple: (None, t_stop) indicates the beginning of the segment to t_stop
* tuple: (t_start, None) indicates from t_start to the end of the segment
strict_slicing: bool, default: True
Control if an error is raised or not when t_start or t_stop
is outside the real time range of the segment.
is outside of the real time range of the segment.
Returns
-------
Expand All @@ -243,7 +241,7 @@ def read_segment(
"""

if lazy:
assert time_slice is None, "For lazy=True you must specify time_slice when LazyObject.load(time_slice=...)"
assert time_slice is None, "For lazy=True you must specify a time_slice when LazyObject.load(time_slice=...)"

assert (
not load_waveforms
Expand Down
13 changes: 12 additions & 1 deletion neo/io/baseio.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def read(self, lazy: bool = False, **kargs):
Returns
------
block_list: list[neo.Block]
block_list: list[neo.core.Block]
Returns all the data from the file as Blocks
"""
if lazy and not self.support_lazy:
Expand All @@ -154,6 +154,17 @@ def read(self, lazy: bool = False, **kargs):
raise NotImplementedError

def write(self, bl, **kargs):
"""
Writes a given block if IO supports writing
Parameters
----------
bl: neo.core.Block
The neo Block to be written
kargs: dict
IO specific additional arguments
"""
if Block in self.writeable_objects:
if isinstance(bl, Sequence):
assert hasattr(self, "write_all_blocks"), (
Expand Down
25 changes: 13 additions & 12 deletions neo/rawio/alphaomegarawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,21 @@
class AlphaOmegaRawIO(BaseRawIO):
"""
AlphaOmega MPX file format 4 reader. Handles several segments.
A segment is a continuous record (when record starts/stops).
A segment is a continuous recording (when recording starts/stops).
Only files in current `dirname` are loaded, subfolders are not explored.
:param dirname: folder from where to load the data
:type dirname: str or Path-like
:param lsx_files: list of lsx files in `dirname` referencing mpx files to
load (optional). If None (default), read all mpx files in `dirname`
:type lsx_files: list of strings or None
:param prune_channels: if True removes the empty channels, defaults to True
:type prune_channels: bool
.. warning::
Parameters
----------
dirname: str | Path
The folder from which the data will be loaded
lsx_files: list[str] | None, default: None
List of lsx files in `dirname` referencing mpx files to load (optional)
If None all mpx files will be read
prune_channels: bool, default: True
If True removes the empty channels
Notes
-----
Because channels must be gathered into coherent streams, channels names
**must** be the default channel names in AlphaRS or Alpha LAB SNR
software.
Expand Down
62 changes: 30 additions & 32 deletions neo/rawio/axographrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,52 +174,50 @@ class AxographRawIO(BaseRawIO):
"""
RawIO class for reading AxoGraph files (.axgd, .axgx)
Args:
filename (string):
File name of the AxoGraph file to read.
force_single_segment (bool):
Episodic files are normally read as multi-Segment Neo objects. This
parameter can force AxographRawIO to put all signals into a single
Segment. Default: False.
Example:
Parameters
----------
filename: str
File name of the AxoGraph file to read.
force_single_segment: bool, default: False
Episodic files are normally read as multi-Segment Neo objects. This
parameter can force AxographRawIO to put all signals into a single
Segment.
Examples
--------
>>> import neo
>>> r = neo.rawio.AxographRawIO(filename=filename)
>>> r.parse_header()
>>> print(r)
>>> reader = neo.rawio.AxographRawIO(filename=filename)
>>> reader.parse_header()
>>> print(reader)
>>> # get signals
>>> raw_chunk = r.get_analogsignal_chunk(
... block_index=0, seg_index=0,
... i_start=0, i_stop=1024,
... channel_names=channel_names)
>>> float_chunk = r.rescale_signal_raw_to_float(
... raw_chunk,
... dtype='float64',
... channel_names=channel_names)
>>> raw_chunk = reader.get_analogsignal_chunk(block_index=0,
... seg_index=0,
... i_start=0,
... i_stop=1024,
... channel_names=channel_names)
>>> float_chunk = r.rescale_signal_raw_to_float(raw_chunk,
... dtype='float64',
... channel_names=channel_names)
>>> print(float_chunk)
>>> # get event markers
>>> ev_raw_times, _, ev_labels = r.get_event_timestamps(
... event_channel_index=0)
>>> ev_times = r.rescale_event_timestamp(
... ev_raw_times, dtype='float64')
>>> ev_raw_times, _, ev_labels = reader.get_event_timestamps(event_channel_index=0)
>>> ev_times = reader.rescale_event_timestamp(ev_raw_times, dtype='float64')
>>> print([ev for ev in zip(ev_times, ev_labels)])
>>> # get interval bars
>>> ep_raw_times, ep_raw_durations, ep_labels = r.get_event_timestamps(
... event_channel_index=1)
>>> ep_times = r.rescale_event_timestamp(
... ep_raw_times, dtype='float64')
>>> ep_durations = r.rescale_epoch_duration(
... ep_raw_durations, dtype='float64')
>>> ep_raw_times, ep_raw_durations, ep_labels = reader.get_event_timestamps(event_channel_index=1)
>>> ep_times = reader.rescale_event_timestamp(ep_raw_times, dtype='float64')
>>> ep_durations = reader.rescale_epoch_duration(ep_raw_durations, dtype='float64')
>>> print([ep for ep in zip(ep_times, ep_durations, ep_labels)])
>>> # get notes
>>> print(r.info['notes'])
>>> print(reader.info['notes'])
>>> # get other miscellaneous info
>>> print(r.info)
>>> print(reader.info)
"""

name = "AxographRawIO"
Expand Down
39 changes: 25 additions & 14 deletions neo/rawio/axonarawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,36 @@

class AxonaRawIO(BaseRawIO):
"""
Class for reading raw, continuous data from the Axona dacqUSB system:
Class for reading raw, continuous data from the Axona dacqUSB system
Parameters
----------
filename: str
The name of the *.bin file containing the data
Notes
-----
http://space-memory-navigation.org/DacqUSBFileFormats.pdf
The raw data is saved in .bin binary files with an accompanying .set
file about the recording setup (see the above manual for details).
Usage::
import neo.rawio
r = neo.rawio.AxonaRawIO(filename=os.path.join(dir_name, base_filename))
r.parse_header()
print(r)
raw_chunk = r.get_analogsignal_chunk(block_index=0, seg_index=0,
i_start=0, i_stop=1024,
channel_names=channel_names)
float_chunk = reader.rescale_signal_raw_to_float(
raw_chunk, dtype='float64',
channel_indexes=[0, 3, 6]
)
Examples
--------
>>> import neo.rawio
>>> r = neo.rawio.AxonaRawIO(filename=os.path.join(dir_name, base_filename))
>>> r.parse_header()
>>> print(r)
>>> raw_chunk = r.get_analogsignal_chunk(block_index=0,
seg_index=0,
i_start=0,
i_stop=1024,
channel_names=channel_names)
>>> float_chunk = reader.rescale_signal_raw_to_float(raw_chunk,
dtype='float64',
channel_indexes=[0, 3, 6])
"""

Expand Down
23 changes: 23 additions & 0 deletions neo/rawio/axonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@


class AxonRawIO(BaseRawIO):
"""
Class for Class for reading data from pCLAMP and AxoScope files (.abf version 1 and 2)
Parameters
----------
filename: str, default: ''
The *.abf file to be read
Notes
-----
This code is a port of abfload and abf2load written in Matlab (BSD-2-Clause licence) by
Copyright (c) 2009, Forrest Collman, [email protected]
Copyright (c) 2004, Harald Hentschke
Examples
--------
>>> import neo.rawio
>>> reader = neo.rawio.AxonRawIO(filename='mydata.abf')
>>> reader.parse_header()
>>> print(reader)
"""
extensions = ["abf"]
rawmode = "one-file"

Expand Down
Loading

0 comments on commit 727d4f2

Please sign in to comment.