Debian Codegraph @

test/greenspline/gspline_8.sh

raw
1 #!/usr/bin/env bash
2 #
3 # Make and test 2-D Cartesian interpolation using both
4 # data values and gradients. We generate input data from
5 # a Gaussian bump on a plane:
6 gmt grdmath -R-2/2/-2/2 -I1 0 0 CDIST 2 DIV 2 POW NEG EXP X 0.1 MUL ADD = bump.grd
7 # Take DDX to get gradients in x-direction
8 gmt grdmath bump.grd DDX = grads.grd
9 # High res versions of same grids for plotting
10 gmt grdmath -R-2/2/-2/2 -I0.1 0 0 CDIST 2 DIV 2 POW NEG EXP X 0.1 MUL ADD = bump1.grd
11 gmt grdmath bump1.grd DDX = grads1.grd
12 # Raw values of value and slope at all nodes inside frame (excluding the border)
13 gmt grd2xyz -R-1/1/-1/1 bump.grd > bump_raw.txt
14 gmt grd2xyz -R-1/1/-1/1 grads.grd > grads_raw.txt
15 # Select two gradients and 7 values for final input
16 awk '{if ($1 == -1 || $2 != 0) print $0}' bump_raw.txt > bump_z.txt
17 #awk '{if ($2 == 0 && $1 != -1) print $0, 90}' grads_raw.txt > bump_g.txt
18 # But because DDX is approximate I redid this on a finer grid to get better values:
19 cat << EOF > bump_g.txt
20 0 0 0.100000202656 90
21 1 0 -0.288589894772 90
22 EOF
23 # Make the test plot
24 gmt begin gspline_8 ps
25 gmt makecpt -Cjet -T-1.5/1.5 # Keep fixed CPT for all plots
26 gmt subplot begin 3x2 -Fs8c -R-2/2/-2/2 -Scb -Srl
27 # First show only data (left) and splined result (right) from just using data values
28 gmt grdimage bump.grd -c
29 gmt plot bump_raw.txt -Sc6p -Gblack
30 gmt greenspline bump_raw.txt -R-2/2/-2/2 -I1 -Sc -Gbump_raw.grd -Z1
31 gmt grdimage bump_raw.grd -c
32 gmt plot bump_raw.txt -Sc6p -Gblack
33 # Now grid both the data (left) and the slope samples and display the splined result
34 gmt grdimage bump.grd -c
35 gmt plot bump_z.txt -Sc6p -Gblack
36 gmt plot bump_g.txt -Sc6p -W0.5p
37 gmt greenspline bump_z.txt -Abump_g.txt+f2 -R-2/2/-2/2 -I1 -Sc -Ggrads_out.grd -Z1
38 gmt greenspline bump_z.txt -Abump_g.txt+f2 -R-2/2/-2/2 -I0.05 -Sc -Ggrads_out1.grd -Z1
39 gmt greenspline bump_z.txt -Abump_g.txt+f2 -R-2/2/-2/2 -I0.05 -Sc -Q90 -Ggrad_out1.grd -Z1
40 gmt grdimage grads_out.grd -Bxaf -Byafg10 -c
41 gmt plot bump_z.txt -Sc6p -Gblack
42 gmt plot bump_g.txt -Sc6p -W0.5p
43 # Sample the two grids along y = 0 where we have the gradient constraints for x = 0,1
44 gmt grdtrack -Gbump1.grd -ELM/RM -o0,2 | gmt plot -R-2/2/-2/2 -W0.5p -Bafg1 -c -l"Without input slope constraints"+jBL
45 gmt grdtrack -Ggrads_out1.grd -ELM/RM -o0,2 | gmt plot -W1.5p -l"With input slope constraints"
46 awk '{if ($2 == 0) print $1, $3}' bump_z.txt | gmt plot -Sc6p -Gblack -l"Data constraint"
47 gmt grdtrack -Gbump1.grd -nn bump_g.txt -o0,4,2 | gmt plot -Sc6p -W0.25p -l"Slope constraint"
48 gmt grdtrack -Gbump1.grd -nn bump_g.txt -o0,4,2 | awk '{print $1, $2, 1, $3}' | gmt plot -Sv9p+e+z3 -W0.75p -Gred
49 echo "SURFACE ALONG y = 0" | gmt text -F+cTL+f10p -Dj5p -Gwhite -W0.25p
50 gmt grdtrack -Ggrads1.grd -ELM/RM -o0,2 | gmt plot -R-2/2/-2/2 -W0.5p -Bafg1 -c -l"Without input slopes"+jBL
51 gmt grdtrack -Ggrad_out1.grd -ELM/RM -o0,2 | gmt plot -W1p -l"With input slopes"
52 gmt plot bump_g.txt -Sc6p -W0.5p -i0,2 -l"Slope constraint"
53 echo "GRADIENT ALONG y = 0" | gmt text -F+cTL+f10p -Dj5p -Gwhite -W0.25p
54 gmt subplot end
55 gmt colorbar -DJBC
56 gmt end