PPG_EVA module
Created on Thu Jan 16 14:37:23 2025
@author: alko18
- class PPG_EVA.JoinSignals(signal_A, signal_B, timestamps_A, timestamps_B)
Bases:
object
- The class for every action where both signals are needed. Includes:
__init__ synchronizing cut
- cut(signal_length_A, signal_length_B)
Cuts both signals to the same length.
Parameters
- length_AInt, optional
Desired length of the reference signal. The default is 138240 (18 min).
- length_BInt, optional
Desired length of the second signal. The default is 34560 (18 min).
Returns
None.
- syncronizing(flag=0)
Parameters
- flagbool, optional
If True, indicates that no equal timestamps were found. Thus adding 12 hours to the reference timestamps anr reiterating in a recursive mannor. The default is 0.
Returns
- self.sync: tupel
The tupel with synchrinized indizes of somno, corsano and the true fs of corsano respectively.
- class PPG_EVA.Processing(signals, timestamps)
Bases:
object
- The class for processing the Signals. Included are:
__init__ pleth_filter struckt (DEPRECATED) resampling slice_list
- pleth_filter(fs, lowcut, highcut, order, resampled=False)
Butterwoth IIR filter second order.
Parameters
- fsInt
Sampling rate in Hertz. The default is 128 Hz.
- lowcutfloat, optional
The default is 0.5.
- highcutfloat, optional
The default is 8.
- orderInt, optional
The default is a Bandpass of 2nd order.
- resampledBool, optional
Wether the Signal is resampled. the resampled signal is a different attribute of this object. The default is False.
Returns
None.
- resampling(sampling_rate, target_rate=128, interpolate_pchip=False)
Parameters
- sampling_rateInt, optional
The original smaplingrate of the signal. The default is 32.
- target_rate: Int
The target samplinrate of the signal, The dafault is 128.
- interpolate_pchip: bool
if True, the resampling is performed by the pchip-method. The default is False and hence C2-Splineinterpolation is used.
- PPG_EVA.ROC(values, refdata, thresholds=None)
!!!Deprecated!!! An attempt to build a ROC-Funktion. Does not work well.
Parameters
- valuesarray
The calculated SQIs.
- refdataarray
- The annotationarray.
1 = True = good 0 = False = bad
Returns
- TPRlist
The True Positive Rate (Sensitivity)
- PPV: list
The precision.
- FPRlist
The False Positive Rate (Specificity)
- thresh: list
The used thresholds.
- PPG_EVA.ROC_mid(values)
!!!Deprecated!!! Calculates a mean ROC for every SQI.
Parameters
- valueslist of lists
A list of ROC-data for a specific SQI
Returns
- list
A list of the mean Sensitivity (Index 0), mean specificity (index 1)
- class PPG_EVA.SQI(signal_chunks, criterion_snr=0, criterion_entropy=0, criterion_zcr=0)
Bases:
object
- The class to calculate all SQIs. Includes:
__init__ shanon_entropy calc_SNR ZCR skewness kurt decision (DEPRECATED) final_decision (DEPRECATED)
- ZCR()
Calculate the ZCR for every sequence.
Returns
- self.signs: list
A list with values for the signs of the signalvalues. 1 = positive -1 = negative
- self.cross_pos: list
A list if the indices where a zero crossing occured.
- self.n_cross: Int
The number of zero crossings.
- self.slope: float
the slope of the lin. regression for every sequence.
- self.intersect: float
the the y-intersect of the lin. regression for every sequence.
- self.variance:
the variance for every sequence.
- calc_SNR(lowcut=0.8, highcut=2.0)
Calculates the Signal- to Noise-Ratio. Defined as the relative power of a signalband to the rest.
Parameters
- lowcutfloat, optional
Lower bound of the frequency band. The default is .8 (48 bpm).
- highcutfloat, optional
higher bound of the frequency band. The default is 2.0 (120 bpm).
Returns
- self.SNR: list
The SNR-values for every sequence.
- self.freq: list
the frequencies for every sequence.
- self.magnitude: list
the magnitudes of the frequencies for every sequence.
- decision()
!!!Deprecated!!! Decides wether the values are good or bad.
Returns
- self.decision_snr: list
List of bool. True for good value and Flase for bad value.
- self.decision_entropy: list
List of bool. True for good value and Flase for bad value.
- self.decision_zcr: list
List of bool. True for good value and Flase for bad value.
- final_decision()
!!!Deprecated!!! A digital logic to combine all SQIs to one. Was used for SNR, Entropy and ZCR. Since these parameters dont apply its not used anymore.
Returns
- wrapperdict
- A dictionary with the final decision. It contains:
min. Annehmbar: the length of chains of succesive sequences that are at least ‘annehmbar’ Gut: the length of chains of succesive sequences that are at least ‘good’ längste min. Annehmbar in Prozent: the longes chain of at least ‘annehmbar’ in percent of the total amount of sequences längste Gut in Prozent: the longes chain of at least ‘good’ in percent of the total amount of sequences, Qualitäten: the raw qualities for every sequence
- kurt()
Calculates the kurtosis for every sequence.
Returns
- self.kurt: list
The kurtosis for every sequence.
- class PPG_EVA.Training(skew_values, kurt_values, data)
Bases:
object
- The class for Training. Includes:
__init__ separate_values building hists
- building_hists(plot=False)
Parameters
- plotbool, optional
If True, all histogrammst will be plotted. The default is False.
Returns
- self.hist: aray
The histogrammvalues.
- self.xedges: array
The xedges if the bins.
- self.yedges: array
The yedges if the bins.
- separate_values()
Separating the values in good and bad data according to the annotation.
- PPG_EVA.classify_data(hist, data1, data2, xedges, yedges, annotation=None, plot=False)
Classify the input data.
Parameters
- histarray
The histogramvalues.
- data1array
The skewness values of a signal.
- data2array
The kurtosis values of a signal.
- xedgesarray
The xedges of the bins.
- yedgesarray
The yedges of the bins.
- annotationarray, optional
The annotation. It is only used to plot the data into the histogramm. The default is None.
- plotbool, optional
If True, the histogram will be plotted with the annotated data. The default is False.
Returns
- scoresarray
The likelihood of a value being good.
- PPG_EVA.decide(values, criterion, zcr=False)
!!!Deprecated!!! Decides weather a value is good or bad.
Parameters
- valuesarray
The values of every signalchunk.
- criterionfloat
The decision criterion.
- zcrbool, optional
Since the ZCR should be minimimal for a good value, the decision is inversed. The default is False.
Returns
- decisionlist
A list of bools. A one (1) for good and a zero (0) for bad.
- PPG_EVA.import_decisionpoints()
!!!Deprecated!!!
Was created to import decision thresholds. Since the classifier is exported with its best threshold this function is obsolete.
Returns
None.
- PPG_EVA.import_training_data(training_values_path)
Imports a excel-sheet with all data of Somno. Futhermore, a rondomization and subdivison into test- and trainingsets is performed.
Parameters
- training_values_pathstring
The specific path of the excel-sheet.
Example: A:my rainingdata raining_data.xlsx
Returns
- validation_sets: dict
Five subsets with a raugh equal amount of good and bad data.
- training_sets: dict
Five subsets wich contain four validation_sets. In every training_set one validation_set is missing.
- test_set: array
One set wich contains 20% of the whole dataset with respect to the subdivision in good and bad data.
- PPG_EVA.lin_reg(signal_chunks, cross_pos)
A funktion wicht performs a lin. regression for every given signalchunk.
Parameters
- signal_chunksarray
The sequenced signal.
- cross_pos2D-list
The Position of each zero crossing for every signal_chunks
Returns
- slopelist
The slope of every lin. regression.
- intersectlist
The y-intercept for every lin. regression.
- PPG_EVA.mean_hists(hists, thresholds)
Calculates the mean from all histograms as final classifier.
Parameters
- histsdict
All five histogramms fromm the trainingsets.
- thresholdsdict
best threshold from every subset.
Returns
- mean_histarray
The mean histogram.
- xedgesarray
The xedges of the bins.
- yedgesarray
The yedges of the bins.
- mean_threshfloat
the mean threshold from the best thresholds.
- PPG_EVA.minimize(values)
!!!Deprecated!!! Find the value with the minimal distance to the koordinates [0,1]
Parameters
- values: list
a list of lists with sensitivity at index 0, specificity at index 1 and coresponding thresholds at index 2.
Returns
- TYPE: Int
The index with the minimal distance to [0,1] and its corresponding threshold
- PPG_EVA.preprocessing(training_signal_path, TN, chunk_length=1, training=True, plot=True)
A preprocessing returns the SQI as objects for each device.
Parameters
- training_signal_pathstring
The baspath to signaldirectory.
- TNstring
The TN-ID to find the signals within the training_signal_path.
- chunk_lengthfloat, optional
The chunklength as a Faktor of one minute. The default is 1. Example:: chunk_length = 1/6 = 60s/6 = 10s chunk_length = 1.5 = 1.5*60 = 90s -> 1.5 minutes
- trainingbool, optional
Weather PPG-Eva is in training mode or not. If False, corsano will only used for synchronicing. Was used for the aqusition of the training_data. The default is True.
- plotbool, optional
If True, the whole signal will be plotted. The default is True.
- PPG_EVA.process(TN_list, train=False, plot=False)
Parameters
- TN_listlist
A list of the names.
- trainbool, optional
If True, PPG-Eva is in training mode. Otherwise it is in Evaluation mode. The default is False.
- plotbool, optional
Deprecated. The default is False.
Returns
- in Train-mode:
- Nothing. The results of the classifier are shown. The operator is prompted to enter:
y : classifier will be saved and PPG-Eva terminates. n : training will be performed again with a new randomization of the sets. q : Quit. PPG.Eva terminates.
- in Evaluation-mode:
- final_results_somno: dict
A dictionairy where the names are the keys. Behind every key is a dictionairy containing the results from wrapping_results() ‘good’: number og good sequences ‘bad’ : number of bad sequences ‘sum’ : nuber of sequences
- PPG_EVA.read_signal(mod_path, signal_key, time_key, sep=',', skiprows=0, date_format=None, header='infer')
Parameters
- mod_pathstring
The modified filepath to the signalfile wit its name as last part. Syntax: path + ‘filename’
- signal_keystring
- The keyword/number for Pandas.Dataframe signal-column.
Somno: signal_key= 2 corsano: signal_key=’value’
- time_keystring
Das Schlüsselwort für den Pandas.DataFrame um auf die Zeitstempel zuzugreifen. The keyword/number for Pandas.Dataframe timestamp-column somno: time_key=0; corsano: time_key=’date’
- sepstring, optional
The seperator used to seperate the columns. Only necessary for Somno. Corsanofiles use the default. The default is ‘,’. sep_somno = ‘;’
- skiprowsinteger, optional
!!!Deprecated!!! The number of rows that should be skipped. Only necessary for Somno (skip 6 rows). The default is 0.
- date_formatstring, optional
Date-format for the timestamps. Only necessary for Somno (“%d.%m.%Y %H:%M:%S,%f”) The default is None.
Returns
- signalsarray
The signal as a timeseries.
- timestampsSeries
the timestamps as pandas.Series.
- PPG_EVA.test_subsets(validation_sets, mean_hist, xedges, yedges, best_thresh, plot=False)
Parameters
- validation_setsdict
A dictionaity containing the data of the subsets -> import_training_data().
- mean_histarray
The classifying histogram.
- xedgesarray
The xedges of the bins.
- yedgesarray
The yedges of the bins.
- best_threshfloat
The mean threshold.
- plotTYPE, optional
If True, the performance of the calssifier on the subsets will be plotted in ROC-Space. The default is False.
Returns
- tuple
A tuple containing the mean fpr mean tpr standard deviation of fpr standard deviation of tpr on the respective indices.
- PPG_EVA.test_testset(test_set, mean_hist, xedges, yedges, best_thresh, val_tupel, plot=False)
Parameters
- test_setndarray
A dictionaity containing the data of the testset -> import_training_data().
- mean_histarray
The classifying histogram.
- xedgesarray
The xedges of the bins.
- yedgesarray
The yedges of the bins.
- best_threshfloat
The mean threshold.
- val_tupeltuple
A tuple containing the mean fpr, mean tpr, standard deviation of fpr, standard deviation of tpr on the respective indices.
- plotbool, optional
If True, the performance ofe the classifier on the testset will be plottet in the ROC-space with the data of the subsets as errorbars. The default is False.
Returns
- test_fprfloat
The fpr of the classifier on the testset.
- test_tprfloat
The tpr of the classifier on the testset.
- PPG_EVA.train_hist(validation_sets, hists, plot=False)
This funktion iterates over the subsets. Here the thresholds for every subset are determined with the use of ROC.
Parameters
- validation_setsdict
A dictionaity containing the data of the subsets -> import_training_data().
- histsdict
A dictionairy containing the histograms of every trainingset.
- plotbool, optional
If True, all five ROC-Curves are plotted. The default is False.
Returns
- master_thresholdsdict
A dictionairy containing the beste threshold for every subset.
- PPG_EVA.variance(slopes, intersect, cross_pos)
A function wich calculates the variance of the data relative to the lin. regression.
Parameters
- slopeslist
The slopes for every lin. regression.
- intersectlist
The y-intersect for ever lin. regression.
- cross_poslist
The position of every zero crossing as an array for every signalchunk.
Returns
- varlist
The normalised variance of the data relative to the lin. regression