Skip to content

Commit ceee09f

Browse files
authored
Merge pull request #1462 from zm711/core-docstrings
Switch Over Core Docstrings to New Style
2 parents 536505d + e5e0a31 commit ceee09f

File tree

9 files changed

+615
-336
lines changed

9 files changed

+615
-336
lines changed

neo/core/dataobject.py

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ class DataObject(BaseNeo, pq.Quantity):
141141
This is the base class from which all objects containing data inherit
142142
It contains common functionality for all those objects and handles array_annotations.
143143
144+
Parameters
145+
----------
146+
name: str | None, default: None
147+
Name of the Neo object
148+
description: str | None, default: None
149+
Human readable string description of the Neo object
150+
array_annotations: dict | None, default: None
151+
Dictionary containing arrays / lists which annotate individual data points of the Neo object.
152+
**annotations: dict | None:
153+
Other keyword annotations to be included
154+
155+
Notes
156+
-----
157+
144158
Common functionality that is not included in BaseNeo includes:
145159
- duplicating with new data
146160
- rescaling the object
@@ -154,13 +168,6 @@ class DataObject(BaseNeo, pq.Quantity):
154168
They can contain the same data types as regular annotations, but are always represented
155169
as numpy arrays of the same length as the number of data points of the annotated neo object.
156170
157-
Args:
158-
name (str, optional): Name of the Neo object
159-
description (str, optional): Human readable string description of the Neo object
160-
file_origin (str, optional): Origin of the data contained in this Neo object
161-
array_annotations (dict, optional): Dictionary containing arrays / lists which annotate
162-
individual data points of the Neo object.
163-
kwargs: regular annotations stored in a separate annotation dictionary
164171
"""
165172

166173
def __init__(self, name=None, description=None, file_origin=None, array_annotations=None, **annotations):
@@ -182,8 +189,13 @@ def array_annotate(self, **array_annotations):
182189
Add array annotations (annotations for individual data points) as arrays to a Neo data
183190
object.
184191
185-
Example:
186-
192+
Parameters
193+
----------
194+
**array_annotations: dict
195+
Series of keyword annotations to add to the object
196+
197+
Examples
198+
--------
187199
>>> obj.array_annotate(code=['a', 'b', 'a'], category=[2, 1, 1])
188200
>>> obj.array_annotations['code'][1]
189201
'b'
@@ -194,12 +206,19 @@ def array_annotate(self, **array_annotations):
194206
def array_annotations_at_index(self, index):
195207
"""
196208
Return dictionary of array annotations at a given index or list of indices
197-
:param index: int, list, numpy array: The index (indices) from which the annotations
198-
are extracted
199-
:return: dictionary of values or numpy arrays containing all array annotations
200-
for given index/indices
201209
202-
Example:
210+
Parameters
211+
----------
212+
index: int | list | np.ndarray
213+
The index (indices) from which the annotations are extracted
214+
215+
Returns
216+
-------
217+
index_annotations: dict
218+
Dictionary of values or numpy arrays containing all array annotations for given index/indices
219+
220+
Examples
221+
--------
203222
>>> obj.array_annotate(code=['a', 'b', 'a'], category=[2, 1, 1])
204223
>>> obj.array_annotations_at_index(1)
205224
{code='b', category=1}
@@ -228,10 +247,22 @@ def array_annotations_at_index(self, index):
228247
def _merge_array_annotations(self, other):
229248
"""
230249
Merges array annotations of 2 different objects.
250+
251+
Parameters
252+
----------
253+
other: any
254+
The annotation to attemp to merge
255+
256+
Returns
257+
-------
258+
merged_array_annotations: dict
259+
The merged annotations
260+
261+
Notes
262+
-----
231263
The merge happens in such a way that the result fits the merged data
232264
In general this means concatenating the arrays from the 2 objects.
233265
If an annotation is only present in one of the objects, it will be omitted
234-
:return Merged array_annotations
235266
"""
236267

237268
merged_array_annotations = {}
@@ -274,9 +305,23 @@ def _merge_array_annotations(self, other):
274305
def rescale(self, units, dtype=None):
275306
"""
276307
Return a copy of the object converted to the specified units.
277-
The `dtype` argument exists only for backward compatibility within quantities, see
308+
309+
Parameters
310+
----------
311+
units: quantity unit
312+
The units to convert the object to
313+
dtype: a numpy dtype
314+
Only exists for backward compatibility see [1]
315+
316+
Returns
317+
-------
318+
self.copy(): Any
319+
A copy of the object with the desired units
320+
321+
Notes
322+
-----
323+
[1] The `dtype` argument exists only for backward compatibility within quantities, see
278324
https://github.com/python-quantities/python-quantities/pull/204
279-
:return: Copy of self with specified units
280325
"""
281326

