Merge grids as mosaic in PyGMT


I’m trying to merge multiple, non overlapping (as far as I know) grids. I understand that it can be done with standard GMT with the grdcut and grdpaste functions, or maybe grdcut isn’t needed because they shouldn’t overlap. What would be the optimal way to do this through PyGMT? I tried using xarray functions to little success, my resulting grid is weirdly striped and out of bounds as shown in the pictures.

The multiple grids plotted one over the other

The resulting grid after trying to merge them

Any idea as to why I’m getting this result? Is there a better way to approach this?

Thank you very much!

Hello @Feva67,

Helping you only based on the posted images appears difficult.
Can you please provide the code you are using for combining and plotting the grids, and also provide the data / grids you are using?

I would use the GDAL “” program if you have GDAL installed and the files are in a GDAL compatible format.

Thanks! I’ll check if the format is compatible

You could dump the grid files with grd2xyz, find the new (combined) region with info, and re-format with xyz2grd.

Looks like a job for grdblend.

Did it with grdblend, using @Andreas 's idea to format the files properly:

for dem in dems:

grid=pygmt.grd2xyz(dem, output_type=‘pandas’, outfile=None)

with open(‘list_of_dems.txt’, ‘w’) as f:
for line in dems:

with Session() as lib: