Displaying gekko variable values in a time-dependent value in spyder IDE

Viewed 148

I'm using GEKKO for a time-dependent DEs model. I am tracking the concentrations of species in a well-mixed compartment model using GEKKO variables; however, I can't view the time-dependent arrays of the concentrations within the spyder IDE. I can plot the concentrations and view the values as graphs, or use the values as reported in the "results" excel file, but it would be useful to see the time-dependent values within spyder. Right now, within the variable explorer of spyder, the variables appear as type gk_variable.GKVariable.

This is a sample of the code I use

from gekko import GEKKO
import numpy as np
import pandas as pd

myFile = pd.read_csv('Time_Array.csv', sep = ',')
myFile.index
myFile.columns
time = np.array(myFile)

m.time = time

FCG = m.Var(value = 6.934045, lb = 0) 
CMG = m.Var(value = 7.01148, lb = 0)

m.Equations([FCG.dt() == Qdiet/Vintestines + Qsynintestine + Kfclg*FCL*(Vliver/Vintestines) - Kfcex*FCG - Kfccm*FCG, CMG.dt() == Kfccm*FCG - Kcmgb * CMG])

m.options.IMODE = 4
m.solve(disp = True)

The above code is a snippet of the model. In the actual model, there are a lot more constants and equations; however, I'd basically like to view the time dependent values of concentrations like FCG and CMG without leaving the spyder IDE. I know that you can do this by inserting print statements in the code, I was wondering if anyone knew of any other cleaner fixes.

Thanks so much!

1 Answers

The .value property is available to see the numeric values of a Gekko parameter or variable. This doesn't show up in the variable explorer so one work-around is to create a new Python variable.

fcg_values = FCG.value

You can also see the first value:

fcg_init = FCG.value[0]

the last value:

fcg_last = FCG.value[-1]

or also a range of values in between:

fcg_inner = FCG.value[2:5]
Related