├── .gitignore ├── .idea ├── .gitignore ├── UVAPadovaAPI.iml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── .nojekyll ├── README.md ├── docs ├── .buildinfo ├── .doctrees │ ├── OESimulator.DataProcessing.doctree │ ├── OESimulator.SimulationData.doctree │ ├── OESimulator.doctree │ ├── Simulator.OESimulator.DataProcessing.doctree │ ├── Simulator.OESimulator.SimulationData.doctree │ ├── Simulator.OESimulator.doctree │ ├── Simulator.UVAPadova.doctree │ ├── Simulator.doctree │ ├── UVAPadova.doctree │ ├── UVAPadovaAPI.doctree │ ├── UVAPadovaAPIWrapper.doctree │ ├── environment.pickle │ ├── index.doctree │ ├── modules.doctree │ ├── uva_padova_API.doctree │ └── uva_padova_API_Wrapper.doctree ├── .nojekyll ├── Makefile ├── OESimulator.DataProcessing.html ├── OESimulator.SimulationData.html ├── OESimulator.html ├── Simulator.OESimulator.DataProcessing.html ├── Simulator.OESimulator.SimulationData.html ├── Simulator.OESimulator.html ├── Simulator.UVAPadova.html ├── Simulator.html ├── UVAPadova.html ├── UVAPadovaAPI.html ├── UVAPadovaAPIWrapper.html ├── _modules │ ├── OESimulator │ │ ├── DataProcessing │ │ │ ├── DBFile.html │ │ │ └── ErrorCodes.html │ │ ├── DataProcessor.html │ │ └── SimulationData │ │ │ ├── DataContainer.html │ │ │ ├── ParamsT1DMS.html │ │ │ ├── PatientData.html │ │ │ ├── PatientParams.html │ │ │ ├── Position.html │ │ │ ├── Scenario.html │ │ │ ├── SimulationData.html │ │ │ ├── Timestamp.html │ │ │ └── Units.html │ ├── Simulator │ │ ├── OESimulator │ │ │ ├── DataProcessing │ │ │ │ ├── DBFile.html │ │ │ │ └── ErrorCodes.html │ │ │ ├── DataProcessor.html │ │ │ └── SimulationData │ │ │ │ ├── DataContainer.html │ │ │ │ ├── ParamsT1DMS.html │ │ │ │ ├── PatientData.html │ │ │ │ ├── PatientParams.html │ │ │ │ ├── Position.html │ │ │ │ ├── Scenario.html │ │ │ │ ├── SimulationData.html │ │ │ │ ├── Timestamp.html │ │ │ │ └── Units.html │ │ └── UVAPadova │ │ │ ├── UVAPadovaSimulator.html │ │ │ ├── VirtualPatientT1DMS.html │ │ │ └── uva_padova_simulator.html │ ├── UVAPadova │ │ └── VirtualPatientT1DMS.html │ ├── UVAPadovaAPI.html │ ├── UVAPadovaAPIWrapper.html │ ├── flask_restful.html │ ├── index.html │ ├── uva_padova_API.html │ └── uva_padova_API_Wrapper.html ├── _sources │ ├── OESimulator.DataProcessing.rst.txt │ ├── OESimulator.SimulationData.rst.txt │ ├── OESimulator.rst.txt │ ├── Simulator.OESimulator.DataProcessing.rst.txt │ ├── Simulator.OESimulator.SimulationData.rst.txt │ ├── Simulator.OESimulator.rst.txt │ ├── Simulator.UVAPadova.rst.txt │ ├── Simulator.rst.txt │ ├── UVAPadova.rst.txt │ ├── UVAPadovaAPI.rst.txt │ ├── UVAPadovaAPIWrapper.rst.txt │ ├── index.rst.txt │ ├── modules.rst.txt │ ├── uva_padova_API.rst.txt │ └── uva_padova_API_Wrapper.rst.txt ├── _static │ ├── basic.css │ ├── css │ │ ├── jast.css │ │ └── redactor.css │ ├── doctools.js │ ├── documentation_options.js │ ├── file.png │ ├── fonts │ │ ├── materialdesignicons-webfont.eot │ │ ├── materialdesignicons-webfont.svg │ │ ├── materialdesignicons-webfont.ttf │ │ ├── materialdesignicons-webfont.woff │ │ └── materialdesignicons-webfont.woff2 │ ├── jquery-3.5.1.js │ ├── jquery.js │ ├── js │ │ └── theme-min.js │ ├── language_data.js │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── underscore-1.13.1.js │ └── underscore.js ├── genindex.html ├── index.html ├── make.bat ├── modules.html ├── objects.inv ├── py-modindex.html ├── search.html ├── searchindex.js ├── source │ ├── Simulator.OESimulator.DataProcessing.rst │ ├── Simulator.OESimulator.SimulationData.rst │ ├── Simulator.OESimulator.rst │ ├── Simulator.UVAPadova.rst │ ├── Simulator.rst │ ├── UVAPadovaAPI.rst │ ├── UVAPadovaAPIWrapper.rst │ ├── conf.py │ ├── index.rst │ ├── layout.svg │ └── modules.rst ├── uva_padova_API.html └── uva_padova_API_Wrapper.html ├── examples └── tests │ ├── cohort_simulation.py │ ├── test01.py │ ├── test01_5min.py │ ├── test02.py │ ├── test02_5min.py │ ├── test03.py │ ├── test03_5min.py │ ├── test04.py │ ├── test04_5min.py │ ├── test05.py │ ├── test05_5min.py │ ├── test06.py │ └── test06_5min.py ├── requirements.txt └── src ├── Simulator ├── OESimulator │ ├── DataProcessing │ │ ├── DBFile.py │ │ ├── ErrorCodes.py │ │ └── __init__.py │ ├── DataProcessor.py │ ├── SimulationData │ │ ├── CONSTANTS.py │ │ ├── DataContainer.py │ │ ├── ParamsT1DMS.py │ │ ├── PatientData.py │ │ ├── PatientParams.py │ │ ├── Position.py │ │ ├── Scenario.py │ │ ├── SimulationData.py │ │ ├── Timestamp.py │ │ ├── Units.py │ │ └── __init__.py │ └── __init__.py ├── UVAPadova │ ├── LicenseManagerAPI.bat │ ├── UVAPadovaSimulator.py │ ├── VirtualPatientT1DMS.py │ ├── __init__.py │ └── connect_function.m └── __init__.py ├── UVAPadovaAPI.py └── UVAPadovaAPIWrapper.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .ropeproject 3 | /doc/build -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/UVAPadovaAPI.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/.nojekyll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # An application programming interface for the widely used academic version of the UVA/Padova Type 1 Diabetes Metabolic simulator 2 | 3 | The UVA/Padova Type 1 Diabetes Simulator is a widely applied tool to test control algorithms among diabetes researchers. The academic version is implemented in Matlab; while Matlab is very popular in the academic field, Python is the most popular programming language. We developed an application programming interface (API) for the simulator in Python, and a representational state transfer (REST) API for additional extension route with a Python reference implementation for easier usage. The interface is designed with the specific purpose of testing control algorithms, thus it does not provide the full functionality of the Matlab simulator. The developed API is tested for different simulation scenarios, showcasing identical results between the API and the programming interface of the original simulator. Additional information and the source code can be found in https://github.com/NeuroDiab/UVAPadovaAPI. 4 | 5 | ## What can I do with the API? 6 | 7 | * Simulate virtual patients from native Python. ⚫ 8 | * Simulate virtual patients through REST API using a Python reference wrapper. 🔵 9 | * Simulate virtual patients through REST API. ⚪ 10 | 11 | 12 | 13 | ## How to get the API up and running? 14 | 15 | ### Requirements: 16 | * Working Matlab version: 17 | * Academic version of the UVA/Padova Type 1 Diabetes Metabolic Simulator. 18 | * Installed Matlab Engine. 19 | * Installed Python. 20 | ### Setup: 21 | * Clone the repository. 22 | * Install requirements.txt. 23 | * Copy src\UVAPadova\connect_function.m to your UVA/Padova Simulator installation folder. 24 | * Run uva_padova_API.py 25 | * Run one of the examples. 26 | 27 | ### Notes: 28 | * If the UVA/Padova Simulator is not installed in the default path, src\UVAPadova\LicenseManagerAPI.bat and src\UVAPadova\VirtualPatientT1DMS.py has to be modified. 29 | 30 | ## Documentation 31 | 32 | https://neurodiab.github.io/UVAPadovaAPI/ 33 | 34 | ## Cite 35 | -------------------------------------------------------------------------------- /docs/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: e3f6d8dfd6c374490b39fd52f240188c 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/.doctrees/OESimulator.DataProcessing.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/OESimulator.DataProcessing.doctree -------------------------------------------------------------------------------- /docs/.doctrees/OESimulator.SimulationData.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/OESimulator.SimulationData.doctree -------------------------------------------------------------------------------- /docs/.doctrees/OESimulator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/OESimulator.doctree -------------------------------------------------------------------------------- /docs/.doctrees/Simulator.OESimulator.DataProcessing.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/Simulator.OESimulator.DataProcessing.doctree -------------------------------------------------------------------------------- /docs/.doctrees/Simulator.OESimulator.SimulationData.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/Simulator.OESimulator.SimulationData.doctree -------------------------------------------------------------------------------- /docs/.doctrees/Simulator.OESimulator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/Simulator.OESimulator.doctree -------------------------------------------------------------------------------- /docs/.doctrees/Simulator.UVAPadova.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/Simulator.UVAPadova.doctree -------------------------------------------------------------------------------- /docs/.doctrees/Simulator.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/Simulator.doctree -------------------------------------------------------------------------------- /docs/.doctrees/UVAPadova.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/UVAPadova.doctree -------------------------------------------------------------------------------- /docs/.doctrees/UVAPadovaAPI.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/UVAPadovaAPI.doctree -------------------------------------------------------------------------------- /docs/.doctrees/UVAPadovaAPIWrapper.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/UVAPadovaAPIWrapper.doctree -------------------------------------------------------------------------------- /docs/.doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/.doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/index.doctree -------------------------------------------------------------------------------- /docs/.doctrees/modules.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/modules.doctree -------------------------------------------------------------------------------- /docs/.doctrees/uva_padova_API.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/uva_padova_API.doctree -------------------------------------------------------------------------------- /docs/.doctrees/uva_padova_API_Wrapper.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.doctrees/uva_padova_API_Wrapper.doctree -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/.nojekyll -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/OESimulator.DataProcessing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | OESimulator.DataProcessing package 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 101 |
102 |
103 | 104 |
105 |

OESimulator.DataProcessing package

106 |
107 |

Submodules

108 |
109 |
110 |

OESimulator.DataProcessing.DBFile module

111 |
112 |
113 |

OESimulator.DataProcessing.ErrorCodes module

114 |
115 |
116 |

Module contents

117 |
118 |
119 | 120 | 121 |
122 | 123 |
124 | 125 | 126 | 127 | 128 | 138 | 139 | 140 | 141 | 142 |
143 | 144 | 158 | 159 | 160 | 161 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /docs/OESimulator.SimulationData.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | OESimulator.SimulationData package 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 101 |
102 |
103 | 104 |
105 |

OESimulator.SimulationData package

106 |
107 |

Submodules

108 |
109 |
110 |

OESimulator.SimulationData.CONSTANTS module

111 |
112 |
113 |

OESimulator.SimulationData.DataContainer module

114 |
115 |
116 |

OESimulator.SimulationData.ParamsT1DMS module

117 |
118 |
119 |

OESimulator.SimulationData.PatientData module

120 |
121 |
122 |

OESimulator.SimulationData.PatientParams module

123 |
124 |
125 |

OESimulator.SimulationData.Position module

126 |
127 |
128 |

OESimulator.SimulationData.Scenario module

129 |
130 |
131 |

OESimulator.SimulationData.SimulationData module

132 |
133 |
134 |

OESimulator.SimulationData.Timestamp module

135 |
136 |
137 |

OESimulator.SimulationData.Units module

138 |
139 |
140 |

Module contents

141 |
142 |
143 | 144 | 145 |
146 | 147 |
148 | 149 | 150 | 151 | 152 | 162 | 163 | 164 | 165 | 166 |
167 | 168 | 182 | 183 | 184 | 185 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /docs/OESimulator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | OESimulator package 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 101 |
102 | 148 | 149 |
150 | 151 | 152 | 153 | 154 | 164 | 165 | 166 | 167 | 168 |
169 | 170 | 184 | 185 | 186 | 187 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /docs/UVAPadova.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | UVAPadova package 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 | 81 | 82 |
83 | 84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 108 |
109 |
110 | 111 |
112 |

UVAPadova package

113 |
114 |

Submodules

115 |
116 |
117 |

UVAPadova.VirtualPatientT1DMS module

118 |
119 |
120 |

UVAPadova.uva_padova_simulator module

121 |
122 |
123 |

Module contents

124 |
125 |
126 | 127 | 128 |
129 | 130 |
131 | 132 | 133 | 142 | 143 | 144 | 145 | 155 | 156 | 157 | 158 | 159 |
160 | 161 | 175 | 176 | 177 | 178 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /docs/_modules/OESimulator/DataProcessing/ErrorCodes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | OESimulator.DataProcessing.ErrorCodes 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 | 73 | 74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 104 |
105 |
106 | 107 |

Source code for OESimulator.DataProcessing.ErrorCodes

108 | from enum import Enum
109 | 
[docs]class ERROR_CODES(Enum): 110 | DATE_INVALID = 1 111 | CGM_EMPTY = 100 112 | CGM_INVALID = 101 113 | CGM_OUTOFRANGE = 102 114 | CGM_GAP = 103 115 | INSULIN_EMPTY = 200 116 | INSULIN_INVALID = 201 117 | CHO_EMPTY = 300 118 | CHO_INVALID = 301
119 |
120 | 121 |
122 | 123 |
124 | 125 | 126 | 127 | 128 | 133 | 134 | 135 | 136 | 137 |
138 | 139 | 153 | 154 | 155 | 156 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/_modules/OESimulator/SimulationData/ParamsT1DMS.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | OESimulator.SimulationData.ParamsT1DMS 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 105 |
106 |
107 | 108 |

