Skip to content

User Guide

RunsData edited this page Nov 11, 2020 · 6 revisions

Installation Instructions:

Option 1 (preferred because it will download all dependencies):

pip install cgmquantify

Option 2 (if Option 1 does not work- this can happen if your pip is not updated or your machine is older):

pip install git+git://github.com/brinnaebent/cgmquantify.git

Option 3 (plan on downloading dependencies yourself):

git clone https://github.com/brinnaebent/cgmquantify.git

Using cgmquantify package:

Importing Package:

import cgmquantify as cgm

List functions to see any updated functions:

dir(cgm)

Dependencies

pandas, numpy, matplotlib, statsmodels, datetime

Formatting your data for input

If you have a Dexcom CGM, use the importdexcom function. (More import functions coming soon!). For all others, please import your data into a pandas dataframe with 3 columns: one column for glucose, another column for your datetime, and another column for the day. An example of how to do this is shown below in examples.

Contributing to this project

If you are interested in contributing to this project, open an Issue under "Contribution Request" and assign the current author (brinnaebent) to the Issue.

Testing this project

Pull the test_ subdirectory. Run either the .py or the .ipynb file. Expected results are located in the .ipynb file.

The functions currently available are:

  • importdexcom(filepath) - takes .csv file with Dexcom CGM formatting and turns it into a data frame, formats time
  • summary(data) - computes glucose summary statistics mean, median, minimum, maximum, first quartile, third quartile
  • interdaysd(data) - computes interday standard deviation
  • interdaycv(data) - computes interday coefficient of variation
  • intradaysd(data) - computes intraday standard deviation: mean, median, standard deviation of all days in data
  • intradaycv(data) - computes intraday coefficient of variation: mean, median, standard deviadtion of all days in data
  • TOR(data, sd=1, sr=5) - computes time outside range (range in standard deviations from mean, default = 1). sr is the sampling rate inverse in minutes of the CGM (default is the Dexcom -> 5 minutes)
  • TIR(data, sd=1, sr=5) - computes time inside range (range in standard deviations from mean, default = 1). sr is the sampling rate inverse in minutes of the CGM (default is the Dexcom -> 5 minutes)
  • POR(data, sd=1, sr=5) - computes percent of time outside range (range in standard deviations from mean, default = 1). sr is the sampling rate inverse in minutes of the CGM (default is the Dexcom -> 5 minutes)
  • MGE(data, sd=1) - computes the mean of glycemic excursions, glycemic excursions indicated by standard deviation, default = 1
  • MGN(data, sd=1) - computes the mean of normal glucose, glycemic excursions indicated by standard deviation, default = 1
  • MAGE(data, std=1) - computes the mean amplitude of glycemic excursions, glycemic excursions indicated by standard deviation, default = 1; calculation following Baghurst's algorithm for MAGE
  • J_index(data) - computes the glycemic variability metric, J-index
  • LBGI(data) - computes glycemic variability metric low blood glucose index
  • HBGI(data) - computes glycemic variability metric high blood glucose index
  • ADRR(data) - computes Average Daily Risk Range, assessment of total daily glucose variations within risk space
  • MODD(data) - computes mean of daily differences in glucose
  • CONGA24(data) - computes continuous overall net glycemic action over 24 hours
  • GMI(data) - computes glycemic management indicator
  • eA1c(data)- computes estimated A1c, according to American Diabetes Association calculator
  • plotglucosebounds(data, upperbound = 180, lowerbound = 70, size=15) - plots visualization of glucose with indicators at bounds (set with defaults hyperglycemic (<70) and hypoglycemic (>180)). Size is the size of your text/axis.
  • plotglucosesd(data, sd=1, size=15) - plots visualization of glucose with indicators at set standard deviation from the mean (default is 1 SD). Size is the size of your text/axis, default=15.
  • plotglucosesmooth(data, size=15) - plots visualization of glucose with LOWESS smoothing applied to the visualization. Size is the size of your text/axis, default=15.

Functions coming soon

  • Input functions for all CGM manufacturers
  • Visualizations and analyses integrated with food logs

Example Code Blocks:

Importing and Formatting data:

  • Read file: df = pd.read_csv(filename)
  • Create data frame: data = pd.DataFrame()
  • Add Time to data: data['Time'] = df['Timestamp (YYYY-MM-DDThh:mm:ss)'] <- change this with the name of your time column
  • Add glucose column to data: data['Glucose'] = pd.to_numeric(df['Glucose Value (mg/dL)']) <- change this with the name of your glucose column
  • Index: data.drop(data.index[:12], inplace=True)
  • Format time to datetime: data['Time'] = pd.to_datetime(data['Time'], format='%Y-%m-%dT%H:%M:%S')
  • Add column for Day: data['Day'] = data['Time'].datetime.date data = data.reset_index()