### C Explaining optimal photometry

Optimal extraction offers serveral advantages over the normal aperture method of photometry.
Formally optimal extraction is equivalent to profile fitting, however it offers more robust error
estimation and a freedom of the bias introduced by mis-estimating the point spread function (PSF). It
has been found to offer a gain of around 10 per cent in signal-to-noise over normal aperture
photometry.

A general formula for summing flux ($F$)
within an aperture is

$$F=\sum _{i,j}{W}_{i,j}\left({D}_{i,j}-{S}_{i,j}\right),$$

where sum is over all the pixels $i$,$j$
within the aperture, where the total count in a pixel is
${D}_{i,j}$, the estimated
sky level is ${S}_{i,j}$
and ${W}_{I,j}$ is
the weight given to each pixel. For normal aperture photometry this is one within the aperture, and
zero outside it.

Finding the optimal value for ${W}_{I,j}$ for each
$i$,$j$
within the aperture is a two step process. Firstly a model profile is fitted to a nearby star (a 2-D
Gaussian has proved adequate for this purpose), the resulting estimated stellar proifle
${P}_{i,j}^{E}$ is
normalised to one.

As shown by Horne (PASP, 1986, 98, 609) once the estimated profile is known the best signal-to-noise
is obtained for

$${W}_{i,j}=\frac{{P}_{i,j}^{E}/{V}_{i,j}}{\sum _{i,j}{\left({P}_{i,j}^{E}\right)}^{2}/{V}_{i,j}},$$

where ${V}_{i,j}$
is the variance for each pixel. Substituting this into our first equation we obtain the basic formula
governing optimal extraction. However at this stage we make a further assumption, that the variance
for each pixel is the same. For very faint stars this is clearly the case (since the counts in each pixel is
dominated by the sky count), for brighter stars though this means that the extraction will be
non-optimal. Hence we have that

$$F=\frac{\sum _{i,j}{P}_{i,j}^{E}\left({D}_{i,j}-{S}_{i,j}\right)}{\sum _{i,j}{\left({P}_{i,j}^{E}\right)}^{2}}.$$

From this we note that if the PSF is wrong there will be no systematic bias in the results, provided
one is interested in the relative brightness of one star with respect to another in the same
frame.

A full treatment of optimal extarction can be found in Tim Naylor’s MNRAS paper “An optimal
extraction algorithm for imaging photometry” (MNRAS, 1998, 296, 339) to which the reader is directed
for further information.