The convolution of a regular grid of Dirac delta functions with a kernel is pretty standard:
import numpy as np
deltas = np.zeros((2048, 2048))
deltas[8::16,8::16] = 1
# Construct a Gaussian kernel
x, y = np.meshgrid(np.linspace(-2, 2, 15), np.linspace(-2, 2, 15))
gauss = np.exp(-(x*x + y*y)/2)
from scipy.signal import convolve2d
convolved_image = convolve2d(deltas, gauss)
Then you get all your Gaussians on a regular grid. An FFT convolution would be a lot faster and is as easy to implement, but that is not my issue.
Now, in order to generate input data for a statistical test, the Gaussians should not be centered exactly at the middle of a pixel, but have a random position anywhere on a pixel. So the chance of its peak being positioned in the lower left corner of a pixel should be equal to its peak being positioned at the center of pixel.
Besides these random positional fluctuations at the pixel level, I would still like to produce a regular grid of Gaussian, so from a distance it would still look like a perfectly regular grid.
How would you code this in Python?