AU-BCE-EE / tric-fil-mod

A trickling filter model to simulate air treatment, written in Python
GNU General Public License v3.0
0 stars 0 forks source link

Add time-variable dirty air concentration #1

Open sashahafner opened 1 year ago

sashahafner commented 1 year ago

This is something for the future.

sashahafner commented 1 year ago

Maybe it is time to start on this

sashahafner commented 1 year ago

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.

sashahafner commented 1 year ago

@afeilberg found scipy.interpolate.intp1d() that creates a function. Let's try this

sashahafner commented 1 year ago

Task: switch to scipy.interpolate.intp1d()

sashahafner commented 1 year ago

Task: use data frame structure from pandas for input concentrations

afeilberg commented 1 year ago

@sashahafner this one: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html

sashahafner commented 1 year ago

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.

sashahafner commented 1 year ago

For now I am sticking with interpolation within rates() using numpy.interp().

sashahafner commented 1 year ago

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')
afeilberg commented 1 year ago

cgin = np.loadtxt('./3peaks.csv', delimiter=';') cgin = np.transpose(cgin)

afeilberg commented 1 year ago

3peaks.csv

sashahafner commented 1 year ago

I will add to a new demo and then update Anders

sashahafner commented 1 year ago

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