Filter grid and create new grid with 3 bands

I would like to filter a grid and create new 3 grids (grdfilter) which I then merge to one single grid with three bands (RGB). Is this possible with gmt? Or gdal?

Reading multiband grids seems to be relatively easy with gmt, but what about writing?

And, does anyone have some good reading about spatial filtering of grids? Tips are welcome!

Maybe grdmix??

In Julia if you prepare the images, anyway you want, from grids then the RemoteS/truecolor function let you do things like in https://www.generic-mapping-tools.org/RemoteS.jl/dev/gallery/L8cube_img/remotes_L8_cube_img/

Thanks both of you for input!

Esteban82:

grdmix [ERROR]: Unsupported image format. Supported formats are:
BMP,GIF,JPG,PNG & TIF

Making tif with gmt (=gd:GTiff) gives:

grdmix [ERROR]: Using this data type (Float32) is not implemented

I’ll test more when I have time.

Joaquim: Thanks for the tip. Unfortunately I’ve not had the time yet to become familar with Julia.

For simple things it costs about ~1/2 h experimenting.

If you filter your three grids then you can combine three grids back to an rub image with grdmix. You just need to ensure things are normalized first. However, it won’t write 3 grids float32 though. That could be a feature request since we know how to do this now (grdcut works, for instance, but won’t help you here).

Paul, you’re just begging for it.

NB! I know I’m not doing what I’m supposed to in the stuff below. Just becoming… acquainted with grdmix.

gmt grdcut @earth_relief_30m  -RNO -Gno[1,2,3]

segfault (note missing file extension (…) in -G:

$ gmt grdmix no1 no2 no3 -C -Gtest
grdmix [WARNING]: Component grid values in no1 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: Component grid values in no2 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: Component grid values in no3 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: The geographical metadata for you image will be lost unless you use TIF
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/x86_64-linux-gnu/libc.so.6(+0x15c501)[0x7f7b01087501]
[0x0]
Stack backtrace:
/usr/local/lib/libgmt.so.6(sig_handler_unix+0xc0)[0x7f7b01277c60]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f7b01104140]
/lib/x86_64-linux-gnu/libc.so.6(+0x15c501)[0x7f7b01087501]
/usr/local/lib/libgmt.so.6(gmt_export_image+0xec)[0x7f7b011c1b4c]
/usr/local/lib/libgmt.so.6(GMT_Write_Data+0x1cec)[0x7f7b011a01dc]
/usr/local/lib/libgmt.so.6(GMT_grdmix+0x1840)[0x7f7b01432f60]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f7b0118ab0e]
gmt(main+0x546)[0x55dc814ba716]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f7b00f51d0a]
gmt(_start+0x2a)[0x55dc814bb4aa]

Add .nc to filename in -G:

$ gmt grdmix no1 no2 no3 -C -Gtest.nc
grdmix [WARNING]: Component grid values in no1 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: Component grid values in no2 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: Component grid values in no3 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: The geographical metadata for you image will be lost unless you use TIF
grdmix [ERROR]: Unsupported image format. Supported formats are:
BMP,GIF,JPG,PNG & TIF
grdmix [ERROR]: Alternatively, append :<driver> for a valid GDAL driver
grdmix (gmtapi_export_image): Unknown Error [test.nc]
[Session gmt (0)]: Error returned from GMT API: GMT_IMAGE_WRITE_ERROR (23)
[Session gmt (0)]: Error returned from GMT API: GMT_IMAGE_WRITE_ERROR (23)
[Session gmt (0)]: Error returned from GMT API: GMT_IMAGE_WRITE_ERROR (23)

Why doesnt grdmix support netcdf?

$ gmt grdmix no1 no2 no3 -C -Gtest.nc -Ni
grdmix [WARNING]: Component grid values in no1 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: Component grid values in no2 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: Component grid values in no3 exceed 0-1 range, probably need to specify -Ni
grdmix [WARNING]: The geographical metadata for you image will be lost unless you use TIF
grdmix [ERROR]: Unsupported image format. Supported formats are:
BMP,GIF,JPG,PNG & TIF
grdmix [ERROR]: Alternatively, append :<driver> for a valid GDAL driver
grdmix (gmtapi_export_image): Unknown Error [test.nc]
[Session gmt (0)]: Error returned from GMT API: GMT_IMAGE_WRITE_ERROR (23)
[Session gmt (0)]: Error returned from GMT API: GMT_IMAGE_WRITE_ERROR (23)
[Session gmt (0)]: Error returned from GMT API: GMT_IMAGE_WRITE_ERROR (23)