<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2002-2-1 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>3.2.1 Nearest neighbor gridding</TITLE> <META NAME="description" CONTENT="3.2.1 Nearest neighbor gridding"> <META NAME="keywords" CONTENT="GMT_Tutorial"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="GMT_Tutorial.css"> <LINK REL="next" HREF="node46.html"> <LINK REL="previous" HREF="node43.html"> <LINK REL="up" HREF="node43.html"> <LINK REL="next" HREF="node45.html"> </HEAD> <BODY bgcolor="#ffffff"> <!--Navigation Panel--> <A NAME="tex2html1020" HREF="node45.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html1014" HREF="node43.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html1008" HREF="node43.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html1016" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html1018" HREF="node63.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html1021" HREF="node45.html">3.2.1.1 Exercises</A> <B> Up:</B> <A NAME="tex2html1015" HREF="node43.html">3.2 Gridding of arbitrarily</A> <B> Previous:</B> <A NAME="tex2html1009" HREF="node43.html">3.2 Gridding of arbitrarily</A> <B> <A NAME="tex2html1017" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html1019" HREF="node63.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H2><A NAME="SECTION00521000000000000000"> 3.2.1 Nearest neighbor gridding</A> </H2> <P> <DIV ALIGN="CENTER"><A NAME="fig:GMT_nearneighbor"></A><A NAME="2351"></A> <TABLE> <CAPTION ALIGN="BOTTOM"><STRONG>Figure 3.1:</STRONG> Search geometry for <A NAME="tex2html174" HREF="../man/nearneighbor.html"><I><B>nearneighbor</B></I></A><A NAME="2357"></A>.</CAPTION> <TR><TD> <DIV ALIGN="CENTER"><IMG WIDTH="232" HEIGHT="232" ALIGN="BOTTOM" BORDER="0" SRC="img34.png" ALT="\includegraphics{scripts/GMT_nearneighbor}"></DIV></TD></TR> </TABLE> </DIV> <P> The <A NAME="tex2html180" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> program <A NAME="tex2html181" HREF="../man/nearneighbor.html"><I><B>nearneighbor</B></I></A><A NAME="2365"></A> implements a simple ``nearest neighbor'' averaging operation. It is the preferred way to grid data when the data density is high. <A NAME="tex2html182" HREF="../man/nearneighbor.html"><I><B>nearneighbor</B></I></A><A NAME="2370"></A> is a local procedure which means it will only consider the control data that is close to the desired output grid node. Only data points inside a specified search radius will be used, and we may also impose the condition that each of the <I>n</I> sectors must have at least one data point in order to assign the nodal value. The nodal value is computed as a weighted average of the nearest data point per sector inside the search radius, with each point weighted according to its distance from the node as follows: <P> <BR><P></P> <DIV ALIGN="CENTER"> <!-- MATH \begin{displaymath} \bar{z} = \frac{\sum_{i=1}^{n} z_{i} w_{i}}{\sum_{i=1}^{n} w_{i}} \quad w_{i} = \left( 1 + \frac{9 r_{i}^{2}}{R^{2}} \right) ^{-1} \end{displaymath} --> <IMG WIDTH="224" HEIGHT="50" BORDER="0" SRC="img35.png" ALT="\begin{displaymath} \bar{z} = \frac{\sum_{i=1}^{n} z_{i} w_{i}}{\sum_{i=1}^{n} w... ...d w_{i} = \left( 1 + \frac{9 r_{i}^{2}}{R^{2}} \right) ^{-1} \end{displaymath}"> </DIV> <BR CLEAR="ALL"> <P></P> <P> <A NAME="1158"></A> <P> The most important switches are listed in Table <A HREF="#tbl:nearneighbor">3.2</A>. <P> <BR><P></P> <DIV ALIGN="CENTER"><A NAME="1607"></A> <TABLE> <CAPTION><STRONG>Table 3.2:</STRONG> Switches used with the <A NAME="tex2html177" HREF="../man/nearneighbor.html"><I><B>nearneighbor</B></I></A><A NAME="2379"></A> program.</CAPTION> <TR><TD> <DIV ALIGN="CENTER"><TABLE CELLPADDING=3 BORDER="1"> <TR><TD ALIGN="CENTER" COLSPAN=1><FONT SIZE="-1"> <I>Option</I></FONT></TD> <TD ALIGN="CENTER" COLSPAN=1><FONT SIZE="-1"> <I>Purpose</I></FONT></TD> </TR> <TR><TH ALIGN="LEFT"><FONT SIZE="-1"> <B>-S</B></FONT><FONT SIZE="-1"><I>radius</I>[</FONT><FONT SIZE="-1"><B>k</B>] </FONT></TH> <TD ALIGN="LEFT"><FONT SIZE="-1"> Sets search radius. Append </FONT><FONT SIZE="-1"><B>k</B> to indicate radius in kilometers [Default is </FONT><FONT SIZE="-1"><I>x</I>-units] </FONT></TD> </TR> <TR><TH ALIGN="LEFT"><FONT SIZE="-1"> <B>-E</B></FONT><FONT SIZE="-1"><I>empty</I> </FONT></TH> <TD ALIGN="LEFT"><FONT SIZE="-1"> Assign this value to unconstrained nodes [Default is NaN] </FONT></TD> </TR> <TR><TH ALIGN="LEFT"><FONT SIZE="-1"> <B>-N</B></FONT><FONT SIZE="-1"><I>sectors</I> </FONT></TH> <TD ALIGN="LEFT"><FONT SIZE="-1"> Sector search, indicate number of sectors [Default is 4] </FONT></TD> </TR> <TR><TH ALIGN="LEFT"><FONT SIZE="-1"> <B>-W</B> </FONT></TH> <TD ALIGN="LEFT"><FONT SIZE="-1"> Read relative weights from the 4th column of input data </FONT></TD> </TR> </TABLE><FONT SIZE="-1"> <A NAME="tbl:nearneighbor"></A></FONT></DIV></TD></TR> </TABLE> </DIV><P></P> <BR> <P> We will grid the data in the file <U>ship.xyz</U> which contains ship observations of bathymetry off Baja California. You can find the file in the sub-directory for example 15. We desire to make a 5' by 5' grid. Running <A NAME="tex2html183" HREF="../man/minmax.html"><I><B>minmax</B></I></A><A NAME="2385"></A> on the file yields <P> <PRE> ship.xyz: N = 82970 <245/254.705> <20/29.99131> <-7708/-9> </PRE> <P> so we choose the region accordingly: <P> <PRE> nearneighbor -R245/255/20/30 -I5m -S40k -Gship.nc -V ship.xyz </PRE> <P> We may get a view of the contour map using <P> <PRE> grdcontour ship.nc -JM6i -P -B2 -C250 -A1000 | ghostview - </PRE> <P> Since the grid <U>ship.nc</U> is stored in netCDF format that is supported by a host of other programs, you can try one of those as well on the same grid. <P> <BR><HR> <!--Table of Child-Links--> <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A> <UL> <LI><A NAME="tex2html1022" HREF="node45.html">3.2.1.1 Exercises</A> </UL> <!--End of Table of Child-Links--> <HR> <!--Navigation Panel--> <A NAME="tex2html1020" HREF="node45.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html1014" HREF="node43.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html1008" HREF="node43.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html1016" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html1018" HREF="node63.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html1021" HREF="node45.html">3.2.1.1 Exercises</A> <B> Up:</B> <A NAME="tex2html1015" HREF="node43.html">3.2 Gridding of arbitrarily</A> <B> Previous:</B> <A NAME="tex2html1009" HREF="node43.html">3.2 Gridding of arbitrarily</A> <B> <A NAME="tex2html1017" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html1019" HREF="node63.html">Index</A></B> <!--End of Navigation Panel--> <ADDRESS> Paul Wessel 2010-07-14 </ADDRESS> </BODY> </HTML>