@ConnorStone Part of the answer to your question sits behind a bit of code that @Alex-Broughton pointed us to above. During the production of preliminary_visit_image, IsrTaskLSST computes an initial value for the variance plane of the image. The way it does this, according to the addVariancePlane code, starts by checking whether the exposure units are “electron” (which it looks up in exposure.metadata[“LSST ISR UNITS”]). Assuming this is true (it is for DP1 visit_images), it sets a variable named gain to 1.0. It also consults the exposure metadata to get the readNoise for each amplifier, stored in “LSST ISR READNOISE {amp.getName()}”.
Having set these numbers, it passes them and the exposure to updateVariance in isrFunctions.py. This takes whatever the preexisting variance plane is (which I’m hoping is just all zeros) and adds to it the image flux in each pixel, multiplied by 1/gain. This is just the Poisson term. Then it adds (readNoise/gain)**2 to each pixel. Since we have gain == 1.0, the variance at this stage is just equal to the image plus readNoise**2.
To be clear: if we make a plot of variance vs. flux in each pixel (in a single amplifier region of a maskedImage), at this stage all the points should lie perfectly along a straight line, with a slope of 1.0 and a y-intercept of readNoise**2.
Now, as Alex and @erykoff pointed to above, the flat fielding then modifies both the image and the variance plane in place, hopefully in a consistent manner. This is a scale factor that will generally change the “effective” gain. My understanding is that every pixel is scaled differently by the flat field correction, which causes the variance vs. flux scatterplot to no longer be a perfectly straight line.
If, as @erykoff asserts, the only other main thing that needs to be taken into account is the flat fielding - and if our image processing pipeline allows flat fielding to be an invertible operation - then if we invert the flat fielding correction, I would expect the effective gain to go back to 1.0. If we can only approximately invert it because of other stuff that happens in visit_image processing, I would expect the effective gain to be approximately 1.0. In practice the effective gain far away from this, closer to 0.4, even after inverting the flat field correction. This is a puzzle that I’d still like to figure out.
This may mainly come down to a units issue as @lskelvin noted above. If the change in units from electrons to nJy should be reflected in the getExposureGains, then if these are not being updated correctly, this may not be solvable in our current code.
When @lskelvin is talking about “empirical” gain estimation he’s referring to estimating the effective gain of the final visit_image by making a simple straight-line fit of variance vs. flux in each pixel. I’ll note that some of the variance vs. flux plots display some pronounced nonlinearities in at least some pixels, even after inverting as many steps of visit_image processing as I know how to do, so there’s some level of risk we have to accept with this method.