Data I/O (vital_sqi.data)

Reading ECG/PPG recordings from disk and the in-memory SignalSQI container that pipelines write to.

Signal I/O

vital_sqi.data.signal_io.ECG_reader(file_name, file_type, channel_num=None, channel_name=None, sampling_rate=None, start_datetime=None)[source]

Reads ECG data from a specified file type and returns a SignalSQI object.

Parameters:
  • file_name (str) – Path to ECG file.

  • file_type (str) – Supported types include ‘edf’, ‘mit’ or ‘csv’.

  • channel_num (list, optional) – List of channel ids to read, starting from 0.

  • channel_name (list, optional) – List of channel names to read.

  • sampling_rate (int or float, optional) – Sampling rate of the signal.

  • start_datetime (str, optional) – Start datetime in ‘%Y-%m-%d %H:%M:%S.%f’ format.

Returns:

SignalSQI object.

Return type:

SignalSQI

vital_sqi.data.signal_io.ECG_writer(signal_sqi, file_name, file_type, info=None)[source]

Writes the SignalSQI object to a file.

Parameters:
  • signal_sqi (SignalSQI) – SignalSQI object containing signals, sampling rate, and sqi.

  • file_name (str) – Name of the file to write, with extension.

  • file_type (str) – Type of file (‘edf’, ‘mit’, ‘csv’).

  • info (list or dict, optional) – Additional header information.

vital_sqi.data.signal_io.PPG_reader(file_name, signal_idx, timestamp_idx, info_idx=[], timestamp_unit='ms', sampling_rate=None, start_datetime=None)[source]

Reads PPG data from a CSV file and returns a SignalSQI object.

This function extracts PPG signal data from a CSV file. It converts the timestamp column to pd.Timestamp format, based on the provided timestamp_unit, and generates timestamps accordingly if start_datetime is provided. If the sampling rate is not specified, it attempts to infer it based on the timestamps.

Parameters:
  • file_name (str) – Path to the PPG file (CSV format).

  • signal_idx (list) – List of indices or names indicating the columns with PPG signal data.

  • timestamp_idx (list) – List containing the index or name of the column with timestamp data.

  • info_idx (list, optional) – List of indices or names of columns with additional information. Default is an empty list.

  • timestamp_unit (str, optional) – Unit of timestamp in the file. Accepts “ms” (milliseconds) or “s” (seconds). Default is “ms”.

  • sampling_rate (int or float, optional) – Sampling rate of the PPG signal. If None, it will be inferred from the timestamps. Default is None.

  • start_datetime (str, optional) – Start datetime in ‘%Y-%m-%d %H:%M:%S.%f’ format. If None, the current time will be used.

Returns:

SignalSQI object containing the PPG signals, metadata, and timestamps.

Return type:

SignalSQI

Raises:

Exception – If there are issues reading the file or interpreting the timestamps.

vital_sqi.data.signal_io.PPG_writer(signal_sqi, file_name, file_type='csv')[source]

Writes PPG SignalSQI data to a specified file format.

This function exports the SignalSQI object containing PPG signal data to either a CSV or Excel file format. The output file includes timestamps and PPG signal values.

Parameters:
  • signal_sqi (SignalSQI) – SignalSQI object containing PPG signals, timestamps, and metadata.

  • file_name (str) – Absolute path for the output file, including the file extension.

  • file_type (str, optional) – Type of file to write. Options are “csv” (default) or “xlsx” for Excel format.

Returns:

True if the file was successfully written, False otherwise.

Return type:

bool

Raises:

Exception – If there are issues writing the file or converting data formats.

SignalSQI container

class vital_sqi.data.signal_sqi_class.SignalSQI(wave_type='ECG', signals=None, sampling_rate=None, start_datetime=None, info=None, sqis=None, rules=None, ruleset=None)[source]

Bases: object

A class representing a signal with its associated Signal Quality Index (SQI) values, rules, and rule set for quality analysis.

update_info(info)[source]

Update the info attribute.

Parameters:

info (list, dict, or pd.DataFrame) – Metadata information.

Returns:

Updated SignalSQI object.

Return type:

SignalSQI

update_sampling_rate(sampling_rate)[source]

Update the sampling rate.

Parameters:

sampling_rate (float) – Sampling rate of the signal.

Returns:

Updated SignalSQI object.

Return type:

SignalSQI

update_signals(signals)[source]

Update the signals attribute.

Parameters:

signals (pd.DataFrame) – DataFrame with signal data, where each column represents a channel.

Returns:

Updated SignalSQI object.

Return type:

SignalSQI

update_start_datetime(start_datetime)[source]

Update the start datetime.

Parameters:

start_datetime (datetime) – Starting datetime of the signal.

Returns:

Updated SignalSQI object.

Return type:

SignalSQI