Source code for OESimulator.SimulationData.ParamsT1DMS

109 | 
[docs]class ParamsT1DMS: 110 | """ ParamsT1DMS stores the Uva/Padova simulator related scenario parameters. 111 | 112 | Note: 113 | All the member variables all the equivalent of the Uva/Padova Matlab simulator variables. 114 | 115 | """ 116 | __slots__ = ['Tsimul','simToD','Qmeals','Tclosed','BGinit','Treg','basal','Qbasal','CR','Qbolus', 117 | 'IV_glucose','IV_insulin','SQg','OB','CR','meal_duration','hardwareN_sensor','hardwareN_pump', 118 | 'hardware_sensorType'] 119 | 120 | def __init__(self): 121 | self.simToD : float = 0.0 122 | self.Qmeals : str = 'total' 123 | self.Treg : float = 0.0 124 | self.meal_duration : float = 15.0 125 | self.Qbasal : str = 'fixed' 126 | self.OB : str = 'off' 127 | self.CR : str = 'off' 128 | self.Qbolus : str = 'total' 129 | self.SQg : float = 1.0
130 |
131 | 132 |
133 | 134 |
135 | 136 | 137 | 138 | 139 | 144 | 145 | 146 | 147 | 148 |
149 | 150 | 164 | 165 | 166 | 167 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /docs/_modules/OESimulator/SimulationData/PatientData.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | OESimulator.SimulationData.PatientData 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 | 73 | 74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 104 |
105 |
106 | 107 |

Source code for OESimulator.SimulationData.PatientData

108 | import numpy as np
109 | from .PatientParams import PatientParams
110 | 
111 | 
[docs]class PatientData(object): 112 | """ Patient data. 113 | Defined by __slots__ as the class only serves quick data access purposes. 114 | """ 115 | __slots__ = ['x_hist_timestamped','patient_params_timestamped','patient_id','patient_params'] 116 | 117 | def __init__(self): 118 | """ Constructor. 119 | 120 | """ 121 | # Stores the historically estimated states with timestamps. 122 | self.x_hist_timestamped: np.ndarray = np.array([], dtype=np.float32) 123 | # Stores the historically estimated patient parameters. 124 | self.patient_params_timestamped: np.ndarray = np.array([], dtype=np.float32) 125 | # Patient ID as in the database. 126 | self.patient_id: str = "" 127 | # Current patient parameters. 128 | self.patient_params = PatientParams() 129 | 130 | @property 131 | def __dict__(self): 132 | return {s: getattr(self, s, None) for s in self.__slots__}
133 |
134 | 135 |
136 | 137 |
138 | 139 | 140 | 141 | 142 | 147 | 148 | 149 | 150 | 151 |
152 | 153 | 167 | 168 | 169 | 170 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /docs/_modules/Simulator/OESimulator/DataProcessing/ErrorCodes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Simulator.OESimulator.DataProcessing.ErrorCodes 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 105 |
106 |
107 | 108 |

Source code for Simulator.OESimulator.DataProcessing.ErrorCodes

109 | from enum import Enum
110 | 
[docs]class ERROR_CODES(Enum): 111 | DATE_INVALID = 1 112 | CGM_EMPTY = 100 113 | CGM_INVALID = 101 114 | CGM_OUTOFRANGE = 102 115 | CGM_GAP = 103 116 | INSULIN_EMPTY = 200 117 | INSULIN_INVALID = 201 118 | CHO_EMPTY = 300 119 | CHO_INVALID = 301
120 |
121 | 122 |
123 | 124 |
125 | 126 | 127 | 128 | 129 | 134 | 135 | 136 | 137 | 138 |
139 | 140 | 154 | 155 | 156 | 157 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/_modules/Simulator/OESimulator/SimulationData/ParamsT1DMS.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Simulator.OESimulator.SimulationData.ParamsT1DMS 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 105 |
106 |
107 | 108 |

Source code for Simulator.OESimulator.SimulationData.ParamsT1DMS

109 | 
[docs]class ParamsT1DMS: 110 | """ ParamsT1DMS stores the Uva/Padova simulator related scenario parameters. 111 | 112 | Note: 113 | All the member variables all the equivalent of the Uva/Padova Matlab simulator variables. 114 | 115 | """ 116 | __slots__ = ['Tsimul','simToD','Qmeals','Tclosed','BGinit','Treg','basal','Qbasal','CR','Qbolus', 117 | 'IV_glucose','IV_insulin','SQg','OB','CR','meal_duration','hardwareN_sensor','hardwareN_pump', 118 | 'hardware_sensorType'] 119 | 120 | def __init__(self): 121 | self.simToD : float = 0.0 122 | self.Qmeals : str = 'total' 123 | self.Treg : float = 0.0 124 | self.meal_duration : float = 15.0 125 | self.Qbasal : str = 'fixed' 126 | self.OB : str = 'off' 127 | self.CR : str = 'off' 128 | self.Qbolus : str = 'total' 129 | self.SQg : float = 1.0
130 |
131 | 132 |
133 | 134 |
135 | 136 | 137 | 138 | 139 | 144 | 145 | 146 | 147 | 148 |
149 | 150 | 164 | 165 | 166 | 167 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /docs/_modules/Simulator/OESimulator/SimulationData/PatientData.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Simulator.OESimulator.SimulationData.PatientData 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 105 |
106 |
107 | 108 |

Source code for Simulator.OESimulator.SimulationData.PatientData

109 | import numpy as np
110 | from .PatientParams import PatientParams
111 | 
112 | 
[docs]class PatientData(object): 113 | """ Patient data. 114 | Defined by __slots__ as the class only serves quick data access purposes. 115 | """ 116 | __slots__ = ['x_hist_timestamped','patient_params_timestamped','patient_id','patient_params'] 117 | 118 | def __init__(self): 119 | """ Constructor. 120 | 121 | """ 122 | # Stores the historically estimated states with timestamps. 123 | self.x_hist_timestamped: np.ndarray = np.array([], dtype=np.float32) 124 | # Stores the historically estimated patient parameters. 125 | self.patient_params_timestamped: np.ndarray = np.array([], dtype=np.float32) 126 | # Patient ID as in the database. 127 | self.patient_id: str = "" 128 | # Current patient parameters. 129 | self.patient_params = PatientParams() 130 | 131 | @property 132 | def __dict__(self): 133 | return {s: getattr(self, s, None) for s in self.__slots__}
134 |
135 | 136 |
137 | 138 |
139 | 140 | 141 | 142 | 143 | 148 | 149 | 150 | 151 | 152 |
153 | 154 | 168 | 169 | 170 | 171 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /docs/_modules/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Overview: module code 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 | 73 | 74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 100 |
101 | 123 | 124 |
125 | 126 | 127 | 128 | 129 | 134 | 135 | 136 | 137 | 138 |
139 | 140 | 154 | 155 | 156 | 157 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/_sources/OESimulator.DataProcessing.rst.txt: -------------------------------------------------------------------------------- 1 | OESimulator.DataProcessing package 2 | ================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | OESimulator.DataProcessing.DBFile module 8 | ---------------------------------------- 9 | 10 | .. automodule:: OESimulator.DataProcessing.DBFile 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | OESimulator.DataProcessing.ErrorCodes module 16 | -------------------------------------------- 17 | 18 | .. automodule:: OESimulator.DataProcessing.ErrorCodes 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: OESimulator.DataProcessing 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/_sources/OESimulator.SimulationData.rst.txt: -------------------------------------------------------------------------------- 1 | OESimulator.SimulationData package 2 | ================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | OESimulator.SimulationData.CONSTANTS module 8 | ------------------------------------------- 9 | 10 | .. automodule:: OESimulator.SimulationData.CONSTANTS 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | OESimulator.SimulationData.DataContainer module 16 | ----------------------------------------------- 17 | 18 | .. automodule:: OESimulator.SimulationData.DataContainer 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | OESimulator.SimulationData.ParamsT1DMS module 24 | --------------------------------------------- 25 | 26 | .. automodule:: OESimulator.SimulationData.ParamsT1DMS 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | OESimulator.SimulationData.PatientData module 32 | --------------------------------------------- 33 | 34 | .. automodule:: OESimulator.SimulationData.PatientData 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | OESimulator.SimulationData.PatientParams module 40 | ----------------------------------------------- 41 | 42 | .. automodule:: OESimulator.SimulationData.PatientParams 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | OESimulator.SimulationData.Position module 48 | ------------------------------------------ 49 | 50 | .. automodule:: OESimulator.SimulationData.Position 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | OESimulator.SimulationData.Scenario module 56 | ------------------------------------------ 57 | 58 | .. automodule:: OESimulator.SimulationData.Scenario 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | OESimulator.SimulationData.SimulationData module 64 | ------------------------------------------------ 65 | 66 | .. automodule:: OESimulator.SimulationData.SimulationData 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | OESimulator.SimulationData.Timestamp module 72 | ------------------------------------------- 73 | 74 | .. automodule:: OESimulator.SimulationData.Timestamp 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | OESimulator.SimulationData.Units module 80 | --------------------------------------- 81 | 82 | .. automodule:: OESimulator.SimulationData.Units 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | Module contents 88 | --------------- 89 | 90 | .. automodule:: OESimulator.SimulationData 91 | :members: 92 | :undoc-members: 93 | :show-inheritance: 94 | -------------------------------------------------------------------------------- /docs/_sources/OESimulator.rst.txt: -------------------------------------------------------------------------------- 1 | OESimulator package 2 | =================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | OESimulator.DataProcessing 11 | OESimulator.SimulationData 12 | 13 | Submodules 14 | ---------- 15 | 16 | OESimulator.DataProcessor module 17 | -------------------------------- 18 | 19 | .. automodule:: OESimulator.DataProcessor 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: OESimulator 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /docs/_sources/Simulator.OESimulator.DataProcessing.rst.txt: -------------------------------------------------------------------------------- 1 | Simulator.OESimulator.DataProcessing package 2 | ============================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | Simulator.OESimulator.DataProcessing.DBFile module 8 | -------------------------------------------------- 9 | 10 | .. automodule:: Simulator.OESimulator.DataProcessing.DBFile 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Simulator.OESimulator.DataProcessing.ErrorCodes module 16 | ------------------------------------------------------ 17 | 18 | .. automodule:: Simulator.OESimulator.DataProcessing.ErrorCodes 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: Simulator.OESimulator.DataProcessing 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/_sources/Simulator.OESimulator.SimulationData.rst.txt: -------------------------------------------------------------------------------- 1 | Simulator.OESimulator.SimulationData package 2 | ============================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | Simulator.OESimulator.SimulationData.CONSTANTS module 8 | ----------------------------------------------------- 9 | 10 | .. automodule:: Simulator.OESimulator.SimulationData.CONSTANTS 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Simulator.OESimulator.SimulationData.DataContainer module 16 | --------------------------------------------------------- 17 | 18 | .. automodule:: Simulator.OESimulator.SimulationData.DataContainer 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Simulator.OESimulator.SimulationData.ParamsT1DMS module 24 | ------------------------------------------------------- 25 | 26 | .. automodule:: Simulator.OESimulator.SimulationData.ParamsT1DMS 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Simulator.OESimulator.SimulationData.PatientData module 32 | ------------------------------------------------------- 33 | 34 | .. automodule:: Simulator.OESimulator.SimulationData.PatientData 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Simulator.OESimulator.SimulationData.PatientParams module 40 | --------------------------------------------------------- 41 | 42 | .. automodule:: Simulator.OESimulator.SimulationData.PatientParams 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Simulator.OESimulator.SimulationData.Position module 48 | ---------------------------------------------------- 49 | 50 | .. automodule:: Simulator.OESimulator.SimulationData.Position 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | Simulator.OESimulator.SimulationData.Scenario module 56 | ---------------------------------------------------- 57 | 58 | .. automodule:: Simulator.OESimulator.SimulationData.Scenario 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | Simulator.OESimulator.SimulationData.SimulationData module 64 | ---------------------------------------------------------- 65 | 66 | .. automodule:: Simulator.OESimulator.SimulationData.SimulationData 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | Simulator.OESimulator.SimulationData.Timestamp module 72 | ----------------------------------------------------- 73 | 74 | .. automodule:: Simulator.OESimulator.SimulationData.Timestamp 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | Simulator.OESimulator.SimulationData.Units module 80 | ------------------------------------------------- 81 | 82 | .. automodule:: Simulator.OESimulator.SimulationData.Units 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | Module contents 88 | --------------- 89 | 90 | .. automodule:: Simulator.OESimulator.SimulationData 91 | :members: 92 | :undoc-members: 93 | :show-inheritance: 94 | -------------------------------------------------------------------------------- /docs/_sources/Simulator.OESimulator.rst.txt: -------------------------------------------------------------------------------- 1 | Simulator.OESimulator package 2 | ============================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | Simulator.OESimulator.DataProcessing 11 | Simulator.OESimulator.SimulationData 12 | 13 | Submodules 14 | ---------- 15 | 16 | Simulator.OESimulator.DataProcessor module 17 | ------------------------------------------ 18 | 19 | .. automodule:: Simulator.OESimulator.DataProcessor 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: Simulator.OESimulator 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /docs/_sources/Simulator.UVAPadova.rst.txt: -------------------------------------------------------------------------------- 1 | Simulator.UVAPadova package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | Simulator.UVAPadova.UVAPadovaSimulator module 8 | --------------------------------------------- 9 | 10 | .. automodule:: Simulator.UVAPadova.UVAPadovaSimulator 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Simulator.UVAPadova.VirtualPatientT1DMS module 16 | ---------------------------------------------- 17 | 18 | .. automodule:: Simulator.UVAPadova.VirtualPatientT1DMS 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: Simulator.UVAPadova 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/_sources/Simulator.rst.txt: -------------------------------------------------------------------------------- 1 | Simulator package 2 | ================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | Simulator.OESimulator 11 | Simulator.UVAPadova 12 | 13 | Module contents 14 | --------------- 15 | 16 | .. automodule:: Simulator 17 | :members: 18 | :undoc-members: 19 | :show-inheritance: 20 | -------------------------------------------------------------------------------- /docs/_sources/UVAPadova.rst.txt: -------------------------------------------------------------------------------- 1 | UVAPadova package 2 | ================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | UVAPadova.VirtualPatientT1DMS module 8 | ------------------------------------ 9 | 10 | .. automodule:: UVAPadova.VirtualPatientT1DMS 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | UVAPadova.uva\_padova\_simulator module 16 | --------------------------------------- 17 | 18 | .. automodule:: UVAPadova.uva_padova_simulator 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: UVAPadova 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/_sources/UVAPadovaAPI.rst.txt: -------------------------------------------------------------------------------- 1 | UVAPadovaAPI module 2 | =================== 3 | 4 | .. automodule:: UVAPadovaAPI 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/UVAPadovaAPIWrapper.rst.txt: -------------------------------------------------------------------------------- 1 | UVAPadovaAPIWrapper module 2 | ========================== 3 | 4 | .. automodule:: UVAPadovaAPIWrapper 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. UVA/PadovaAPI documentation master file, created by 2 | sphinx-quickstart on Mon Sep 12 11:12:52 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to UVA/Padova API's documentation! 7 | ======================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | UVAPadovaAPI 14 | UVAPadovaAPIWrapper 15 | Simulator.UVAPadova 16 | 17 | 18 | Indices and tables 19 | ================== 20 | 21 | * :ref:`genindex` 22 | * :ref:`modindex` 23 | * :ref:`search` 24 | -------------------------------------------------------------------------------- /docs/_sources/modules.rst.txt: -------------------------------------------------------------------------------- 1 | src 2 | === 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | Simulator 8 | UVAPadovaAPI 9 | UVAPadovaAPIWrapper 10 | -------------------------------------------------------------------------------- /docs/_sources/uva_padova_API.rst.txt: -------------------------------------------------------------------------------- 1 | uva\_padova\_API module 2 | ======================= 3 | 4 | .. automodule:: uva_padova_API 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_sources/uva_padova_API_Wrapper.rst.txt: -------------------------------------------------------------------------------- 1 | uva\_padova\_API\_Wrapper module 2 | ================================ 3 | 4 | .. automodule:: uva_padova_API_Wrapper 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false 12 | }; -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/fonts/materialdesignicons-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/_static/fonts/materialdesignicons-webfont.eot -------------------------------------------------------------------------------- /docs/_static/fonts/materialdesignicons-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/_static/fonts/materialdesignicons-webfont.ttf -------------------------------------------------------------------------------- /docs/_static/fonts/materialdesignicons-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/_static/fonts/materialdesignicons-webfont.woff -------------------------------------------------------------------------------- /docs/_static/fonts/materialdesignicons-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/_static/fonts/materialdesignicons-webfont.woff2 -------------------------------------------------------------------------------- /docs/_static/js/theme-min.js: -------------------------------------------------------------------------------- 1 | function has_class(e,s){return e.classList?e.classList.contains(s):new RegExp("(^| )"+s+"( |$)","gi").test(e.className)}function add_class(e,s){e.classList?e.classList.add(s):e.className+=" "+s}function toggle_class(e,s){if(e.classList)e.classList.toggle(s);else{var a=e.className.split(" "),t=a.indexOf(s);t>=0?a.splice(t,1):a.push(s),e.className=a.join(" ")}}function wrap(e,s){e.parentNode.insertBefore(s,e),s.appendChild(e)}function add_event(e,s,a,t){s&&(e.addEventListener?e.addEventListener(s,a,!!t):e.attachEvent("on"+s,a))}var i=0,tables=document.querySelectorAll("table.docutils");for(i=0;i 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Welcome to UVA/Padova API’s documentation! 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 | 75 | 76 |
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 102 |
103 |
104 | 105 |
106 |

