Package: vital-sqi
Vital_sqi: Signal quality control of physiological signalsDescriptionVital_sqi is a Python package for signal quality index (SQI) extraction and quality assignment
for ECG and PPG waveforms. The package provides:Support PPG and ECG waveforms in various data formats extracted from wearables.Unified point of access for the current state-of-the-art SQIs: standard statistics, HRV, RR interval, and waveform based SQIs.Rule-based classification of signal quality using user-defined thresholds for the extracted SQIs per signal segment.Pipeline and GUIs for SQI extraction and quality assignment.Prerequisites and InstallationThe package works withPython 3.7andPython 3.8.pip install vital_sqiGetting startedThe package is built around three classes:SignalSQIRuleRulesetsignal_objSignalSQIobject, has the following attributes:signal_obj.signalcontaining waveform data (pandas dataframe).signal_obj.sampling_ratecontaining sampling rate, either input by user or automatically inferred from the waveform.signal_obj.sqiscontaining SQIs (pandas dataframe) that are derived by functions ofvital_sqi.sqimodules or an
external table, with SQI values as columns and signal segments as rows. After signal classification, decision ofacceptorrejectfor each signal segment is indecisioncolumn. If signal segmentation is done with the package,
the table will contain also coordinates in columnstartandend.signal_obj.rulesandsignal_obj.rulesetcontaining a list ofrulesand arulesetused for signal classification.ruleslist ofRuleobjects, in which each corresponds to an SQI and contains thresholds for quality assignment.
Rules could be read intosignal_objfrom.jsonfile in the following format:"test_sqi":{"name":"test_sqi","def":[{"op":">","value":"10","label":"reject"},{"op":">=","value":"3","label":"accept"},{"op":"<","value":"3","label":"reject"}],"desc":"","ref":""}rulesetobject of classRulesetcontains a set of selectedrules(selected from the list of rules insignal_obj.rule) and the order to apply them in quality
assignment (see schema below). Notice that this is not a tree-based classification.PipelinesThe package includes two pipelines for ECG (similarly for PPG) data as follows:vital_sqi.pipeline_highlevel.get_ecg_sqisto extract SQIs for ECG segments.fromvital_sqi.pipeline.pipeline_highlevelimport*fromvital_sqi.data.signal_sqi_classimportSignalSQIimportosfile_in=os.path.abspath('tests/test_data/example.edf')sqi_dict=os.path.abspath('tests/test_data/sqi_dict.json')segments,signal_sqi_obj=get_ecg_sqis(file_in,sqi_dict,'edf')vital_sqi.pipeline_highlevel.get_qualified_ecgto extract SQIs, use those to classify ECG signal asacceptorrejectusing user-defined thresholds. Therulesandrulesetare defined in json format. Templates are found invital_sqi/resourcefolder:sqi_dict.jsonforrulesandrule_dict_test.jsonforruleset.fromvital_sqi.pipeline.pipeline_highlevelimport*fromvital_sqi.data.signal_sqi_classimportSignalSQIimportosfile_in=os.path.abspath('tests/test_data/example.edf')sqi_dict=os.path.abspath('tests/test_data/sqi_dict.json')rule_dict_filename=os.path.abspath('tests/test_data/rule_dict_test.json')ruleset_order={3:'skewness_1',2:'entropy',1:'perfusion'}output_dir=tempfile.gettempdir()signal_obj=get_qualified_ecg(file_name=file_in,sqi_dict_filename=sqi_dict,file_type='edf',duration=30,rule_dict_filename=rule_dict_filename,ruleset_order=ruleset_order,output_dir=output_dir)We also provide an GUI to easily defineruleandruleset, and execute them with an input SQI table (Help - hyperlink to readthedocs)Main stepsFollowing are the main steps to use the package for SQI extraction and signal classification. For details, see thedocumentation.1. Reading/WritingSignal waveform is read into an object ofSignalSQIclass and written to the following format usingvital_sqi.datamodule.ECG: EDF, MIT (physio.net), csv.PPG: csv.
Classified segments are written to csv files usingvital_sqi.preprocess.segment_split.save_segment2.Preprocessing and segmentationvital_sqi.preprocessingallows doing:Several signal preprocessing steps such as trimming, tapering, smoothing, bandpass filter etc. For PPG,
it is possible to filter the signal based on columns such as SpO2, perfusion, etc.Signal segmentation has two options: splitting by duration and by beat (which includes beat detection).3. SQI extractionThe implemented SQIs,vital_sqi.sqimodule, are divided into 4 groups:Standard statistics SQIs such as kurtosis, skewness, entropy, etc.Heart rate variability (HRV) based SQIs such as sdnn, sdsd, rmssd, etc.RR interval-based SQIs such as ectopic, correlogram, msq, etc.Waveform-based SQIs: dtw, qrs_energy, qrs_a etc.The functionvital_sqi.pipeline_function.extract_sqiis used to extract a number of SQIs from segments. The requested SQIs
are defined in a json file called SQI dictionary. We provide a dictionary template for all implemented SQIs, with default
parameters, invital_sqi/resource/sqi_dict.json.4. Quality classificationThe package allows making rule set from SQIs and user-defined thresholds for quality classification. A segment assigned
asacceptpass all rules in the set, otherwisereject. Rules in the set have ordered, which might help to
improve speed.We ran brute force threshold searching for an in-house PPG dataset (generated with Smartcare, doubly annotated
by domain experts) to obtain a set of recommended thresholds, as found inresource/rule_dict.json.References