I love Tom Forth’s Population around a point website and have spent quite a bit of time there. I have often tried to find the most populated circle in certain countries but, obviously, it’s a crude way to go about it. That got me thinking, could I use convolution and NumPy to find the 20km r circle with the highest population on earth.

Convolution slides a window over the raster and sums up what’s underneath it. Doing that pixel-by-pixel for a disc shape would be quite slow, since it would be re-summing ~1,257 pixels at every single location on Earth. The workaround is to build the disc out of horizontal strips (each row of the circle has a width you can work out from basic circle geometry, and you sum each strip using a running cumulative sum instead of re-adding pixels every time). Stack the strips back together and you’ve got the exact disc sum, just much faster.
I used the 2025 1km resolution Global Human Settlement Layer (GHSL) for the calculation and even on my M1 Mac, it only took about 2 minutes to run for the entire planet.
The point that’s the centre of the r = 20km circle is here.
One very important caveat is that there are limitations with how the dataset was created. The GHSL is not a direct headcount. It takes population totals and distributes them onto a (in this case) 1km population grid based on built-up areas. It’s essentially a (hopefully reasonably) accurate estimate.