(14) Gridding of data and trend surfaces
This example shows how one goes from randomly spaced data points to an evenly sampled surface. We arrange for four panels using the subplot command. First we plot the distribution and values of our raw data set (same as in Example (12) Optimal triangulation of data). We choose an equidistant grid and run blockmean which preprocesses the data to avoid aliasing. The dashed lines indicate the logical blocks used by blockmean; all points inside a given bin will be averaged. The logical blocks are drawn from a temporary file we make on the fly within the shell script. The processed data is then gridded with the surface program and contoured every 25 units. A most important point here is that blockmean, blockmedian, or blockmode should always be run prior to running surface, and both of these steps must use the same grid interval. We use grdtrend to fit a bicubic trend surface to the gridded data, contour it as well, and sample both grid files along a diagonal transect using grdtrack. The bottom panel compares the gridded (solid line) and bicubic trend (dashed line) along the transect using plot
#!/usr/bin/env bash
# GMT EXAMPLE 14
#
# Purpose: Showing simple gridding, contouring, and resampling along tracks
# GMT modules: blockmean, grdcontour, grdtrack, grdtrend, project, text,
# GMT modules: set, plot, surface, subplot
# Unix progs: rm
#
gmt begin ex14
gmt set MAP_GRID_PEN_PRIMARY thinnest,-
# calculate mean data and grids
gmt blockmean @Table_5_11.txt -R0/7/0/7 -I1 > mean.xyz
gmt surface mean.xyz -Gdata.nc
gmt grdtrend data.nc -N10 -Ttrend.nc
gmt project -C0/0 -E7/7 -G0.1 -N > track
# Sample along diagonal
gmt grdtrack track -Gdata.nc -o2,3 > data.d
gmt grdtrack track -Gtrend.nc -o2,3 > trend.d
gmt plot -Ra -JX15c/3.5c data.d -Wthick -Bx1 -By50 -BWSne
gmt plot trend.d -Wthinner,-
gmt subplot begin 2x2 -M0.1c -Ff15c -BWSne -Yh+1c -R0/7/0/7
# First draw network and label the nodes
gmt plot @Table_5_11.txt -Sc0.12c -Gblack -c0,0
gmt text @Table_5_11.txt -D3p/0 -F+f6p+jLM -N
# Then draw gmt blockmean cells and label data values using one decimal
gmt plot mean.xyz -Ss0.12c -Gblack -c0,1
gmt text -D11p/0 -F+f6p+jLM+z%.1f -Gwhite -W -C1p -N mean.xyz
# Then gmt surface and contour the data
gmt grdcontour data.nc -C25 -A50 -Gd8c -S4 -c1,0
gmt plot mean.xyz -Ss0.12c -Gblack
# Fit bicubic trend to data and compare to gridded gmt surface
gmt grdcontour trend.nc -C25 -A50 -Glct/cb -S4 -c1,1
gmt plot track -Wthick,.
gmt subplot end
gmt end show
rm -f mean.xyz track trend.nc data.nc data.d trend.d