Simulator.OESimulator.SimulationData package¶
Submodules¶
Simulator.OESimulator.SimulationData.CONSTANTS module¶
- Simulator.OESimulator.SimulationData.CONSTANTS.DATETIME_FORMAT: str = '%d-%m-%Y %H:%M:%S'¶
Date format.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_BW: float = 110.0¶
Maximum value of the body weight.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_CI: float = 3350.0¶
Maximum value of the insulin clearance.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_EGP: float = 2.23¶
Maximum value of the endogenous glucose production.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_GEZI: float = 0.07¶
Maximum value of the glucose consumption at zero insulin level.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_P2: float = 0.1¶
Maximum value of the rate constant of the insulin effect.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_SI: float = 0.0021¶
Maximum value of the insulin sensitivity.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_TAU1: float = 70.0¶
Maximum value of the time constant of the insulin absorption in the 1st compartment.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_TAU2: float = 50.0¶
Maximum value of the time constant of the insulin absorption in the 2nd compartment.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_TAUD: float = 60.0¶
Maximum value of the time constant of the CHO absorption.
- Simulator.OESimulator.SimulationData.CONSTANTS.MAX_VG: float = 1000.0¶
Maximum value of the glucose distribution volume.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_BW: float = 50.0¶
Minimum value of the body weight.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_CI: float = 372.0¶
Minimum value of the insulin clearance.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_EGP: float = 0.062¶
Minimum value of the endogenous glucose production.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_GEZI: float = 0.0005¶
Minimum value of the glucose consumption at zero insulin level.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_P2: float = 0.02¶
Minimum value of the rate constant of the insulin effect.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_SI: float = 2.3e-06¶
Minimum value of the insulin sensitivity.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_TAU1: float = 10.0¶
Minimum value of the time constant of the insulin absorption in the 1st compartment.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_TAU2: float = 10.0¶
Minimum value of the time constant of the insulin absorption in the 2nd compartment.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_TAUD: float = 10.0¶
Minimum value of the time constant of the CHO absorption.
- Simulator.OESimulator.SimulationData.CONSTANTS.MIN_VG: float = 100.0¶
Minimum value of the glucose distribution volume.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_BW: float = 69.7¶
Nominal value of the body weight.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_CI: float = 1200.0¶
Nominal value of the insulin clearance.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_EGP: float = 1.488¶
Nominal value of the endogenous glucose production.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_GEZI: float = 3.03e-08¶
Nominal value of the glucose consumption at zero insulin level.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_P2: float = 0.010288¶
Nominal value of the rate constant of the insulin effect.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_SI: float = 0.0007¶
Nominal value of the insulin sensitivity.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_TAU1: float = 70.05¶
Nominal value of the time constant of the insulin absorption in the 1st compartment.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_TAU2: float = 43.4¶
Nominal value of the time constant of the insulin absorption in the 2nd compartment.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_TAUD: float = 40.0¶
Nominal value of the time constant of the CHO absorption.
- Simulator.OESimulator.SimulationData.CONSTANTS.NOMINAL_VG: float = 180.0¶
Nominal value of the glucose distribution volume.
Simulator.OESimulator.SimulationData.DataContainer module¶
- class Simulator.OESimulator.SimulationData.DataContainer.DataContainer(scalar: Optional[float] = None, array: Optional[numpy.ndarray] = None, timestamped_array: Optional[numpy.ndarray] = None, impulsive: bool = False)[source]¶
Bases:
object
Stores data in different formats (scalar, array (with Ts sampling), timestamped array). Defined by __slots__ as the class only serves quick data access purposes.
- property as_array: numpy.ndarray¶
Gets and sets the variable in array format.
Note
Sampled based on the Ts variable of the Scenario.
- Returns
Returns data in array format.
- Return type
float
- property as_scalar¶
Gets and sets the variable in scalar format.
Note
When array format exists, it returns the value corresponding to the current time point. It is relevant only as an attribute of the SimulationData.
- Returns
Returns data in scalar format.
- Return type
float
- property as_timestamped_array: numpy.ndarray¶
Gets and sets the variable in timestamped array format.
Note
Times points are given in Unix timestamp format [minutes].
- Returns
Returns data in timestamped array format.
- Return type
float
Examples
>>> print(self.as_timestamped_array) [[26679390 30 40] [26679540 15 10]]
- impulsive¶
Simulator.OESimulator.SimulationData.ParamsT1DMS module¶
- class Simulator.OESimulator.SimulationData.ParamsT1DMS.ParamsT1DMS[source]¶
Bases:
object
ParamsT1DMS stores the Uva/Padova simulator related scenario parameters.
Note
All the member variables all the equivalent of the Uva/Padova Matlab simulator variables.
- BGinit¶
- CR¶
- IV_glucose¶
- IV_insulin¶
- OB¶
- Qbasal¶
- Qbolus¶
- Qmeals¶
- SQg¶
- Tclosed¶
- Treg¶
- Tsimul¶
- basal¶
- hardwareN_pump¶
- hardwareN_sensor¶
- hardware_sensorType¶
- meal_duration¶
- simToD¶
Simulator.OESimulator.SimulationData.PatientData module¶
Simulator.OESimulator.SimulationData.PatientParams module¶
- class Simulator.OESimulator.SimulationData.PatientParams.PatientParams(sigma: float = 0.0)[source]¶
Bases:
object
Stores the mathematical model parameters of the patient. Defined by __slots__ as the class only serves quick data access purposes.
- Parameters
BW (float) – Body weight of the patient.
GEZI (DataContainer) – Glucose consumption at zero insulin level.
EGP (DataContainer) – Endogenous glucose production.
CI (float) – Insulin clearance.
tau1 (float) – Time constant of the absorption of the insulin in the 1st compartment.
tau2 (float) – Time constant of the absorption of the insulin in the 2nd compartment.
p2 (float) – Rate constant of the insulin effect.
taud (DataContainer) – Time constant of the absoprtion of the CHO.
meals (DataContainer) – CHO contents of the meals.
Examples
>>> print(PatientParams(sigma=0.0)) --------------------------- Patient parameters: BW:70 GEZI:3e-08 EGP:1.5 CI:1.2e+03 SI:0.0007 tau1:70 tau2:43 p2:0.01 taud:40 Vg:1.8e+02 meal_tauds: ---------------------------
- BW¶
- CI¶
- EGP¶
- GEZI¶
- SI¶
- Vg¶
- is_up_to_date¶
- meals¶
- p2¶
- tau1¶
- tau2¶
- taud¶
Simulator.OESimulator.SimulationData.Position module¶
- class Simulator.OESimulator.SimulationData.Position.Position[source]¶
Bases:
object
Defines the position (column index) of the data of interest in an ndarray. Defined by __slots__ as the class only serves quick data access purposes.
- Parameters
basal – Position (column index) of the basal rate value in an ndarray.
bolus – Position (column index) of the bolus value in an ndarray.
meal – Position (column index) of the cho content in an ndarray.
time_constant – Position (column index) of the time constant in an ndarray.
glucose_level – Position (column index) of the glucose value in an ndarray.
- basal¶
- bolus¶
- glucose_level¶
- meal¶
- time_constant¶
Simulator.OESimulator.SimulationData.Scenario module¶
- class Simulator.OESimulator.SimulationData.Scenario.Scenario(start_time: Union[str, int] = '%d-%m-%Y %H:%M:%S or integer', end_time: Union[str, int] = '%d-%m-%Y %H:%M:%S or integer', scenario_setting: str = '', verbose: bool = False)[source]¶
Bases:
object
Scenario class provides a storage and interface for the simulation related information (time points of the simulation horizon, meal, insulin inputs, units, sampling time, etc.). Defined by __slots__ as the class only serves quick data access purposes.
- Parameters
scenario_setting (str) – Scenario setting: manual/DT/azure.
Ts (int) – sampling time (Default: 5 minutes)
basal_insulin (float) – Current basal insulin input.
bolus_insulin (float) – Current bolus insulin input.
rate_of_appearance (float) – Current rate of appearance input.
no_boluses (int) – Number of boluses in the window.
no_meals (int) – Number of meals in the window.
units (Units) – Units of the scenario.
position (Position) – Positions of the input values in a multidimensional array.
start_time (Timestamp) – Start time of the scenario.
end_time (Timestamp) – End time of the scenario str/int.
t_start (float) – Start time of the scenario (unix time, minute).
t_end (float) – End time of the scenario (unix time, minute).
manual_meals (ndarray) – User defined meal scheme. 2D array [timepoint, cho content, absorption time constant]
manual_boluses (ndarray) – User defined bolus scheme. 2D array [timepoint, insulin content]
manual_basal_insulin (ndarray) – User defined basal insulin scheme. 2D array [timepoint, insulin rate]
verbose (bool) – Prints information upon the creation of the Scenario and warning messages are activated.
params_t1dms (ParamsT1DMS) – Stores the Uva/Padova Matlab simulator related parameters.
Examples
>>> scenario = Scenario(0,1000,"manual",verbose=True) --------------------------- Current scenario: Start time: 01-01-1970 00:00:00 End time: 01-01-1970 16:40:00 Sampling time: 5 Scenario setting: manual ---------------------------
>>> scenario = Scenario("22-09-2020 07:00:00", "22-09-2020 19:00:00", "emulated", verbose=True) --------------------------- Current scenario: Start time: 22-09-2020 07:00:00 End time: 22-09-2020 19:00:00 Sampling time: 5 Scenario setting: emulated ---------------------------
- Ts¶
- appendBasalInsulin(next_basal: float = 0.0, unit: str = 'U/hr')[source]¶
Modifies the basal rate in the next time pont (defined by Ts).
- Parameters
next_basal – New basal rate.
unit – Unit of the basal rate.
- appendBolusInsulin(next_bolus: float = 0.0, unit: str = 'U')[source]¶
Appends bolus insulin to the already defined scenario.
- Parameters
next_bolus – Bolus value in the next time point (defined by Ts).
unit – Unit of the bolus.
- basal_insulin¶
- bolus_insulin¶
- checkScheme(time_array: Tuple[float, ...], value_scheme: Tuple[float, ...]) → bool[source]¶
Checks the validity of the used defined arrays, the following criterias have to be met.
- Parameters
time_array – Time points of the input array.
value_scheme – Values of the input array.
- Returns
True if the scheme is properly defined.
- Return type
bool
- Raises
Value error – ERROR: The time and value array have to be of equal length.
Value error – ERROR: Values have to be >= 0.
Value error – WARNING: Time points defined before the start time of the scenario.
Value error – WARNING: Time points defined after the end time of the scenario.
Value error – WARNING: Time points have to be strictly monotonically increasing.
- cho¶
- end_time¶
- ident_horizon¶
- manual_basal_insulin¶
- manual_boluses¶
- manual_meals¶
- no_boluses¶
- no_meals¶
- params_t1dms¶
- plot(show=True)[source]¶
Plots the CHO and insulin intakes of the scenario. Horizontal axis in UNIX timestamp [minutes].
Examples
>>> self.plot()
- position¶
- rate_of_appearance¶
- scenario_setting¶
- setManualBasalInsulin(basal_insulin_values: Union[float, Tuple[float]] = 0.0, basal_insulin_times: Optional[Tuple[float]] = None, unit: str = 'U/hr')[source]¶
Creates 2D numpy array for the basal insulin.
Note
If a scalar basal rate is provided without time point, it is assumed that the basal rate is active since 0 unix time.
- Parameters
basal_insulin_values – User defined basal rate.
basal_insulin_times – User defined time point, when the basal rate is activated.
unit – Unit of the basal rate.
Examples
>>> self.setManualBasalInsulin(1.0,unit=r"U/hr")
- setManualBolusScheme(bolus_times: Union[Tuple[float, ...], Tuple[str, ...]], bolus_values: Tuple[float, ...], unit: str = 'U') → numpy.ndarray[source]¶
Creates the 2D numpy array for the bolus scheme.
Note
If the timepoints are strings, it converts to unix timestamps. Checks the validity of input arrays. Sets the no_boluses attribute based on the number of meals in the input arrays.
- Parameters
bolus_times – User defined time points of the boluses.
bolus_values – User defined bolus values.
unit – Unit of the bolus values.
- Returns
2D numpy array containing the combined time points and values.
- Return type
ndarray
Examples
>>> self.setManualBolusScheme(bolus_times=("22-09-2020 07:00:00", "22-09-2020 12:00:00", "22-09-2020 18:00:00"),bolus_values=(2, 4, 3))
- setManualMealScheme(meal_times: Union[Tuple[float, ...], Tuple[str, ...]], meal_values: Tuple[float, ...], time_constants: Optional[Tuple[float, ...]] = None, unit: str = 'g') → numpy.ndarray[source]¶
Creates the 2D numpy array for the meal scheme.
Note
If the timepoints are strings, it converts to unix timestamps. Checks the validity of input arrays. Sets the no_meals attribute based on the number of meals in the input arrays.
- Parameters
meal_times – User defined time points of the meals.
meal_values – User defined meal values.
unit – Unit of the meal values.
- Returns
2D numpy array containing the combined time points and values.
- Return type
ndarray
Examples
>>> self.setManualMealScheme(meal_times=("22-09-2020 06:00:00", "22-09-2020 12:00:00", "22-09-2020 18:00:00"),meal_values=(10, 40, 30),time_constants=(30,30,40)) Warning: You have inputs defined before the start time of the scenario.
- setParamsT1DMS(simToD: float = 0.0, Qmeals: str = 'total', Treg: float = 0.0, meal_duration: float = 15.0, Qbasal: str = 'fixed', OB='off', Qbolus: str = 'total', SQg: float = 1.0)[source]¶
Sets the Uva/Padova simulator related parameters of the scenario.
- Parameters
simToD (float) – Represents the “simToD” variable of the UVA/Padova simulator.
Qmeals (str) – Represents the “Qmeals” variable of the UVA/Padova simulator.
Treg (str) – Represents the “Treg” variable of the UVA/Padova simulator.
meal_duration (float) – Represents the “meal_duration” variable of the UVA/Padova simulator.
Qbasal (str) – Represents the “Qbasal” variable of the UVA/Padova simulator.
OB (str) – Represents the “OB” variable of the UVA/Padova simulator.
Qbolus (str) – Represents the “Qbolus” variable of the UVA/Padova simulator.
SQg (float) – Represents the “SQg” variable of the UVA/Padova simulator.
- shift(time_shift: Optional[int] = None, next_meal: Optional[float] = None, next_taud: Optional[float] = None, next_bolus: Optional[float] = None, next_basal_insulin: Optional[float] = None)[source]¶
Shifts the scenario by the user defined time.
Note
Default of Ts shift is assumed without any modification on the CHO and insulin scheme.
- Parameters
time_shift – The time [minutes] by which the scenario is shifted. Default value of Ts.
next_meal – CHO content of the meal in the shifted time step.
next_taud – Absorption time constant of the meal in the shifted time step.
next_bolus – Bolus insulin in the shifted time step.
next_basal_insulin – Modified basal rate from the shifted time step.
- start_time¶
- t_pred¶
- units¶
- verbose¶
Simulator.OESimulator.SimulationData.SimulationData module¶
- class Simulator.OESimulator.SimulationData.SimulationData.SimulationData(scenario: Simulator.OESimulator.SimulationData.Scenario.Scenario)[source]¶
Bases:
object
Stores all the necessary information to simulate a virtual patient. Created by DataProcessor instance. Defined by __slots__ as the class only serves quick data access purposes.
- Parameters
t_start (int) – Start time of the simulation horizon in Unix timestamp format [minutes].
t_end (int) – Start time of the simulation horizon in Unix timestamp format [minutes].
scenario (Scenario) – Scenario of the simulation.
units (Units) – Units of the simulated mathematical model.
glucose_level (ndarray) – Measured glucose levels (if available).
meal (DataContainer) – Meal consumptions in the simulation horizon.
basal (DataContainer) – Basal infusion rates in the simulation horizon.
bolus (DataContainer) – Bolus injections in the simulation horizon.
rate_of_appearance (DataContainer) – Generated rate of appearance values of the mathematical model in Ts sample time resolution.
EGP (DataContainer) – Generated EGP values of the mathematical model in Ts sample time resolution.
GEZI (DataContainer) – Generated GEZI values of the mathematical model in Ts sample time resolution.
SI (DataContainer) – Generated SI values of the mathematical model in Ts sample time resolution.
iterator_range (range) – Iterator for the simulation horizon.
time_axis (list) – Timepoints of the simulation horizon in Unix timestamp format [minutes].
t_section (tuple) – Stores the timepoints where the daily intervals change based on the circadian rhythm. Always at meal consumptions.
- EGP¶
- GEZI¶
- SI¶
- Vg¶
- basal¶
- bolus¶
- glucose_level¶
- is_meal_up_to_date¶
- iterator_range¶
- meal¶
- rate_of_appearance¶
- scenario¶
- t_end¶
- t_sections¶
- t_start¶
- time_axis¶
- time_range¶
- trim(new_start_time: Optional[Union[str, int]] = None, new_end_time: Optional[Union[str, int]] = None)[source]¶
Trims all the arrays, which are sampled in Ts resolution inbetween the new start and end time.
Note
Serves for quick resimulation, if the patient parameters and inputs remain the same and only the start or the end time of the horizon is changed.
- Parameters
new_start_time (Union[str,int]) – New start time of the simulation horizon.
new_end_time (Union[str,int]) – New end time of the simulation horizon.
Examples
>>> print(self.basal.as_array.shape) >>> self.trim(self.scenario.start_time.as_int+60,self.scenario.end_time.as_int) >>> print(self.basal.as_array.shape) (577,) (565,)
- units¶
Simulator.OESimulator.SimulationData.Timestamp module¶
- class Simulator.OESimulator.SimulationData.Timestamp.Timestamp(timestamp: Optional[Union[str, int]] = None)[source]¶
Bases:
object
Stores time information in three alternative formats (Unix timestamp [minutes], string, datetime) Defined by __slots__ as the class only serves quick data access purposes.
Note
Can be initialized in string or Unix timestamp [minutes] format. It automatically converts to the rest of the formats.
- Raises
ValueError – If the provided string format is not %d-%m-%Y %H:%M:%S.
- property as_datetime¶
Gets and sets timestamp based on datetime object.
- Returns
Timestamp in datetime format.
- Return type
datetime
Examples
>>> print(Timestamp(26679500).as_datetime) 2020-09-22 10:20:00
- property as_int¶
Gets and sets timestamp based on Unix timestamp [minutes] format.
- Returns
Timestamp in Unix timestamp [minutes] format.
- Return type
int
Examples
>>> print(Timestamp("22-09-2020 10:20:00").as_int) 26679500
- property as_str¶
Gets and sets timestamp based on string format.
- Returns
Timestamp in string format.
- Return type
str
Examples
>>> print(Timestamp(26679500).as_str) 22-09-2020 10:20:00
Simulator.OESimulator.SimulationData.Units module¶
- class Simulator.OESimulator.SimulationData.Units.Units[source]¶
Bases:
object
Defines the units of the variables in strings. Defined by __slots__ as the class only serves quick data access purposes.
- Parameters
basal (str) – Unit of the basal rate.
bolus (str) – Unit of the bolus insulin.
insulin (str) – Unit of the insulin input.
meal (str) – Unit of the meal.
- basal¶
- bolus¶
- static convertUnits(original_value: Union[float, numpy.ndarray], unit_from: str, unit_to: str, Ts: float) → Union[float, numpy.ndarray][source]¶
Convert values between different units.
Note
- Possible conversions:
from U/hr to uU/min from U to uU/min (based on Ts) from g to g/min (based on Ts) from uU/min to U/min
- Parameters
original_value – The unconverted value(s).
unit_from – Unit of the unconverted value(s).
unit_to – Unit of the converted value(s).
Ts – Sampling time.
- Returns
The converted value(s).
- Return type
Union[float, ndarray]
Examples
>>> print(Units.convertUnits(original_value=10,unit_from="U/hr",unit_to=r"uU/min",Ts=5)) 166666.666
- insulin¶
- meal¶