I have some data stored in a object Foo()
.
Foo.data
is a list of n x m np.array, where each array represent some experimental data at a specific time. The array is composed by m variables, and n correspond to the number of different point where measurement has been taken.
We can consider that we have at our disposal a list of variables name, e.g:
var_names=['x','volume','u','L_bar','rho','P',.....]
I want like to make data more accessible, defining something like:
def Foo.P(self,x,time)
index_t=time_list.index(time)
index_x=var_names.index(x)
index_P=var_names.index(P)
return Foo.data[index_t][index_x,index_P]
The question is: considering that the list of variables is not fixed,but it can vary, can I automatically define some functions that do what I show before without explicitly defining one for each variable?
I mean, I would like to have a bunch of function such as, Foo.P, Foo.volume, Foo.u, Foo.rho that extract the value of the variable given by the function name, for a (x,time) position, without defining all of them one by one.