bioevents package

Submodules

bioevents.colors module

class bioevents.colors.Colors[source]

Bases: object

BLUE1: str = '#6dc5d5'

bioevents.event_handling module

class bioevents.event_handling.Event(on, off=None, tolerances=None)[source]

Bases: object

abuts(other)[source]

Determines whether the onset of one event is the offset of the other

default_duration = 1
property duration
classmethod from_duration(on, duration, tolerances=None)[source]
property off
property on
overlaps(other)[source]

Determines whether this event “overlaps” another, based on various criteria.

Notes

It’s important to note that this overlap is not necessarily a “symmetrical” operation. Because the duration and tolerances of THIS event are used, self.overlaps(other) may differ from other.overlaps(self). This is by design, given that a “reference” or “truth” event should govern the acceptance criteria of “predicted” event annotations, and not the other way around.

property tolerances
class bioevents.event_handling.EventClassSeries(event_stack: Dict[IntEnum, EventSeries], missing_enum: Optional[IntEnum] = None)[source]

Bases: EventStack

A special type of EventStack wherein every timestamp is expected to have one and only one class

Notes

Useful for performing class confusion or agreement analytic, such as with hypnogram annotations

as_array(round_method_on=<ufunc 'ceil'>, round_method_off=<ufunc 'floor'>)[source]

Export all events as a list of classes

epoch_confusion_matrix(other, normalize=None)[source]

Generates a confusion matrix with ‘other’, epoch-by-epoch via boolean logic

Parameters:
Returns:

mat

Return type:

pd.DataFrame

event_confusion_matrix(other, assimilate_events=True)[source]

Generate a class-wise confusion matrix with ‘other’

Parameters:
  • other (EventClassSeries) –

  • assimilate_events (Optional(bool), default=True) – If true, any overlapping Events from either series will be counted as one.

Returns:

mat

Return type:

pd.DataFrame

classmethod from_array(class_array, sampling_rate: float = 1.0)[source]

Initialize from a 1-D array of classes

class bioevents.event_handling.EventSeries(events, duration=None, sampling_rate: float = 1.0)[source]

Bases: list

append(item)[source]

Overrides built-in default to make sure the Event is concurrent with this series

as_bools(round_method_on=<ufunc 'ceil'>, round_method_off=<ufunc 'floor'>)[source]

Converts the Events to a boolean array, using parameterizable rounding methods

as_dataframe()[source]

Export events to a DataFrame

compute_agreement(other, normalize=False)[source]

Computes an agreement matrix with the given EventSeries

Parameters:
  • other (EventSeries) –

  • normalize (Optional(bool), default=False) – Normalize results rows by the number of events in the respective “reference” series

Returns:

mat – 2 x 2 agreement matrix

Return type:

pd.DataFrame

debounce(persistence_period: float, min_duration: float) EventSeries[source]

Debounce the given signal to remove short events and merge close ones

Parameters:
  • persistence_period (float) – merge any two events separated by less than this number (of samples)

  • min_duration (float) – after merging close events, remove all events under this duration (in samples)

Returns:

debounced

Return type:

EventSeries

References

Description of debouncing applied in engineering context: https://my.eng.utah.edu/~cs5780/debouncing.pdf

property duration
epoch_confusion_matrix(other, normalize=None)[source]

Generates a confusion matrix with the given EventSeries epoch-by-epoch via boolean logic

Parameters:
  • other (EventSeries) –

  • normalize (Optional(bool), default=False) –

Returns:

mat

Return type:

pd.DataFrame

event_confusion_matrix(other, normalize=None, assimilate_events=True)[source]

Generates a confusion matrix with the given EventSeries via Event-wise logic

Parameters:
  • other (EventSeries) –

  • normalize (Optional(bool), default=False) –

  • assimilate_events (Optional(bool), default=True) – If true, any overlapping Events from either series will be counted as one.

Returns:

mat

Return type:

pd.DataFrame

extend(item)[source]

Overrides built-in default to make sure the Events are concurrent with this series

classmethod from_bools(bools, sampling_rate: float = 1.0)[source]

Converts the given boolean array into a series of discrete Events

is_compatible(item)[source]

See if self vs. other functions can be used with this item

plot(bottom=0, top=1, color=None, as_seconds=True)[source]

Simple plot with events filled between the given y values

resample(sampling_rate)[source]
property sampling_rate
set_tolerances(vals)[source]

Iteratively set the tolerances for all Events to the given vals

spans_event(item)[source]

See if the given event falls within the time bounds of this series

trim(start: Optional[int] = None, end: Optional[int] = None)[source]
class bioevents.event_handling.EventStack(event_stack: Dict[IntEnum, EventSeries])[source]

Bases: dict

KEY_ASSIGNED_ENUM = 'AssignedEnum'
KEY_DURATION = 'duration'
KEY_EVENT_STACK = 'event_stack'
KEY_META = 'meta'
KEY_SAMPLING_RATE = 'sampling_rate'
property classes
property duration
classmethod from_dict(data: dict, intenum: IntEnum) EventStack[source]
classmethod from_string_keys(event_stack: Dict[str, EventSeries])[source]
plot()[source]

Stacks individual series onto the same plot

classmethod read_json(filepath, intenum: IntEnum)[source]

Construct from the given filepath

resample(sampling_rate)[source]

Make a new EventStack with resampled EventSeries values

property sampling_rate
set_tolerances(vals)[source]

Iteratively set the tolerances of all Events within all EventSeries

to_dict() dict[source]
trim(start: Optional[int] = None, end: Optional[int] = None)[source]

Make a new, trimmed version of this EventStack

write_json(filepath)[source]

Serializes and exports event data to a JSON file

Notes

We’re not exporting any OverlapTolerances here… seems like the kind of thing you’d only want to do explicitly during analysis anyway

class bioevents.event_handling.MissingDataLabels(value)[source]

Bases: IntEnum

An enumeration.

ARTIFACT = -2
DISAGREE = -3
MISSING = 0
UNSCORABLE = -1
class bioevents.event_handling.OverlapTolerances(diff_on=inf, diff_off=inf, ratio_on=inf, ratio_off=inf)[source]

Bases: object

class bioevents.event_handling.SeizureEvent(on, off=None, tolerances=None)[source]

Bases: Event

default_duration = 120
bioevents.event_handling.confusion_matrix(true, pred, normalize=None)[source]

Notes

This is a paraphrased implementation of scikit-learn’s. We can use that method, but this allows our footprint and dependencies to remain minimal.

bioevents.hypnogram module

Module contents

Top-level package for BioEvents.