I'm attempting to down-sample a raster (resampling to a coarser/ larger pixel size) with continuous, floating-point values. I generally use bilinear resampling for the up-sampling case (resampling to a finer resolution), so I thought I would use it here, too. I'm finding that whether I use gdal.ReprojectImage() or gdal.Warp (which is a wrapper for gdalwarp), I get large NoData chunks in the output image wherever there was at least one NoData value in the input image. I would have assumed that as long as there was some data in an output pixel (which subsumes multiple smaller pixels), there would be a valid output value.

The effect is quite striking visually. The original raster image (9-km resolution on an equal-area grid) looks like this: Original image

The resampled raster image (1-degree equirectangular projection) looks like this: Resampled image

Sample Python code used to resample the original equal-area raster is below; there is an equivalent with gdal.ReprojectImage() but it is much more verbose.

import gdal
from gdal import gdalconst

ds = gdal.Warp(
    'temp.file', original_raster,
    format = 'MEM', xRes = 1, yRes = 1,
    dstSRS = "EPSG:4326",
    outputBounds = (-179.5, -90.5, 180.5, 89.5),
    resampleAlg = gdalconst.GRA_Bilinear, 
    outputType = gdalconst.GDT_Float32)

In contrast, a nearest-neighbor resampling (changing resampleAlg argument) produces a continuous 1-degree grid, with no "holes" in the output raster. Nearest neighbor is much simpler, of course, but is there an option to calculate weights for bilinear resampling in a way that NoData pixels don't contaminate output pixels in this way?

  • Please provide test data. – user30184 Mar 1 '20 at 16:13
  • What is you GDAL version (gdalinfo --version)? Test data would still be appreciated. – user30184 Aug 5 '20 at 9:07
  • I'm using GDAL 3.0.4. HDF5 data granules are publicly available; a representative granule would be this one. The "SOC/soc_mean" field. – Arthur Aug 5 '20 at 16:58
  • I agree with user Mike T that bilinear interpolation is not suitable for large downscaling. Read also stackoverflow.com/questions/49879466/…. The result would probably look better if you downscale the image in several small steps. That would also reduce the possibility that all the four neighboring pixels used for interpolation happens to be nodata. Try other interpolation methods and edit your question if you have problems with them as well. Overviews created with gdaladdo -r gauss -ro soc_mean.tifdo not seem to have holes. – user30184 Aug 6 '20 at 7:12
  • Averaging produces the same issue in upscaling--NoData values contaminate aggregate values. Averaging is a perfectly suitable use case for these data (which use the nested EASE2-Grid 2.0 CRS) and other datasets. – Arthur Sep 23 '20 at 16:31

When re-gridding to a coarser raster, always use an aggregation method, such as 'average' for continuous variables or 'mode' for categorical variables. Other appropriate aggregate methods for continuous variables include min, Q1, median, Q3 and max.

Interpolation algorithms including 'bilinear' (among others) should only be used when re-gridding to a finer resolution. Expect weird/bad results when re-gridding to a coarser raster, since that's not what these algorithms are designed for.

  • I'm getting the same holes when up-scaling with GRA_Average (averaging). NoData values seem to contaminate aggregate values. Averaging is a perfectly suitable use case for these data (which use the nested EASE2-Grid 2.0 CRS) and other datasets. – Arthur Sep 23 '20 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.