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

Report function does not work #42

Open
yujiadeng opened this issue Jan 3, 2022 · 2 comments
Open

Report function does not work #42

yujiadeng opened this issue Jan 3, 2022 · 2 comments

Comments

@yujiadeng
Copy link

yujiadeng commented Jan 3, 2022

Hi, I just installed the package from pip. I was running the tutorial and failed to get the visualizations.

Reproduce:

from simglucose.simulation.env import T1DSimEnv
from simglucose.controller.basal_bolus_ctrller import BBController
from simglucose.sensor.cgm import CGMSensor
from simglucose.actuator.pump import InsulinPump
from simglucose.patient.t1dpatient import T1DPatient
from simglucose.simulation.scenario_gen import RandomScenario
from simglucose.simulation.scenario import CustomScenario
from simglucose.simulation.sim_engine import SimObj, sim, batch_sim
from datetime import timedelta
from datetime import datetime

# specify start_time as the beginning of today
now = datetime.now()
start_time = datetime.combine(now.date(), datetime.min.time())

# --------- Create Random Scenario --------------
# Specify results saving path
path = './results'

# Create a simulation environment
patient = T1DPatient.withName('adolescent#001')
sensor = CGMSensor.withName('Dexcom', seed=1)
pump = InsulinPump.withName('Insulet')
scenario = RandomScenario(start_time=start_time, seed=1)
env = T1DSimEnv(patient, sensor, pump, scenario)

# Create a controller
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)

from simglucose.analysis.report import report
import pandas as pd
from pathlib import Path

result_filename = './results/adolescent#001.csv'
df = pd.read_csv(result_filename, index_col=0)
report(df)

I found all errors raised in the plot function is regarding to BG which is defined by BG = df.unstack(level=0).BG. I tried both single day/ >1 days and looks the plot functions always raise error. What shape should BG be?

@jxx123
Copy link
Owner

jxx123 commented Feb 2, 2022

This might be a dependency issue. Mine is good. I feel there is some updates in pandas causing this issue, but I agree the report function is written in quite a messy way. I will need to install the latest pandas and debug more.

@yihuicai
Copy link
Contributor

yihuicai commented Jul 24, 2023

I also met a similar issue when generating report, seems the numpy calculations returns an object which object is not compatible with DataFrame object in pandas library:

Traceback (most recent call last): File "/home/alan/simglucose/sim_origin.py", line 6, in <module> simulate(start_time=datetime.combine(datetime.now().date(), datetime.min.time()),controller=BBController(),cgm_seed=123412,animate=False,parallel=True) File "/home/alan/simglucose/simglucose/simulation/user_interface.py", line 383, in simulate results, ri_per_hour, zone_stats, figs, axes = report(df, save_path) File "/home/alan/simglucose/simglucose/analysis/report.py", line 251, in report ri_per_hour, ri_mean, fig_ri, ax5 = risk_index_trace(BG, visualize=False) File "/home/alan/simglucose/simglucose/analysis/report.py", line 102, in risk_index_trace fBG_df = pd.concat(fBG, axis=1).transpose() File "/home/alan/.local/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 372, in concat op = _Concatenator( File "/home/alan/.local/lib/python3.10/site-packages/pandas/core/reshape/concat.py", line 462, in __init__ raise TypeError(msg) TypeError: cannot concatenate object of type '<class 'numpy.float64'>'; only Series and DataFrame objs are valid

My dependencies are:

pandas: 2.0.2
numpy: 1.24.3
Python: 3.10.6

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

3 participants