├── .gitignore ├── kubios ├── __init__.py ├── keys.json └── kubios.py ├── LICENSE.txt ├── README.md └── SampleExport.txt /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.pyc 3 | -------------------------------------------------------------------------------- /kubios/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Kubios Import & Export 4 | ---------------------- 5 | 6 | This package provides functions to export NN/RR interval series in KUBIOS readable formats and import KUBIOS HRV results 7 | from KUBIOS report files in .TXT format. 8 | 9 | Notes 10 | ----- 11 | .. This module is part of the master thesis 12 | "Development of an Open-Source Python Toolbox for Heart Rate Variability (HRV)". 13 | 14 | Author 15 | ------ 16 | .. Pedro Gomes, Master Student, University of Applied Sciences Hamburg 17 | 18 | Thesis Supervisors 19 | ------------------ 20 | .. Hugo Silva, PhD, Instituto de Telecomunicacoes, PLUX wireless biosignals S.A. 21 | .. Prof. Dr. Petra Margaritoff, University of Applied Sciences Hamburg 22 | 23 | Last Update 24 | ----------- 25 | 13-09-2018 26 | 27 | :copyright: (c) 2018 by Pedro Gomes 28 | :license: BSD 3-clause, see LICENSE for more details. 29 | """ 30 | # allow lazy import 31 | from kubios import * 32 | 33 | # Package info 34 | __author__ = "Pedro Gomes" 35 | __email__ = "pgomes92@gmail.com" 36 | __maintainer__ = "Pedro Gomes" 37 | __status__ = "Development" 38 | __license__ = "BSD 3-Clause License" 39 | __version__ = "0.1" 40 | name = "kubios" 41 | description = "Python package to support KUBIOS file management." 42 | long_description = "Python package to export RRI data in KUBIOS readable format and to read/import KUBIOS results " \ 43 | "from KUBIOS reports." 44 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Pedro Gomes 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /kubios/keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "hr_mean": "Mean HR (beats/min)", 3 | "hr_min": "Min HR (beats/min)", 4 | "hr_max": "Maximum Heart Rate (bpm)", 5 | "nn_mean": "Mean RR (ms)", 6 | "sdnn": "STD RR (ms)", 7 | "sdnn_index": "SDNN index (ms)", 8 | "sdann": "SDANN (ms)", 9 | "rmssd": "RMSSD (ms)", 10 | "nnXX": "NNxx (beats)", 11 | "pnnXX": "pNNxx (%)", 12 | "tinn": "TINN (ms)", 13 | "tri_index": "RR tri index", 14 | "fft_peak": ["VLF (Hz)", "LF (Hz)","HF (Hz)"], 15 | "fft_abs": ["VLF (ms^2)", "LF (ms^2)","HF (ms^2)"], 16 | "fft_log": ["VLF (log)", "LF (log)", "HF (log)"], 17 | "fft_rel": ["VLF (%)", "LF (%)", "HF (%)"], 18 | "fft_norm": ["LF (n.u.)", "HF (n.u.)"], 19 | "fft_total": "Total power", 20 | "fft_ratio": "LF/HF ratio", 21 | "ar_peak": ["VLF (Hz)", "LF (Hz)", "HF (Hz)"], 22 | "ar_abs": ["VLF (ms^2)", "LF (ms^2)","HF (ms^2)"], 23 | "ar_log": ["VLF (log)", "LF (log)", "HF (log)"], 24 | "ar_rel": ["VLF (%)", "LF (%)", "HF (%)"], 25 | "ar_norm": ["LF (n.u.)", "HF (n.u.)"], 26 | "ar_total": "Total power", 27 | "ar_ratio": "LF/HF ratio", 28 | "sd1": "SD1 (ms)", 29 | "sd2": "SD2 (ms)", 30 | "sd_ratio": "SD2/SD1 ratio", 31 | "apen": "Approximate entropy (ApEn)", 32 | "sampen": "Sample entropy (SampEn)", 33 | "dfa_alpha1": "alpha 1", 34 | "dfa_alpha2": "alpha 2", 35 | "pns_index": "PNS index", 36 | "sns_index": "SNS index", 37 | "stress_index": "Stress index", 38 | "band_vlf": "VLF:", 39 | "band_lf": "LF:", 40 | "band_hf": "HF:", 41 | "interpolation": "Interpolation rate", 42 | "ar_model": "AR model order", 43 | "fft_window": "Window width", 44 | "fft_overlap": "Window overlap", 45 | "fft_grid": "Points in frequency-domain", 46 | "threshold": "Threshold for NNxx/pNNxx" 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KUBIOS Import & Export for Python 2 | 3 | This Python package enables easy exportation of NN/RR interval series or signals to KUBIOS HRV friendly files and structured formats and to import HRV analysis results from KUBIOS HRV report files in .txt format. 4 | 5 | The exported signals are stored in the Type 1 format as presented on page 14 and 15 of the [KUBIOS User Guide](https://www.kubios.com/downloads/Kubios_HRV_Users_Guide.pdf). 6 | 7 | ## Installation 8 | This package can be installed using the `pip` tool: 9 | 10 | ```python 11 | pip install kubios 12 | ``` 13 | 14 | ## How to Use this Package 15 | 16 | #### export_nni() 17 | Use the `export_nni()` function to export a series of NN/RR interval or ECG signal data to a KUBIOS readable file format. 18 | 19 | ```python 20 | import numpy as np 21 | from kubios import export_nni 22 | 23 | # Load NNI series 24 | nni = np.load('SampleSeries.npy') 25 | 26 | # Export NNI series 27 | export_nni(nni) 28 | ``` 29 | 30 | Use the `output_path` variable to specify the file path where to store the exported file and `output_file` to specify the file name. Use only the `output_file` if you want to set the absolute file path in a single string. If no value for the `output_file` is provided, a file name (incl. time stamp) will automatically be generated. 31 | 32 | ```python 33 | import numpy as np 34 | from kubios import export_nni 35 | 36 | # Load NNI series 37 | nni = np.load('SampleSeries.npy') 38 | 39 | # Export NNI series with specific file name 40 | export_nni(nni, output_file='export.txt) 41 | 42 | # Export NNI series to specific path & specific file name 43 | export_nni(nni, output_path='/my/favorite/path/', output_file='export.txt') 44 | 45 | # Export NNI series to specific path with automatic file name generation 46 | export_nni(nni, output_path='/my/favorite/path/') 47 | ``` 48 | 49 | #### import_report() 50 | Use the ```import_report()``` function to read a KUBIOS HRV report files in .txt format. The results will be returned in a Python dictionary. 51 | 52 | ```python 53 | from kubios import import_report 54 | 55 | # Import HRV results from KUBIOS report 56 | results = import_report('SampleReport.txt') 57 | 58 | # Get SDNN value 59 | results['sdnn'] 60 | ``` 61 | 62 | ## Dependencies 63 | - [numpy](http://www.numpy.org) 64 | 65 | ## Context of this Work 66 | This package is under development within the scope of my master thesis _"Development of an Open-Source Python Toolbox for Heart Rate Variability (HRV)"_ at the [University of Applied Sciences Hamburg, Germany (Faculty Life Sciences, Department of Biomedical Engineering)](https://www.haw-hamburg.de/fakultaeten-und-departments/ls/studium-und-lehre/master-studiengaenge/mbme.html) and [PLUX wireless biosignals, S.A.](http://www.plux.info), Lisbon, Portugal. 67 | 68 | ## Disclaimer 69 | This package is not part of the official KUBIOS software. 70 | 71 | This program is distributed in the hope it will be useful and provided to you "as is", but WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program is NOT intended for medical diagnosis. We expressly disclaim any liability whatsoever for any direct, indirect, consequential, incidental or special damages, including, without limitation, lost revenues, lost profits, losses resulting from business interruption or loss of data, regardless of the form of action or legal theory under which the liability may be asserted, even if advised of the possibility of such damages. 72 | -------------------------------------------------------------------------------- /SampleExport.txt: -------------------------------------------------------------------------------- 1 | # SIGNAL/SERIES EXPORT - KUBIOS 2 | # File: RandomSamples 3 | # Device: n/a 4 | # DeviceID / MAC: n/a 5 | # Sampling rate: n/a 6 | # Resolution: n/A 7 | # Comment: These are the RR intervals of the SampleSeries. 8 | 766.000 9 | 766.000 10 | 727.000 11 | 789.000 12 | 789.000 13 | 750.000 14 | 766.000 15 | 797.000 16 | 898.000 17 | 836.000 18 | 789.000 19 | 766.000 20 | 711.000 21 | 680.000 22 | 664.000 23 | 688.000 24 | 758.000 25 | 742.000 26 | 742.000 27 | 734.000 28 | 773.000 29 | 859.000 30 | 812.000 31 | 766.000 32 | 773.000 33 | 773.000 34 | 758.000 35 | 734.000 36 | 750.000 37 | 773.000 38 | 750.000 39 | 766.000 40 | 820.000 41 | 1156.000 42 | 883.000 43 | 781.000 44 | 797.000 45 | 812.000 46 | 781.000 47 | 766.000 48 | 727.000 49 | 727.000 50 | 727.000 51 | 812.000 52 | 883.000 53 | 812.000 54 | 789.000 55 | 766.000 56 | 781.000 57 | 828.000 58 | 852.000 59 | 836.000 60 | 812.000 61 | 758.000 62 | 742.000 63 | 719.000 64 | 711.000 65 | 758.000 66 | 781.000 67 | 820.000 68 | 820.000 69 | 758.000 70 | 758.000 71 | 727.000 72 | 742.000 73 | 719.000 74 | 719.000 75 | 703.000 76 | 711.000 77 | 805.000 78 | 773.000 79 | 719.000 80 | 680.000 81 | 664.000 82 | 680.000 83 | 719.000 84 | 766.000 85 | 805.000 86 | 742.000 87 | 719.000 88 | 734.000 89 | 789.000 90 | 914.000 91 | 1094.000 92 | 906.000 93 | 789.000 94 | 758.000 95 | 758.000 96 | 750.000 97 | 742.000 98 | 742.000 99 | 727.000 100 | 758.000 101 | 852.000 102 | 812.000 103 | 773.000 104 | 789.000 105 | 797.000 106 | 797.000 107 | 766.000 108 | 742.000 109 | 766.000 110 | 742.000 111 | 719.000 112 | 703.000 113 | 742.000 114 | 883.000 115 | 1039.000 116 | 898.000 117 | 773.000 118 | 750.000 119 | 727.000 120 | 727.000 121 | 711.000 122 | 781.000 123 | 859.000 124 | 789.000 125 | 805.000 126 | 805.000 127 | 1047.000 128 | 875.000 129 | 773.000 130 | 719.000 131 | 680.000 132 | 656.000 133 | 664.000 134 | 656.000 135 | 641.000 136 | 617.000 137 | 617.000 138 | 617.000 139 | 609.000 140 | 602.000 141 | 594.000 142 | 578.000 143 | 594.000 144 | 578.000 145 | 562.000 146 | 570.000 147 | 555.000 148 | 547.000 149 | 547.000 150 | 547.000 151 | 555.000 152 | 539.000 153 | 539.000 154 | 555.000 155 | 578.000 156 | 633.000 157 | 672.000 158 | 648.000 159 | 664.000 160 | 672.000 161 | 656.000 162 | 633.000 163 | 617.000 164 | 602.000 165 | 609.000 166 | 625.000 167 | 641.000 168 | 633.000 169 | 633.000 170 | 633.000 171 | 648.000 172 | 664.000 173 | 734.000 174 | 711.000 175 | 766.000 176 | 766.000 177 | 773.000 178 | 688.000 179 | 656.000 180 | 648.000 181 | 656.000 182 | 672.000 183 | 703.000 184 | 711.000 185 | 742.000 186 | 703.000 187 | 742.000 188 | 812.000 189 | 828.000 190 | 734.000 191 | 711.000 192 | 680.000 193 | 664.000 194 | 625.000 195 | 625.000 196 | 625.000 197 | 648.000 198 | 656.000 199 | 664.000 200 | 695.000 201 | 758.000 202 | 898.000 203 | 969.000 204 | 875.000 205 | 773.000 206 | 711.000 207 | 680.000 208 | 648.000 209 | 609.000 210 | 594.000 211 | 594.000 212 | 602.000 213 | 625.000 214 | 625.000 215 | 633.000 216 | 641.000 217 | 664.000 218 | 1008.000 219 | 836.000 220 | 789.000 221 | 836.000 222 | 828.000 223 | 789.000 224 | 789.000 225 | 758.000 226 | 695.000 227 | 680.000 228 | 664.000 229 | 633.000 230 | 641.000 231 | 633.000 232 | 680.000 233 | 859.000 234 | 1031.000 235 | 805.000 236 | 781.000 237 | 852.000 238 | 906.000 239 | 875.000 240 | 797.000 241 | 781.000 242 | 805.000 243 | 734.000 244 | 719.000 245 | 758.000 246 | 766.000 247 | 727.000 248 | 711.000 249 | 727.000 250 | 742.000 251 | 734.000 252 | 719.000 253 | 703.000 254 | 680.000 255 | 656.000 256 | 656.000 257 | 609.000 258 | 617.000 259 | 602.000 260 | 594.000 261 | 602.000 262 | 594.000 263 | 594.000 264 | 609.000 265 | 625.000 266 | 633.000 267 | 695.000 268 | 1039.000 269 | 1094.000 270 | 867.000 271 | 812.000 272 | 734.000 273 | 672.000 274 | 656.000 275 | 633.000 276 | 641.000 277 | 656.000 278 | 633.000 279 | 633.000 280 | 648.000 281 | 641.000 282 | 648.000 283 | 641.000 284 | 648.000 285 | 648.000 286 | 641.000 287 | 633.000 288 | 633.000 289 | 617.000 290 | 609.000 291 | 594.000 292 | 602.000 293 | 609.000 294 | 617.000 295 | 617.000 296 | 617.000 297 | 633.000 298 | 648.000 299 | 641.000 300 | 664.000 301 | 656.000 302 | 672.000 303 | 648.000 304 | 664.000 305 | 641.000 306 | 617.000 307 | 609.000 308 | 617.000 309 | 594.000 310 | 609.000 311 | 578.000 312 | 602.000 313 | 633.000 314 | 758.000 315 | 930.000 316 | 773.000 317 | 773.000 318 | 789.000 319 | 766.000 320 | 711.000 321 | 680.000 322 | 656.000 323 | 633.000 324 | 617.000 325 | 609.000 326 | 617.000 327 | 633.000 328 | 633.000 329 | 633.000 330 | 617.000 331 | 602.000 332 | 602.000 333 | 625.000 334 | 633.000 335 | 664.000 336 | 680.000 337 | 688.000 338 | 648.000 339 | 648.000 340 | 656.000 341 | 664.000 342 | 680.000 343 | 648.000 344 | 672.000 345 | 656.000 346 | 648.000 347 | 648.000 348 | 648.000 349 | 617.000 350 | 617.000 351 | 625.000 352 | 625.000 353 | 633.000 354 | 617.000 355 | 633.000 356 | 641.000 357 | 664.000 358 | 641.000 359 | 680.000 360 | 711.000 361 | 734.000 362 | 695.000 363 | 688.000 364 | 680.000 365 | 672.000 366 | 680.000 367 | 688.000 368 | 680.000 369 | 680.000 370 | 672.000 371 | 680.000 372 | 695.000 373 | 727.000 374 | 727.000 375 | 711.000 376 | 719.000 377 | 742.000 378 | 695.000 379 | 695.000 380 | 680.000 381 | 695.000 382 | 680.000 383 | 664.000 384 | 656.000 385 | 672.000 386 | 688.000 387 | 680.000 388 | 695.000 389 | 742.000 390 | 773.000 391 | 773.000 392 | 758.000 393 | 773.000 394 | 750.000 395 | 719.000 396 | 695.000 397 | 688.000 398 | 719.000 399 | 688.000 400 | 695.000 401 | 680.000 402 | 711.000 403 | 719.000 404 | 719.000 405 | 703.000 406 | 648.000 407 | 648.000 408 | 641.000 409 | 648.000 410 | 656.000 411 | 664.000 412 | 641.000 413 | 656.000 414 | 656.000 415 | 664.000 416 | 656.000 417 | 641.000 418 | 641.000 419 | 625.000 420 | 672.000 421 | 664.000 422 | 656.000 423 | 656.000 424 | 625.000 425 | 633.000 426 | 609.000 427 | 617.000 428 | 625.000 429 | 633.000 430 | 633.000 431 | -------------------------------------------------------------------------------- /kubios/kubios.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Kubios Import & Export 4 | ---------------------- 5 | 6 | This module provides functions to export NN/RR interval series in KUBIOS readable formats and import KUBIOS HRV results 7 | from KUBIOS report files in .TXT format. 8 | 9 | Notes 10 | ----- 11 | .. This module is part of the master thesis 12 | "Development of an Open-Source Python Toolbox for Heart Rate Variability (HRV)". 13 | 14 | Author 15 | ------ 16 | .. Pedro Gomes, Master Student, University of Applied Sciences Hamburg 17 | 18 | Thesis Supervisors 19 | ------------------ 20 | .. Hugo Silva, PhD, Instituto de Telecomunicacoes, PLUX wireless biosignals S.A. 21 | .. Prof. Dr. Petra Margaritoff, University of Applied Sciences Hamburg 22 | 23 | Last Update 24 | ----------- 25 | 13-09-2018 26 | 27 | :copyright: (c) 2018 by Pedro Gomes 28 | :license: BSD 3-clause, see LICENSE for more details. 29 | """ 30 | # Imports 31 | import json 32 | import os 33 | import datetime as dt 34 | 35 | 36 | def export_nni(series=None, output_path=None, output_file=None, info=None): 37 | """Exports NN or RR interval series into a KUBIOS readable file in *.TXT format. 38 | 39 | Parameters 40 | ---------- 41 | series : array_like 42 | ECG signal or NN/RR interval series in (s) or (ms). 43 | output_path : str, optional 44 | Absolute path to where the export files should be stored (alternatively add it directly to the 'output_file') 45 | output_file : str 46 | Name of the exported file. 47 | info : dict, optional 48 | Dictionary with information about the ECG acquisition. 49 | Keys: 'file' File name of the original ECG acquisition. 50 | 'device' Device used for acquisition. 51 | 'deviceID' Device ID (e.g. MAC address) 52 | 'sampling rate' Sampling rate used for acquisition. 53 | 'sampling resolution' Sampling resolution used for acquisition. 54 | 'comment' String comment(s). 55 | 56 | Raises 57 | ------ 58 | TypeError 59 | If input data is provided. 60 | """ 61 | # Check input 62 | if series is None: 63 | raise TypeError("No input data ('nni') provided. Please specify input data.") 64 | 65 | # Output file name generation 66 | if output_file is None: 67 | output_file = '/series_export' + dt.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + '.txt' 68 | elif output_file[-4:] != '.txt': 69 | output_file += '.txt' 70 | 71 | if output_path is not None: 72 | output_file = output_path + output_file 73 | 74 | # Information file 75 | if info is None: 76 | info = dict() 77 | 78 | info['file'] = str(info['file']) if 'file' in info.keys() else 'n/a' 79 | info['device'] = str(info['device'])if 'device' in info.keys() else 'n/a' 80 | info['deviceID'] = str(info['deviceID']) if 'deviceID' in info.keys() else 'n/a' 81 | info['sampling_rate'] = str(info['sampling_rate']) if 'sampling_rate' in info.keys() else 'n/a' 82 | info['sampling_resolution'] = str(info['sampling_resolution']) if 'sampling_resolution' in info.keys() else 'n/a' 83 | info['comment'] = str(info['comment']) if 'comment' in info.keys() else 'n/a' 84 | 85 | vals = (info['file'], info['device'], info['deviceID'], info['sampling_rate'], info['sampling_resolution'], 86 | info['comment']) 87 | 88 | header = '# SIGNAL/SERIES EXPORT - KUBIOS\n' \ 89 | '# File: %s\n' \ 90 | '# Device: %s\n' \ 91 | '# DeviceID / MAC: %s\n' \ 92 | '# Sampling rate: %s\n' \ 93 | '# Resolution: %s\n' \ 94 | '# Comment: %s\n' % vals 95 | 96 | # Output data 97 | with open(output_file, 'w+') as f: 98 | f.write(header) 99 | for i in series: 100 | f.write('%.3f\n' % i) 101 | 102 | 103 | def import_report(rfile=None, delimiter=','): 104 | """Imports HRV results from a KUBIOS report file in .txt format. 105 | 106 | Parameters 107 | ---------- 108 | rfile : str, file handler 109 | Absolute filepath or file handler of the KUBIOS report file. 110 | delimiter : str, character 111 | Delimiter used in KUBIOS report file. 112 | 113 | Returns 114 | ------- 115 | results : dict 116 | Imported parameter values from the KUBIOS report file. 117 | 118 | Raises 119 | ------ 120 | TypeError 121 | If 'rfile' is not str or file handler. 122 | IOError 123 | If provided file does not exist. 124 | TypeError 125 | If 'rfile' is not a KUBIOS report file. 126 | """ 127 | # Check input 128 | if type(rfile) is not str and type(rfile) is not file: 129 | raise TypeError('Unsupported file format. Please provide file path (str) or file handler.') 130 | elif type(rfile) is str: 131 | if not os.path.isfile(rfile): 132 | raise IOError('KUBIOS report file does not exist. Please verify input data.') 133 | 134 | # Check if file is a Kubios export file 135 | with open(rfile, 'r') as f: 136 | if 'Kubios HRV' not in f.read(): 137 | raise TypeError("This file does not seem to be a KUBIOS report file.") 138 | 139 | # Load HRV keys 140 | dir_ = os.path.split(__file__) 141 | with open(os.path.join(dir_[0], 'keys.json')) as j: 142 | hrv_parameters = json.load(j) 143 | 144 | # Get non-available parameters 145 | results = {} 146 | frequency_arrays = ['fft_peak', 'fft_abs', 'fft_log', 'fft_rel', 'fft_norm', 'ar_peak', 'ar_abs', 'ar_log', 147 | 'ar_norm', 'ar_rel'] 148 | 149 | for key in hrv_parameters.keys(): 150 | if 'fft_' in key or 'ar_' in key: 151 | if key in frequency_arrays: 152 | results[str(key)] = list() 153 | 154 | # Get available parameters 155 | with open(rfile, 'r') as f: 156 | content = f.readlines() 157 | 158 | # Get data 159 | for line in content: 160 | line = line.split(delimiter) 161 | for key, label in hrv_parameters.items(): 162 | if type(label) is unicode: 163 | if str(label) in line[0]: 164 | index = 2 if key in ['ar_total', 'ar_ratio'] else (1 if len(line) > 1 else 0) 165 | try: 166 | val = float(line[index].lstrip()) 167 | except ValueError: 168 | val = str(line[index]).rstrip().lstrip().replace('\n', '').replace('\r', '') 169 | if key in ['interpolation', 'ar_model', 'fft_window', 'fft_overlap', 'fft_grid', 'threshold']: 170 | val = float(''.join(i for i in val if i.isdigit())) 171 | results[str(key)] = val if not line[index].isspace() else 'n/a' 172 | else: 173 | for l in label: 174 | if str(l) == line[0].rstrip().lstrip().replace(':', ''): 175 | index = 1 if 'fft_' in key else 2 176 | val = float(line[index].lstrip()) if not line[index].isspace() else 'n/a' 177 | results[str(key)].append(val) 178 | return results 179 | 180 | if __name__ == "__main__": 181 | """ 182 | Example Script - Kubios Package 183 | """ 184 | import numpy as np 185 | 186 | # Get a NNI series (alternatively ECG data) 187 | nni = np.load('SampleSeries.npy') 188 | 189 | # Create info dictionary (optional) 190 | info = { 191 | 'file': 'RandomSamples', 192 | 'device': 'n/a', 193 | 'deviceID': 'n/a', 194 | 'sampling_rate': 'n/a', 195 | 'sampling_resolution': 'n/A', 196 | 'comment': 'These are the RR intervals of the SampleSeries.' 197 | } 198 | 199 | # Create Kubios readable file with imported data (ECG, RR, or NN) 200 | export_nni(nni, output_file='SampleExport.txt', info=info) 201 | 202 | # Load Sample Kubios Report 203 | results = import_report('SampleReport.txt') 204 | 205 | for key in results.keys(): 206 | print(key, results[key]) 207 | --------------------------------------------------------------------------------