Open sashahafner opened 1 year ago
Maybe it is time to start on this
I've added time-variable dirty air/water concentrations.
834a62a4cee27c0a697b7c32e7be7483d42ab7d0
Used an array for inputs
cgin = np.array([[0, 1000, 1100, 3600, 3700, 5000, 7200], [1, 3, 1, 1, 4, 2, 2]])
and in rates()
if type(clin) is np.ndarray:
clin = np.interp(t, clin[0], clin[1])
There might be a more efficient object.
I couldn't find a Python equivalent of approxfun()
.
inpterp()
just does interpolation, so the times and concentrations all have to be passed to rates()
.
I guess this is OK.
Sure makes the code simple.
Alternatively I guess we could define a function within the main model function and then send it to rates()
.
Will have to see if that is possible.
@afeilberg found scipy.interpolate.intp1d() that creates a function. Let's try this
Task: switch to scipy.interpolate.intp1d()
Task: use data frame structure from pandas for input concentrations
@sashahafner this one: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html
Some details on interpolation here: https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html
It seems that interp1d is "legacy" and no longer updated.
For now I am sticking with interpolation within rates()
using numpy.interp()
.
Task: use data frame structure from pandas for input concentrations
Done in f0b28094645fcbe295c6ea9da40385befbd22a92
In rates()
:
# If time-variable concentrations coming in are given, get interpolated values
if type(clin) is pd.core.frame.DataFrame:
clin = np.interp(t, clin.iloc[:, 0], clin.iloc[:, 1])
elif type(clin) is np.ndarray:
clin = np.interp(t, clin[0], clin[1])
elif not (type(clin) is int or type(clin) is float):
sys.exit('Error: clin input must be float, integer, numpy array, or a pandas data frame, but is none of these')
cgin = np.loadtxt('./3peaks.csv', delimiter=';') cgin = np.transpose(cgin)
I will add to a new demo and then update Anders
Thanks @afeilberg. Done in demo 11:
https://github.com/AU-BCE-EE/tric-fil-mod/tree/main/demos/11_time_var_file
Pretty neat.
I ended up using read_csv()
from pandas, because it directly creates a data frame, which is probably more straightforward now that the function accepts data frames in addition to arrays.
7d4721996f79ca4e30e871806229cbd5a2b36da7
This is something for the future.