next up previous contents index
Next: Saving Data as CSV Up: esys.escript Classes Previous: Functions of Data objects   Contents   Index


Interpolating Data

In some cases, it may be useful to produce Data objects which fit some user defined function. Manually modifying each value in the Data object is not a good idea since it depends on knowing the location and order of each datapoint in the domain. Instead esys.escript can use an interpolation table to produce a Data object.

The following example is available as int_save.py in the examples directory. We will produce a Data object which aproximates a sine curve.


\begin{python}
from esys.escript import saveDataCSV, sup
import numpy
from esys....
...e(n,n)
x=r.getX()
x0=x[0]
x1=x[1]  ...

First we produce an interpolation table.
\begin{python}
sine_table=[0, 0.70710678118654746, 1, 0.70710678118654746, 0,
-0.70710678118654746, -1, -0.70710678118654746, 0]
\end{python}

We wish to identify 0 and $ 1$ with the ends of the curve. That is, with the first and eighth values in the table.


\begin{python}
numslices=len(sine_table)-1
\par
minval=0
maxval=1
\par
step=sup(maxval-minval)/numslices
\end{python}

So the values $ v$ from the input lie in the interval minval$ \leq v < $ maxval. step represents the gap (in the input range) between entries in the table. By default values of $ v$ outside the table argument range (minval, maxval) will be pushed back into the range, ie. if $ v <$ minval the value minval will be used to evaluate the table. Similarly, for values $ v>$ maxval the value maxval is used.

Now we produce our new Data object.


\begin{python}
result=x0.interpolateTable(sine_table, minval, step, toobig)
\end{python}
Any values which interpolate to larger than toobig will raise an exception. You can switch on boundary checking by adding ''check_boundaries=True`` the argument list.

Now for a 2D example. We will interpolate a surface such that the bottom edge is the sine curve described above. The amplitude of the curve decreases as we move towards the top edge.

Our interpolation table will have three rows.
\begin{python}
st=numpy.array(sine_table)
\par
table=[st, 0.5*st, 0*st ]
\end{python}

The use of numpy and multiplication here is just to save typing.


\begin{python}
result2=x1.interpolateTable(table, 0, 0.55, x0, minval, step, toobig)
\end{python}

In the 2D case, the parameters for the x1 direction (min=0, step=0.55) come first followed by the x0 data object and its parameters. By default, if a point is specified which is outside the boundary, then interpolateTable will operate as if the point was on the boundary. Passing check_boundaries=True will interpolateTable to reject any points outside the boundaries.


next up previous contents index
Next: Saving Data as CSV Up: esys.escript Classes Previous: Functions of Data objects   Contents   Index
esys@esscc.uq.edu.au