My script loops over a number of geotiffs. Some are fully within the specified region, some partially, some are outside. Usually, grdimage and grdcont handle that correctly, but one tile with partial coverage (3504250.tif, attached) crashes the script with a “segmentation fault”. Maybe there’s something wrong with my pygmt installation. Or maybe it’s the grdcont-code. Because the script will not crash if I extend the specified region by 1 m [504999,508000,5250000,5252000). It’s probably a 1-pixel/fence-post problem.
#!/opt/miniconda3/envs/ext/bin/python
import pygmt
import sys
import os
os.environ['PROJ_LIB'] = '/opt/miniconda3/envs/ext/share/proj'
os.environ['GTIFF_SRS_SOURCE'] = 'EPSG'
fname = (sys.argv[0].replace('.py','.pdf'))
region = [505000,508000,5250000,5252000]
fig = pygmt.Figure()
pygmt.makecpt(cmap='dem1',series='766/946')
for fdem in os.listdir('.'):
if (fdem!="3504250.tif"): continue
print(fdem)
print(pygmt.grdinfo(fdem))
fig.grdimage(fdem,projection='x1:10000',region=region,
frame=['SWne','xa5000g1000+lEasting [m]','ya5000g1000+lNorthing [m]'])
fig.grdcontour(fdem,levels=[900],annotation='100',pen='black')
fig.show()
Apparently 3504250.tif is outside the specified region. grdimage produces an empty plot with a color bar, but see the corrections below (the plot and plotting command not shown).
grdcontour crashes with the specified region (plots normally with the region defined by the grid):
gmt grdcontour -Jx1:10000 -R505000/508000/5250000/5252000 3504250.tif -B -png test-grdcontour
ERROR: Caught signal number 11 (Segmentation fault) at
/home/mkononets/miniforge3/envs/gmt/bin/../lib/libgmt.so.6(+0x10a80f)[0x7fb62a2cc80f]
[0x55c17dff1bd0]
Stack backtrace:
/home/mkononets/miniforge3/envs/gmt/bin/../lib/libgmt.so.6(gmt_sig_handler_unix+0xed)[0x7fb62a32a51d]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7fb629fb4520]
/home/mkononets/miniforge3/envs/gmt/bin/../lib/libgmt.so.6(+0x10a80f)[0x7fb62a2cc80f]
/home/mkononets/miniforge3/envs/gmt/bin/../lib/libgmt.so.6(gmt_contours+0x216)[0x7fb62a2e18d6]
/home/mkononets/miniforge3/envs/gmt/bin/../lib/libgmt.so.6(GMT_grdcontour+0x26bc)[0x7fb62a4a8cfc]
/home/mkononets/miniforge3/envs/gmt/bin/../lib/libgmt.so.6(GMT_Call_Module+0x615)[0x7fb62a21c2b5]
gmt(+0x25c2)[0x55bd6fa565c2]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7fb629f9bd90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7fb629f9be40]
gmt(+0x3393)[0x55bd6fa57393]
Correction, it was a semi-valid color bar stretching from zero to approx 905, while gmt grdinfo 3504250.tif -R505000/508000/5250000/5252000 gives v_min: 717.440002441 v_max: 906.679992676 name: z
Another correction, the grid is not completely outside the region, one data column is included, more from the above mentioned gmt grdinfo:
3504250.tif: x_min: 504999.5 x_max: 505000.5 x_inc: 1 name: x n_columns: 1
3504250.tif: y_min: 5249999.5 y_max: 5251000.5 y_inc: 1 name: y n_rows: 1001
3504250.tif: v_min: 717.440002441 v_max: 906.679992676 name: z
with -R504999/... it’s two data columns and grdcontour is not crashing anymore: