API Reference — Metrics¶
The metrics layer computes clinical statistics from a CGM time series.
High-level facade¶
The GlucoseAnalysis facade (in cgmpy.analysis.core) provides all
metrics via methods:
from cgmpy import GlucoseAnalysis
analysis = GlucoseAnalysis("data.csv")
analysis.mean()
analysis.TIR()
analysis.cv()
analysis.gmi()
analysis.MAGE()
# ... see the API reference for the full list.
See cgmpy.analysis.core.GlucoseAnalysis for the full method list.
Pure functions¶
All metric calculations are also available as standalone functions:
| Module | Functions |
|---|---|
cgmpy.metrics.basic |
mean, median, sd, cv, gmi, percentile |
cgmpy.metrics.time_in_range |
tir, tar, tbr, data_completeness |
cgmpy.metrics.variability.sd |
sd_global, sd_within_day, sd_between_timepoints, ... |
cgmpy.metrics.variability.mage |
mage_simple, mage_baghurst |
cgmpy.metrics.variability.modd |
modd |
cgmpy.metrics.variability.conga |
conga |
cgmpy.metrics.variability.lability |
lability_index |
cgmpy.metrics.variability.risk |
j_index, lbgi, hbgi, gri, adrr, m_value, grade |
Targets¶
cgmpy.metrics.targets.GlucoseTargets
dataclass
¶
Class to define glucose targets for metrics calculation.
Source code in cgmpy/metrics/targets.py
standard
classmethod
¶
Standard targets for general diabetes. Level 2 hypo < 54, Level 1 hypo 54-70, TIR 70-180, TAR 180-250, TAR > 250.
Source code in cgmpy/metrics/targets.py
pregnancy
classmethod
¶
Specific targets for pregnancy. Level 2 hypo < 55, Level 1 hypo 55-63, TIR 63-140, TAR 140-250, TAR > 250.
Source code in cgmpy/metrics/targets.py
cgmpy.metrics.targets.get_targets
¶
get_targets(target_type: str = 'diabetes') -> GlucoseTargets
Factory function to get glucose targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_type
|
str
|
Either 'diabetes' (default) or 'pregnancy'. |
'diabetes'
|
Returns:
| Type | Description |
|---|---|
GlucoseTargets
|
GlucoseTargets object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in cgmpy/metrics/targets.py
Pregnancy¶
cgmpy.metrics.pregnancy.PregnancyAnalysis
¶
Analysis of CGM data during pregnancy (pregestational and gestational).
Provides trimester-specific metrics and reports for pregnant women with diabetes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_source
|
str | DataFrame | GlucoseData
|
A file path or DataFrame with glucose data. |
required |
delivery_date
|
str
|
Estimated delivery date in 'YYYY-MM-DD' format. |
required |
week
|
int
|
Gestation week at delivery. |
required |
day
|
int
|
Additional days (default 0). |
0
|
**kwargs
|
Any
|
Additional arguments passed to |
{}
|
Source code in cgmpy/metrics/pregnancy.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
summary_by_trimester
¶
Simplified comparative summary.
Source code in cgmpy/metrics/pregnancy.py
all_simplified
¶
Simplified metrics dictionary for overall pregnancy data.
Source code in cgmpy/metrics/pregnancy.py
calculate_all_metrics
¶
Complete analysis summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flatten
|
bool
|
If True, returns a flat dictionary with prefixes (total_, t1_, t2_, t3_, gest_) suitable for CSV/DataFrames. |
False
|