(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 -JX6i/1.4i data.d -Wthick -Bx1 -By50 -BWSne
	gmt plot trend.d -Wthinner,-
	gmt subplot begin 2x2 -M0.05i -Ff6i/6i -BWSne -Yh+0.4i
		# First draw network and label the nodes
		gmt plot @Table_5_11.txt -R0/7/0/7 -Sc0.05i -Gblack -c0,0
		gmt text @Table_5_11.txt -D0.1c/0 -F+f6p+jLM -N
		# Then draw gmt blockmean cells and label data values using one decimal
		gmt plot mean.xyz -Ss0.05i -Gblack -c0,1
		gmt text -D0.15c/0 -F+f6p+jLM+z%.1f -Gwhite -W -C0.01i -N mean.xyz
		# Then gmt surface and contour the data
		gmt grdcontour data.nc -C25 -A50 -Gd3i -S4 -c1,0
		gmt plot mean.xyz -Ss0.05i -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
../_images/ex14.png

Gridding of data and trend surfaces.