das.annot#

Utilities for dealing with annotations.

class das.annot.Events(data: Optional[Dict[str, List[float]]] = None, categories: Optional[Dict[str, str]] = None, add_names_from_categories: bool = True)[source]#

Utility class for dealing with annotations.

add_name(name, category='segment', times=None, overwrite: bool = False, append: bool = False, sort_after_append: bool = False)[source]#

[summary]

Parameters
  • name ([type]) – [description]

  • category (str, optional) – [description]. Defaults to ‘segment’.

  • times ([type], optional) – [description]. Defaults to None.

  • overwrite (bool, optional) – [description]. Defaults to False.

  • append (bool, optional) – [description]. Defaults to False.

  • sort_after_append (bool, optional) – [description]. Defaults to False.

add_time(name, start_seconds, stop_seconds=None)[source]#

[summary]

Parameters
  • name ([type]) – [description]

  • start_seconds ([type]) – [description]

  • stop_seconds ([type], optional) – [description]. Defaults to None.

delete_name(name)[source]#

[summary]

Parameters

name ([type]) – [description]

delete_range(name, t0, t1, strict: bool = True)[source]#

Deletes events within the range.

Need to start and stop after t0 and before t1 (non-inclusive bounds).

Parameters
  • name ([type]) – [description]

  • t0 ([type]) – [description]

  • t1 ([type]) – [description]

  • strict (bool) – if true, only matches events that start AND stop within the range, if false, matches events that start OR stop within the range

Returns

number of deleted events

Return type

int

filter_range(name, t0, t1, strict: bool = False)[source]#

Returns events within the range.

Need to start and stop after t0 and before t1 (non-inclusive bounds).

Parameters
  • name ([type]) – [description]

  • t0 ([type]) – [description]

  • t1 ([type]) – [description]

  • strict (bool) – if true, only matches events that start AND stop within the range, if false, matches events that start OR stop within the range

Returns

[N, 2] list of start_seconds and stop_seconds in the range

Return type

List[float]

classmethod from_dataset(ds)[source]#

[summary]

Parameters

ds ([type]) – [description]

Returns

[description]

Return type

[type]

classmethod from_df(df, possible_event_names: Optional[List] = None)[source]#

[summary]

Parameters
  • df (pd.DataFrame) – with columns name, start_seconds, end_seconds.

  • possible_event_names (list, optional) – [description]. Defaults to [].

Returns

[description]

Return type

Events

classmethod from_lists(names, start_seconds, stop_seconds, possible_event_names: Optional[List] = None)[source]#

[summary]

Parameters
  • names ([type]) – [description]

  • start_seconds ([type]) – [description]

  • stop_seconds ([type]) – [description]

  • possible_event_names (list, optional) – [description]. Defaults to [].

Returns

[description]

Return type

[type]

move_time(name, old_time, new_time)[source]#

[summary]

Parameters
  • name ([type]) – [description]

  • old_time ([type]) – [description]

  • new_time ([type]) – [description]

select_range(name: str, t0: Optional[float] = None, t1: Optional[float] = None, strict: bool = True)[source]#

Get indices of events within the range.

Need to start and stop after t0 and before t1 (non-inclusive bounds).

Parameters
  • name (str) – [description]

  • t0 (float, optional) – [description]

  • t1 (float, optional) – [description]

  • strict (bool, optional) – if true, only matches events that start AND stop within the range, if false, matches events that start OR stop within the range

Returns

List of indices of events within the range

Return type

List[uint]

to_dataset() xarray.core.dataset.Dataset[source]#

Returns an xarray dataset.

Returns

with the data arrays event_names and event_times.

Return type

xr.Dataset

to_df(preserve_empty: bool = True) pandas.core.frame.DataFrame[source]#

Convert to pandas.DataFrame

Parameters

preserve_empty (bool, optional) – In keeping with the convention that events have identical start and stop times and segments do not, empty events are coded with np.nan as both start and stop and empty segments are coded as np.nan as start and 0 as stop. from_df() will obey this convention - if both start and stop are np.nan, the name will be a segment, if only the start is np.nan (the stop does not matter), the name will be an event Defaults to True.

Returns

with columns name, start_seconds, stop_seconds, one row per event.

Return type

pandas.DataFrame