1
0
Fork 0
mirror of https://github.com/Findus23/Bachelors-Thesis.git synced 2024-08-27 19:52:12 +02:00
Bachelors-Thesis/41_griddata.tex

83 lines
5.2 KiB
TeX
Raw Permalink Normal View History

2019-08-01 13:37:48 +02:00
% !TeX spellcheck = en_US
2019-08-29 10:56:46 +02:00
\section{Multidimensional linear interpolation}
2019-08-01 13:36:02 +02:00
\subsection{Theory}
One of the easiest ways to interpolate a new value between two known values is linear interpolation. It takes the closest values and creates a linear function between them.
2019-08-26 17:18:10 +02:00
In one dimension, linear interpolation is pretty trivial. For example, let's assume that we have 20 random points $P$ between 0 and 1 (\textcolor{Red}{\textbullet} and \textcolor{Blue}{\textbullet} in Figure \ref{fig:one-dim-interpolation}) and have a new point $I$ (\textcolor{Green}{\textbullet}) at $0.4$ for which we want to interpolate. Finding the two closest points (\textcolor{Red}{\textbullet}) above and below is trivial as there is only one dimension to compare. Now, if we have measured a value $f(P)$ for each of these points, a straight line (\textcolor{LightGreen}{\textbf{|}}) between the two closest values can be drawn and an interpolated value for $f(I)$ can be found.
2019-08-01 13:36:02 +02:00
2019-08-26 17:18:10 +02:00
\begin{figure}[] % also temporary
2019-08-01 13:36:02 +02:00
\centering
2019-08-20 16:32:22 +02:00
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[width=\linewidth]{images/vis1d.pdf}
2019-08-26 17:18:10 +02:00
\caption{A one-dimensional example of linear interpolation}
2019-08-20 16:32:22 +02:00
\label{fig:one-dim-interpolation}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[width=\linewidth]{images/vis2d1.pdf}
2019-08-26 17:18:10 +02:00
\caption{A set of two-dimensional datapoints}
2019-08-20 16:32:22 +02:00
\label{fig:3dinterpolate-1}
\end{subfigure}
\caption{}
2019-08-01 13:36:02 +02:00
\end{figure}
In two dimensions things get more complicated as we now have a set of points with $X$ and $Y$ coordinates (Figure \ref{fig:3dinterpolate-1}). One fast way to find the closest points to the point that should be interpolated is using Delaunay triangulation. This is a method to separate the space between the points into triangles while trying to maximize their smallest angle and to make sure no other point is inside the circumcircle of the triangles\footcite{Delaunay}. Connecting the centers of the circumcircles results in a Voronoi diagram.
Afterwards, the closest three points can be found very quickly by checking the nodes of the surrounding triangle (Figure \ref{fig:3dinterpolate-2}). If we now again have a function $f(X,Y)$ similar to the one-dimensional example, we can create a unique plain through the three points and get the interpolated value for any pair of $X$ and $Y$ on this layer. (Figure \ref{fig:3dinterpolate-3})
2019-08-01 13:36:02 +02:00
2019-08-26 17:18:10 +02:00
\begin{figure}[] % also temporary
2019-08-01 13:36:02 +02:00
\centering
2019-08-26 17:18:10 +02:00
\begin{subfigure}[t]{0.48\textwidth}
2019-08-01 13:36:02 +02:00
\centering
2019-08-20 16:32:22 +02:00
\includegraphics[width=\linewidth]{images/vis2d2.pdf}
2019-08-26 17:18:10 +02:00
\caption{A Delaunay triangulation of the points from Figure~\ref{fig:3dinterpolate-1}}
\label{fig:3dinterpolate-2}
2019-08-01 13:36:02 +02:00
\end{subfigure}%
~
2019-08-26 17:18:10 +02:00
\begin{subfigure}[t]{0.48\textwidth}
2019-08-01 13:36:02 +02:00
\centering
2019-08-20 16:32:22 +02:00
\includegraphics[width=\linewidth]{images/vis2d3.pdf}
2019-08-26 17:18:10 +02:00
\caption{A $f(X,Y)$ interpolated via the green plane}
\label{fig:3dinterpolate-3}
2019-08-01 13:36:02 +02:00
\end{subfigure}
2019-08-20 16:32:22 +02:00
\caption{}
2019-08-01 13:36:02 +02:00
\end{figure}
2019-08-20 16:32:22 +02:00
2019-08-01 13:36:02 +02:00
2019-09-17 17:34:24 +02:00
This approach has the advantage that it can be extended in more than two dimensions by replacing the triangle in the Delaunay triangulation with an n-simplex in n dimensions. The \texttt{scipy.spatial.Delaunay} python function allows to quickly calculate it thanks to the \texttt{Qhull} library\footnote{\url{http://www.qhull.org/}}. One noticeable limitation of this method is that data can't be extrapolated. Therefore, the possible output is limited to the convex hull of the input parameter space (as seen in Figure \ref{fig:3dinterpolate-2}).
2019-08-01 13:36:02 +02:00
\subsection{Implementation}
\label{sec:griddata-implementation}
2019-08-20 16:32:22 +02:00
For doing the actual interpolations, the \texttt{scipy.interpolate.griddata} function is used with the \texttt{method="linear"} argument which itself uses \texttt{scipy.interpolate.LinearNDInterpolator} to do an interpolation similar to the one described above. The function is given a $6\times n$ matrix of the six parameters and an $n$-sized list of the water retention fraction for those $n$ simulations. In addition, \texttt{griddata} supports not only calculating interpolations for one set of parameters, but also for lists of parameters which allows to quickly generate 2d diagrams as seen in Figure \ref{fig:griddataresults}.
\subsection{Results}
2019-08-01 13:36:02 +02:00
2019-09-19 17:31:41 +02:00
Most notable about the results of the griddata interpolation (Figure \ref{fig:griddataresults}) are the many fine details that can be seen. This is mostly caused by the fact that this method only uses the closest values for interpolations and therefore there is no smoothing. These details might just be random derivations of the simulation and not a higher resolution of the data. Another thing that can be seen in the bottom right corner of Figure \ref{fig:griddata1} is that griddata can't extrapolate data.
2019-08-26 17:18:10 +02:00
2019-08-20 16:32:22 +02:00
\begin{figure}[h!] % also temporary
\centering
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[width=\linewidth]{images/plots/griddata1.pdf}
\caption{$m_{total}=\num{e22}$, $\gamma=0.6$, $wt=wp=0.15$}
\label{fig:griddata1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.5\textwidth}
\centering
\includegraphics[width=\linewidth]{images/plots/griddata2.pdf}
\caption{$m_{total}=\num{e24}$, $\gamma=0.6$, $wt=wp=0.15$}
\label{fig:griddata2}
\end{subfigure}
\caption{Interpolation result using griddata}
\label{fig:griddataresults}
2019-09-17 17:34:24 +02:00
\end{figure}