Data handling
These moduls are responsible for data handling, including reading, saving, cutting and plotting.
pyPSG.IO.data_handling
- pyPSG.IO.data_handling.save_data(data, output_path)
Save a dictionary of data to a MATLAB .mat file.
- Parameters:
data (dict) – A dictionary containing variable names as keys and the corresponding data as values.
output_path (str) – Path where the .mat file will be saved. If it doesn’t end with ‘.mat’, it will be added automatically.
- Returns:
None
- pyPSG.IO.data_handling.save_data_csv(data, output_path)
Save dictionary contents into CSV files.
Parameters
- datadict
Dictionary containing biomarker data.
- output_dirstr
Directory where CSV files will be saved.
- pyPSG.IO.data_handling.save_data_mat(data, output_path)
Save a dictionary of data to a MATLAB .mat file.
- Parameters:
data (dict) – A dictionary containing variable names as keys and the corresponding data as values.
output_path (str) – Path where the .mat file will be saved. If it doesn’t end with ‘.mat’, it will be added automatically.
- Returns:
None
pyPSG.IO.edf_cut
- pyPSG.IO.edf_cut.cut_edf(edf_path, output_path, start_time, duration)
Extract a segment from an EDF file and save it as a new EDF file. Time is specified in sec.
- Parameters:
edf_path (str) – Path to the input EDF file.
output_path (str) – Path where the new EDF file will be saved.
start_time (float) – Start time of the segment to cut (in seconds).
duration (float) – Duration of the segment to cut (in seconds).
- Returns:
None
pyPSG.IO.edf_read
- pyPSG.IO.edf_read.read_edf_signals(edf_path, channel_names)
Load raw data from EDF file.
- Parameters:
edf_path (str) – Path to the EDF file.
channel_names (list[str]) – List of channel names to extract from the EDF file.
- Returns:
A dictionary where each key is a channel name and the value is another dictionary with: - ‘signal’: The signal data. - ‘fs’: The sampling frequency (in Hz) of the signal.
pyPSG.IO.plot
- pyPSG.IO.plot.plot_raw_data(signals)
Plots raw physiological signals for the first 60 seconds of data.
- Parameters:
signals (dict) – Dictionary containing signal data for each channel. Keys are channel names, values are dictionaries with keys: - “signal”: array-like, the raw signal values - “fs”: float, sampling frequency in Hz - “unit”: str, unit of the signal (e.g., ‘mV’, ‘%’, ‘au’)
- Returns:
None. Displays a matplotlib figure with one subplot per signal channel.
- Return type:
None
- pyPSG.IO.plot.plot_variability(signals, ppg_name, ecg_name, matlab_path)
Computes and plots breath rate variability (BRV) from PPG and heart rate variability (HRV) from ECG.
BRV is calculated from detected PPG peaks, HRV from detected ECG peaks. Both are computed in 60-second sliding windows, and plotted as BPM over time.
- Parameters:
ppg_signal (array-like) – Raw PPG signal.
ppg_fs (float) – Sampling frequency of the PPG signal in Hz.
ecg_signal (array-like) – Raw ECG signal.
ecg_fs (float) – Sampling frequency of the ECG signal in Hz.
matlab_path (str) – Path to the MATLAB executable (required for ECG peak detection).
- Returns:
None. Displays a matplotlib figure comparing BRV and HRV over time.
- Return type:
None