Welcome to UVA/Padova API’s documentation!

107 | 121 |
122 |
123 |

Indices and tables

124 | 129 |
130 | 131 | 132 |
133 | 134 |
135 | 136 | 137 | 146 | 147 | 148 | 149 | 159 | 160 | 161 | 162 | 163 |
164 | 165 | 179 | 180 | 181 | 182 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/modules.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | src 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 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 101 |
102 | 137 | 138 |
139 | 140 | 141 | 142 | 143 | 153 | 154 | 155 | 156 | 157 |
158 | 159 | 173 | 174 | 175 | 176 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/docs/objects.inv -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Search 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 | 73 | 74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 100 |
101 |
102 | 103 | 113 | 114 |
115 | 116 | 117 |
118 | 119 |
120 |
121 | 122 |
123 | 124 |
125 | 126 | 127 | 128 | 129 | 132 | 133 | 134 | 135 | 136 |
137 | 138 | 152 | 153 | 154 | 155 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /docs/source/Simulator.OESimulator.DataProcessing.rst: -------------------------------------------------------------------------------- 1 | Simulator.OESimulator.DataProcessing package 2 | ============================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | Simulator.OESimulator.DataProcessing.DBFile module 8 | -------------------------------------------------- 9 | 10 | .. automodule:: Simulator.OESimulator.DataProcessing.DBFile 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Simulator.OESimulator.DataProcessing.ErrorCodes module 16 | ------------------------------------------------------ 17 | 18 | .. automodule:: Simulator.OESimulator.DataProcessing.ErrorCodes 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: Simulator.OESimulator.DataProcessing 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/Simulator.OESimulator.SimulationData.rst: -------------------------------------------------------------------------------- 1 | Simulator.OESimulator.SimulationData package 2 | ============================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | Simulator.OESimulator.SimulationData.CONSTANTS module 8 | ----------------------------------------------------- 9 | 10 | .. automodule:: Simulator.OESimulator.SimulationData.CONSTANTS 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Simulator.OESimulator.SimulationData.DataContainer module 16 | --------------------------------------------------------- 17 | 18 | .. automodule:: Simulator.OESimulator.SimulationData.DataContainer 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Simulator.OESimulator.SimulationData.ParamsT1DMS module 24 | ------------------------------------------------------- 25 | 26 | .. automodule:: Simulator.OESimulator.SimulationData.ParamsT1DMS 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Simulator.OESimulator.SimulationData.PatientData module 32 | ------------------------------------------------------- 33 | 34 | .. automodule:: Simulator.OESimulator.SimulationData.PatientData 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Simulator.OESimulator.SimulationData.PatientParams module 40 | --------------------------------------------------------- 41 | 42 | .. automodule:: Simulator.OESimulator.SimulationData.PatientParams 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Simulator.OESimulator.SimulationData.Position module 48 | ---------------------------------------------------- 49 | 50 | .. automodule:: Simulator.OESimulator.SimulationData.Position 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | Simulator.OESimulator.SimulationData.Scenario module 56 | ---------------------------------------------------- 57 | 58 | .. automodule:: Simulator.OESimulator.SimulationData.Scenario 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | Simulator.OESimulator.SimulationData.SimulationData module 64 | ---------------------------------------------------------- 65 | 66 | .. automodule:: Simulator.OESimulator.SimulationData.SimulationData 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | Simulator.OESimulator.SimulationData.Timestamp module 72 | ----------------------------------------------------- 73 | 74 | .. automodule:: Simulator.OESimulator.SimulationData.Timestamp 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | Simulator.OESimulator.SimulationData.Units module 80 | ------------------------------------------------- 81 | 82 | .. automodule:: Simulator.OESimulator.SimulationData.Units 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | Module contents 88 | --------------- 89 | 90 | .. automodule:: Simulator.OESimulator.SimulationData 91 | :members: 92 | :undoc-members: 93 | :show-inheritance: 94 | -------------------------------------------------------------------------------- /docs/source/Simulator.OESimulator.rst: -------------------------------------------------------------------------------- 1 | Simulator.OESimulator package 2 | ============================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | Simulator.OESimulator.DataProcessing 11 | Simulator.OESimulator.SimulationData 12 | 13 | Submodules 14 | ---------- 15 | 16 | Simulator.OESimulator.DataProcessor module 17 | ------------------------------------------ 18 | 19 | .. automodule:: Simulator.OESimulator.DataProcessor 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | 24 | Module contents 25 | --------------- 26 | 27 | .. automodule:: Simulator.OESimulator 28 | :members: 29 | :undoc-members: 30 | :show-inheritance: 31 | -------------------------------------------------------------------------------- /docs/source/Simulator.UVAPadova.rst: -------------------------------------------------------------------------------- 1 | Simulator.UVAPadova package 2 | =========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | Simulator.UVAPadova.UVAPadovaSimulator module 8 | --------------------------------------------- 9 | 10 | .. automodule:: Simulator.UVAPadova.UVAPadovaSimulator 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Simulator.UVAPadova.VirtualPatientT1DMS module 16 | ---------------------------------------------- 17 | 18 | .. automodule:: Simulator.UVAPadova.VirtualPatientT1DMS 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: Simulator.UVAPadova 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/Simulator.rst: -------------------------------------------------------------------------------- 1 | Simulator package 2 | ================= 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | Simulator.OESimulator 11 | Simulator.UVAPadova 12 | 13 | Module contents 14 | --------------- 15 | 16 | .. automodule:: Simulator 17 | :members: 18 | :undoc-members: 19 | :show-inheritance: 20 | -------------------------------------------------------------------------------- /docs/source/UVAPadovaAPI.rst: -------------------------------------------------------------------------------- 1 | UVAPadovaAPI module 2 | =================== 3 | 4 | .. automodule:: UVAPadovaAPI 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/source/UVAPadovaAPIWrapper.rst: -------------------------------------------------------------------------------- 1 | UVAPadovaAPIWrapper module 2 | ========================== 3 | 4 | .. automodule:: UVAPadovaAPIWrapper 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | #sys.path.append('D:/Kutatas/UvaPadova/src') 17 | sys.path.append('C:/mentes/obuda/BlackAnt/PythonUVa/uvapadovatemp/src') 18 | 19 | import sphinx_redactor_theme 20 | html_theme = 'sphinx_redactor_theme' 21 | html_theme_path = [sphinx_redactor_theme.get_html_theme_path()] 22 | 23 | 24 | # -- Project information ----------------------------------------------------- 25 | 26 | project = 'UVA/Padova API' 27 | copyright = '2022, ntoth,msiket,lszasz,knovak,geigner' 28 | author = 'ntoth,msiket,lszasz,knovak,geigner' 29 | 30 | 31 | # -- General configuration --------------------------------------------------- 32 | 33 | # Add any Sphinx extension module names here, as strings. They can be 34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 35 | # ones. 36 | extensions = ['sphinx.ext.napoleon','sphinx.ext.viewcode'] 37 | 38 | # Add any paths that contain templates here, relative to this directory. 39 | templates_path = ['_templates'] 40 | 41 | # List of patterns, relative to source directory, that match files and 42 | # directories to ignore when looking for source files. 43 | # This pattern also affects html_static_path and html_extra_path. 44 | exclude_patterns = [] 45 | 46 | 47 | # -- Options for HTML output ------------------------------------------------- 48 | 49 | # The theme to use for HTML and HTML Help pages. See the documentation for 50 | # a list of builtin themes. 51 | # 52 | html_theme = 'sphinx_redactor_theme' 53 | 54 | # Add any paths that contain custom static files (such as style sheets) here, 55 | # relative to this directory. They are copied after the builtin static files, 56 | # so a file named "default.css" will overwrite the builtin "default.css". 57 | html_static_path = ['_static'] -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. UVA/PadovaAPI documentation master file, created by 2 | sphinx-quickstart on Mon Sep 12 11:12:52 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to UVA/Padova API's documentation! 7 | ======================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :caption: Contents: 12 | 13 | UVAPadovaAPI 14 | UVAPadovaAPIWrapper 15 | Simulator.UVAPadova 16 | 17 | 18 | Indices and tables 19 | ================== 20 | 21 | * :ref:`genindex` 22 | * :ref:`modindex` 23 | * :ref:`search` 24 | -------------------------------------------------------------------------------- /docs/source/modules.rst: -------------------------------------------------------------------------------- 1 | src 2 | === 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | Simulator 8 | UVAPadovaAPI 9 | UVAPadovaAPIWrapper 10 | -------------------------------------------------------------------------------- /docs/uva_padova_API.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | uva_padova_API module 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 | 76 | 77 |
78 | 79 |
80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 103 |
104 |
105 | 106 |
107 |

uva_padova_API module

108 |
109 | 110 | 111 |
112 | 113 |
114 | 115 | 116 | 130 | 131 | 132 | 133 | 143 | 144 | 145 | 146 | 147 |
148 | 149 | 163 | 164 | 165 | 166 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /docs/uva_padova_API_Wrapper.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | uva_padova_API_Wrapper module 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 | 76 | 77 |
78 | 79 |
80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 103 |
104 |
105 | 106 |
107 |

uva_padova_API_Wrapper module

