Surface to interpolate and create contour map

Hello everyone
I am using surface command to interpolate my data and get a smoother contour distribution, but for some reason it doesn’t work well for part of my data. Also, some of the contours are outside of a specific area (red rectangle) and it shouldn’t be like that.

I would appreciate your help :slight_smile:

I attach the input file and the plot. This is the script to create the grid file from xyz and to plot the contours.

ps=slip_dist-interpolate.ps
gmt blockmean File4Interpola.txt -R-76.25/-74.25/8.55/10.8 -I0.01m/0.01m > File4Interpola-bm.xyz
gmt surface File4Interpola-bm.xyz -GFile4Interpola.grd -T0 -I0.01m/0.01m -R -Ll0 -Lu1.0 -Am
gmt pscoast -R-77.5/-73.5/7.5/12 -JM6i -Ba1 -BWSne -N1 -N3 -Df -W -Xc -Yc -Sghostwhite -K > $ps
gmt grdcontour File4Interpola.grd -R -J -C0.1 -S0.01 -A0.2+f10p -W1p,black -O -K >> $ps
gmt psxy -R -JM -SJ -W1.0,red -O << END >> $ps
-75.20112505742531993968 9.57695945571200752958 20.0 200 175
END
gmt psconvert $ps -A -Tt

File4Interpola.txt (43.1 KB)
slip_dist-interpolate.tif (208.7 KB)

Sometimes it helps to “see” the input data, and think about what is happening to it.

Attached is a map of your input File4Interpola.txt file. Your input data appears to be a regular grid, but tilted with respect to lat/lon lines. There are 800 points in your original file.

A very small -I value (0.01m) was chosen for Blockmean which essentially outputs the same values as found in the input file. File4Interpola-bm.xyz is essentially the same as File4Interpola.txt, but with fewer significant digits (for lats/lons) and fewer points (794). Did you mean to do that?

Then you ran surface using -I0.01m/0.01m. This will create a lat/lon aligned grid of size 12001x13501. Probably too high resolution to be meaningful.

Because the File4Interpola.grd file is now aligned with lat/lon lines, the contour plot will extend contours beyond the range of the original data. To trim it to the original bounds, you’ll need to use grdcut with the -F option.

Hope this provides some guidance!

input_data.pdf (81.1 KB)