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:
- vital_sqi.data.signal_io.ECG_writer(signal_sqi, file_name, file_type, info=None)[source]
Writes the SignalSQI object to a file.
- 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:
- 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:
- Returns:
True if the file was successfully written, False otherwise.
- Return type:
- 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:
objectA class representing a signal with its associated Signal Quality Index (SQI) values, rules, and rule set for quality analysis.