Python Library

Introduction

A library for accessing VitalDB data with API in Python language.

Installation

To use this library, please save as the library file (vitaldb.py) from the following address.

https://raw.githubusercontent.com/vitaldb/vitalutils/master/python/vitaldb.py

You need to download or copy vitaldb.py file to the project folder where you will write the Python code.

If you get an error message that there is no library when you run it, you need to install library such as pandas or requests.

pip install pandas

pip install requests

Library Description

Currently, the library contains only one function to load VitalDB data.

def load_cases(tnames, caseids=[], interval=1, maxcases=10)

Parameter list

  • tnames: list or comma separated track names (with device names)
  • caseids: list of caseids to load. If missing, the cases in which have tnames are automatically selected.
  • interval: time interval of each row
  • maxcases: stop loading if this number of cases are loaded

Return value

   {

        caseid1 : numpy.array([

            [sample[0] of tnames[0], sample[0] of tnames[1], … samples[0] of tnames[last]],

            [sample[1] of tnames[0], sample[1] of tnames[1], … samples[1] of tnames[last]],

            ...

            [sample[last] of tnames[0], sample[last] of tnames[1], … samples[last] of tnames[last]],

        ]),

        caseid2 : numpy.array([

            [sample[0] of tnames[0], sample[0] of tnames[1], … samples[0] of tnames[last]],

            [sample[1] of tnames[0], sample[1] of tnames[1], … samples[1] of tnames[last]],

            ...

            [sample[last] of tnames[0], sample[last] of tnames[1], … samples[last] of tnames[last]],

        ]),

        ...

    }

Example Code

The following example code downloads 10 cases of arterial waveform from vitaldb and saves it as a png file.

Code

import matplotlib.pyplot as plt

from vitaldb import load_cases

cases = load_cases('SNUADC/ART,Solar8000/ART_SBP', interval=1/100, maxcases=1)

for caseid, case in cases.items():

    plt.figure(figsize=(20, 5))

    plt.plot(case[:, 0])

    plt.savefig('{}.png'.format(caseid))

Results