glucopy.Gframe#
- class glucopy.Gframe(data=None, unit: str = 'mg/dL', date_column: list[str] | str | int = 0, cgm_column: str | int = 1, date_format: str | None = None, dropna: bool = True)[source]#
Class for the analysis of CGM data. it uses a pandas DataFrame as the main data structure.
To create a Gframe object from a csv file or an excel file, check Input/Output glucopy.read_csv() and glucopy.read_excel().
- Parameters:
data (pandas DataFrame) – DataFrame containing the CGM signal information, it will be saved into a DataFrame with the columns [‘Timestamp’,’Day’,’Time’,’CGM’]
unit (str, default 'mg/dL') – CGM signal measurement unit.
date_column (str or str array, default None) – The name or names of the column(s) containing the date information If it’s a str, it will be the name of the single column containing the date information If it’s a str array, it will be the 2 names of the columns containing the date information, eg. [‘Date’,’Time’] If it’s None, it will be assumed that the date information is in the first column
cgm_column (str, default None) – The name of the column containing the CGM signal information If it’s None, it will be assumed that the CGM signal information is in the second column
date_format (str, default None) – Format of the date information, if None, it will be assumed that the date information is in a consistent format
dropna (bool, default True) – If True, removes all rows with NaN values
- data#
DataFrame containing the CGM signal information, it will be saved into a DataFrame with the columns:
‘Timestamp’ : datetime64[ns] # pandas datetime
‘Day’ : datetime.date
‘Time’ : datetime.time
‘CGM’ : number
- Type:
pandas DataFrame
- unit#
CGM signal measurement unit. Can be ‘mg/dL’ or ‘mmol/L’.
- Type:
str
- n_samples#
Number of samples in the data.
- Type:
int
- n_days#
Number of days in the data.
- Type:
int
- max#
Maximum value of the CGM signal.
- Type:
float
- min#
Minimum value of the CGM signal.
- Type:
float
Examples
Creating a Gframe object from a pandas DataFrame:
In [1]: import glucopy as gp In [2]: import pandas as pd In [3]: df = pd.DataFrame({'Timestamp':['2020-01-01 12:00:00','2020-01-01 12:05:00','2020-01-01 12:10:00'], ...: 'CGM':[100,110,120]}) ...: In [4]: gf = gp.Gframe(df) In [5]: gf Out[5]: Timestamp Day Time CGM 0 2020-01-01 12:00:00 2020-01-01 12:00:00 100 1 2020-01-01 12:05:00 2020-01-01 12:05:00 110 2 2020-01-01 12:10:00 2020-01-01 12:10:00 120
Creating a Gframe object from a pandas DataFrame with extra columns:
In [6]: df = pd.DataFrame({'Timestamp':['2020-01-01 12:00:00','2020-01-01 12:05:00','2020-01-01 12:10:00'], ...: 'Extra':[1,2,3], ...: 'CGM':[100,110,120]}) ...: In [7]: gf = gp.Gframe(df, cgm_column='CGM', date_column='Timestamp') In [8]: gf Out[8]: Timestamp Day Time CGM 0 2020-01-01 12:00:00 2020-01-01 12:00:00 100 1 2020-01-01 12:05:00 2020-01-01 12:05:00 110 2 2020-01-01 12:10:00 2020-01-01 12:10:00 120
- __init__(data=None, unit: str = 'mg/dL', date_column: list[str] | str | int = 0, cgm_column: str | int = 1, date_format: str | None = None, dropna: bool = True)[source]#
Methods
__init__
([data, unit, date_column, ...])adrr
()Calculates the Average Daily Risk Range (ADRR).
auc
([per_day, time_unit, threshold, above])Calculates the Area Under the Curve (AUC) using the trapezoidal rule.
bgi
([per_day, index_type, maximum])Calculates the Low Blood Glucose Index (LBGI) or the High Blood Glucose Index (LBGI).
conga
([per_day, m, slack, ignore_na, ddof])Calculates the Continuous Overall Net Glycaemic Action (CONGA).
convert_unit
([new_unit])Converts the unit of the CGM signal.
cv
([per_day, ddof])Calculates the Coefficient of Variation (CV) of the CGM values.
dfa
([per_day, scale, overlap, integrate, ...])Calculates the Detrended Fluctuation Analysis (DFA) using neurokit2.fractal_dfa().
dt
([per_day])Calculates the Distance Travelled (DT).
fd
([per_day, interval, decimals, count])Calculates the Frequency Distribution (Fi) for a given target range of glucose.
grade
([percentage])Calculates the contributions of the Glycaemic Risk Assessment Diabetes Equation (GRADE) to Hypoglycaemia, Euglycaemia and Hyperglycaemia.
gvp
()Calculates the Glucose Variability Percentage (GVP), with time in minutes.
hbgi
([per_day, maximum])This is an alias for
glucopy.Gframe.bgi()
with index_type='h'.iqr
([per_day, interpolation])Calculates the Interquartile Range (IQR) of the CGM values.
lbgi
([per_day, maximum])This is an alias for
glucopy.Gframe.bgi()
with index_type='l'.mag
([per_day, time_unit])Calculates the Mean Absolute Glucose Change per unit of time (MAG).
mage
([per_day])Calculates the Mean Amplitude of Glycaemic Excursions (MAGE).
mard
(smbg_df[, slack, interpolate])Calculates the Mean Absolute Relative Difference (MARD).
mean
([per_day])Calculates the mean of the CGM values.
modd
([target_time, slack, ignore_na])Calculates the Mean of Daily Differences (MODD).
mse
([per_day, scale, dimension, tolerance, ...])Calculates the Multiscale Sample Entropy using neurokit2.entropy_multiscale()
pcv
([per_day, ddof])Calculates the Percentage Coefficient of Variation (%CV) of the CGM values.
qscore
([slack])Calculates the Q-Score.
quantile
([per_day, q, interpolation])Calculates the quantile of the CGM values.
samp_en
([per_day, delay, dimension, tolerance])Calculates the Sample Entropy using neurokit2.entropy_sample()
std
([per_day, ddof])Calculates the standard deviation of the CGM values.
summary
([auc_time_unit, mag_time_unit, ...])Calculates a summary of the metrics for the entire dataset or for each day separately.
tir
([per_day, interval, percentage, decimals])Calculates the Time in Range (TIR) for a given target range of glucose.