<!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>7.16 Gridding of data, continued</TITLE> <META NAME="description" CONTENT="7.16 Gridding of data, continued"> <META NAME="keywords" CONTENT="GMT_Docs"> <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_Docs.css"> <LINK REL="next" HREF="node140.html"> <LINK REL="previous" HREF="node138.html"> <LINK REL="up" HREF="node123.html"> <LINK REL="next" HREF="node140.html"> </HEAD> <BODY bgcolor="#ffffff"> <!--Navigation Panel--> <A NAME="tex2html4676" HREF="node140.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html4670" HREF="node123.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html4664" HREF="node138.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html4672" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html4674" HREF="node258.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html4677" HREF="node140.html">7.17 Images clipped by</A> <B> Up:</B> <A NAME="tex2html4671" HREF="node123.html">7. Creating GMT Graphics</A> <B> Previous:</B> <A NAME="tex2html4665" HREF="node138.html">7.15 Gridding, contouring, and</A> <B> <A NAME="tex2html4673" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html4675" HREF="node258.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H1><A NAME="SECTION0015160000000000000000"></A> <A NAME="25003"></A> <BR> 7.16 Gridding of data, continued </H1> <P> <A NAME="tex2html1485" HREF="../man/pscontour.html"><I><B>pscontour</B></I></A><A NAME="25770"></A> (for contouring) and <A NAME="tex2html1486" HREF="../man/triangulate.html"><I><B>triangulate</B></I></A><A NAME="25775"></A> (for gridding) use the simplest method of interpolating data: a Delaunay triangulation (see Section <A HREF="node135.html#sec:example_12">7.12</A>) which forms <IMG WIDTH="43" HEIGHT="31" ALIGN="MIDDLE" BORDER="0" SRC="img176.png" ALT="$z(x, y)$"> as a union of planar triangular facets. One advantage of this method is that it will not extrapolate <IMG WIDTH="43" HEIGHT="31" ALIGN="MIDDLE" BORDER="0" SRC="img176.png" ALT="$z(x, y)$"> beyond the convex hull of the input (<I>x, y</I>) data. Another is that it will not estimate a <I>z</I> value above or below the local bounds on any triangle. A disadvantage is that the <IMG WIDTH="43" HEIGHT="31" ALIGN="MIDDLE" BORDER="0" SRC="img176.png" ALT="$z(x, y)$"> surface is not differentiable, but has sharp kinks at triangle edges and thus also along contours. This may not look physically reasonable, but it can be filtered later (last panel below). <A NAME="tex2html1487" HREF="../man/surface.html"><I><B>surface</B></I></A><A NAME="25780"></A> can be used to generate a higher-order (smooth and differentiable) interpolation of <IMG WIDTH="43" HEIGHT="31" ALIGN="MIDDLE" BORDER="0" SRC="img176.png" ALT="$z(x, y)$"> onto a grid, after which the grid may be illustrated (<A NAME="tex2html1488" HREF="../man/grdcontour.html"><I><B>grdcontour</B></I></A><A NAME="25785"></A>, <A NAME="tex2html1489" HREF="../man/grdimage.html"><I><B>grdimage</B></I></A><A NAME="25790"></A>, <A NAME="tex2html1490" HREF="../man/grdview.html"><I><B>grdview</B></I></A><A NAME="25795"></A>). <A NAME="tex2html1491" HREF="../man/surface.html"><I><B>surface</B></I></A><A NAME="25800"></A> will interpolate to all (<I>x, y</I>) points in a rectangular region, and thus will extrapolate beyond the convex hull of the data. However, this can be masked out in various ways (see Section <A HREF="node138.html#sec:example_15">7.15</A>). <P> A more serious objection is that <A NAME="tex2html1492" HREF="../man/surface.html"><I><B>surface</B></I></A><A NAME="25805"></A> may estimate <I>z</I> values outside the local range of the data (note area near <I>x</I> = 0.8, <I>y</I> = 5.3). This commonly happens when the default tension value of zero is used to create a ``minimum curvature'' (most smooth) interpolant. <A NAME="tex2html1493" HREF="../man/surface.html"><I><B>surface</B></I></A><A NAME="25810"></A> can be used with non-zero tension to partially overcome this problem. The limiting value <IMG WIDTH="78" HEIGHT="29" ALIGN="MIDDLE" BORDER="0" SRC="img177.png" ALT="$tension = 1$"> should approximate the triangulation, while a value between 0 and 1 may yield a good compromise between the above two cases. A value of 0.5 is shown here (Figure <A HREF="#fig:GMT_example_16">7.16</A>). A side effect of the tension is that it tends to make the contours turn near the edges of the domain so that they approach the edge from a perpendicular direction. A solution is to use <A NAME="tex2html1494" HREF="../man/surface.html"><I><B>surface</B></I></A><A NAME="25815"></A> in a larger area and then use <A NAME="tex2html1495" HREF="../man/grdcut.html"><I><B>grdcut</B></I></A><A NAME="25820"></A> to cut out the desired smaller area. Another way to achieve a compromise is to interpolate the data to a grid and then filter the grid using <A NAME="tex2html1496" HREF="../man/grdfft.html"><I><B>grdfft</B></I></A><A NAME="25825"></A> or <A NAME="tex2html1497" HREF="../man/grdfilter.html"><I><B>grdfilter</B></I></A><A NAME="25830"></A>. The latter can handle grids containing ``NaN'' values and it can do median and mode filters as well as convolutions. Shown here is <A NAME="tex2html1498" HREF="../man/triangulate.html"><I><B>triangulate</B></I></A><A NAME="25835"></A> followed by <A NAME="tex2html1499" HREF="../man/grdfilter.html"><I><B>grdfilter</B></I></A><A NAME="25840"></A>. Note that the filter has done some extrapolation beyond the convex hull of the original <I>x, y</I> values. The ``best'' smooth approximation of <IMG WIDTH="43" HEIGHT="31" ALIGN="MIDDLE" BORDER="0" SRC="img176.png" ALT="$z(x, y)$"> depends on the errors in the data and the physical laws obeyed by <I>z</I>. <A NAME="tex2html1500" HREF="http://gmt.soest.hawaii.edu"><B>GMT</B></A> cannot always do the ``best'' thing but it offers great flexibility through its combinations of tools. We illustrate all four solutions using a cpt file that contains color fills, predefined patterns for interval (900,925) and NaN, an image pattern for interval (875,900), and a ``skip slice'' request for interval (700,725). <P> <BR CLEAR="ALL"> <HR> <BR> <PRE>#!/bin/sh # GMT EXAMPLE 16 # # Purpose: Illustrates interpolation methods using same data as Example 12. # GMT progs: gmtset, grdview, grdfilter, pscontour, psscale, pstext, surface, triangulate # Unix progs: echo, rm # # Illustrate various means of contouring, using triangulate and surface. # ps=example_16.ps gmtset ANNOT_FONT_SIZE_PRIMARY 9 # pscontour -R0/6.5/-0.2/6.5 -Jx0.45i -P -K -Y5.5i -Ba2f1WSne table_5.11 -Cex16.cpt -I > $ps echo "3.25 7 18 0 4 CB pscontour (triangulate)" | pstext -R -J -O -K -N >> $ps # surface table_5.11 -R -I0.2 -Graws0.nc grdview raws0.nc -R -J -Ba2f1WSne -Cex16.cpt -Qs -O -K -X3.5i >> $ps echo "3.25 7 18 0 4 CB surface (tension = 0)" | pstext -R -J -O -K -N >> $ps # surface table_5.11 -R -I0.2 -Graws5.nc -T0.5 grdview raws5.nc -R -J -Ba2f1WSne -Cex16.cpt -Qs -O -K -Y-3.75i -X-3.5i >> $ps echo "3.25 7 18 0 4 CB surface (tension = 0.5)" | pstext -R -J -O -K -N >> $ps # triangulate table_5.11 -Grawt.nc -R -I0.2 > /dev/null grdfilter rawt.nc -Gfiltered.nc -D0 -Fc1 grdview filtered.nc -R -J -Ba2f1WSne -Cex16.cpt -Qs -O -K -X3.5i >> $ps echo "3.25 7 18 0 4 CB triangulate @~\256@~ grdfilter" | pstext -R -J -O -K -N >> $ps echo "3.2125 7.5 32 0 4 CB Gridding of Data" | pstext -R0/10/0/10 -Jx1i -O -K -N -X-3.5i >> $ps psscale -D3.25i/0.35i/5i/0.25ih -Cex16.cpt -O -U"Example 16 in Cookbook" -Y-0.75i >> $ps # rm -f *.nc .gmt* </PRE> <BR CLEAR="ALL"> <HR> <DIV ALIGN="CENTER"><A NAME="fig:GMT_example_16"></A><A NAME="25849"></A> <TABLE> <CAPTION ALIGN="BOTTOM"><STRONG>Figure 7.16:</STRONG> More ways to grid data.</CAPTION> <TR><TD> <DIV ALIGN="CENTER"><IMG WIDTH="464" HEIGHT="600" ALIGN="BOTTOM" BORDER="0" SRC="img178.png" ALT="\includegraphics[scale=0.6]{scripts/example_16}"></DIV></TD></TR> </TABLE> </DIV> <P> <A NAME="25033"></A> <P> <HR> <!--Navigation Panel--> <A NAME="tex2html4676" HREF="node140.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html4670" HREF="node123.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html4664" HREF="node138.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html4672" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html4674" HREF="node258.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html4677" HREF="node140.html">7.17 Images clipped by</A> <B> Up:</B> <A NAME="tex2html4671" HREF="node123.html">7. Creating GMT Graphics</A> <B> Previous:</B> <A NAME="tex2html4665" HREF="node138.html">7.15 Gridding, contouring, and</A> <B> <A NAME="tex2html4673" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html4675" HREF="node258.html">Index</A></B> <!--End of Navigation Panel--> <ADDRESS> Paul Wessel 2011-02-27 </ADDRESS> </BODY> </HTML>