Pinnacle
openseize.file_io.annotations.Pinnacle
Bases: Annotations
A reader of Pinnacle Technologies© annotation csv files.
This annotation reader's 'read' method reads annotations into a list of Annotation dataclass instances. Each Annotation dataclass has the following attributes:
- label: A string label given to an annotation.
- time: Time, relative to recording start, in secs of an annotation.
- duration: The duration in seconds of an annotation.
- channel: The channel(s) an annotation was detected on.
Attributes:
Name | Type | Description |
---|---|---|
path |
Python path instance to Pinnacle© file. |
|
kwargs |
Any valid kwarg for csv.DictReader initializer. |
Examples:
>>> # read the annotations from the demo annotation file
>>> from openseize.demos import paths
>>> filepath = paths.locate('annotations_001.txt')
>>> from openseize.io.annotations import Pinnacle
>>> # read the 'rest' and 'exploring' annotations
>>> with Pinnacle(filepath, start=6) as pinnacle:
>>> annotations = pinnacle.read(labels=['rest', 'exploring'])
>>> # get the first annotation and print it
>>> print(annotations[0])
>>> # print the first annotations duration
>>> print(annotations[0].duration)
Source code in openseize/file_io/annotations.py
open(path, start=0, delimiter='\t', **kwargs)
Opens a Pinnacle formatted CSV annotation file.
Called by 'Annotations.init' to initialize this Pinnacle context manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
A annotation file path location. |
required |
start |
int
|
The row number of the column headers in the file. |
0
|
delimiter |
str
|
The string character separating columns in the file. |
'\t'
|
**kwargs |
Any valid keyword argument for CSV.DictReader builtin. |
{}
|
Returns:
Type | Description |
---|---|
IO[str]
|
A tuple (file_obj, DictReader) where file_obj is the open file |
Iterable[dict]
|
instance and DictReader is the builtin csv DictReader. |
Source code in openseize/file_io/annotations.py
label(row)
time(row)
duration(row)
Measures the duration of an annotation for a row in this file.
Source code in openseize/file_io/annotations.py
Bases and Mixins
openseize.file_io.bases.Annotations
Bases: abc.ABC
Abstract base class for reading annotation data.
Annotation data may be stored in a variety of formats; csv files, pickled objects, etc. This ABC defines all annotation readers as context managers that read annotation files. Inheritors must override: open, label, time, duration and channel methods.
Attributes:
Name | Type | Description |
---|---|---|
path |
Python path instance to an annotation file. |
|
**kwargs |
Any valid kwarg for concrete 'open' method. |
Source code in openseize/file_io/bases.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
__init__(path, **kwargs)
Initialize this Annotations reader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
typing.Union[str, Path]
|
A path location to an annotation file. |
required |
**kwargs |
Any valid kwarg for a subclasses 'open' method. |
{}
|
Source code in openseize/file_io/bases.py
read(labels=None)
Reads annotations with labels to a list of Annotation instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels |
typing.Optional[typing.Sequence[str]]
|
A sequence of annotation string labels for which Annotation instances will be returned. If None, return all. |
None
|
Returns:
Type | Description |
---|---|
typing.List[Annotation]
|
A list of Annotation dataclass instances (see Annotation). |
Source code in openseize/file_io/bases.py
openseize.file_io.bases.Annotation
dataclass
An object for storing a predefined set of annotation attributes that can be updated with user defined attributes after object creation.
Attributes:
Name | Type | Description |
---|---|---|
label |
str
|
The string name of this annotation. |
time |
float
|
The time this annotation was made in seconds relative to the recording start. |
duration |
float
|
The duration of this annotation in seconds. |
channel |
Any
|
The string name or integer index of the channel this annotation created from. |