108 |
109 | 110 | 111 |
112 | 113 |
114 | 115 | 116 | 130 | 131 | 132 | 133 | 143 | 144 | 145 | 146 | 147 |
148 | 149 | 163 | 164 | 165 | 166 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /examples/tests/cohort_simulation.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 4 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 5 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 6 | import matlab.engine 7 | import pickle 8 | 9 | tstart = 0 10 | tend = 1700 11 | 12 | patients = ["adult#001.mat","adult#002.mat","adult#003.mat","adult#004.mat","adult#005.mat", 13 | "adult#006.mat","adult#007.mat","adult#008.mat","adult#009.mat","adult#010.mat"] 14 | 15 | insulin_scalers = [0.5,0.5,0.7,0.3,0.5,1,0.5,1,0.3,0.3] 16 | 17 | patient = VirtualPatientT1DMS(patient_name="adult#001.mat", BGinit=matlab.double([])) # , eng=eng, path=path 18 | 19 | for patient_name,insulin_scaler in zip(patients,insulin_scalers): 20 | 21 | patient.patient = patient_name 22 | 23 | b = np.asarray([3,3,4,3,3,2])*insulin_scaler 24 | bt = [7.3*60, 10.3*60, 13*60, 15.25*60, 18.25*60, 21.1*60] 25 | m = np.asarray([35,10,65,20,45]) 26 | mt = [7.5*60, 10.5*60, 12*60, 16.5*60, 18.5*60] 27 | 28 | b = tuple(b) 29 | bt = tuple(bt) 30 | m = tuple(m) 31 | mt = tuple(mt) 32 | Tsim = float(tend - tstart) 33 | scenario = Scenario(tstart,tend,"t1dms") 34 | scenario.Ts = 1 35 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 36 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 37 | scenario.setManualBasalInsulin(patient.Quest.basal, unit=r"U/hr") 38 | scenario.setHardware(sensor='guardianRT.scs', pump='Generic_1.pmp') 39 | scenario.setParamsT1DMS() 40 | 41 | T1DMSprocessor = DataProcessor() 42 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 43 | 44 | 45 | patient.simulatePatient(simulation_data=T1DMSdata) 46 | 47 | # save_object = {} 48 | # save_object["scenario"] = Scenario 49 | # save_object["data"] = T1DMSdata 50 | # save_object["result"] = patient.result 51 | # filehandler = open(patient_name+".pkl", "wb") 52 | # pickle.dump(save_object, filehandler) 53 | 54 | scenario.plot(show=False) 55 | patient.plotHistoricalStates() -------------------------------------------------------------------------------- /examples/tests/test01.py: -------------------------------------------------------------------------------- 1 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 2 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 3 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 4 | import matlab.engine 5 | 6 | tstart = 0 7 | tend = 60 8 | b = [] 9 | bt = [] 10 | m = [] 11 | mt = [] 12 | 13 | # test01: 0.1 U bolus insulin in every 5 minutes, 0.0 U basal, no meal 14 | 15 | for i in range(1,tend+1): 16 | if i%5==0: 17 | b.append(0.1) 18 | bt.append(i) 19 | 20 | b = tuple(b) 21 | bt = tuple(bt) 22 | m = tuple(m) 23 | mt = tuple(mt) 24 | Tsim = float(tend - tstart) 25 | scenario = Scenario(tstart,tend,"t1dms") 26 | scenario.Ts = 1 27 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 28 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 29 | scenario.setManualBasalInsulin(0.0, unit=r"U/hr") 30 | scenario.setHardware(sensor='guardianRT.scs', pump='Generic_1.pmp') 31 | scenario.setParamsT1DMS() 32 | 33 | T1DMSprocessor = DataProcessor() # Tsimul, Tclosed, hardware, IVgluc,ins are in dataprocessor 34 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 35 | 36 | patient = VirtualPatientT1DMS(patient_name="adult#005.mat", BGinit=matlab.double([])) # , eng=eng, path=path 37 | 38 | patient.simulatePatient(simulation_data=T1DMSdata) # matlab engine 39 | 40 | patient.plotHistoricalStates() -------------------------------------------------------------------------------- /examples/tests/test01_5min.py: -------------------------------------------------------------------------------- 1 | from src.UVAPadovaAPIWrapper import UvaPadovaAPI 2 | import numpy as np 3 | from scipy.io import savemat 4 | 5 | 6 | tsim = 60 7 | tsim=int(tsim/5) 8 | insulins = np.zeros(tsim) 9 | chos = np.zeros(tsim) 10 | insulins[:] = 0.1 11 | 12 | virtual_patient = UvaPadovaAPI() 13 | virtual_patient.initializePatient("adult#005") 14 | for i in range(tsim): 15 | step_result = virtual_patient.doSimulation(chos[i],insulins[i]) 16 | print(step_result) 17 | #savemat('test5_1.mat',{'Glucose':virtual_patient.listOfBloodGlucoseValues}) 18 | print("") -------------------------------------------------------------------------------- /examples/tests/test02.py: -------------------------------------------------------------------------------- 1 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 2 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 3 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 4 | import matlab.engine 5 | tstart = 0 6 | tend = 60 7 | b = [] 8 | bt = [] 9 | m = [] 10 | mt = [] 11 | 12 | # test02: 0.0 U bolus insulin, 1.2 U basal insulin, no meal 13 | 14 | b = tuple(b) 15 | bt = tuple(bt) 16 | m = tuple(m) 17 | mt = tuple(mt) 18 | Tsim = float(tend - tstart) 19 | scenario = Scenario(tstart,tend,"t1dms") 20 | scenario.Ts = 1 21 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 22 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 23 | scenario.setManualBasalInsulin(1.2, unit=r"U/hr") 24 | scenario.setHardware(sensor='guardianRT.scs', pump='Generic_1.pmp') 25 | scenario.setParamsT1DMS() 26 | 27 | T1DMSprocessor = DataProcessor() # Tsimul, Tclosed, hardware, IVgluc,ins are in dataprocessor 28 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 29 | 30 | patient = VirtualPatientT1DMS(patient_name="adult#005.mat", BGinit=matlab.double([])) # , eng=eng, path=path 31 | 32 | patient.simulatePatient(simulation_data=T1DMSdata) # matlab engine 33 | 34 | patient.plotHistoricalStates() -------------------------------------------------------------------------------- /examples/tests/test02_5min.py: -------------------------------------------------------------------------------- 1 | from src.UVAPadovaAPIWrapper import UvaPadovaAPI 2 | import numpy as np 3 | from scipy.io import savemat 4 | 5 | 6 | tsim = 60 7 | tsim=int(tsim/5) 8 | insulins = np.zeros(tsim) 9 | chos = np.zeros(tsim) 10 | 11 | virtual_patient = UvaPadovaAPI() 12 | virtual_patient.initializePatient("adult#005") 13 | 14 | for i in range(tsim): 15 | step_result = virtual_patient.doSimulation(chos[i],insulins[i]) 16 | print(step_result) 17 | #savemat('test5_2.mat',{'Glucose':virtual_patient.listOfBloodGlucoseValues}) 18 | print("") -------------------------------------------------------------------------------- /examples/tests/test03.py: -------------------------------------------------------------------------------- 1 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 2 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 3 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 4 | import matlab.engine 5 | 6 | tstart = 0 7 | tend = 1440 8 | b = [] 9 | bt = [] 10 | m = [] 11 | mt = [] 12 | 13 | 14 | for i in range(1,tend+1): 15 | if i%120 == 0: 16 | if (i/120)%2 == 0: 17 | b.append(2) 18 | m.append(45) 19 | else: 20 | b.append(1) 21 | m.append(30) 22 | mt.append(i) 23 | bt.append(i) 24 | 25 | Tsim = float(tend - tstart) 26 | scenario = Scenario(tstart,tend,"t1dms") 27 | scenario.Ts = 1 28 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 29 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 30 | scenario.setManualBasalInsulin(1, unit=r"U/hr") 31 | scenario.setHardware(sensor='dexcom.scs', pump='Generic_1.pmp') 32 | scenario.setParamsT1DMS() 33 | 34 | T1DMSprocessor = DataProcessor() # Tsimul, Tclosed, hardware, IVgluc,ins are in dataprocessor 35 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 36 | patient = VirtualPatientT1DMS(patient_name="adolescent#003.mat", BGinit=matlab.double([])) # , eng=eng, path=path adolescent#003.mat 37 | 38 | patient.simulatePatient(simulation_data=T1DMSdata) # matlab engine 39 | patient.plotHistoricalStates() -------------------------------------------------------------------------------- /examples/tests/test03_5min.py: -------------------------------------------------------------------------------- 1 | from src.UVAPadovaAPIWrapper import UvaPadovaAPI 2 | import numpy as np 3 | from scipy.io import savemat 4 | 5 | 6 | tsim = 1440 7 | tsim=int(tsim/5) 8 | insulins = np.zeros(tsim) 9 | chos = np.zeros(tsim) 10 | 11 | for i in range(1,tsim+1): 12 | if i%24 == 0: 13 | if (i/24)%2 == 0: 14 | insulins[i-1] = 2 15 | chos[i-1] = 45 16 | else: 17 | insulins[i-1] = 1 18 | chos[i-1] = 30 19 | 20 | virtual_patient = UvaPadovaAPI() 21 | virtual_patient.initializePatient("adolescent#003") 22 | for i in range(tsim): 23 | step_result = virtual_patient.doSimulation(chos[i],insulins[i]) 24 | print(step_result) 25 | #savemat('test5_3.mat',{'Glucose':virtual_patient.listOfBloodGlucoseValues}) 26 | print("") -------------------------------------------------------------------------------- /examples/tests/test04.py: -------------------------------------------------------------------------------- 1 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 2 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 3 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 4 | import matlab.engine 5 | tstart = 0 6 | tend = 1440 7 | b = [] 8 | bt = [] 9 | m = [] 10 | mt = [] 11 | 12 | # test04: 0.0 U bolus insulin, 0.0 U basal insulin, no meal 13 | 14 | b = tuple(b) 15 | bt = tuple(bt) 16 | m = tuple(m) 17 | mt = tuple(mt) 18 | Tsim = float(tend - tstart) 19 | scenario = Scenario(tstart,tend,"t1dms") 20 | scenario.Ts = 1 21 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 22 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 23 | scenario.setManualBasalInsulin(0.0, unit=r"U/hr") 24 | scenario.setHardware(sensor='dexcom25.scs', pump='Generic_1.pmp') 25 | scenario.setParamsT1DMS() 26 | 27 | T1DMSprocessor = DataProcessor() # Tsimul, Tclosed, hardware, IVgluc,ins are in dataprocessor 28 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 29 | 30 | patient = VirtualPatientT1DMS(patient_name="adult#002.mat", BGinit=matlab.double([])) # , eng=eng, path=path 31 | 32 | patient.simulatePatient(simulation_data=T1DMSdata) # matlab engine 33 | 34 | patient.plotHistoricalStates() 35 | -------------------------------------------------------------------------------- /examples/tests/test04_5min.py: -------------------------------------------------------------------------------- 1 | from src.UVAPadovaAPIWrapper import UvaPadovaAPI 2 | import numpy as np 3 | from scipy.io import savemat 4 | 5 | 6 | tsim = 1440 7 | tsim=int(tsim/5) 8 | insulins = np.zeros(tsim) 9 | chos = np.zeros(tsim) 10 | 11 | virtual_patient = UvaPadovaAPI() 12 | virtual_patient.initializePatient("adult#002") 13 | for i in range(tsim): 14 | step_result = virtual_patient.doSimulation(chos[i],insulins[i]) 15 | print(step_result) 16 | #savemat('test5_4.mat',{'Glucose':virtual_patient.listOfBloodGlucoseValues}) 17 | print("") -------------------------------------------------------------------------------- /examples/tests/test05.py: -------------------------------------------------------------------------------- 1 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 2 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 3 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 4 | import matlab.engine 5 | 6 | tstart = 0 7 | tend = 60 8 | b = [] 9 | bt = [] 10 | m = [] 11 | mt = [] 12 | 13 | # test05: bolus insulin increasing by 0.1 U in every 5 minutes starting from 0.1 U, 14 | # 0.0 U basal insulin, no meal 15 | 16 | for i in range(1,tend+1): 17 | if i%5 == 0: 18 | b.append(round(0.1*(i/5),1)) 19 | bt.append(i) 20 | 21 | b = tuple(b) 22 | bt = tuple(bt) 23 | m = tuple(m) 24 | mt = tuple(mt) 25 | Tsim = float(tend - tstart) 26 | scenario = Scenario(tstart,tend,"t1dms") 27 | scenario.Ts = 1 28 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 29 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 30 | scenario.setManualBasalInsulin(0.0, unit=r"U/hr") 31 | scenario.setHardware(sensor='guardianRT.scs', pump='Generic_1.pmp') 32 | scenario.setParamsT1DMS() 33 | 34 | T1DMSprocessor = DataProcessor() # Tsimul, Tclosed, hardware, IVgluc,ins are in dataprocessor 35 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 36 | 37 | patient = VirtualPatientT1DMS(patient_name="adult#001.mat", BGinit=matlab.double([])) # , eng=eng, path=path 38 | 39 | patient.simulatePatient(simulation_data=T1DMSdata) # matlab engine 40 | 41 | patient.plotHistoricalStates() 42 | -------------------------------------------------------------------------------- /examples/tests/test05_5min.py: -------------------------------------------------------------------------------- 1 | from src.UVAPadovaAPIWrapper import UvaPadovaAPI 2 | import numpy as np 3 | from scipy.io import savemat 4 | 5 | 6 | tsim = 60 7 | tsim=int(tsim/5) 8 | insulins = np.zeros(tsim) 9 | chos = np.zeros(tsim) 10 | 11 | for i in range(len(insulins)): 12 | insulins[i] = 0.1 + round(0.1 * i, 1) 13 | 14 | virtual_patient = UvaPadovaAPI() 15 | virtual_patient.initializePatient("adult#001") 16 | for i in range(tsim): 17 | step_result = virtual_patient.doSimulation(chos[i],insulins[i]) 18 | print(step_result) 19 | #savemat('test5_5.mat',{'Glucose':virtual_patient.listOfBloodGlucoseValues}) 20 | print("") -------------------------------------------------------------------------------- /examples/tests/test06.py: -------------------------------------------------------------------------------- 1 | from src.Simulator.OESimulator.SimulationData.Scenario import Scenario 2 | from src.Simulator.OESimulator.DataProcessor import DataProcessor 3 | from src.Simulator.UVAPadova.VirtualPatientT1DMS import VirtualPatientT1DMS 4 | import matlab.engine 5 | 6 | tstart = 0 7 | tend = 1440 8 | b = [4,7,2,8,2] 9 | bt = [7*60,12*60,16*60,18*60,23*60] 10 | m = [45,70,20,80,20] 11 | mt = [7*60,12*60,16*60,18*60,23*60] 12 | 13 | b = tuple(b) 14 | bt = tuple(bt) 15 | m = tuple(m) 16 | mt = tuple(mt) 17 | Tsim = float(tend - tstart) 18 | scenario = Scenario(tstart,tend,"t1dms") 19 | scenario.Ts = 1 20 | scenario.setManualMealScheme(meal_times=mt, meal_values=m, unit='g') 21 | scenario.setManualBolusScheme(bolus_times=bt, bolus_values=b, unit='U') 22 | scenario.setManualBasalInsulin(0.0, unit=r"U/hr") 23 | scenario.setHardware(sensor='guardianRT.scs', pump='Generic_1.pmp') 24 | scenario.setParamsT1DMS() 25 | 26 | T1DMSprocessor = DataProcessor() # Tsimul, Tclosed, hardware, IVgluc,ins are in dataprocessor 27 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=scenario) 28 | 29 | patient = VirtualPatientT1DMS(patient_name="adolescent#001.mat", BGinit=matlab.double([])) # , eng=eng, path=path 30 | 31 | patient.simulatePatient(simulation_data=T1DMSdata) # matlab engine 32 | patient.plotHistoricalStates() -------------------------------------------------------------------------------- /examples/tests/test06_5min.py: -------------------------------------------------------------------------------- 1 | from src.UVAPadovaAPIWrapper import UvaPadovaAPI 2 | import numpy as np 3 | from scipy.io import savemat 4 | 5 | 6 | tsim = 1440 7 | tsim=int(tsim/5) 8 | insulins = np.zeros(tsim) 9 | chos = np.zeros(tsim) 10 | 11 | # # test 06 12 | b = [4,7,2,8,2] 13 | bt = [7*60,12*60,16*60,18*60,23*60] 14 | m = [45,70,20,80,20] 15 | mt = [7*60,12*60,16*60,18*60,23*60] 16 | 17 | for i in range(len(mt)): 18 | for j in range(1,tsim+1): 19 | if j*5 == mt[i]: 20 | insulins[j-1] = b[i] 21 | chos[j-1] = m[i] 22 | 23 | virtual_patient = UvaPadovaAPI() 24 | virtual_patient.initializePatient("adolescent#001") 25 | for i in range(tsim): 26 | step_result = virtual_patient.doSimulation(chos[i],insulins[i]) 27 | print(step_result) 28 | #savemat('test5_6.mat',{'Glucose':virtual_patient.listOfBloodGlucoseValues}) 29 | print("") -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.0.3 2 | Flask_RESTful==0.3.9 3 | matlab==0.1 4 | matplotlib==3.5.2 5 | numpy==1.21.6 6 | pyperclip==1.8.2 7 | requests==2.24.0 8 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/DataProcessing/DBFile.py: -------------------------------------------------------------------------------- 1 | FAILED = False 2 | SUCCESS = True 3 | 4 | class DBFile(): 5 | def __init__(self, source): 6 | self.source = source 7 | self.glucose_values, self.glucose_times = [],[] 8 | self.meal_values, self.meal_times = [], [] 9 | self.bolus_values, self.bolus_times = [],[] 10 | self.basal_values, self.basal_times = [],[] 11 | 12 | def loadCGM(self): 13 | for id, info in self.source.items(): 14 | try: 15 | if "source" in info: 16 | if (info["type"] == "glucose" and ( 17 | info["source"] == "LIBRE_FREESTYLE" or info["source"] == "CARELINK")): 18 | self.glucose_times.append( info["timestamp"] / 60.0) 19 | self.glucose_values.append( info["value"] * 18.018) 20 | except: 21 | return FAILED 22 | return SUCCESS 23 | 24 | def loadMeals(self): 25 | for id, info in self.source.items(): 26 | try: 27 | if (info["type"] == "meal"): 28 | tmp_meal = 0.0 29 | for food in info["foods"]: 30 | if "carbohydrates" in food["details"]: 31 | tmp_meal = tmp_meal + float(food["details"]["carbohydrates"]) * float(food["amount"]) * float(food[ 32 | "weights"]) / 100.0 33 | if "carbohydrate" in food["details"]: 34 | tmp_meal = tmp_meal + float(food["details"]["carbohydrate"]) * float(food["amount"]) * float(food[ 35 | "weights"]) / 100.0 36 | self.meal_values.append(tmp_meal) 37 | self.meal_times.append(info["timestamp"] / 60.0) 38 | except BaseException as e: 39 | print(str(e)) 40 | return FAILED 41 | return SUCCESS 42 | 43 | def loadInsulin(self): 44 | for id, info in self.source.items(): 45 | try: 46 | if info["type"] == "insulin": 47 | if (info["subtype"].isnumeric() and int(info["subtype"])<16) or info["subtype"]=="short": 48 | self.bolus_values.append(float(info["value"])) 49 | self.bolus_times.append(float(info["timestamp"]) / 60.0) 50 | if (info["subtype"].isnumeric() and int(info["subtype"])>=16 or info["subtype"]=="long") : 51 | self.basal_values.append(float(info["value"]) / 24.0) 52 | self.basal_times.append(float(info["timestamp"]) / 60.0) 53 | except BaseException as e: 54 | print(str(e)) 55 | return FAILED 56 | return SUCCESS 57 | 58 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/DataProcessing/ErrorCodes.py: -------------------------------------------------------------------------------- 1 | from enum import Enum 2 | class ERROR_CODES(Enum): 3 | DATE_INVALID = 1 4 | CGM_EMPTY = 100 5 | CGM_INVALID = 101 6 | CGM_OUTOFRANGE = 102 7 | CGM_GAP = 103 8 | INSULIN_EMPTY = 200 9 | INSULIN_INVALID = 201 10 | CHO_EMPTY = 300 11 | CHO_INVALID = 301 -------------------------------------------------------------------------------- /src/Simulator/OESimulator/DataProcessing/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/src/Simulator/OESimulator/DataProcessing/__init__.py -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/CONSTANTS.py: -------------------------------------------------------------------------------- 1 | NOMINAL_BW: float = 69.7 2 | """ Nominal value of the body weight. 3 | 4 | """ 5 | 6 | NOMINAL_GEZI: float = 3.03e-08 7 | """ Nominal value of the glucose consumption at zero insulin level. 8 | 9 | """ 10 | 11 | NOMINAL_EGP: float = 1.488 12 | """ Nominal value of the endogenous glucose production. 13 | 14 | """ 15 | 16 | NOMINAL_CI: float = 1200.0 17 | """ Nominal value of the insulin clearance. 18 | 19 | """ 20 | 21 | NOMINAL_SI: float = 7.0e-04 22 | """ Nominal value of the insulin sensitivity. 23 | 24 | """ 25 | 26 | NOMINAL_TAU1: float = 70.0500000000000 27 | """ Nominal value of the time constant of the insulin absorption in the 1st compartment. 28 | 29 | """ 30 | 31 | NOMINAL_TAU2: float = 43.4 32 | """ Nominal value of the time constant of the insulin absorption in the 2nd compartment. 33 | 34 | """ 35 | 36 | NOMINAL_P2: float = 0.010288 37 | """ Nominal value of the rate constant of the insulin effect. 38 | 39 | """ 40 | 41 | NOMINAL_TAUD: float = 40.0 42 | """ Nominal value of the time constant of the CHO absorption. 43 | 44 | """ 45 | 46 | NOMINAL_VG: float = 180.0 47 | """ Nominal value of the glucose distribution volume. 48 | 49 | """ 50 | 51 | NOMINAL_PARAMS = [NOMINAL_BW, NOMINAL_GEZI, NOMINAL_EGP, NOMINAL_CI, NOMINAL_SI, NOMINAL_TAU1, NOMINAL_TAU2, NOMINAL_P2, NOMINAL_TAUD, NOMINAL_VG] 52 | 53 | SIGMA_BW: float = 1.0 54 | SIGMA_GEZI: float = 3E-9 55 | SIGMA_EGP: float = 0.1 56 | SIGMA_CI: float = 100 57 | SIGMA_SI: float = 1E-5 58 | SIGMA_TAU1: float = 1.0 59 | SIGMA_TAU2: float = 1.0 60 | SIGMA_P2: float = 1E-3 61 | SIGMA_TAUD: float = 1.0 62 | SIGMA_VG: float = 1.0 63 | 64 | SIGMA_PARAMS = [SIGMA_BW, SIGMA_GEZI, SIGMA_EGP, SIGMA_CI, SIGMA_SI, SIGMA_TAU1, SIGMA_TAU2, SIGMA_P2, SIGMA_TAUD, SIGMA_VG] 65 | 66 | 67 | MIN_BW: float = 50.0 68 | """ Minimum value of the body weight. 69 | 70 | """ 71 | 72 | MIN_GEZI: float = 5E-4 73 | """ Minimum value of the glucose consumption at zero insulin level. 74 | 75 | """ 76 | 77 | MIN_EGP: float = 0.062 78 | """ Minimum value of the endogenous glucose production. 79 | 80 | """ 81 | 82 | MIN_CI: float = 372.0 83 | """ Minimum value of the insulin clearance. 84 | 85 | """ 86 | 87 | MIN_SI: float = 2.3E-6 88 | """ Minimum value of the insulin sensitivity. 89 | 90 | """ 91 | 92 | MIN_TAU1: float = 10.0 93 | """ Minimum value of the time constant of the insulin absorption in the 1st compartment. 94 | 95 | """ 96 | 97 | MIN_TAU2: float = 10.0 98 | """ Minimum value of the time constant of the insulin absorption in the 2nd compartment. 99 | 100 | """ 101 | 102 | MIN_P2: float = 1.0/50.0 103 | """ Minimum value of the rate constant of the insulin effect. 104 | 105 | """ 106 | 107 | MIN_TAUD: float = 10.0 108 | """ Minimum value of the time constant of the CHO absorption. 109 | 110 | """ 111 | 112 | MIN_VG: float = 100.0 113 | """ Minimum value of the glucose distribution volume. 114 | 115 | """ 116 | 117 | MAX_BW: float = 110.0 118 | """ Maximum value of the body weight. 119 | 120 | """ 121 | 122 | MAX_GEZI: float = 7E-2 123 | """ Maximum value of the glucose consumption at zero insulin level. 124 | 125 | """ 126 | 127 | MAX_EGP: float = 2.23 128 | """ Maximum value of the endogenous glucose production. 129 | 130 | """ 131 | 132 | MAX_CI: float = 3350.0 133 | """ Maximum value of the insulin clearance. 134 | 135 | """ 136 | 137 | MAX_SI: float = 0.0021 138 | """ Maximum value of the insulin sensitivity. 139 | 140 | """ 141 | 142 | MAX_TAU1: float = 70.0#50.0 143 | """ Maximum value of the time constant of the insulin absorption in the 1st compartment. 144 | 145 | """ 146 | 147 | MAX_TAU2: float = 50.0 148 | """ Maximum value of the time constant of the insulin absorption in the 2nd compartment. 149 | 150 | """ 151 | 152 | MAX_P2: float = 1.0/10.0 153 | """ Maximum value of the rate constant of the insulin effect. 154 | 155 | """ 156 | 157 | MAX_TAUD: float = 60.0 158 | """ Maximum value of the time constant of the CHO absorption. 159 | 160 | """ 161 | 162 | MAX_VG: float = 1000.0 163 | """ Maximum value of the glucose distribution volume. 164 | 165 | """ 166 | 167 | MIN_PARAMS = [MIN_BW, MIN_GEZI, MIN_EGP, MIN_CI, MIN_SI, MIN_TAU1, MIN_TAU2, MIN_P2, MIN_TAUD, MIN_VG] 168 | MAX_PARAMS = [MAX_BW, MAX_GEZI, MAX_EGP, MAX_CI, MAX_SI, MAX_TAU1, MAX_TAU2, MAX_P2, MAX_TAUD, MAX_VG] 169 | 170 | COLOR_WARNING: str = '\033[93m' 171 | COLOR_OK: str = '\033[92m' 172 | COLOR_FAIL: str = '\033[91m' 173 | COLOR_END: str = '\033[0m' 174 | 175 | DATETIME_FORMAT: str = '%d-%m-%Y %H:%M:%S' 176 | """ Date format. 177 | 178 | """ -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/DataContainer.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | from typing import Union, List, Tuple 4 | 5 | class DataContainer(object): 6 | """ Stores data in different formats (scalar, array (with Ts sampling), timestamped array). 7 | Defined by __slots__ as the class only serves quick data access purposes. 8 | """ 9 | __slots__ = ['_scalar','_array','_timestamped_array','impulsive'] 10 | def __init__(self, scalar: float = None, array: np.ndarray = None, timestamped_array: np.ndarray = None, impulsive: bool = False): 11 | """ Constructor. 12 | 13 | """ 14 | if scalar is not None: 15 | self._scalar = scalar 16 | else: 17 | self._scalar = np.nan 18 | if array is not None: 19 | self._array = array 20 | else: 21 | self._array = np.array([], dtype=float) 22 | if timestamped_array is not None: 23 | self._timestamped_array = timestamped_array 24 | else: 25 | self._timestamped_array: np.ndarray = np.array([], dtype=np.float64) 26 | self.impulsive = impulsive 27 | 28 | @property 29 | def as_scalar(self): 30 | """ Gets and sets the variable in scalar format. 31 | 32 | Note: 33 | When array format exists, it returns the value corresponding to the current time point. It is relevant only as an attribute of the SimulationData. 34 | 35 | Returns: 36 | float : Returns data in scalar format. 37 | """ 38 | return self._scalar 39 | 40 | @as_scalar.setter 41 | def as_scalar(self, value): 42 | self._scalar = value 43 | 44 | @property 45 | def as_array(self) -> np.ndarray: 46 | """ Gets and sets the variable in array format. 47 | 48 | Note: 49 | Sampled based on the Ts variable of the Scenario. 50 | 51 | Returns: 52 | float : Returns data in array format. 53 | """ 54 | return self._array 55 | 56 | @as_array.setter 57 | def as_array(self, array): 58 | self._array = array 59 | 60 | 61 | @property 62 | def as_timestamped_array(self) -> np.ndarray: 63 | """ Gets and sets the variable in timestamped array format. 64 | 65 | Note: 66 | Times points are given in Unix timestamp format [minutes]. 67 | 68 | Returns: 69 | float : Returns data in timestamped array format. 70 | 71 | Examples: 72 | >>> print(self.as_timestamped_array) 73 | [[26679390 30 40] 74 | [26679540 15 10]] 75 | """ 76 | return self._timestamped_array 77 | 78 | @as_timestamped_array.setter 79 | def as_timestamped_array(self, array): 80 | self._timestamped_array = array 81 | 82 | @property 83 | def __dict__(self): 84 | return {s: getattr(self, s, None) for s in self.__slots__} 85 | 86 | def copyTimestampedArrayToArray(self, start_time, Ts, position): 87 | inputs_in_horizon = (self._timestamped_array[:,0]-start_time)>=0 88 | indexes = np.ceil((self._timestamped_array[inputs_in_horizon, 0] - start_time) / Ts).astype(int) 89 | if np.any(inputs_in_horizon): 90 | if(self.impulsive): 91 | self._array[indexes] = self._timestamped_array[inputs_in_horizon, position] 92 | else: 93 | prev_i = 0 94 | b_i = 0 95 | if (len(indexes) < 2): 96 | # If only 1 basal value is found in the raw data file for the current horizon, this value used until the end 97 | self._array[0:] = self._timestamped_array[0, position] 98 | else: 99 | # If more than 1 basal value found, each basal value is used up until the time point where the next basal is defined 100 | for bolus_i in indexes[1:]: 101 | self._array[prev_i:bolus_i] = self._timestamped_array[b_i, position] 102 | b_i = b_i + 1 103 | prev_i = bolus_i 104 | # The last basal value is used until the end 105 | self._array[prev_i:] = self._timestamped_array[b_i, position] 106 | 107 | 108 | def copy(self): 109 | """ Create a deep copy of the instance. 110 | 111 | Returns: 112 | DataContainer : Deep copy of the instance. 113 | 114 | """ 115 | data_container = DataContainer() 116 | for attribute in self.__slots__: 117 | if isinstance(getattr(self, attribute), np.ndarray): 118 | setattr(data_container, attribute, getattr(self, attribute).copy()) 119 | else: 120 | setattr(data_container, attribute, getattr(self, attribute)) 121 | return data_container 122 | 123 | def plot(self): 124 | """ If array or timestamped_array exists it plots the stored data. 125 | 126 | Note: 127 | Array or timestamped_array format needed. 128 | 129 | Examples: 130 | >>> self.plot() 131 | """ 132 | if self._timestamped_array.size: 133 | for row in self._timestamped_array: 134 | plt.arrow(row[0], 0, 0,row[1]) 135 | elif self._array.size: 136 | plt.plot(self._array) 137 | plt.show() 138 | 139 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/ParamsT1DMS.py: -------------------------------------------------------------------------------- 1 | class ParamsT1DMS: 2 | """ ParamsT1DMS stores the Uva/Padova simulator related scenario parameters. 3 | 4 | Note: 5 | All the member variables all the equivalent of the Uva/Padova Matlab simulator variables. 6 | 7 | """ 8 | __slots__ = ['Tsimul','simToD','Qmeals','Tclosed','BGinit','Treg','basal','Qbasal','CR','Qbolus', 9 | 'IV_glucose','IV_insulin','SQg','OB','CR','meal_duration','hardwareN_sensor','hardwareN_pump', 10 | 'hardware_sensorType'] 11 | 12 | def __init__(self): 13 | self.simToD : float = 0.0 14 | self.Qmeals : str = 'total' 15 | self.Treg : float = 0.0 16 | self.meal_duration : float = 15.0 17 | self.Qbasal : str = 'fixed' 18 | self.OB : str = 'off' 19 | self.CR : str = 'off' 20 | self.Qbolus : str = 'total' 21 | self.SQg : float = 1.0 22 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/PatientData.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from .PatientParams import PatientParams 3 | 4 | class PatientData(object): 5 | """ Patient data. 6 | Defined by __slots__ as the class only serves quick data access purposes. 7 | """ 8 | __slots__ = ['x_hist_timestamped','patient_params_timestamped','patient_id','patient_params'] 9 | 10 | def __init__(self): 11 | """ Constructor. 12 | 13 | """ 14 | # Stores the historically estimated states with timestamps. 15 | self.x_hist_timestamped: np.ndarray = np.array([], dtype=np.float32) 16 | # Stores the historically estimated patient parameters. 17 | self.patient_params_timestamped: np.ndarray = np.array([], dtype=np.float32) 18 | # Patient ID as in the database. 19 | self.patient_id: str = "" 20 | # Current patient parameters. 21 | self.patient_params = PatientParams() 22 | 23 | @property 24 | def __dict__(self): 25 | return {s: getattr(self, s, None) for s in self.__slots__} 26 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/PatientParams.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from random import gauss 3 | 4 | from . import CONSTANTS 5 | from .DataContainer import DataContainer 6 | 7 | class PatientParams(object): 8 | """ Stores the mathematical model parameters of the patient. 9 | Defined by __slots__ as the class only serves quick data access purposes. 10 | 11 | Args: 12 | BW (float): Body weight of the patient. 13 | GEZI (DataContainer): Glucose consumption at zero insulin level. 14 | EGP (DataContainer): Endogenous glucose production. 15 | CI (float): Insulin clearance. 16 | tau1 (float): Time constant of the absorption of the insulin in the 1st compartment. 17 | tau2 (float): Time constant of the absorption of the insulin in the 2nd compartment. 18 | p2 (float): Rate constant of the insulin effect. 19 | taud (DataContainer): Time constant of the absoprtion of the CHO. 20 | meals (DataContainer): CHO contents of the meals. 21 | 22 | Examples: 23 | >>> print(PatientParams(sigma=0.0)) 24 | --------------------------- 25 | 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 26 | meal_tauds: 27 | --------------------------- 28 | """ 29 | __slots__ = ['EGP','GEZI','p2','tau1','tau2','taud','Vg','BW','CI','SI','meals','is_up_to_date'] 30 | 31 | def __init__(self, sigma: float = 0.0): 32 | """ Constructor. 33 | sigma : Standard deviation, when a random patient is being created from a normal distribution. 34 | """ 35 | generated_params = [CONSTANTS.NOMINAL_BW + gauss(0, CONSTANTS.SIGMA_BW) * sigma, CONSTANTS.NOMINAL_GEZI + gauss(0, CONSTANTS.SIGMA_GEZI) * sigma, 36 | CONSTANTS.NOMINAL_EGP + gauss(0, CONSTANTS.SIGMA_EGP) * sigma, CONSTANTS.NOMINAL_CI + gauss(0, CONSTANTS.SIGMA_CI) * sigma, 37 | CONSTANTS.NOMINAL_SI + gauss(0, CONSTANTS.SIGMA_SI) * sigma, CONSTANTS.NOMINAL_TAU1 + gauss(0, CONSTANTS.SIGMA_TAU1) * sigma, 38 | CONSTANTS.NOMINAL_TAU2 + gauss(0, CONSTANTS.SIGMA_TAU2) * sigma, CONSTANTS.NOMINAL_P2 + gauss(0, CONSTANTS.SIGMA_P2) * sigma, 39 | CONSTANTS.NOMINAL_TAUD + gauss(0, CONSTANTS.SIGMA_TAUD) * sigma, CONSTANTS.NOMINAL_VG + gauss(0, CONSTANTS.SIGMA_VG) * sigma] 40 | # Constrains the parameters to be relevant ranges. 41 | if sigma > 0.0: 42 | generated_params = [min_param if param < min_param else param 43 | for (param, min_param) in zip(generated_params, CONSTANTS.MIN_PARAMS)] 44 | generated_params = [max_param if param > max_param else param 45 | for (param, max_param) in zip(generated_params, CONSTANTS.MAX_PARAMS)] 46 | self.BW: float = generated_params[0] 47 | self.GEZI: DataContainer = DataContainer(scalar=generated_params[1]) 48 | self.EGP: DataContainer = DataContainer(scalar=generated_params[2]) 49 | # self.EGP: float = generated_params[2] 50 | self.CI: float = generated_params[3] 51 | self.SI: DataContainer = DataContainer(scalar=generated_params[4]) 52 | self.tau1: float = generated_params[5] 53 | self.tau2: float = generated_params[6] 54 | self.p2: float = generated_params[7] 55 | self.taud: DataContainer = DataContainer(scalar=generated_params[8]) 56 | self.Vg: float = generated_params[9] 57 | self.taud.as_array = np.array([], dtype=np.float64) 58 | self.meals: np.ndarray = np.array([], dtype=np.float64) 59 | self.EGP.as_array = self.EGP.as_scalar*np.ones(1, dtype=np.float64) 60 | self.GEZI.as_array = self.GEZI.as_scalar*np.ones(1, dtype=np.float64) 61 | self.SI.as_array = self.SI.as_scalar*np.ones(1, dtype=np.float64) 62 | self.is_up_to_date: bool = False 63 | 64 | @property 65 | def __dict__(self): 66 | return {s: getattr(self, s, None) for s in self.__slots__} 67 | 68 | def __repr__(self): 69 | """ Parameter representations. 70 | """ 71 | lines = "---------------------------\n" 72 | representation = "Patient parameters: BW:%0.2g GEZI:%0.2g EGP:%0.2g CI:%0.2g SI:%0.2g tau1:%0.2g tau2:%0.2g" \ 73 | " p2:%0.2g taud:%0.2g Vg:%0.2g \n meal_tauds:" % (self.BW, self.GEZI.as_scalar, self.EGP.as_scalar, self.CI, self.SI.as_scalar 74 | , self.tau1, self.tau2, self.p2, self.taud.as_scalar, self.Vg) 75 | meal_tauds = [str("%0.2g"%i)+" " for i in self.taud.as_array] 76 | return lines+representation + "".join(meal_tauds)+"\n"+lines 77 | 78 | def copy(self): 79 | """ Create a deep copy of the instance. 80 | 81 | Returns: 82 | PatientParams : Deep copy of the instance. 83 | 84 | """ 85 | patient_params = PatientParams() 86 | for attribute in self.__slots__: 87 | for attribute in self.__slots__: 88 | if hasattr(self, attribute): 89 | if isinstance(getattr(self, attribute), (np.ndarray, DataContainer)): 90 | setattr(patient_params, attribute, getattr(self, attribute).copy()) 91 | else: 92 | setattr(patient_params, attribute, getattr(self, attribute)) 93 | return patient_params 94 | 95 | 96 | def vectorizeScalarParams(self): 97 | """ Organizes the scalar patient parameters into a list in the following order: [BW, CI, tau1, tau2, p2, Vg] 98 | 99 | """ 100 | vectorized_params = [] 101 | vectorized_params.append(self.BW) 102 | vectorized_params.append(self.CI) 103 | vectorized_params.append(self.tau1) 104 | vectorized_params.append(self.tau2) 105 | vectorized_params.append(self.p2) 106 | vectorized_params.append(self.Vg) 107 | return vectorized_params 108 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/Position.py: -------------------------------------------------------------------------------- 1 | class Position(object): 2 | """ Defines the position (column index) of the data of interest in an ndarray. 3 | Defined by __slots__ as the class only serves quick data access purposes. 4 | 5 | Args: 6 | basal: Position (column index) of the basal rate value in an ndarray. 7 | bolus: Position (column index) of the bolus value in an ndarray. 8 | meal: Position (column index) of the cho content in an ndarray. 9 | time_constant: Position (column index) of the time constant in an ndarray. 10 | glucose_level: Position (column index) of the glucose value in an ndarray. 11 | """ 12 | __slots__ = ['basal','bolus','meal', 13 | 'glucose_level','time_constant'] 14 | def __init__(self): 15 | """ Constructor initalized with default position values. 16 | """ 17 | self.basal: int = 1 18 | self.bolus: int = 1 19 | self.meal: int = 1 20 | self.time_constant: int = -1 21 | self.glucose_level: int = 1 22 | 23 | @property 24 | def __dict__(self): 25 | return {s: getattr(self, s, None) for s in self.__slots__} 26 | 27 | def copy(self): 28 | """ Create a deep copy of the instance. 29 | 30 | Returns: 31 | Position : Deep copy of the instance. 32 | 33 | """ 34 | position = Position() 35 | for attribute in self.__slots__: 36 | if hasattr(self, attribute): 37 | setattr(position, attribute, getattr(self, attribute)) 38 | return position 39 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/Timestamp.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | from .CONSTANTS import * 3 | import calendar as cal 4 | from typing import Union 5 | 6 | 7 | 8 | class Timestamp(object): 9 | """ Stores time information in three alternative formats (Unix timestamp [minutes], string, datetime) 10 | Defined by __slots__ as the class only serves quick data access purposes. 11 | 12 | Note: 13 | Can be initialized in string or Unix timestamp [minutes] format. It automatically converts to the rest of the 14 | formats. 15 | 16 | Raises: 17 | ValueError: If the provided string format is not %d-%m-%Y %H:%M:%S. 18 | """ 19 | __slots__ = ['_str','_int','_datetime'] 20 | def __init__(self, timestamp: Union[str,int] = None): 21 | """ Constructor. 22 | 23 | """ 24 | if isinstance(timestamp, str): 25 | try: 26 | self._str = timestamp 27 | self._datetime = datetime.datetime.strptime(timestamp, DATETIME_FORMAT) 28 | self._int: int = int( 29 | cal.timegm(datetime.datetime.strptime(timestamp, DATETIME_FORMAT).timetuple()) / 60.0) 30 | except ValueError: 31 | raise ValueError("Incorrect date format, should be %d-%m-%Y %H:%M:%S or int [minutes]") 32 | if isinstance(timestamp, int): 33 | self._int = timestamp 34 | self._datetime = datetime.datetime.utcfromtimestamp(self._int*60) 35 | self._str = self._datetime.strftime(DATETIME_FORMAT) 36 | 37 | def copy(self): 38 | """ Create a deep copy of the instance. 39 | 40 | Returns: 41 | Timestamp : Deep copy of the instance. 42 | 43 | """ 44 | timestamp = Timestamp() 45 | for attribute in self.__slots__: 46 | if hasattr(self, attribute): 47 | setattr(timestamp, attribute, getattr(self, attribute)) 48 | return timestamp 49 | 50 | 51 | @property 52 | def as_int(self): 53 | """ Gets and sets timestamp based on Unix timestamp [minutes] format. 54 | 55 | Returns: 56 | int : Timestamp in Unix timestamp [minutes] format. 57 | 58 | Examples: 59 | >>> print(Timestamp("22-09-2020 10:20:00").as_int) 60 | 26679500 61 | 62 | """ 63 | return self._int 64 | 65 | @as_int.setter 66 | def as_int(self, timestamp): 67 | self._int = timestamp 68 | self._datetime = datetime.datetime.utcfromtimestamp(self._int*60) 69 | self._str = self._datetime.strftime(DATETIME_FORMAT) 70 | 71 | @property 72 | def as_str(self): 73 | """ Gets and sets timestamp based on string format. 74 | 75 | Returns: 76 | str : Timestamp in string format. 77 | 78 | Examples: 79 | >>> print(Timestamp(26679500).as_str) 80 | 22-09-2020 10:20:00 81 | 82 | """ 83 | return self._str 84 | 85 | @as_str.setter 86 | def as_str(self, timestamp): 87 | self._str = timestamp 88 | try: 89 | self._datetime = datetime.datetime.strptime(timestamp, DATETIME_FORMAT) 90 | self._int: int = int( 91 | cal.timegm(datetime.datetime.strptime(timestamp, DATETIME_FORMAT).timetuple()) / 60.0) 92 | except ValueError: 93 | raise ValueError("Incorrect date format, should be %d-%m-%Y %H:%M:%S or int [minutes]") 94 | 95 | @property 96 | def as_datetime(self): 97 | """ Gets and sets timestamp based on datetime object. 98 | 99 | Returns: 100 | datetime : Timestamp in datetime format. 101 | 102 | Examples: 103 | >>> print(Timestamp(26679500).as_datetime) 104 | 2020-09-22 10:20:00 105 | 106 | """ 107 | return self._datetime 108 | 109 | @as_datetime.setter 110 | def as_datetime(self, timestamp): 111 | try: 112 | self._datetime = timestamp 113 | self._str = self._datetime.strftime(DATETIME_FORMAT) 114 | self._int: int = int( 115 | cal.timegm(datetime.datetime.strptime(self._str, DATETIME_FORMAT).timetuple()) / 60.0) 116 | except ValueError: 117 | raise ValueError("Incorrect date format, should be %d-%m-%Y %H:%M:%S or int [minutes]") 118 | 119 | 120 | @property 121 | def __dict__(self): 122 | return {s: getattr(self, s, None) for s in self.__slots__} -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/Units.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from typing import Union, List, Tuple 3 | # from .Scenario import Scenario 4 | 5 | 6 | class Units(object): 7 | """ Defines the units of the variables in strings. 8 | Defined by __slots__ as the class only serves quick data access purposes. 9 | 10 | Args: 11 | basal (str): Unit of the basal rate. 12 | bolus (str): Unit of the bolus insulin. 13 | insulin (str): Unit of the insulin input. 14 | meal (str): Unit of the meal. 15 | """ 16 | __slots__ = ['basal','bolus','insulin','meal'] 17 | def __init__(self): 18 | """ Constructor initalized with default values. 19 | 20 | """ 21 | self.basal: str = r"U/hr" 22 | self.bolus: str = "U" 23 | self.insulin: str = r"uU/min" 24 | self.meal: str = "g" 25 | 26 | @property 27 | def __dict__(self): 28 | return {s: getattr(self, s, None) for s in self.__slots__} 29 | 30 | def copy(self): 31 | """ Create a deep copy of the instance. 32 | 33 | Returns: 34 | Units : Deep copy of the instance. 35 | 36 | """ 37 | units = Units() 38 | for attribute in self.__slots__: 39 | if hasattr(self, attribute): 40 | setattr(units, attribute, getattr(self, attribute)) 41 | return units 42 | 43 | @staticmethod 44 | def convertUnits(original_value: Union[float, np.ndarray], unit_from: str, unit_to: str, Ts: float) -> Union[float, np.ndarray]: 45 | """ Convert values between different units. 46 | 47 | Note: 48 | Possible conversions: 49 | from U/hr to uU/min 50 | from U to uU/min (based on Ts) 51 | from g to g/min (based on Ts) 52 | from uU/min to U/min 53 | 54 | Args: 55 | original_value : The unconverted value(s). 56 | unit_from : Unit of the unconverted value(s). 57 | unit_to : Unit of the converted value(s). 58 | Ts : Sampling time. 59 | 60 | Returns: 61 | Union[float, ndarray] : The converted value(s). 62 | 63 | Examples: 64 | >>> print(Units.convertUnits(original_value=10,unit_from="U/hr",unit_to=r"uU/min",Ts=5)) 65 | 166666.666 66 | 67 | """ 68 | if unit_to == unit_from: 69 | return original_value 70 | converted_value = 'nan' 71 | if (unit_from == r"U/hr" and unit_to == r"uU/min"): 72 | converted_value = original_value / 60.0 * 1E6 73 | if (unit_from == "U" and unit_to == r"uU/min"): 74 | converted_value = original_value * 1E6 / Ts 75 | if (unit_from == r"uU/min" and unit_to == "U"): 76 | converted_value = original_value / 1E6 * Ts 77 | if (unit_from == "g" and unit_to == r"g/min"): 78 | converted_value = original_value / Ts 79 | if (unit_from == r"uU/min" and unit_to == r"U/min"): 80 | converted_value = original_value/1E6 81 | return converted_value 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/Simulator/OESimulator/SimulationData/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/src/Simulator/OESimulator/SimulationData/__init__.py -------------------------------------------------------------------------------- /src/Simulator/OESimulator/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/src/Simulator/OESimulator/__init__.py -------------------------------------------------------------------------------- /src/Simulator/UVAPadova/LicenseManagerAPI.bat: -------------------------------------------------------------------------------- 1 | @start /D "C:/T1DMS_Install/UVa PadovaT1DM Simulator v3.2.1" LicenseManager.exe T1DMS 3.2.1 -provider epsilongrp -server http://a106.hostedactivation.com -name mate -------------------------------------------------------------------------------- /src/Simulator/UVAPadova/UVAPadovaSimulator.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | from ..OESimulator.SimulationData.Scenario import Scenario 4 | from ..OESimulator.DataProcessor import DataProcessor 5 | from .VirtualPatientT1DMS import VirtualPatientT1DMS 6 | import matlab.engine 7 | import time 8 | 9 | 10 | class UvaPadovaSimulator: 11 | """ 12 | This class can be store the current state of a simulation and can extend it by 5 minutes per step. 13 | 14 | Note: 15 | This class was created exclusively to serve the API. 16 | 17 | Args: 18 | patient (obj) : 19 | A VirtualPatientT1DMS object, which represents a virtual patient and controls the MATLAB engine. 20 | scenario (obj): 21 | A Scenario object, which provides a storage and interface for the simulation related information. 22 | chLostFlag (bool): 23 | A flag which indicates whether the meal could be considered according to 24 | the rules of the UvaPadovaSimulator or not. 25 | tEndReal (int): The duration of the simulation in minutes. 26 | i_times (list(int)): The list of minutes when was insulin intake. 27 | meals (list(float)): The list of the amounts of carbohydrate taken. 28 | m_times (list(int)): The list of minutes when was carbohydrate intake. 29 | insulins (list(float)): The list of the amounts of insulin taken. 30 | sensor (str): The type of the CGM sensor currently in use. Defaults to 'guardianRT.scs' 31 | pump (str): The type of the insulin pump currently in use. Defaults to 'Generic_1.pmp' 32 | 33 | """ 34 | 35 | def __init__(self, patient_name: str): 36 | self.patient = VirtualPatientT1DMS(patient_name=patient_name, BGinit=matlab.double([])) 37 | self.scenario = None 38 | self.chLostFlag = False 39 | self.tEndReal = 0 40 | self.i_times = list() 41 | self.meals = list() 42 | self.m_times = list() 43 | self.insulins = list() 44 | self.sensor = 'guardianRT.scs' 45 | self.pump = 'Generic_1.pmp' 46 | 47 | def doSimulation(self, carbohydrate: float, insulin: float): 48 | """ 49 | This method extends the initialized simulation by 5 minutes. 50 | The method invokes the MATHLAB engine with an extended Scenario. 51 | 52 | 53 | Args: 54 | carbohydrate (float): 55 | The amount of carbohydrate intake, in the last five minutes (in grams). 56 | Zero if there wasn't carbohydrate intake. 57 | insulin (float): 58 | The amount of insulin intake, in the last five minutes (in unites). 59 | Zero if there wasn't insulin intake. 60 | 61 | Returns: 62 | The blood glucose level value at the end of the simulation. 63 | """ 64 | self.chLostFlag = False # reset the flag 65 | self.__buildScenario(carbohydrate, insulin) 66 | T1DMSprocessor = DataProcessor() 67 | T1DMSdata, patient_data = T1DMSprocessor.processData(scenario=self.scenario) 68 | self.patient.simulatePatient(simulation_data=T1DMSdata) 69 | return self.patient.bg[self.tEndReal][0] 70 | 71 | def __buildScenario(self, carbohydrate: float, insulin: float): 72 | """This method builds and the extended Scenario, considering the simulation rules of UvaPadova Simulator. 73 | 74 | Args: 75 | carbohydrate (float): 76 | The amount of carbohydrate intake, in the last five minutes (in grams). 77 | Zero if there wasn't carbohydrate intake. 78 | insulin (float): 79 | The amount of insulin intake, in the last five minutes (in unites). 80 | Zero if there wasn't insulin intake. 81 | """ 82 | # Update values 83 | self.tEndReal += 5 84 | if carbohydrate != 0 and self.__newChIsEnabled(): 85 | self.m_times.append(self.tEndReal) 86 | self.meals.append(carbohydrate) 87 | if insulin != 0: 88 | self.i_times.append(self.tEndReal) 89 | self.insulins.append(insulin) 90 | if self.tEndReal < 30: 91 | tend = 30 92 | else: 93 | tend = self.tEndReal 94 | 95 | # Create Scenario 96 | self.scenario = Scenario(0, tend, "t1dms") 97 | self.scenario.Ts = 1 98 | self.scenario.setManualMealScheme(meal_times=tuple(self.m_times), meal_values=tuple(self.meals), unit='g') 99 | self.scenario.setManualBolusScheme(bolus_times=tuple(self.i_times), bolus_values=tuple(self.insulins), unit='U') 100 | self.scenario.setManualBasalInsulin(0.0, unit=r"U/hr") 101 | self.scenario.setHardware(sensor=self.sensor, pump=self.pump) 102 | self.scenario.setParamsT1DMS() 103 | 104 | def __newChIsEnabled(self) -> bool: 105 | """This method checks the meal could be considered according to the rules of the UvaPadova Simulator or not 106 | and sets the chLostFlag's value. 107 | 108 | Returns: 109 | bool: True if the carbohydrate intake can be considered. False otherwise. 110 | """ 111 | if self.tEndReal >= 60 and (not self.m_times or (self.tEndReal - self.m_times[-1]) >= 60): 112 | return True 113 | else: 114 | self.chLostFlag = True 115 | return False 116 | -------------------------------------------------------------------------------- /src/Simulator/UVAPadova/VirtualPatientT1DMS.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import math 3 | import matlab.engine 4 | import matplotlib.pyplot as plt 5 | import time 6 | from dataclasses import dataclass 7 | from collections import namedtuple 8 | 9 | @dataclass 10 | class Quest: 11 | """Class for keeping track of an item in inventory.""" 12 | OB: float 13 | MD: float 14 | TDI: float 15 | age: float 16 | t1dm_duration: float 17 | names: str 18 | weight: float 19 | basal: float 20 | fastingBG: float 21 | 22 | 23 | class VirtualPatientT1DMS: 24 | """ VirtualPatientT1DMS class implements a virtual patient on the basis of the OE simulator, and controls the MATLAB engine. 25 | 26 | Args: 27 | BGinit : 28 | patient (str): Patient ID. 29 | eng : Matlab engine for Python. 30 | simulation_data (SimulationData): Stores all the simulation related data. 31 | hardwareN (dict): Represents the "hardwareN" variable of the UVA/Padova simulator. 32 | hardware (dict): Represents the "hardware" variable of the UVA/Padova simulator. 33 | rep (int): Represents the "rep" variable of the UVA/Padova simulator. 34 | bck_meals (matlab.double): Represents the "bck_meals" variable of the UVA/Padova simulator. 35 | bck_meal_announce (matlab.double): Represents the "bck_meal_announce" variable of the UVA/Padova simulator. 36 | bck_SQinsulin (dict): Represents the "bck_SQinsulin" variable of the UVA/Padova simulator. 37 | ind (int): Represents the "ind" variable of the UVA/Padova simulator. 38 | sc (dict): Represents the "sc" variable of the UVA/Padova simulator. 39 | result (dict): Represents the "res_aux" variable of the UVA/Padova simulator. 40 | bg (np.array): Stores the simulated blood glucose trajectory. 41 | """ 42 | 43 | def __init__(self, patient_name: str, BGinit: list): 44 | """ Constructor. 45 | 46 | Note: 47 | Starts the Matlab engine. 48 | 49 | Args: 50 | patient_name : Patient ID as given in the UVA/Padova simulator. 51 | BGinit : Initial blood glucose concentration of the patient. If empty, basal conditions is assumed. 52 | """ 53 | self.BGinit = BGinit 54 | self.eng = matlab.engine.start_matlab() 55 | path = "C:/T1DMS_Install/UVa PadovaT1DM Simulator v3.2.1/" 56 | self.eng.cd(path, nargout=0) 57 | self.patient = patient_name 58 | 59 | @property 60 | def patient(self): 61 | return self._patient 62 | 63 | @patient.setter 64 | def patient(self, value): 65 | self._patient = value 66 | self.Quest = Quest(**self.eng.load_quest(value)) 67 | print( 68 | "Patient info:" + self.patient + " basal:%.2f" % self.Quest.basal + " fasting BG:%.2f" % self.Quest.fastingBG) 69 | 70 | def simulatePatient(self, simulation_data: dict): 71 | """ Simulates the patient based on the data given in the simulation_data argument. 72 | 73 | Args: 74 | simulation_data (SimulationData): Stores the simulation related information. 75 | """ 76 | self.simulation_data = simulation_data 77 | self.hardwareN = simulation_data['hardwareN'] 78 | self.hardware = simulation_data['hardware'] 79 | self.rep = 1 80 | self.bck_meals = simulation_data['Lscenario']['meals'] 81 | self.bck_meal_announce = simulation_data['Lscenario']['meal_announce'] 82 | self.bck_SQinsulin = simulation_data['Lscenario']['SQ_insulin']['signals'] 83 | self.ind = 1 84 | self.sc = simulation_data['Lscenario'] 85 | 86 | simulation_data['Lscenario']['BGinit'] = self.BGinit 87 | start_time = time.time() 88 | res_aux = self.eng.connect_function(self.sc, 89 | self.patient, 90 | self.hardwareN, 91 | self.hardware, 92 | self.rep, 93 | self.bck_meals, 94 | self.bck_meal_announce, 95 | self.bck_SQinsulin, 96 | self.ind) 97 | print("T1DMS simulation time: " + str(time.time()-start_time)) 98 | self.result = res_aux 99 | self.bg = np.asarray(self.result[0]['G']['signals']['values']) 100 | 101 | def plotHistoricalStates(self): 102 | """ Plots the result of the simulatePatient() function. 103 | """ 104 | bg = np.asarray(self.result[0]['G']['signals']['values']) 105 | sensor_noise = np.asarray(self.result[0]['sensor']['signals']['values']) 106 | 107 | plt.plot(bg, label="BG") 108 | plt.plot(sensor_noise, label="CGM") 109 | plt.legend() 110 | plt.title(self.patient) 111 | plt.show() 112 | 113 | rmse = math.sqrt(np.square(np.subtract(bg,sensor_noise)).mean()) 114 | print(rmse) -------------------------------------------------------------------------------- /src/Simulator/UVAPadova/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/src/Simulator/UVAPadova/__init__.py -------------------------------------------------------------------------------- /src/Simulator/UVAPadova/connect_function.m: -------------------------------------------------------------------------------- 1 | function res_aux = connect_function(sc,patient,hardwareN,hardware,rep,bck_meals,bck_meal_announce,bck_SQinsulin,ind) 2 | 3 | 4 | hardware=load_hardware(hardwareN,hardware); 5 | 6 | save hardware 7 | 8 | Lstruttura=load_subject(patient); 9 | 10 | save Lstruttura 11 | 12 | struttura = Lstruttura; 13 | 14 | %seed=sum(100*clock); 15 | seed = 1000; 16 | struttura.rg=RandStream.create('mrg32k3a','NumStreams',1,'StreamIndices',1,'Seed',seed); 17 | 18 | hd = hardware; 19 | 20 | res_aux = run_simulation(sc,struttura,hd,rep,bck_meals,bck_meal_announce,bck_SQinsulin,ind); 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Simulator/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuroDiab/UVAPadovaAPI/82ac3382ea81fa821be4146b4f05e7bd8fad67a5/src/Simulator/__init__.py -------------------------------------------------------------------------------- /src/UVAPadovaAPI.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request 2 | from flask_restful import Resource, Api 3 | import json 4 | from Simulator.UVAPadova.UVAPadovaSimulator import UvaPadovaSimulator 5 | from dataclasses import dataclass, asdict 6 | import subprocess 7 | import pyperclip 8 | 9 | uva_padova_simulator = None 10 | """ 11 | This modul level variable will be contain (after initialization) an UvaPadovaSimulator instance, 12 | which represents the current state of the simulation and modifies it. 13 | """ 14 | 15 | 16 | class SimulationCreator(Resource): 17 | """This class handles the requests to initialize a simulation. 18 | 19 | Note: 20 | The API doesn't check the correctness of the input parameters. 21 | To enter the input parameters correctly, please read the documentation of UVAPadova Simulator. 22 | 23 | """ 24 | def get(self): 25 | """ A new simulation can be created by an HTTP GET request. For the initialization, the patient ID is required 26 | as a HTTP GET parameter. Optionally, the type of insulin pump or/and CGM sensor used for the simulation 27 | can also be specified as a HTTP GET parameter. 28 | 29 | Returns: 30 | str: A HTTP status code according to the success of the request. 31 | 32 | Examples: 33 | >>> http://:/createSimulation?patientid=&pump=&sensor= 34 | """ 35 | if "id" in request.args: 36 | patient_name = request.args.get("id") 37 | elif "name" in request.args: 38 | patient_name = request.args.get("name") 39 | elif "patientname" in request.args: 40 | patient_name = request.args.get("patientname") 41 | elif "patientid" in request.args: 42 | patient_name = request.args.get("patienid") 43 | else: 44 | return "", "400 The patient ID is required for initialization as HTTP GET parameter!" 45 | global uva_padova_simulator 46 | uva_padova_simulator = UvaPadovaSimulator(patient_name=patient_name) 47 | if "pump" in request.args: 48 | uva_padova_simulator.pump = request.args.get("pump") 49 | if "sensor" in request.args: 50 | uva_padova_simulator.sensor = request.args.get("sensor") 51 | return json.dumps(asdict(uva_padova_simulator.patient.Quest)) 52 | #return "", '200 The ' + patient_name + " patient successfully loaded." 53 | 54 | 55 | class Simulate(Resource): 56 | """This class handles the requests to modify the current state of the simulation. 57 | 58 | Note: 59 | The API doesn't check the correctness of the input parameters. 60 | To enter the input parameters correctly, please read the documentation of UVAPadova Simulator. 61 | 62 | """ 63 | def get(self): 64 | """ 65 | The simulation can be extended by 5 minutes by an HTTP GET request. 66 | If carbohydrate or insulin intake occurred in the last 5 minutes, 67 | their amount can be specified as an HTTP GET parameter. 68 | 69 | 70 | Examples: 71 | >>> http://:/simulate?carbohydrate=&insulin= 72 | 73 | 74 | Returns: 75 | str: 76 | A HTTP status code according to the success of the request. 77 | Furthermore, if the simulation request was successful, the function returns a JSON string, 78 | which contains the "bloodGlucose" value at the end of the simulation 79 | and optionally other alerts related to the simulation. 80 | """ 81 | if "ch" in request.args: 82 | carbohydrate = float(request.args.get("ch")) 83 | elif "c" in request.args: 84 | carbohydrate = float(request.args.get("c")) 85 | elif "carbohydrate" in request.args: 86 | carbohydrate = float(request.args.get("carbohydrate")) 87 | elif "meal" in request.args: 88 | carbohydrate = float(request.args.get("meal")) 89 | elif "mealvalue" in request.args: 90 | carbohydrate = float(request.args.get("mealvalue")) 91 | else: 92 | carbohydrate = 0 93 | if "insulin" in request.args: 94 | insulin = float(request.args.get("insulin")) 95 | elif "i" in request.args: 96 | insulin = float(request.args.get("i")) 97 | elif "bolus" in request.args: 98 | insulin = float(request.args.get("bolus")) 99 | elif "bolusinsulin" in request.args: 100 | insulin = float(request.args.get("bolusinsulin")) 101 | elif "bolusvalue" in request.args: 102 | insulin = float(request.args.get("bolusvalue")) 103 | else: 104 | insulin = 0 105 | global uva_padova_simulator 106 | if uva_padova_simulator is not None: 107 | result = {"bloodGlucose": uva_padova_simulator.doSimulation(carbohydrate, insulin)} 108 | else: 109 | return "", "409 Patient wasn't initialized." 110 | if uva_padova_simulator.chLostFlag: 111 | result["Alert"] = "Carbohydrate intake was ignored, because at least one hour should pass between meals." 112 | return json.dumps(result), 200 113 | 114 | def post(self): 115 | """ 116 | During the simulation the type of the insulin pump or the CGM sensor can be changed by an HTTP POST request. 117 | The type of the new pump (or sensor) is required as HTTP POST parameter. 118 | 119 | 120 | Returns: 121 | int: A HTTP status code according to the success of the request. 122 | """ 123 | if "pump" in request.args: 124 | uva_padova_simulator.pump = request.args.get("pump") 125 | if "sensor" in request.args: 126 | uva_padova_simulator.sensor = request.args.get("sensor") 127 | return "", 200 128 | 129 | 130 | app = Flask(__name__) 131 | api = Api(app) 132 | api.add_resource(SimulationCreator, '/createSimulation') 133 | api.add_resource(Simulate, '/simulate') 134 | 135 | 136 | if __name__ == '__main__': 137 | app.run(host='0.0.0.0') 138 | 139 | 140 | -------------------------------------------------------------------------------- /src/UVAPadovaAPIWrapper.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | from .Simulator.UVAPadova.VirtualPatientT1DMS import Quest 4 | 5 | 6 | class UvaPadovaAPI: 7 | """ 8 | This class can be used by a client to make requests to the UVAPadovaAPI simply from Python code. 9 | In addition, the attributes of the class make input and output data more organized. 10 | 11 | Note: 12 | The methods don't check the correctness of the input parameters. 13 | To enter the input parameters correctly, please read the documentation of UVAPadova Simulator. 14 | 15 | Args: 16 | HOST_ADDRESS (str): The IP address of the server that runs the UVAPadovaAPI.py. 17 | PORT (int): The port number where the UVAPadovaAPI.py can be accessed on the server. 18 | listOfCarbohydrateIntakes (list(float)): 19 | A list which contains the carbohydrate intakes during the simulation line. 20 | listOfInsulinIntakes (list(float)): A list which contains the insulin intakes during the simulation line. 21 | listOfBloodGlucoseValues (list(float)):A list which contains the blood glucose values in 5 minute increments. 22 | 23 | """ 24 | 25 | def __init__(self, HOST_ADDRESS: str = "127.0.0.1", PORT: int = 5000): 26 | """ 27 | Args: 28 | HOST_ADDRESS (str, optional): The IP address of the server that runs the UVAPadovaAPI.py. 29 | Defaults to the loopback address. 30 | PORT (int, optional): The port number where the UVAPadovaAPI.py can be accessed on the server. 31 | Defaults to 5000. 32 | 33 | """ 34 | 35 | 36 | self.HOST_ADDRESS = "http://" + HOST_ADDRESS 37 | self.PORT = PORT 38 | self.listOfCarbohydrateIntakes = list() 39 | self.listOfInsulinIntakes = list() 40 | self.listOfBloodGlucoseValues = list() 41 | 42 | def initializePatient(self, patient_name: str, pump: str = None, sensor: str = None) -> bool: 43 | """ 44 | This method initialize a new simulation (resets the simulation line). 45 | 46 | Args: 47 | patient_name (str): The identifier of the patient. 48 | pump (str, optional): The type of the insulin pump. 49 | sensor (str, optional): The type of the CGM sensor. 50 | 51 | Returns: 52 | bool: If the initialization was successful returns true, otherwise returns false. 53 | """ 54 | params = {'id': patient_name} 55 | if pump is not None: 56 | params["pump"] = pump 57 | if sensor is not None: 58 | params["sensor"] = sensor 59 | response = requests.get(url=self.HOST_ADDRESS+":"+str(self.PORT)+"/createSimulation", params=params) 60 | if response.ok: 61 | result = response.json() 62 | result = json.loads(result) 63 | self.Quest = Quest(**result) 64 | self.listOfCarbohydrateIntakes.clear() 65 | self.listOfInsulinIntakes.clear() 66 | self.listOfBloodGlucoseValues.clear() 67 | return response.ok 68 | 69 | def setPump(self, pump: str) -> bool: 70 | """This method changes the insulin pump. 71 | 72 | Args: 73 | pump (str): The name of the pump. 74 | 75 | Returns: 76 | bool: If the request was successful returns true, otherwise returns false. 77 | """ 78 | params = {'pump': pump} 79 | response = requests.post(url=self.HOST_ADDRESS + ":" + str(self.PORT) + "/simulate", params=params) 80 | return response.ok 81 | 82 | def setSensor(self, sensor: str) -> bool: 83 | """This method changes the CGM. 84 | 85 | Args: 86 | sensor (str): The name of the CGM. 87 | 88 | Returns: 89 | bool: If the request was successful returns true, otherwise returns false. 90 | """ 91 | params = {'sensor': sensor} 92 | response = requests.post(url=self.HOST_ADDRESS + ":" + str(self.PORT) + "/simulate", params=params) 93 | return response.ok 94 | 95 | def doSimulation(self, carbohydrate: float = None, insulin: float = None): 96 | """This method extends the initialized simulation by 5 minutes. 97 | Insulin or/and carbohydrate intake can be added to the simulation. 98 | 99 | Note: 100 | Before calling this function, please initialize a patient by "initializePatient" function. 101 | 102 | Args: 103 | carbohydrate (float, optional): The amount of carbohydrate intake, in the last five minutes (in grams). 104 | insulin (float, optional): The amount of insulin intake, in the last five minutes (unit). 105 | 106 | Returns: 107 | If the simulation request was successful, the function returns a dictionary, 108 | which contains the "bloodGlucose" value at the end of the simulation 109 | and optionally other alerts related to the simulation. 110 | 111 | If the simulation request was unsuccessful, the function returns the reason of the error (string format). 112 | 113 | """ 114 | params = {} 115 | if carbohydrate is not None: 116 | self.listOfCarbohydrateIntakes.append(float(carbohydrate)) 117 | params["ch"] = carbohydrate 118 | if insulin is not None: 119 | self.listOfInsulinIntakes.append(float(insulin)) 120 | params["insulin"] = insulin 121 | response = requests.get(url=self.HOST_ADDRESS + ":" + str(self.PORT) + "/simulate", params=params) 122 | if response.ok: 123 | result = response.json() 124 | result = json.loads(result) 125 | self.listOfBloodGlucoseValues.append(float(result["bloodGlucose"])) 126 | return result 127 | else: 128 | return response.reason 129 | --------------------------------------------------------------------------------