Shape of resulting merged image is not what I expect
I'm not sure if this is a bug or a subtle unexpected behaviour of the function rasterio.merge.merge.
I'm creating a mosaic with several images for the whole globe. The resolution is such that the image should be 16000x8001 (width x height). The calculation of the resolution is done through these variables:
pixels = 16000
res = 360 / pixels
xmin = -180 - res / 2
xmax = 180 - res / 2
ymin = -90 - res / 2
ymax = 90 + res / 2
Which result in xmin, xmax, ymin, ymax = (-180.01125, 179.98875, -90.01125, 90.01125). OK, the problem is that when I use merge as:
mosaic, out_trans = merge(files, bounds=(xmin, ymin, xmax, ymax), res=res, method='max')
The shape os mosaic is NOT (4, 16000, 8001), but (4, 16000, 8002) (note the extra row).
I think the problem comes from a rounding issue. In my python terminal (ymax-ymin)/res = 8001.000000000001 (whereas (xmax-xmin)/res = 16000.0). This rounding error of 1E-12 seems to be forcing the number of rows to be 8002 instead of 8001. This might seem like a tiny approximation error, but the problem is that controlling the shape of the image is very important for further calculations downstream of the algorithm.
Is this what it is supposed to happen? Is there a way to "force" merge to produce an image of the expected shape 16000x8001?