Grdblend with blockmean


I would like to blend several grids together and have the output be downsampled with the blockmean algorithm instead of grdsample’s interpolation.

Is there a way to do this in one step? The doc for grdblend says it uses grdsample, but I specifically want to block-average the input pixels into the output pixels.


No. grdblend does not do averaging. You will either have to dumb down the grids before blending or do it to the blended grid afterwards. If you want a square boxcar filter (blockmean) then either you have to dumb those grids to xyz and run via blockmean -G or you can run grdfilter with that type of filter on the final grid.

Thanks for the advice. I tried your 2nd option (grdfilter), but the resulting output grid had a checkerboard pattern of noise imprinted on it (no NaNs, though) that looked like an aliasing effect. That suggests to me that there was some kind of registration/alignment problem with the grid dimensions or the pixel size, but I do not understand how that could be. I have verified that the input grid is correct.

So, maybe the grdfilter command isn’t doing what I expected. I just want to blockmean the input grid pixel scale by a factor of 2x and shrink the boundaries.

Here is the grdfilter command I used:
gmt grdfilter ldem_60s_final_adj_20mpp_surf.grd -Gldem_80s_final_adj_40mpp_surf.grd -D0 -Fb0.04 -I0.04 -R-304/304/-304/304

And the info for the input and output grids:

Input grid:

ldem_60s_final_adj_20mpp_surf.grd: Title:
ldem_60s_final_adj_20mpp_surf.grd: Command: gmt grdblend blendTiles_tmp20_60.txt_20mpp_surf.list -I0.02= -R-931.2/931.2/-931.2/931.2 -G/dev/shm/ldem_60s_final_adj_20mpp_surf.grd -r
ldem_60s_final_adj_20mpp_surf.grd: Remark:
ldem_60s_final_adj_20mpp_surf.grd: Pixel node registration used [Cartesian grid]
ldem_60s_final_adj_20mpp_surf.grd: Grid file format: nf = GMT netCDF format (32-bit float), COARDS, CF-1.5
ldem_60s_final_adj_20mpp_surf.grd: x_min: -931.2 x_max: 931.2 x_inc: 0.02 name: x n_columns: 93120
ldem_60s_final_adj_20mpp_surf.grd: y_min: -931.2 y_max: 931.2 y_inc: 0.02 name: y n_rows: 93120
ldem_60s_final_adj_20mpp_surf.grd: z_min: -9.12978649139 z_max: 7.02721118927 name: z
ldem_60s_final_adj_20mpp_surf.grd: scale_factor: 1 add_offset: 0
ldem_60s_final_adj_20mpp_surf.grd: format: netCDF-4 chunk_size: 129,129 shuffle: on deflation_level: 3

Output grid:

ldem_80s_final_adj_40mpp_surf.grd: Title:
ldem_80s_final_adj_40mpp_surf.grd: Command: gmt grdfilter ldem_60s_final_adj_20mpp_surf.grd -Gldem_80s_final_adj_40mpp_surf.grd -D0 -Fb0.04 -I0.04 -R-304/304/-304/304
ldem_80s_final_adj_40mpp_surf.grd: Remark:
ldem_80s_final_adj_40mpp_surf.grd: Pixel node registration used [Cartesian grid]
ldem_80s_final_adj_40mpp_surf.grd: Grid file format: nf = GMT netCDF format (32-bit float), COARDS, CF-1.5
ldem_80s_final_adj_40mpp_surf.grd: x_min: -304 x_max: 304 x_inc: 0.04 name: x n_columns: 15200
ldem_80s_final_adj_40mpp_surf.grd: y_min: -304 y_max: 304 y_inc: 0.04 name: y n_rows: 15200
ldem_80s_final_adj_40mpp_surf.grd: z_min: -7.29654073715 z_max: 7.02672386169 name: z
ldem_80s_final_adj_40mpp_surf.grd: scale_factor: 1 add_offset: 0
ldem_80s_final_adj_40mpp_surf.grd: format: netCDF-4 chunk_size: 129,129 shuffle: on deflation_level: 3

Thanks for your help with this.


Perhaps it wont work with grdfilter, but I was thinking -Dp and -Fb3/3 for a rectangular averaging filter.

If not, then the safest would be to do your blending, then dump grd2xyz and pipe to blockmean and do the blocking there (and use -G to write to a grid).