Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor sample_time affects reported CHO and Insulin #78

Open
PrangerStefan opened this issue Apr 3, 2024 · 0 comments
Open

Sensor sample_time affects reported CHO and Insulin #78

PrangerStefan opened this issue Apr 3, 2024 · 0 comments

Comments

@PrangerStefan
Copy link

First of all, thanks a lot for the implementation of this simulation!

While inspecting and playing around with the implementation I have found that the sensors sample_time affects the reported CHO and Insulin.

Using the second scenario defined in advanced_scenario.py and comparing the Dexcom (sample_size = 3.0) and GuardianRT (sample_size = 5.0), I come to the following with the Dexcom sensor:

        mini_step: BG:  49.677, measured CGM:   48.167, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.004644444444444445
        mini_step: BG:  99.354, measured CGM:   96.334, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.00928888888888889
        mini_step: BG:  149.032, measured CGM:  144.882, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.013933333333333336
BG:     149.032, measured CGM:  144.882, carbo (CHO):   0.000, insulin: 0.013933333333333336
        mini_step: BG:  49.677, measured CGM:   48.548, carbo (CHO):    15.000 (tmp_CHO:45.000), insulin:       0.004644444444444445
        mini_step: BG:  99.354, measured CGM:   97.096, carbo (CHO):    15.000 (tmp_CHO:0.000), insulin:        0.00928888888888889
        mini_step: BG:  149.032, measured CGM:  146.033, carbo (CHO):   15.000 (tmp_CHO:0.000), insulin:        0.013933333333333336
BG:     149.032, measured CGM:  146.033, carbo (CHO):   15.000, insulin:        0.013933333333333336
        mini_step: BG:  49.677, measured CGM:   48.937, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.42131111111111114
        mini_step: BG:  99.355, measured CGM:   97.874, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.8426222222222223
        mini_step: BG:  149.033, measured CGM:  147.163, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 1.2639333333333334
BG:     149.033, measured CGM:  147.163, carbo (CHO):   0.000, insulin: 1.2639333333333334

Note, that these are three steps around 7am, when according to the scenario 45 units of CHO are to be consumed.

The same simulation using GuardianRT:

        mini_step: BG:  29.806, measured CGM:   29.051, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.002786666666666667
        mini_step: BG:  59.613, measured CGM:   58.101, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.005573333333333334
        mini_step: BG:  89.419, measured CGM:   87.152, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.008360000000000001
        mini_step: BG:  119.225, measured CGM:  116.202, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.011146666666666668
        mini_step: BG:  149.032, measured CGM:  145.639, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.013933333333333334
BG:     149.032, measured CGM:  145.639, carbo (CHO):   0.000, insulin: 0.013933333333333334
        mini_step: BG:  29.806, measured CGM:   29.436, carbo (CHO):    9.000 (tmp_CHO:45.000), insulin:        0.002786666666666667
        mini_step: BG:  59.613, measured CGM:   58.872, carbo (CHO):    9.000 (tmp_CHO:0.000), insulin: 0.005573333333333334
        mini_step: BG:  89.419, measured CGM:   88.309, carbo (CHO):    9.000 (tmp_CHO:0.000), insulin: 0.008360000000000001
        mini_step: BG:  119.225, measured CGM:  117.745, carbo (CHO):   9.000 (tmp_CHO:0.000), insulin: 0.011146666666666668
        mini_step: BG:  149.032, measured CGM:  147.478, carbo (CHO):   9.000 (tmp_CHO:0.000), insulin: 0.013933333333333334
BG:     149.032, measured CGM:  147.478, carbo (CHO):   9.000, insulin: 0.013933333333333334
        mini_step: BG:  29.807, measured CGM:   29.733, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.15278666666666668
        mini_step: BG:  59.614, measured CGM:   59.467, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.30557333333333336
        mini_step: BG:  89.422, measured CGM:   89.200, carbo (CHO):    0.000 (tmp_CHO:0.000), insulin: 0.45836000000000005
        mini_step: BG:  119.231, measured CGM:  118.933, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.6111466666666667
        mini_step: BG:  149.043, measured CGM:  148.751, carbo (CHO):   0.000 (tmp_CHO:0.000), insulin: 0.7639333333333334
BG:     149.043, measured CGM:  148.751, carbo (CHO):   0.000, insulin: 0.7639333333333334

The comparison between these two sensors shows the difference in reported CHO and insulin:
Dexcom_GuardianRT_comparison
It seems that this is only a cosmetic error (I am guessing this by comparing the trajectories of BG). I am happy to provide a PR...

The logs from above have been created with with:

diff --git i/examples/advanced_tutorial.py w/examples/advanced_tutorial.py
index 1249c88..f194ad9 100644
--- i/examples/advanced_tutorial.py
+++ w/examples/advanced_tutorial.py
@@ -29,8 +29,8 @@ controller = BBController()
 
 # Put them together to create a simulation object
 s1 = SimObj(env, controller, timedelta(days=1), animate=False, path=path)
-results1 = sim(s1)
-print(results1)
+#results1 = sim(s1)
+#print(results1)
 
 # --------- Create Custom Scenario --------------
 # Create a simulation environment
@@ -46,7 +46,7 @@ env = T1DSimEnv(patient, sensor, pump, scenario)
 controller = BBController()
 
 # Put them together to create a simulation object
-s2 = SimObj(env, controller, timedelta(days=1), animate=False, path=path)
+s2 = SimObj(env, controller, timedelta(days=1), animate=True, path=path)
 results2 = sim(s2)
 print(results2)
 
diff --git i/simglucose/simulation/env.py w/simglucose/simulation/env.py
index 45a43cb..c96a6b1 100644
--- i/simglucose/simulation/env.py
+++ w/simglucose/simulation/env.py
@@ -79,6 +79,8 @@ class T1DSimEnv(object):
             insulin += tmp_insulin / self.sample_time
             BG += tmp_BG / self.sample_time
             CGM += tmp_CGM / self.sample_time
+            print(f"\tmini_step: BG:\t{BG:4.3f}, measured CGM:\t{CGM:3.3f}, carbo (CHO):\t{CHO:3.3f} (tmp_CHO:{tmp_CHO:3.3f}), insulin:\t{insulin}")
+        print(f"BG:\t{BG:4.3f}, measured CGM:\t{CGM:3.3f}, carbo (CHO):\t{CHO:3.3f}, insulin:\t{insulin}")
 
         # Compute risk index
         horizon = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant