I am working with a bunch of images downloaded from elevation.alaska.gov. After downloading them, I use gdal.Warp() to convert them to EPSG:4326 so they can work with grdimage (if I don’t, I get a Your grid y's or latitudes appear to be outside the map region and will be skipped
error). I then loop through the files, calling grdimage() on each one, to add them to the figure.
Unfortunately, with some of the files produced this way, calling grdimage causes a segfault with the following error message being printed:
grdimage (gmt_gdalread): Could not reallocate memory [137438953472.00 Gb, 18446744073709451063 items of 8 bytes]
I have made one such image that produces this issue available here: https://univalaska-my.sharepoint.com/:i:/g/personal/ijbrewster_alaska_edu/EUk4DMuOx9JKor3FIAohiLMBfcwPvz3h6WZ2lHGHa-dmXw?e=1UMyyz
and a minimal code example that reproduces the issue:
import pygmt
test_file = '/path/to/23.tiff'
bounds = [
-183,
-176.37,
50.155,
53.228
]
fig = pygmt.Figure()
fig.basemap(projection="M8i", region=bounds, frame=('WeSn', 'afg'))
fig.grdimage(test_file, dpi = 100, monochrome = True)
I am so far unable to find anything special/different about this file relative to all the ones that work. Perhaps someone here can shed some light on the issue?
I’m also happy to entertain suggestions for process improvements - for example, is there a way I can use the original .tif files in grdimage
directly, rather than having to run them through gdal.Warp()
? If so, maybe that would solve the issue.
I have tried feeding all the files to gdal.Warp()
to produce a single large file, and this does appear to work, however a) it is extremely slow, b) it uses a LOT of memory, and c) it produces a 22GB tiff file from only around 4GB of source files for the bounds listed in the example code. I’m thinking because the individual files actually have very little coverage relative to the target area. I’m also thinking the final file size is responsible for the slowness, as it shuffles 22GB to/from the disk. As such, I would prefer to work with the individual files, if possible.