Data¶
The data-preparation classes that turn a raw DataFrame into the model-ready
rbg_data. Each is one half of a blueprint.
SingleMealT1DData¶
Prepare and store time-series data for the ReplayBG simulation pipeline.
The class converts a pandas dataframe into the arrays and metadata needed by the model and twinning procedure. It extracts time, glucose, insulin, and meal information, and organizes them into regularly sampled vectors that can be consumed by the simulator. This variant handles a single (unlabelled) meal channel.
...
Attributes:
| Name | Type | Description |
|---|---|---|
data_to_input |
dict
|
Mapping from input-channel index to attribute name used to build |
u2ss |
float
|
Mean basal insulin value, used as a steady-state basal estimate. |
body_weight |
float
|
Patient body weight used to normalize inputs. |
yts |
int
|
Number of simulation integration steps per data sample. |
tsteps |
int
|
Total number of simulation steps. |
tysteps |
int
|
Number of data-sampling steps represented in the simulation. |
t_data |
ndarray
|
Original time values from the dataframe. |
t_hour |
ndarray
|
Hour value expanded to simulation resolution. |
t_min |
ndarray
|
Minute value expanded to simulation resolution. |
y |
ndarray
|
Glucose values as a float array. |
y_idxs |
ndarray
|
Indices of non-missing glucose observations. |
basal |
ndarray
|
Basal insulin input expanded to simulation resolution. |
bolus |
ndarray
|
Bolus insulin input expanded to simulation resolution. |
bolus_label |
ndarray
|
Labels associated with bolus events. |
meal |
ndarray
|
Meal carbohydrate input expanded to simulation resolution. |
meal_announcement |
ndarray
|
Meal announcement signal. |
meal_type |
ndarray
|
Labels associated with meal events. |
forcing_ip |
ndarray
|
External forcing added directly to the plasma insulin compartment (zero unless overridden after construction). |
forcing_ra |
ndarray
|
External forcing added directly to the glucose rate of appearance (zero unless overridden after construction). |
u |
ndarray
|
Combined input matrix used by the model. |
Methods:
| Name | Description |
|---|---|
None |
|
Source code in src/py_replay_bg/data/single_meal_t1d_data.py
9 10 11 12 13 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 | |
data_to_input = {0: 'meal', 1: 'bolus', 2: 'basal', 3: 'forcing_ip', 4: 'forcing_ra'}
instance-attribute
¶
u2ss = np.mean(data.basal.values) * 1000 / body_weight
instance-attribute
¶
body_weight = body_weight
instance-attribute
¶
yts = 5
instance-attribute
¶
y = data.glucose.values.astype(float)
instance-attribute
¶
y_idxs = np.where(~np.isnan(self.y))[0]
instance-attribute
¶
forcing_ip = np.zeros([self.tsteps])
instance-attribute
¶
forcing_ra = np.zeros([self.tsteps])
instance-attribute
¶
__init__(data=None, data_to_input=None, body_weight=100.0, environment=None)
¶
Constructs all the necessary attributes for the data object from a dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input dataframe containing the raw replay data. |
: None
|
data_to_input
|
dict
|
Mapping from input indices to attribute names used to assemble the
model input matrix. If |
: None
|
body_weight
|
float
|
Patient body weight used to normalize insulin and meal inputs. |
: 100.
|
environment
|
Environment
|
Environment object containing simulation settings such as the integration time step. |
: None
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If required dataframe columns are missing. |
TypeError
|
If |
Source code in src/py_replay_bg/data/single_meal_t1d_data.py
MultiMealT1DData¶
Prepare and store time-series data for the ReplayBG simulation pipeline.
The class converts a pandas dataframe into the arrays and metadata needed by the model and twinning procedure. It extracts time, glucose, insulin, and meal information, and organizes them into regularly sampled vectors that can be consumed by the simulator. This variant handles multiple labelled daily meals (breakfast, lunch, dinner, snack, hypo-treatment).
...
Attributes:
| Name | Type | Description |
|---|---|---|
data_to_input |
dict
|
Mapping from input-channel index to attribute name used to build |
u2ss |
float
|
Mean basal insulin value, used as a steady-state basal estimate. |
body_weight |
float
|
Patient body weight used to normalize inputs. |
yts |
int
|
Number of simulation integration steps per data sample. |
tsteps |
int
|
Total number of simulation steps. |
tysteps |
int
|
Number of data-sampling steps represented in the simulation. |
t_data |
ndarray
|
Original time values from the dataframe. |
t_hour |
ndarray
|
Hour value expanded to simulation resolution. |
t_min |
ndarray
|
Minute value expanded to simulation resolution. |
y |
ndarray
|
Glucose values as a float array. |
y_idxs |
ndarray
|
Indices of non-missing glucose observations. |
basal |
ndarray
|
Basal insulin input expanded to simulation resolution. |
bolus |
ndarray
|
Bolus insulin input expanded to simulation resolution. |
bolus_label |
ndarray
|
Labels associated with bolus events. |
meal |
ndarray
|
Meal carbohydrate input expanded to simulation resolution. |
meal_announcement |
ndarray
|
Meal announcement signal. |
meal_type |
ndarray
|
Labels associated with meal events. |
forcing_ip |
ndarray
|
External forcing added directly to the plasma insulin compartment (zero unless overridden after construction). |
forcing_ra |
ndarray
|
External forcing added directly to the glucose rate of appearance (zero unless overridden after construction). |
u |
ndarray
|
Combined input matrix used by the model. |
Methods:
| Name | Description |
|---|---|
None |
|
Source code in src/py_replay_bg/data/multi_meal_t1d_data.py
9 10 11 12 13 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | |
data_to_input = {0: 'meal_B', 1: 'meal_L', 2: 'meal_D', 3: 'meal_S', 4: 'meal_H', 5: 'bolus', 6: 'basal', 7: 't_hour', 8: 'forcing_ip', 9: 'forcing_ra'}
instance-attribute
¶
u2ss = np.mean(data.basal.values) * 1000 / body_weight
instance-attribute
¶
body_weight = body_weight
instance-attribute
¶
yts = 5
instance-attribute
¶
y = data.glucose.values.astype(float)
instance-attribute
¶
y_idxs = np.where(~np.isnan(self.y))[0]
instance-attribute
¶
forcing_ip = np.zeros([self.tsteps])
instance-attribute
¶
forcing_ra = np.zeros([self.tsteps])
instance-attribute
¶
__init__(data=None, data_to_input=None, body_weight=100.0, environment=None)
¶
Constructs all the necessary attributes for the data object from a dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input dataframe containing the raw replay data. |
: None
|
data_to_input
|
dict
|
Mapping from input indices to attribute names used to assemble the
model input matrix. If |
: None
|
body_weight
|
float
|
Patient body weight used to normalize insulin and meal inputs. |
: 100.
|
environment
|
Environment
|
Environment object containing simulation settings such as the integration time step. |
: None
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If required dataframe columns are missing. |
TypeError
|
If |
Source code in src/py_replay_bg/data/multi_meal_t1d_data.py
MultiMealExtendedT1DData¶
Prepare and store time-series data for the ReplayBG simulation pipeline.
The class converts a pandas dataframe into the arrays and metadata needed by
the model and twinning procedure. It extracts time, glucose, insulin, and
meal information, and organizes them into regularly sampled vectors that can
be consumed by the simulator. This extended variant adds second-occurrence
meal channels (B2, L2, S2) to support simulations spanning more
than one day.
...
Attributes:
| Name | Type | Description |
|---|---|---|
data_to_input |
dict
|
Mapping from input-channel index to attribute name used to build |
u2ss |
float
|
Mean basal insulin value, used as a steady-state basal estimate. |
body_weight |
float
|
Patient body weight used to normalize inputs. |
yts |
int
|
Number of simulation integration steps per data sample. |
tsteps |
int
|
Total number of simulation steps. |
tysteps |
int
|
Number of data-sampling steps represented in the simulation. |
t_data |
ndarray
|
Original time values from the dataframe. |
t_hour |
ndarray
|
Hour value expanded to simulation resolution. |
t_min |
ndarray
|
Minute value expanded to simulation resolution. |
y |
ndarray
|
Glucose values as a float array. |
y_idxs |
ndarray
|
Indices of non-missing glucose observations. |
basal |
ndarray
|
Basal insulin input expanded to simulation resolution. |
bolus |
ndarray
|
Bolus insulin input expanded to simulation resolution. |
bolus_label |
ndarray
|
Labels associated with bolus events. |
meal |
ndarray
|
Meal carbohydrate input expanded to simulation resolution. |
meal_announcement |
ndarray
|
Meal announcement signal. |
meal_type |
ndarray
|
Labels associated with meal events. |
forcing_ip |
ndarray
|
External forcing added directly to the plasma insulin compartment (zero unless overridden after construction). |
forcing_ra |
ndarray
|
External forcing added directly to the glucose rate of appearance (zero unless overridden after construction). |
u |
ndarray
|
Combined input matrix used by the model. |
Methods:
| Name | Description |
|---|---|
None |
|
Source code in src/py_replay_bg/data/multi_meal_extended_t1d_data.py
9 10 11 12 13 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
data_to_input = {0: 'meal_B', 1: 'meal_L', 2: 'meal_D', 3: 'meal_S', 4: 'meal_H', 5: 'meal_B2', 6: 'meal_L2', 7: 'meal_S2', 8: 'bolus', 9: 'basal', 10: 't_hour', 11: 'forcing_ip', 12: 'forcing_ra'}
instance-attribute
¶
u2ss = np.mean(data.basal.values) * 1000 / body_weight
instance-attribute
¶
body_weight = body_weight
instance-attribute
¶
yts = 5
instance-attribute
¶
y = data.glucose.values.astype(float)
instance-attribute
¶
y_idxs = np.where(~np.isnan(self.y))[0]
instance-attribute
¶
forcing_ip = np.zeros([self.tsteps])
instance-attribute
¶
forcing_ra = np.zeros([self.tsteps])
instance-attribute
¶
__init__(data=None, data_to_input=None, body_weight=100.0, environment=None)
¶
Constructs all the necessary attributes for the data object from a dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Input dataframe containing the raw replay data. |
: None
|
data_to_input
|
dict
|
Mapping from input indices to attribute names used to assemble the
model input matrix. If |
: None
|
body_weight
|
float
|
Patient body weight used to normalize insulin and meal inputs. |
: 100.
|
environment
|
Environment
|
Environment object containing simulation settings such as the integration time step. |
: None
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If required dataframe columns are missing. |
TypeError
|
If |