282327
# Use simpler functionality, if nothing will be changed
@@ -309,6 +354,16 @@ def as_array(self, units=None):
309354
"""
310355
Return the object's data as a plain NumPy array.
311356
357+
Parameters
358+
----------
359+
units: quantities units | None, default: None
360+
The data return as a np.ndarray with units requested
361+
362+
Returns
363+
-------
364+
data_array: np.ndarray
365+
The data as an array
366+
312367
If `units` is specified, first rescale to those units.
313368
"""
314369
if units:
@@ -375,7 +430,7 @@ def __deepcopy__(self, memo):
375430
return new_obj
376431

377432

378-
class ArrayDict(dict):
433+
class ArrayDict(dict):
379434
"""Dictionary subclass to handle array annotations
380435
381436
When setting `obj.array_annotations[key]=value`, checks for consistency

neo/core/epoch.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ class Epoch(DataObject):
5151
"""
5252
Array of epochs.
5353
54+
Parameters
55+
----------
56+
times: quantity array 1D | numpy array 1D | list | None, default: None
57+
The start times of each time period.
58+
If None, generates an empty array
59+
durations: quantity array 1D | numpy array 1D | list | quantity scalar | float | None, default: None
60+
The length(s) of each time period.
61+
If a scalar/float, the same value is used for all time periods.
62+
If None, generates an empty array
63+
labels: numpy.array 1D dtype='U' | list | None, default: None
64+
Names or labels for the time periods.
65+
If None, creates an empty array
66+
units: quantity units | str | None, default: None
67+
The units for the time
68+
Required if the times is a list or NumPy, not required if it is a :class:`Quantity`
69+
name: (str) A label for the dataset,
70+
description: (str) Text description,
71+
file_origin: (str) Filesystem path or URL of the original data file.
72+
5473
*Usage*::
5574
5675
>>> from neo.core import Epoch
@@ -69,20 +88,10 @@ class Epoch(DataObject):
6988
array(['btn0', 'btn1', 'btn2'],
7089
dtype='<U4')
7190
72-
*Required attributes/properties*:
73-
:times: (quantity array 1D, numpy array 1D or list) The start times
74-
of each time period.
75-
:durations: (quantity array 1D, numpy array 1D, list, quantity scalar or float)
76-
The length(s) of each time period.
77-
If a scalar/float, the same value is used for all time periods.
78-
:labels: (numpy.array 1D dtype='U' or list) Names or labels for the time periods.
79-
:units: (quantity units or str) Required if the times is a list or NumPy
80-
array, not if it is a :class:`Quantity`
91+
8192
8293
*Recommended attributes/properties*:
83-
:name: (str) A label for the dataset,
84-
:description: (str) Text description,
85-
:file_origin: (str) Filesystem path or URL of the original data file.
94+
8695
8796
*Optional attributes/properties*:
8897
:array_annotations: (dict) Dict mapping strings to numpy arrays containing annotations \

neo/core/event.py

