Biodata

class biobabel.Biodata

This is the core object of the Biobabel logic. This object represents a collection of streams of physiological data (channels) as well as some set of triggers (event markers). We have methods to print() and display() the data.

add_channel(hdrdat)

Create a new channel with specified header information and data.

Parameters:

hdrdat – is a tuple (hdr,dat) where hdr is a dict containing the header and dat is the data stream itself (a one-dimensional array).

add_marker(m, timepoints)

Add a marker with a given label m and set of time points.

Parameters:
  • m – str, the name of the marker to be added

  • timepoints – float list, the time points (in seconds) indicated by this new marker. Or if only a single time point, can be entered as a single float.

add_meta(k, v, replace=True)

Add metadata.

Parameters:
  • k – str, the metadata key

  • v – str, the metadata value

  • replace – bool, if True, replace any existing metadata key value, otherwise add a new key

Example:

biodata.add_meta('date','2024-03-22')
clear()

Clear all data currently in the object

clear_markers()

Remove all markers

copy()

Create a deep copy of this data object.

crop(tfrom=None, tend=None)

Crop the data to a given time range.

Parameters:
  • tfrom – float, number of seconds that should be clipped from the beginning of the data streams

  • tend – float, the end point to which all data should be clipped.

Example:

biodata.clip(5,12) # will clip all data before 5 seconds and after 12 seconds (yielding typically a 7 second data file)
drop(what)

Drop channels.

Parameters:

what – str or list of str, an ID or a list of IDs for the channels to be dropped.

find(crit={})

Find all channels that satisfy the metadata criteria and return them as (hdr,dat)

Parameters:

crit – a dictionary containing key-value pairs for searching the channels.

Returns:

the channels (hdr,dat) satisfying the search criteria.

Example:

biodata.find({'modality':'ecg'}) # will return all channels where modality equals ecg
find_channels(crit={})

Find the channel id’s satisfying certain criteria.

Parameters:

crit – a dictionary containing key-value pairs for searching the channels.

Returns:

the channel IDs satisfying the search criteria.

Return type:

str list

Example:

biodata.find_channels({'modality':'ecg'}) # will return all channel IDs for channels whose modality equals ecg
get(chid)

Get a particular channel data

Parameters:

chid – str, the channel ID

Returns:

(hdr,dat) tuple containing the header and data for the given channel, respectively.

get_closest_sample(chid, t)

Find the sample closest in time to the point t.

Parameters:
  • chid – str, the channel ID

  • t – float, the time point to which we want to find the closest sample.

Returns:

the sample index closest to the given time value

Return type:

int

get_duration(chid=None)

Get the duration of a channel in seconds

Parameters:

chid – str, the channel ID

Returns:

the duration in seconds

Return type:

float

get_marker(m)

For a given marker, returns a list of time points stored under that marker.

Parameters:

m – str, the marker name

Returns:

the list of time points indicated by that marker, in seconds.

Return type:

float list

get_markers()

Returns a list of names of markers.

Returns:

list of marker names

Return type:

str list

get_participants()

Return a list of participants in the current object

Returns:

a list of participant IDs

Return type:

str list

get_time(chid)

Given a channel, reproduce a time vector

Parameters:

chid – str, the channel ID

Returns:

a list of timestamps of the same length as the data, starting at zero.

Return type:

numpy.array of floats

html_report()

Return a simple quick-and-dirty HTML rendition of the data.

Returns:

standalone HTML code containing base64-encoded images

Return type:

str

merge(other)

Merge data from another biodata object into the current object.

Parameters:

other – Biodata, another object to be merged into the current object

plot(channels=None, figsize=(12, 7), timerange=None, show=True, markers=True)

Produce a simple inspection plot of the entirety of the data. The channels argument can indicate a channel or a list of channels to be plotted.

Parameters:
  • channels – list of str, the channel ids for the data you want to plot

  • figsize – the desired figure size in inches (as specified by matplotlib)

  • timerange – a tuple indicating the start and end times of the desired plot time range, or None to plt all

  • show – bool, whether to call plot.show() or not when completed

  • markers – whether to draw tempoeral position of embedded markers

print()

Print a human readable summary of the data contained.

rename(old_id, new_id)

Rename channels

Parameters:
  • old_id – str, the current channel ID

  • new_id – str, the desired new channel ID.

save(fname)

Save current data file in hdphysio5 format

Parameters:

fname – str, the filename of the file to be created.

At present, only saving in the native HDF5 is supported.

select(what)

Drop all but a select list of channels.

Parameters:

what – str or list of str, an ID or a list of IDs for the channels to be dropped.

Example:

biodata.select(['ecg','ppg']) # will drop all channels except `ecg` and `ppg`
summarize_channel(chid)

Return a human-readable summary of the channel indicated by the given id.

Parameters:

chid – str, channel id

Returns:

summary of the channel

Return type:

str

summary()

Return a human-readable summary of the current data (in str format).

Returns:

summary

Return type:

str

uniquefy(ident)

Return a channel id that is unique (does not exist yet), as close as possible to the given id.

Parameters:

ident – str, the id to start from

Returns:

a channel id that does not exist yet

Return type:

str

If ident is already unique, it will be returned.

update_channel(ident, specs)

Update the header of a particular channel.

Parameters:
  • ident – str, the channel ID to be modified

  • specs – dict, a list of key-values that should be changed in the meta data.

For example, update_channel(‘b_ecg’,{‘modality’:’eeg’}) will set the modality of the channel with ID ‘b_ecg’ (assuming it exists) to ‘eeg’, overriding any prior value.

Any existing metadata will be overwritten.