There a number of ways. A common way is to estimate the background noise at each pixel after defect, dark and flat processing. A (relatively) simple way is to tile the image with a number of sub-images, (say 64×64 pixels by way of example) and compute the pixel histogram of each tile. Assuming that the majority of the pixels are sky and a minority are stars, discard the top 10% or so (which are presumably the stars) and fit a Gaussian to what remains (presumably the background). That Gaussian determines the sigma of the background at that point. Then interpolate (by whatever means, by a biquadratic fit, perhaps, or with cubic splines) to estimate the sigma at each pixel. The weight map is then 1/(sigma^2).
(Typo alert: undersampled to be precise…)