Lines changed: 81 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,40 +47,46 @@ def _new_event(
4747

4848
class Event(DataObject):
4949
"""
50-
Array of events.
51-
52-
*Usage*::
53-
54-
>>> from neo.core import Event
55-
>>> from quantities import s
56-
>>> import numpy as np
57-
>>>
58-
>>> evt = Event(np.arange(0, 30, 10)*s,
59-
... labels=np.array(['trig0', 'trig1', 'trig2'],
60-
... dtype='U'))
61-
>>>
62-
>>> evt.times
63-
array([ 0., 10., 20.]) * s
64-
>>> evt.labels
65-
array(['trig0', 'trig1', 'trig2'],
50+
Array of events which are the start times of events along with the labels
51+
of the events
52+
53+
Parameters
54+
----------
55+
times: quantity array 1d | list
56+
The times of the events
57+
labels: numpy.ndarray 1d dtype='U' | list
58+
Names or labels for the events
59+
units: quantity units | None, default: None
60+
If times are list the units of the times
61+
If times is a quantity array this is ignored
62+
name: str | None, default: None
63+
An optional label for the dataset
64+
description: str | None, default: None
65+
An optional text descriptoin of the dataset
66+
file_orgin: str | None, default: None
67+
The filesystem path or url of the original data file
68+
array_annotations: dict | None, default: None
69+
Dict mapping strings to numpy arrays containing annotations for all data points
70+
**annotations: dict
71+
Additional user specified metadata stored in the annotations attribue
72+
73+
Examples
74+
--------
75+
76+
>>> from neo.core import Event
77+
>>> from quantities import s
78+
>>> import numpy as np
79+
>>>
80+
>>> evt = Event(np.arange(0, 30, 10)*s,
81+
... labels=np.array(['trig0', 'trig1', 'trig2'],
82+
... dtype='U'))
83+
>>>
84+
>>> evt.times
85+
array([ 0., 10., 20.]) * s
86+
>>> evt.labels
87+
array(['trig0', 'trig1', 'trig2'],
6688
dtype='<U5')
6789
68-
*Required attributes/properties*:
69-
:times: (quantity array 1D) The time of the events.
70-
:labels: (numpy.array 1D dtype='U' or list) Names or labels for the events.
71-
72-
*Recommended attributes/properties*:
73-
:name: (str) A label for the dataset.
74-
:description: (str) Text description.
75-
:file_origin: (str) Filesystem path or URL of the original data file.
76-
77-
*Optional attributes/properties*:
78-
:array_annotations: (dict) Dict mapping strings to numpy arrays containing annotations \
79-
for all data points
80-
81-
Note: Any other additional arguments are assumed to be user-specific
82-
metadata and stored in :attr:`annotations`.
83-
8490
"""
8591

8692
_parent_objects = ("Segment",)
@@ -212,9 +218,24 @@ def _repr_pretty_(self, pp, cycle):
212218
def rescale(self, units, dtype=None):
213219
"""
214220
Return a copy of the :class:`Event` converted to the specified units
221+
222+
Parameters
223+
----------
224+
units: quantity units
225+
The units to convert the Event to
226+
dtype: None
227+
Exists for backward compatiblity within quantities see Notes for more info
228+
229+
Returns
230+
-------
231+
obj: neo.core.Event
232+
A copy of the event with the specified units
233+
234+
Notes
235+
-----
215236
The `dtype` argument exists only for backward compatibility within quantities, see
216237
https://github.com/python-quantities/python-quantities/pull/204
217-
:return: Copy of self with specified units
238+
218239
"""
219240
# Use simpler functionality, if nothing will be changed
220241
dim = pq.quantity.validate_dimensionality(units)
@@ -235,12 +256,19 @@ def times(self):
235256

236257
def merge(self, other):
237258
"""
238-
Merge the another :class:`Event` into this one.
239-
240-
The :class:`Event` objects are concatenated horizontally
259+
Merge another :class:`Event` into this one.
260+
261+
Parameter
262+
---------
263+
other: neo.core.Event
264+
The `Event` to merge into this one
265+
266+
Notes
267+
-----
268+
* The :class:`Event` objects are concatenated horizontally
241269
(column-wise), :func:`np.hstack`).
242270
243-
If the attributes of the two :class:`Event` are not
271+
* If the attributes of the two :class:`Event` are not
244272
compatible, and Exception is raised.
245273
"""
246274
othertimes = other.times.rescale(self.times.units)
@@ -319,10 +347,22 @@ def duplicate_with_new_data(self, times, labels, units=None):
319347

320348
def time_slice(self, t_start, t_stop):
321349
"""
322-
Creates a new :class:`Event` corresponding to the time slice of
323-
the original :class:`Event` between (and including) times
324-
:attr:`t_start` and :attr:`t_stop`. Either parameter can also be None
325-
to use infinite endpoints for the time interval.
350+
Creates a new `Event` corresponding to the time slice of the original `Event` between (and including) times
351+
`t_start` and `t_stop`.
352+
353+
Parameters
354+
----------
355+
t_start: float | None
356+
The starting time of the time slice
357+
If None will use -np.inf for the starting time
358+
t_stop: float | None
359+
The stopping time of the time slice
360+
If None will use np.inf for the stopping time
361+
362+
Returns
363+
-------
364+
new_evt: neo.core.Event
365+
The new `Event` limited by the time points
326366
"""
327367
_t_start = t_start
328368
_t_stop = t_stop

0 commit comments

Comments
 (0)