11institutetext: 1 School of Physics, O’Brien Centre for Science North,
University College Dublin, Belfield, Dublin 4, Ireland

# The AUTOmated Photometry Of Transients pipeline

AutoPhOT

S. J. Brennan1 and M. Fraser1

(Received XXX ; accepted XXX)

We present the AUTOmated Photometry Of Transients (AutoPhOT) package, a novel
automated pipeline that is designed for rapid, publication-quality photometry
of transients. AutoPhOT is built from the ground up using Python 3 - with no
dependencies on legacy software. Capabilities of AutoPhOT include aperture and
PSF-fitting photometry, template subtraction, and calculation of limiting
magnitudes through artificial source injection. AutoPhOT is also capable of
calibrating photometry against either survey catalogs (e.g. SDSS, PanSTARRS),
or using a custom set of local photometric standards. We demonstrate the
ability of AutoPhOT to reproduce lightcurves found in the published
literature. AutoPhOT’s ability to recover source fluxes is consistent with
commonly used software e.g. DAOPHOT, using both aperture and PSF photometry.
We also demonstrate that AutoPhOT can reproduce published lightcurves for a
selection of transients with minimal human intervention.

###### Key Words.:

Methods: data analysis, Techniques: image processing, Techniques: photometric

##  1 Introduction

For over three decades, the most commonly used packages for photometry are
part of the Image Reduction and Analysis Facility (IRAF)111IRAF is distributed
by the National Optical Astronomy Observatory, which is operated by the
Association of Universities for Research in Astronomy (AURA) under cooperative
agreement with the National Science Foundation (Tody, 1986, 1993). Within
IRAF,  DAOPHOT (Stetson, 1987) is a suite of packages designed to perform
photometry in crowded fields (i.e when sources are closely spaced together).

In 2013, the National Optical Astronomy Observatories (NOAO) suspended further
development of IRAF, and since then a community of astronomers has worked on
maintaining the packages and adapting the current version (V2.16 / March 22,
2012) to work on modern hardware. However, a large portion of IRAF code cannot
be compiled as a 64-bit executable, and must be built as a 32-bit program.
Recently, several popular operating systems (e.g. MacOS) have dropped 32-bit
support, which is required for IRAF. With continued development, as well as
the emergence of new programming languages, IRAF has become more and more
difficult to build and maintain on current architectures. Furthermore, PyRAF
(Science Software Branch at STScI, 2012), the main Python 2.7 wrapper for
IRAF, has lost support and, as of January 1 2020, Users have been encourage to
move to the currently supported Python 3 framework.

Besides IRAF/ DAOPHOT there are a number of other photometry packages in use
today. SExtractor (Bertin & Arnouts, 1996) is a source detection and
deblending tool used extensively for photometric measurements and is the basis
for many modern photometric pipelines (e.g. Mommert, 2017; Merlin et al.,
2019). Other stand-alone photometry packages have been developed such as
A-PHOT (Merlin et al., 2019) and PhotometryPipeline (Mommert, 2017), that
mainly perform aperture photometry on ground based images.

Photometry tools have also been developed as part of ASTROPY (Astropy
Collaboration et al., 2013, 2018), which is a community led project to develop
a set of core software tools for astronomy in Python 3.

In this paper we present the AUTOmated PHotometry of Transients Pipeline
(hereafter refereed to as AutoPhOT). AutoPhOT was designed to provide a fast,
precise, and accurate means to measure the magnitude of astronomical point
sources with little human interaction. The software has been built from the
ground up, removing any dependence on the commonly used IRAF or any deprecated
Python packages (for example those that rely on Python 2).

AutoPhOT is designed to address some of the specific needs to astronomers
working of transient phenomena such as supernovae. Observational campaigns for
transients often yield heterogeneous datasets, which include images spanning
several nights to decades, taken in a variety of photometric bands, and using
different telescope and instrument configurations. For precise photometry,
careful extraction of photometric data is required. However, the effect of
different instruments and slightly different filter throughputs can increase
the overall scatter in photometric data. Furthermore, photometry performed by
different astronomers may show discrepancies based on the choice of parameters
used e.g. quality/number of sequence stars used, aperture size, background
subtraction etc.

AutoPhOT uses ASTROPY packages extensively. As ASTROPY is community driven,
widely used, and written in Python 3, AutoPhOT is likely to have support from
these packages for the foreseeable future.

AutoPhOT can accept astronomical images from most ground based telescopes and
cameras, and will adapt to image quality and/or telescope parameters to
provide a homogeneous photometric output. AutoPhOT is available on
Github222https://github.com/Astro-Sean/autophot and available for installation
though Conda 333https://anaconda.org/astro-sean/autophot. AutoPhOT will
receive continued support, and one should refer to the online documentation
for up-to-date information and further implementations
444https://autophot.readthedocs.io/en/latest/.

The purpose of this paper is to briefly outline the AutoPhOT package555Version
1.0.2. We discuss the automated preprocessing within AutoPhOT in Sect. 2 and
how photometric measurements are made in Sect. 3. We provide a brief outline
of the photometric calibration in Sect. 4. We outline the limiting magnitude
package in Sect. 6. Finally, we discuss the performance of AutoPhOT and its
ability to provide science-ready results in Sect. 7.

##  2 Pre-processing

###  2.1 Image reduction

Due to the specific nuances of various CCDs, it is left to the User or
observing facility to correctly reduce the images prior to running AutoPhOT.
These steps should typically include bias, flat-field and bad pixel
corrections. For a general overview on these reduction steps, see Howell
(2006).

###  2.2 Image stacking

AutoPhOT does not perform image stacking. Often multiple exposures will be
taken in the same bandpass during the night, in particular when long exposures
that are susceptible to cosmic rays are used.

It is difficult to produce a universal image stacking procedure, and it is
hence left to the User to stack images if they so wish666For example with
CCDPROC (Craig et al., 2017). AutoPhOT hence treats multiple images taken on
the same night independently. The User is cautioned that if they combine
images, they should update the header keywords for gain and readout noise
where necessary before running AutoPhOT.

###  2.3 Target Identification

AutoPhOT implements the Transient Name Server777https://www.wis-tns.org/ (TNS)
Python API to obtain the most up-to-date coordinates of a particular
transient. These coordinates are transformed from right ascension (RA) and
declination (Dec) into X and Y pixel coordinates using the image World
Coordinate System (WCS), see Sec. 2.5.

If a transient is not known to the TNS then the RA and DEC can be manually
specifed by the User.

###  2.4 Parsing image and instrument metadata

Flexible Image Transport System (FITS) files are commonly used to store
astronomical image. These files typically contain a 2D image as well as the
image metadata stored as keyword-value pairs in a human-readable ASCII header.
While FITS header keywords contain critical information about the observation
itself, such as exposure time, filter, telescope, these keywords are often
inconsistent between different observatories.

When AutoPhOT is run on an image from a new telescope, the software asks the
User to clarify certain keywords using the check_teledata package. For
example, this may involve clarifying whether “SDSS-U” refers to Sloan $u$ or
Johnson-Cousins $U$. This is the only step in running autophot which requires
human intervention, but is necessary due to the ambiguous filter naming
conventions used by some telescopes.

After the AutoPhOT telescope check function has run, the results are saved as
a human-readable Yaml file (see example in Listing 1) allowing for easy
additions, alterations or corrections. When AutoPhOT is subsequently run on
images from the same telescope and instrument, it will lookup filter names
etc. in this Yaml file.

Listing 1: Example of entry in telescope.yml for the Nordic Optical Telescope
(NOT). This entry includes instrument-specific information needed for header
keyword translation (FILTER, AIRMASS, GAIN), filter keywords (g_SDSS: g,
B_Bes: B, etc) as well as location information and extinction terms, discussed
further in Sect. 4.3

⬇

NOT:

INSTRUME:

ALFOSC_FASU:

Name: NOT+ALFOSC

AIRMASS: AIRMASS

GAIN: GAIN

RDNOISE: READNOISE

filter_key_0: FILTER

filter_key_1: FILTER1

pixel_scale: 0.213

B_Bes: B

V_Bes: V

color_index:

B:

B-V:

m: 0.014

m_err: 0.007

V:

B-V:

m: -0.106

m_err: 0.012

.

.

.

NOTCAM:

Name: NOT+NOTCAM

AIRMASS: AIRMASS

GAIN: GAIN

.

.

.

extinction:

ex_B: 0.203

ex_I: 0.019

ex_R: 0.069

.

.

.

location:

alt: 2327

lat: 28.76

lon: -17.88

name: lapalma

Along with filter names, the Yaml database (shown in Listing 1) contains other
instrument-specific information necessary for automated execution of AutoPhOT.
The nested dictionary structure allows for multiple instruments at the same
telescope (in the example shown information is given for both the ALFOSC and
NOTCam instruments mounted on the Nordic Optical Telescope).

filter_key_0 gives the fits header key which gives the filter names888At the
time of writing these filters are Johnson-Cousins $U$, $B$, $V$, $R$, $I$,
Sloan- $u$, $g$, $r$, $i$, $z$ and NIR- $J$, $H$, $K$ . To account for
instruments with multiple filter wheels, this keyword can be iterated i.e.
filter_key_0, filter_key_1, etc. If it finds an incompatible header value i.e.
if the filter corresponds to $CLEAR$ or $AIR$, it is ignored unless requested
otherwise by the User999This is necessary in the case of unfiltered
observations..

AutoPhOT requires at minimum for an image to have the TELESCOPE and INSTRUME
keywords. Both keywords are standard fits
keywords101010https://heasarc.gsfc.nasa.gov/docs/fcg/standard_dict.html and
are virtually ubiquitous across all astronomical images. If not found, an
error is raised and the User is asked for their intervention.

A pre-populated Yaml file with information and keywords for several commonly-
used telescopes is provided as part of AutoPhOT.

###  2.5 Solving for the World Coordinate System

Astronomical images require a World Coordinate System (WCS) to convert sky
coordinates to X and Y pixel coordinates. Many images may have WCS values
written during the reduction process. However, it is not uncommon for an image
to have an offset WCS or be missing WCS information entirely. AutoPhOT assumes
the WCS is unreliable when there is a significant (default is $2\times FWHM$)
offset between the catalog positions of sources in the image, and their
measured position. In such cases (and where a WCS is missing entirely),
AutoPhOT calls a local instance of
Astrometry.net111111https://astrometry.net/use.html (Lang et al., 2010).
Source detection is performed on the input image, and asterisms (sets of four
or five stars) are geometrically matched to pre-indexed catalogs. Solving for
the WCS values typically takes from $\sim 5s$ to $\sim 30s$ per
image121212Using a 2017 MacBook Pro, with a 2.5 GHz Intel Core i7 processor
with 8 Gb DDR3 RAM..

###  2.6 Cosmic Ray removal

Cosmic Rays (CRs) are high energy particles that impact the CCD detector and
can result in bright points or streaks on the CCD image. For images with long
exposure times, CRs can be problematic as they may lie on top of regions or
sources of interest.

To mask and remove cosmic rays, AutoPhOT uses an instance of
Astroscrappy131313https://github.com/astropy/astroscrappy (van Dokkum et al.,
2012; McCully & Tewes, 2019) which is a Python 3 adaptation of the commonly
used LACosmic code (van Dokkum et al., 2012).

###  2.7 Measuring image Full Width Half Maximum

The Full Width Half Maximum (FWHM) of point sources in an image is determined
by the astronomical seeing when the image was taken, as well as the telescope
and instrument optics. AutoPhOT measures the FWHM of an image by fitting an
analytical model (by default a Moffat function; Moffat, 1969) to a few tens of
bright isolated sources in the field.

Firstly, AutoPhOT needs to adapt to the number of point sources in an image. A
deep image with a large field of view (FoV) will have considerably more
sources than a shallow image with a small FoV. Too few sources may lead to
poorly sampled (or incorrect) values of the FWHM, while too many sources may
indicate the detection threshold is too low (i.e. background noise is detected
as a source) and needlessly increases the computation time. Fig. 1 illustrates
the process for finding the FWHM of an image. AutoPhOT’s FWHM function in the
FIND package aims to obtain a well sampled value for the FWHM of the image
without any prior knowledge of the number of sources in the field. The process
begins with a search for point-like searches using the DAOFIND (Stetson, 1987)
algorithm, together with an initial guess for the threshold value (that is,
the minimum counts above the background level for a source to be considered).
The first iteration returns a small set of bright sources, measures their FWHM
and updates the initial guess for the FWHM value.

Figure 1: Flowchart showing the iterative process of finding the FWHM of image
using AutoPhOT. We do not show the adaptive threshold step size for purpose of
clarity.

The process continues to search for sources above the threshold value in the
field. If too many sources are detected, the loop will rerun the algorithm
with a higher threshold value. This change in threshold value is adaptively
set based on the number of sources detected.

We use sigma clipping is used to remove extended sources (e.g. faint galaxies,
saturated sources, etc) which may have slipped through. In classical sigma
clipping, if we have a median value for the FWHM with a standard deviation,
$\sigma$, then only values with within $\pm n\sigma$ of the median is used,
where n is some value, which by default is set to $n=3$. AutoPhOT uses a more
robust method to determine outliers via the median absolute deviation given
by:

$\begin{split}\sigma_{MAD}=\frac{MAD}{\Phi^{-1}(P)}\approx 1.4826\cdot MAD\\\
\rm{where}\leavevmode\nobreak\ MAD=median(|X_{i}-\mu|)\end{split}$ (1)

where $\Phi^{-1}(P)$ is the normal inverse cumulative distribution function
evaluated at probability P = 3/4. Assuming a normal distribution of FWHM
values, $n=3$ would mean that $\sim 99\%$ of FWHM measurement would fall
within this value. Once a FWHM value is found for an image it is then used
henceforth for this image for building the PSF model and photometric
measurements.

##  3 Photometry

Fundamentally, photometry consists of the measuring the incident photon flux
from an astronomical source and calibrating this onto a standard system. We
can define the difference in magnitude between two sources $m_{1}$ and $m_{2}$
as

$m_{1}-m_{2}=-2.5\cdot Log_{10}\left(\frac{F_{1}}{F_{2}}\right)$ (2)

where $F_{1}$ and $F_{2}$ are the measured fluxes (counts per second) from two
sources. As Eq. 2 describes a relative system, we also need to define some
fiducial stars with known magnitudes. One such definition is the “Vega”
magnitude system, where the magnitude of the star Vega in any given filter is
taken to be 0141414In practice, the modern definition of the Vega magnitude
system implies that Vega itself has a magnitude of 0.03. In this case, the
magnitude of any other star is simply related to the flux ratio of that star
and Vega as follows:

$m_{1}=-2.5\cdot Log_{10}\left(\frac{F_{1}}{F_{Vega}}\right)$ (3)

When performing photometry on transients, we typically measure the
instrumental magnitude of the transient itself as well as several reference
sources with known catalog magnitudes in the image. Comparing the magnitude
offset with the literature values of these reference sources (which can be
unique to each image due to varying nightly conditions) and applying it to the
transient, we can place the measurement of the transient onto a standard
system. We define the apparent magnitude of the transient as

$\begin{split}m_{T}=-2.5\cdot
Log_{10}(F_{T})+\left\langle\sum_{i}m_{cat,i}+2.5\cdot
Log_{10}(F_{i})\right\rangle\\\ \rightarrow
m_{T}=m_{instrumental,T}+ZP\end{split}$ (4)

where $m_{T}$ is the unknown apparent magnitude of the transient with a flux
$F_{T}$. The later term describes the magnitude offset or zeropoint (ZP) for
the image and is found by subtracting the catalog magnitude , $m_{cat,i}$,
from the measured magnitude, $-2.5\cdot log_{10}(F_{i})$. An average value for
the zeropoint is typically calculated using a few tens of sources in the
field, typically close to the transient position.

Applying simply a zeropoint will typically result in photometry that is
accurate to $O\sim 0.1$ mag or better. For more precise calibration, and in
particular to ensure homogeneous measurements across different instruments,
one must apply additional corrections beside the zeropoint. These include
color correction ($CC_{\lambda}$) terms and aperture corrections, which we
discuss in Sect. 4.

###  3.1 Aperture Photometry

AutoPhOT can perform either aperture or PSF-fitting photometry on images. Both
methods have their advantages and limitations. Aperture photometry is a simple
way to measure the number of counts within a defined area around a source.
This technique makes no assumption about the shape of the source and simply
involves summing up the counts within a aperture of a certain radius placed at
the centroid of a source.

AutoPhOT begins by using aperture photometry as an initial guess to find the
approximate magnitude of bright sources. If PSF-fitting photometry is not
used, for example if it fails due to a lack of bright isolated sources in the
field151515Sources must have a signal to noise ratio of greater that 25 to be
used in the PSF model by default., aperture photometry is implemented.
Aperture photometry can yield accurate results for bright, isolated sources
(flux dominated), but may give measurements with larger uncertainties for
faint sources (noise dominated), see Appendix B.

To perform aperture photometry, AutoPhOT first finds the centroid of a point
source by fitting a Gaussian function. To accurately measure the brightness of
a source, the background flux must be subtracted. This can be done in several
ways in AutoPhOT, including a local median subtraction or fitting a 2D
polynomial surface to the background region.

Choosing the optimum background subtraction requires some prior knowledge of
the FWHM. The median subtraction method is best for a cutout with a flat
background (e.g. template subtracted images, see Sect. 5), or for a smoothly
varying background over the scale of a few FWHM. For a background with strong
variations (e.g. a on the edge of a extended source) the surface fitting
algorithm performs best. For consistency, AutoPhOT retains the same background
subtraction method (surface fitting by default) for all point source
measurements.

Figure 2: Aperture photometry of an isolated point source showing the aperture
radius (solid red line) as well as the background annulus (faded regions) and
assumed background value (green solid line, taken as the median annulus
value). We also include projections along the X and Y axes.

We demonstrate the aperture photometry functionality in Fig. 2. In this case
the background counts have been found within an annulus centred on the source
position. The counts from the source can then be found using:

$\begin{split}F_{\lambda}\times t_{exp}=counts_{ap}-\langle
counts_{sky}\rangle\cdot n_{pix}\\\ \end{split}$ (5)

where $counts_{ap}$ is the total counts within the aperture area, $\langle
counts_{sky}\rangle$ is the average counts due to the sky background and
$n_{pix}$ is the number of pixels within our aperture.

Figure 3: Sample of S/N values within a given aperture given in the major
axis. Mean Curve Of Growth (COG) given as blue and optimum radius taken as
maximum of this curve, given by blue arrow. The optimum radius is multiplied
by 1.5 to allow for any discrepancy in centroiding.

There is a balance when selecting an optimum aperture size. The aperture
should be large such that most of the light from the star is captured.
However, it should be small enough so that contamination from the sky
background and unrelated sources in minimized. Fig. 3 demonstrates a search
for optimum aperture size in AutoPhOT 161616This value can also be fixed and
the default is taken as 1.6 $\times$ FWHM. For a sample of bright sources
found from Sect. 2.7, the signal-to-noise ratio is measured within a series of
apertures of increasing radii. Typically the S/N will reach a maximum at 1–2
times the FWHM, although this can vary depending on the PSF. The aperture
radius at which the S/N is maximized is then multiplied by 1.5 to allow for
any error in centroiding and used as new aperture radius for the image.

To account for any discrepancy in aperture size (e.g. missing flux due to
finite aperture size) we employ an aperture correction to account for noise
dominated wings of faint sources, which will miss counts due to lower S/N of
the PSF wings. A smaller aperture will lead to a larger aperture correction
and vice-versa, with typical corrections being less $\sim 0.1$ mag. This is
not necessary if PSF photometry is used.

Figure 4:  Histogram shows magnitude of the ratio of our large aperture size
with $r=2.5\times FWHM$ and normal aperture size with $r=1.6\times FWHM$ for a
single image. This is the aperture correction used when aperture photometry is
employed.

To calculate the aperture correction, the bright sources found in Sect. 2.7
are measured with a large aperture size and the standard aperture size.
AutoPhOT uses an large aperture size with $r=2.5\times FWHM$ and normal
aperture size with $r=1.6\times FWHM$171717Both values are adjusted if an
optimum aperture size is used. Using Eq. 2, the ratio of these values gives a
magnitude correction which compensates for the flux lost due to a finite
aperture size. In Fig. 4 we plot the distribution of aperture corrections for
a sample of bright, isolated sources. The average value and standard deviation
are taken as the aperture correction, which is applied to all sources measured
with standard aperture size during aperture photometry.

Aperture photometry has its drawbacks. It performs poorly in crowded fields,
where contamination from neighbouring sources can interfere with measurements
of a single point source. Additionally transients that occur close to their
host may have complex backgrounds which may contaminate measurements. Aperture
photometry is more susceptible to CCD detector defects such as hot/cold and
dead pixels and CRs. Moreover, aperture photometry assumes a flat weight
function across the aperture and is susceptible to centroiding discrepancies.
Point sources inherently have a Gaussian-like weight function which can more
accurately account for the PSF.

Although aperture photometry can always be used (with varying results),
modelling the PSF of a star can provide more accurate measurements and can be
applied to more dynamic scenarios, such as blended sources and high background
scenarios.

###  3.2 Point Spread Function Photometry

All point sources in an image, regardless of their brightness or colour have
the same shape to their PSF181818As long as the sources are unresolved and not
saturated.. The amplitude of the PSF will of course change with brightness.

PSF-fitting photometry uses bright sources in the field to build a semi-
analytical model which is then fitted to fainter sources to find their
instrumental magnitude. PSF photometry is the method of choice for crowded
fields and can give better results for low S/N sources when compared to
aperture photometry.

AutoPhOT assumes that the PSF is non-spatially varying across the image,
meaning points sources will in theory appear the same regardless of their
location on the image. In practice this may not be the case for images that
cover a large FoV (Howell, 2006). If AutoPhOT detects a significant variation
in PSF shape across the images, if will only perform measurements within a
radius around the transient position where the PSF is approximately constant.

The PSF package designed for AutoPhOT is based on the work of Stetson (1987),
Massey & Davis (1992) and Heasley (1999). AutoPhOT uses “well-behaved” sources
to build the PSF model which will then be used to measure the amplitude of
sources in the field. These sources must be have a high S/N, isolated from
their neighbours and have a relatively smooth background. This is done by
building a compound model comprised of an analytical component (such as
Gaussian or Moffat) along with a numerical residual table obtained during the
fitting process. Although sources are selected from Sect. 2.7, the User may
supply the coordinates of PSF stars.

If a FWHM of an image is comparable to the pixel size, the image is said to be
under sampled. In this case PSF-fitting photometry is particularly susceptible
to centroiding errors (Wildey, 1992; Lauer, 1999). If AutoPhOT finds a very
small FWHM for an image (default is 2 pixels) aperture photometry is used
instead.

Figure 5 illustrates the process of building a PSF model in AutoPhOT. Bright
isolated sources are located and fitted with an analytical function (first
panel). The best fit location is noted and the analytic model is subtracted to
leave a residual image (second panel). The residual image is resampled onto a
finer pixel grid and shifted (third panel and fourth panel). The compound
(analytic and residual) PSF model is then normalized to unity. This process is
repeated for several (typically $\sim$ 10 sources) bright isolated sources, to
create an average residual image. The final step is to resample the average
residual image back to to the original pixel scale. We ensure flux in
conserved during this process. Our final PSF model is then simply:

$PSF(x,y,A)=M(x_{0},y_{0},A,FWHM)+R(x_{0},y_{0},A)$ (6)

where $M$ is the a 2D Moffat function (or Gaussian function if selected) and
$R$ is the residual image. We can fix the FWHM to the value found for the
image as discussed in Sect. 2.7, so the PSF model can be fitted with three
parameters, $x_{0}$ and $y_{0}$ (the centroid of the sources), and $A$ its
amplitude.

Figure 5: Demonstration of the steps taken to build residual table for PSF
photometry. Bright isolated sources are located as in Sect. 2.7. A cutout is
taken around the source, and an analytical function is fitted and subtracted.
The image is then resampled to a finer pixel grid (default: $\times$10). The
residual image is then rolled (discretely shifted along x and y) such that the
location of best fit is at the image center. This is repeated for several
bright isolated sources to obtain an average residual. This figure can be
produced in AutoPhOT using the plots_PSF_model_residual command.

We integrate under the analytical model between bounds set by the FWHM and
aperture size, and perform aperture photometry on the residual table with the
same bounds. This is the counts in a PSF model with amplitude equal to 1. When
fitting the PSF model we implement the same re-sampling technique to allow for
sub-pixel fitting. We can then simple multiply the fitted amplitude of the
source with the counts under our normalised PSF model to find the counts for
any given source.

In Fig. 6 we show an example of the residual image after fitting our PSF model
to a source and subtracting it off. In this example the point source is almost
symmetric. A signature of a suitable PSF model is that after subtraction,
there is little to no evidence of the prior point source.

Figure 6: Example of PSF subtraction. The main panels show a cutout of the
transient location before (left) and after (right) PSF subtraction, while
projections along the x and y axis are also shown for each panel. The source
is cleanly subtracted and there is no sign of a residual in the subtracted
panel. This figure is can be reproduced using the plot_PSF_residuals command.

##  4 Calibrating photometry

A crucial step in photometry is calibrating instrumental magnitudes onto a
standard photometric system. Due to the sparsity of photometric nights (i.e.
nights when there are no clouds or other issues with atmospheric
transparency), this zeropoint calibration must be obtained for each image.
Furthermore, even on photometric nights, there may be a gradual shift in
zeropoint due to the cleanliness/coating of the mirrors over time (for an
example of this effect, see fig. 3 in Harbeck et al., 2018). We discuss the
zeropoint calibration in Sect. 4.1. In some cases it is sufficient to apply
the zeropoint correction alone to produce calibrated, publication-ready
photometry.

However, in cases where multiple instruments have been used to observe a
supernova measurements, one must account for differences between telescopes.
In particular, we must consider effects due slight manufacturing differences
between filter sets which may give systematic offsets for the same transients
measured using different instruments. These effects typically accounts for
$\sim 0.1\leavevmode\nobreak\ mag$ corrections to photometry.

###  4.1 Zeropoint Calibration

The zeropoint is used to calibrate an instrumental magnitude to a standard
magnitude system using Eq. 4. For a given image, AutoPhOT will search for a
catalog covering the field of interest with the correct filters available.
Alternatively, the User can specify their desired catalog, or provide a custom
catalog for the field.

Fig. 7 illustrates how sources are identified in an image to determine the
zeropoint as well to build the PSF model. In this example a local region 3′
around the target position is selected. If the image contained many sources,
this can reduce computation times considerably.

Figure 7: Demonstration of source detection for catalog sources. PSF stars
(blue circles) are selected on the basis of their brightness and isolation. In
this example we only consider sources close to the transient location
($<3^{\prime}$)

We show the zeropoint calibration for the image shown in 7 in Fig. 8. In this
example we include sigma-clipping (see Sect. 2.7) to remove any outliers as
well as a S/N cutoff. The result shows a distribution with a well defined peak
which is used as the zeropoint for this image.

Figure 8: Zeropoint diagnostic plot from AutoPhOT. Left panels show zeropoint
measurements before (upper left) and after (lower left) a 3$\sigma$ clipping.
Upper left panel shows a skewed tail for fainter instrumental magnitudes
(notice the different y-axis between the two subplots). Right panel shows
zeropoint distribution with a probability density function with a well defined
peak.

###  4.2 Color terms

Along with the zeropoint, it is usually necessary to apply colour terms when
calibrating instrumental magnitudes. Colour terms are a consequence of filters
and CCDs having a non-uniform response over the bandpass of a filter. For
example, a $z$-band filter may transmit light with wavelengths between 8200
and 9200 Å. However, if this filter is used with a CCD that has a much lower
quantum efficiency in the red, then we will detect more counts from a blue
source than a red, even if they have the same z-band magnitude. This effect,
which manifests itself as a colour-dependent shift in zeropoint, can be as
much as 0.1 mag. Moreover due to small differences in the effective pass band
of different observatory filter system, we must determine the color term for
each instrument individually to a produce a homogeneous dataset.

We demonstrate the effect of neglecting any colour information when
determining the zeropoint of an image in Fig. 9 and Fig. 10. A clear
discrepancy is seen and is correlated with the color of the sequence stars
used; in this case, the zeropoint under represents blue sources and slightly
overestimates redder sources by $\sim 0.1$-mag. In Fig. 10, we see a shift of
$\sim 0.1$-mag in the zeropoint magnitude as well as smaller scatter among
sources in the field.

Figure 9: Demonstration of the effect of point source colour on zeropoint
calibration. X-axis shows the catalog colour of sources, while the Y-axis
shows the g-band magnitudes minus their instrumental magnitude and image
zeropoint. Red squares are binned magnitudes with errorbars equal to the
standard deviation of magnitudes in each bin. The solid black line shows the
best fit using EMCEE (Foreman-Mackey et al., 2013). The lower panel shows the
same points with the color correction applied.  Figure 10: Discrepancy of
zeropoint measurements when ignoring color correction (black) and including it
(red).

For transient measurements, observations in two closely spaced filters are
required e.g. B-V, taken at approximately the same time. Additionally the
color term of the instrument and telescope must be known. This can be found
using stars in the field with standard magnitudes in literature to determine
the effect of stellar color i.e. the fitted line given in Fig. 9. The slope of
this line ($CT_{BV}$) is then used to correct for the zeropoint for each image
where appropriate color information is available. As we have more unknowns
variables than known, we can iterate through Eq. 7 to solve for the true,
color corrected magnitude.

$\displaystyle M_{True,\leavevmode\nobreak\ B,\leavevmode\nobreak\
i}=m_{inst,\leavevmode\nobreak\ B}+ZP_{B}+CT_{B,BV}\leavevmode\nobreak\
(M_{True,\leavevmode\nobreak\ B,\leavevmode\nobreak\
i-1}-M_{True,\leavevmode\nobreak\ V,\leavevmode\nobreak\ i-1})$ (7)
$\displaystyle M_{True,\leavevmode\nobreak\ V,\leavevmode\nobreak\
i}=m_{inst,\leavevmode\nobreak\ V}+ZP_{V}+CT_{V,VB}\leavevmode\nobreak\
(M_{True,\leavevmode\nobreak\ B,\leavevmode\nobreak\
i-1}-M_{True,\leavevmode\nobreak\ V,\leavevmode\nobreak\ i-1})$

The above equation demonstrates the process of applying a colour correction to
two measurements in filters $B$ and $V$. Both filters have a colour term known
a priori, where $CT_{B,BV}$ is the slope of $M_{B}$ \- $M_{V}$ v.s. $M_{B}$ \-
$M_{B,inst}$ and similarly for $CT_{B,BA}$. For convenience and stability,
AutoPhOT solves for the color term corrections using the iterative Jacobi
method. We rearrange Eq. 7 into the form $Ax=b$ which gives:

$\displaystyle\begin{bmatrix}1-CT_{B,BV}&CT_{B,BV}\\\
CT_{V,VB}&1-CT_{V,VB}\end{bmatrix}\begin{bmatrix}M_{True,\leavevmode\nobreak\
B,\leavevmode\nobreak\ i}\\\ M_{True,\leavevmode\nobreak\
V,\leavevmode\nobreak\
i}\end{bmatrix}=\begin{bmatrix}m_{inst,\leavevmode\nobreak\ B}+ZP_{B}\\\
m_{inst,\leavevmode\nobreak\ V}+ZP_{V}\end{bmatrix}$ (8)

This is a quick method to apply a colour correction and typically converges in
$\sim$10 iterations.

###  4.3 Atmospheric Extinction

We can account for the effect of atmospheric extinction using the following:

$\displaystyle M_{\lambda,corrected}=M_{\lambda}+\kappa_{\lambda}\cdot sec(z)$
(9)

where $M_{\lambda}$ is the magnitude in a given filter, $\lambda$,
$\kappa_{\lambda}$ is the extinction coefficient in magnitudes per unit
airmass and $sec(z)$ is simply the secant of the zenith angle $z$. Taking
account of the airmass correction is particularly necessary when calibrating
photometry to standard fields (e.g. Landolt, 1992). An observer may wish to
obtain a more precise set of sequence stars for their transient measurements.
This will involve observing a standard field on a night that is photometric,
as well as the transient location. The zeropoint measurements of the standard
field will be at a different airmass than the transient. Using Eq. 9, and the
standard field measurement, an observer can perform photometry on a set of
sequence stars around the transient location and place them on a standard
system. This can be used for future measurements of the transient.

There is no trivial way to approximate the extinction at a specific telescope
site. We provide an approximation which AutoPhOT uses in Appendix A, although
for accurate photometry, the User should provide the known extinction curve
for a given site.

##  5 Image Subtraction

If a transient is close to its host nucleus, occurs near another point source,
or has faded to a level comparable to the background, it may be necessary to
perform difference imaging (e.g. Alard & Lupton, 1998). Difference imaging
involves scaling and subtracting a template images (assumed to have no
transient flux) from a science images, removing a strong bright or host
contamination. Prior to subtraction images must be precisely aligned (i.e. to
subpixel precision), scaled to a common intensity, and be convolved with a
kernel so that their PSFs match.

Currently, AutoPhOT includes HOTPANTS 191919High Order Transform of PSF ANd
Template Subtraction202020https://github.com/acbecker/hotpants (Becker, 2015)
and PyZogy 212121https://github.com/dguevel/PyZOGY (Zackay et al., 2016) for
image subtraction. The User can select what package they require, with
HOTPANTS set as the default. Prior to template subtraction, AutoPhOT aligns
the science and template images using WCS
alignment222222https://reproject.readthedocs.io/en/stable/ or point source
alignment232323https://astroalign.readthedocs.io/en/latest/(Beroiz, 2019).
Furthermore both images are cropped to exclude any regions with no flux after
alignment.

##  6 Limiting Magnitude

A limiting magnitude is the brightest magnitude a source could have and remain
undetected at a given significance level. Even when a transient is not visible
in an image, a limiting magnitude can help constrain explosion times in SNe or
decay rates of GW merger events.

A relatively crude method to find the limiting magnitude of an image is to
attempt to recover known sources in the FoV. In Fig. 11 we show the difference
between the recovered magnitude of sources in an image and their catalog
magnitude. The difference is close to zero for the majority of brighter
sources, but then becomes significant for fainter sources with
$M_{Catalog}>18.1$. AutoPhOT will calculate the limiting magnitude from the
first magnitude bin where the difference exceeds a specified threshold (set
using the equations in Appendix B). Although this is relatively
straightforward, it can fail in sparse fields, and of course is not feasible
when the image is deeper than the catalog.

Figure 11: Difference between measured magnitude versus catalog magnitude for
sequence sources in an image. We adopt a 3$\sigma$ threshold for source
detection corresponding to $\delta(M)\approx 0.31\leavevmode\nobreak\ mag$
using Eq. 13.

The second way that AutoPhOT can calculate the limiting magnitude is through
what we refer to as the “probabilistic limiting magnitude” illustrated in Fig.
12. We assume that the pixels are uncorrelated, and contain only noise from a
uniform background sky. After excising the expected position of the transient,
we proceed to select $n$ pixels at random (where $n=\pi r^{2}$), and sum
together the counts in these $n$ pixels from a background subtracted cutout of
the transient location. Repeating this many times for different random sets of
$n$ pixels, we obtain a distribution of summed counts (shown in the upper
panel in Fig. 12). We can then ask the question “what is the probability we
would obtain this number of counts or greater by chance?”. Setting the
threshold to $3\sigma$, in the example shown we can see that we are unlikely
to find a source with more than $\sim 3,500$ counts, and we hence adopt this
as our limiting magnitude.

Figure 12: The upper panel shows the distribution of summed counts for a
random set of pixels close to the expected source location. Bottom left shows
a cutout of the transient location; pixels marked in red are excluded when
creating the distribution. Bottom right is the same image with injected PSF
sources (marked with red circles) with magnitude equal to the
$F_{UL,\beta=0.75}$ limiting magnitude,see Appendix. D

Finally, the most rigorous limiting magnitude is determined though injecting
and recovering artificial sources. Using an initial guess from the
probabilistic limiting magnitude described above, artificial sources built
from the PSF model (see Sect.3.2) and with realistic noise are injected in set
positions (default $3\leavevmode\nobreak\ \times\leavevmode\nobreak\ FWHM$)
around the target location. The magnitudes of the injected sources are then
gradually adjusted until they are no longer recovered by AutoPhOT above
$3\sigma$ (or some other criteria).

Fig. 13 demonstrates the artificial source injection package. In this example
the image is template subtracted and we use the $\beta^{\prime}$ detection
criteria (see Appendix D). Starting with an initial guess from the
probabilistic limiting magnitude, the injected magnitude is adjusted
incrementally until it meets our detection criteria, which it will typically
overshoot. The magnitude increment is then reversed, using a smaller step size
until the detection criteria is again fulfilled. Sources are deemed lost when
where their individual recovered measurements give a $\beta<0.75$. We take the
limiting magnitude to be the magnitude at which 80% of sources are lost.

Figure 13: Diagnostic plot from AutoPhOT’s artificial source injection
package. Top panel shows the change in the detection probability
($1-\beta^{\prime}$) for artificially injected sources. In this example the
sources are considered lost at $\beta=0.75$ and the detection cutoff is
reached when $80\%$ of sources are lost (black line with circles). The
leftmost image cutouts illustrate locations around the target location before
(upper) and after (lower) sources were injected randomly at the limiting
magnitude. The remaining four panels demonstrate closes up of these injected
sources

##  7 Testing and validation

###  7.1 Testing of photometry packages

In this section we demonstrate AutoPhOT’s ability to recover the magnitude of
sequence stars in the field. As this is a novel PSF-fitting package, we
compare against the aperture photometry package available in AutoPhOT as well
as from the well established photometry package DAOPHOT (Stetson, 1987).

Fig. 14 shows both aperture and PSF photometry can accurately determine the
magnitude of relatively bright sources ($M\lessapprox 19\leavevmode\nobreak\
mag$). However, at fainter magnitudes, aperture photometry can longer performs
as well, as seen in the larger scatter. Incorrect centroiding may become an
issue with aperture photometry when the source flux is comparable to the
background. PSF photometry can perform much better at fainter magnitudes.
Unlike aperture photometry, the PSF model attempts to measure shape of a
point-like source using more information on the shape of the PSF.

Figure 14:  Demonstration of recovered magnitude using aperture photometry
(upper panel) and the PSF-fitting package (lower panel) from AutoPhOT. Y-axis
shoes the derived zeropoint magnitude for each source. Solid lines show a
moving mean value with dashed lines indicating the standard deviation in each
bin. Horizontal errorbars show the uncertainty on catalog magnitudes, vertical
errorbars are uncertainties on recovered magnitudes from AutoPhOT.

Fig. 15 compares the PSF and aperture photometry from AutoPhOT and DAOPHOT
(Stetson, 1987). The PSF fitting package from AutoPhOT can match the recovered
instrumental magnitude from DAOPHOT, even at faint magnitudes where the flux
from the source becomes comparable to the sky background. Aperture photometry
can result in similar magnitudes but suffers from centroiding errors at
fainter magnitudes. However for such low fluxes, PSF-fitting photometry should
be used.

Figure 15: Comparison of measured instrumental magnitude using DAOPHOT and
AutoPhOT. The upper two panels show the difference in recovered magnitude
using PSF-fitting photometry with AutoPhOT and DAOPHOT, and the difference in
error. The lower two panels show the same but for aperture photometry. In each
case the x-axis gives the instrumental magnitude from AutoPhOT. The same
aperture radius was used in all cases. For the first and third panel, the
errorbars are the combination of (added in quadrature) uncertainties from both
AutoPhOT and DAOPHOT. In panels two and four, the y axis shows DAOPHOT err \-
AutoPhOT err (i.e. the uncertainties from AutoPhOT are slightly smaller than
those returned by DAOPHOT for faint sources).

We test the effectiveness of the AutoPhOT limiting magnitude packages in Fig.
16. We use a relatively shallow image, and a reference catalog containing
fainter sources. We see that below the computed upper limit of $\sim
18.5\leavevmode\nobreak\ mag$, sources are not detected. Brighter than $\sim
18.5\leavevmode\nobreak\ mag$, we recover sources at magnitudes consistent
with their catalog values.

Figure 16: Demonstration of inject_sources function. Upper panel: if the
recovered magnitude is less than the magnitude limit, the source cannot be
recovered. Blue points indicate the magnitude of injected sources. In cases
where the source could not be recovered we indicate the limiting magnitude
with a green arrow, otherwise we plot recovered sources as red points. The
solid line shows a perfect recovery of sources. Lower panel: Measured S/N for
each source. The horizontal line highlights a S/N of 3 while the vertical line
highlights the approximate magnitude of sources recovered, set at
$18.5\leavevmode\nobreak\ mag$.

###  7.2 Performance

Figure 17: r-band light curves produced by AutoPhOT compared to those found in
literature. AutoPhOT points are given as points with error bars and literature
values given as shaded band with width equal to the error at each point. In
descending order, we compare the output from AutoPhOT for AT 2018cow (Perley
et al., 2018; Prentice et al., 2018b) using template subtraction and aperture
photometry, SN 2016coi (Prentice et al., 2018a) and SN 2016iae (Prentice &
Mazzali, 2017) without subtraction using both PSF and aperture photometry.
Center panels compare both measurements with the upper panel showing the
difference between measurements ($\Delta\leavevmode\nobreak\
Mag=\textsc{AutoPhOT}-literature$) and lower panel showing the difference in
error ($\Delta\leavevmode\nobreak\
Mag_{err}=\textsc{AutoPhOT}_{err}-literature_{err}$) for each transient. Right
panels highlight the site of the transient event.

Fig. 17 shows a comparison of AutoPhOT photometry against published
lightcurves in the literature for three transients found in three different
environments, namely AT 2018cow (Perley et al., 2018; Prentice et al., 2018b),
SN 2016coi (Prentice et al., 2018a) and 2016iae (Prentice & Mazzali, 2017).
AutoPhOT was run on the same data as used in the referenced publications, and
while a combination of techniques was used for each transient (i.e. template
subtraction, PSF-fitting and aperture photometry) as detailed in the caption,
in all cases this was run without human intervention.

We report several diagnostic parameters for these three transients in Tab. 1,
including execution time. The most time consuming step is matching and fitting
sequence stars to determine the zeropoint. This can be addressed by limiting
the region where sequence sources are measured or providing AutoPhOT with a
list of sources to use.

Transient | Images | Time taken [$hr$] | Time per image [$\frac{s}{image}$] | Mean Residual [$mag$] | Mean Error Residual [mag]
---|---|---|---|---|---
AT 2018cow | 187 | 3.32 | 64 | 0.041 | 0.008
SN 2016iae | 259 | 4.69 | 65 | 0.007 | 0.020
SN 2018coi | 25 | 0.35 | 34 | 0.011 | 0.039
Table 1: Performance of AutoPhOT computing $r$-band lightcurves from Fig.
17.Photometry for AT 2018cow was performed using template subtraction and
aperture photometry (similar to the Perley et al. 2018, although a custom host
subtraction pipeline was used in this case.), whereas SN 2016coi (Prentice et
al., 2018a) and 2016iae (Prentice & Mazzali, 2017) were reduced without
subtraction using both PSF and aperture photometry where appropriate.
Photometry performed using a 2017 MacBook Pro, using a 2.5 GHz Intel Core i7
processor with 8 Gb DDR3 RAM.

##  8 Conclusions and Future Development

We present our photometry pipeline, Automated Photometry of Transients
(AutoPhOT), a new publicly available code for performing PSF-fitting, aperture
and template-subtraction photometry on astronomical images, as well as
photometric calibration. This code is based on Python 3 and associated
packages such as ASTROPY. With the deprecation of Python 2 and popular
photometry packages within IRAF, AutoPhOT provides accurate photometry with
little User setup or monitoring. AutoPhOT has already been used in several
scientific publications (Chen et al. 2021, Fraser et al. 2021, Brennan et al.
2021a, Brennan et al. 2021b, Elias-Rosa et al. in prep, and Engrave
Collaboration et al. in prep) at the time of writing.

Future work includes adapting to a wider range of images with irregularities,
such as satellite trails, saturated sources, and CCD imperfections. The
AutoPhOT project will also ultimately include a User-friendly web interface as
well as an Application Programming Interface (API). This will allow for both
fast and simple photometry without the need to maintain local software, as
well as easy command line access. Additional functionality will allow for
calibrated photometry using standard fields observations. Further releases of
AutoPhOT will include additional corrections such as spatially varying PSF
models and potentially S-corrections (Stritzinger et al., 2002).

The pipeline is publicly available and detailed installation and execution
instructions can be found from https://github.com/Astro-Sean/autophot

##  Appendix A Atmospheric Extinction Calculation

To deduce the extinction parameters across a range of photometric filters, one
may observe a series of stars throughout a night at different airmasses.
Fitting a slope to the data should show a clear trend of zeropoint magnitude
versus airmass, being more extreme in the bluer bands than in the red.
AutoPhOT can accept these values as shown in Code. 1.

If unknown, AutoPhOT makes an rough approximation of the extinction due to
airmass that relies on the altitude of the telescope site and the wavelength
being observed. There are three main contributors to atmospheric extinction;
Rayleigh scattering of light by molecules smaller than the wavelength of the
scattered light, absorption due to Ozone in the upper atmosphere, and aerosol
extinction by scattering and absorption by particles with diameters of the
order of the wavelength or larger e.g dust/ash particles.

Absorption/scattering by Rayleigh scattering is described by Hayes & Latham
(1975) and is given by:

$\displaystyle\alpha_{\lambda,Rayleigh}=0.0094977\cdot\lambda^{-4}\cdot
n_{s}(\lambda)^{2}\cdot e^{\frac{-h}{7.996}}$ $\displaystyle
where\leavevmode\nobreak\
n_{s}(\lambda)=0.23465+\frac{107.6}{146-\lambda^{-2}}+\frac{0.93161}{41-\lambda^{-2}},$

where $\lambda$ is the effective wavelength of the observation in $\mu$m and
$h$ is the altitude above sea level in $km$. $n_{s}(\lambda)$ describes the
refractive index of thin incoming light.

Molecular absorption, mainly due to atmospheric ozone and water, can be
described by:

$\displaystyle\alpha_{\lambda,Ozone}=1.11\cdot
T_{Ozone}\cdot\kappa_{Ozone}(\lambda)$ (10)

where $T_{Ozone}$ is the thickness of the Ozone layer above the telescope
scope taken at $0\leavevmode\nobreak\ ^{\circ}C$ and 1 atm, and is assumed to
be 0.3 cm. $\kappa_{Ozone}(\lambda)$ is the absorption coefficient for Ozone
taken from Inn & Tanaka (1953).

By default, AutoPhOT will assume the total atmospheric extinction is
$\alpha_{\lambda}=\alpha_{\lambda,Rayleigh}+\alpha_{\lambda,Ozone}$. This can
be a suitable approximation for many telescope sites e.g. La Silla and Roque
de los Muchachos, Fig. 29. In practice high particulate levels in the air can
account for large discrepancies, especially in the redder bands, e.g. Paranal
and Mauna Kea. This can be accounted for by including the atmospheric
extinction due to aerosols. This is given by:

Figure 18: Theoretical atmospheric extinction curves for several sites
including La Silla
272727https://www.eso.org/sci/observing/tools/Extinction.html, Roque de los
Muchachos282828https://www.ing.iac.es/astronomy/observing/conditions/wlext.dat,
Paranal(Patat et al., 2011), and Muana
Kea292929https://www2.keck.hawaii.edu/inst/common/exts.html. We include a
match to the Paranal extinction curve using
$\alpha_{\lambda}=\alpha_{\lambda,Rayleigh}+\alpha_{\lambda,Ozone}+\alpha_{\lambda,Aerosol}$
with b = -2, $A_{0}$ = 0.05 and $H_{0}$ = 1.5. It is difficult to fit the
extinction curve at found at Muana Kea, likely due to high levels of volcanic
dust.

$\displaystyle\alpha_{\lambda,Aerosol}=A_{0}\cdot\lambda^{-b}\cdot
e^{\frac{-h}{H_{o}}}$ (11)

where $A_{0}$ is the same extinction for $\lambda$=1 $\mu$m and $b$ is a
coefficient dependent on the size of aerosol particles and their size
distribution and $H_{0}$ is the scale height. The aerosol extinction is the
most variable and problematic. It is left to the User to include this
correction however with a priori knowledge, it can produce good results (e.g.
for Paranel in Fig. 29).

##  Appendix B Error Calculations

The uncertainty on the calibrated magnitude of a source is calculated as:

$\displaystyle\delta m=\sqrt{\delta m_{inst}^{2}+\delta ZP^{2}}$ (12)

We take the error from the zeropoint calibration ($\delta ZP$) to be the
standard deviation from measurements of sources in the field. Prior to this,
appropriate sigma clipping and S/N cutoffs are applied. The error associated
with the measurement of the transient itself ($\delta m_{inst}$) requires more
attention. The uncertainty in magnitude of a source is related to the S/N
ratio as follows:

$\displaystyle m_{inst}\pm\delta\leavevmode\nobreak\ m_{inst}$
$\displaystyle=-2.5Log_{10}(S\pm N)$
$\displaystyle=-2.5Log_{10}(S(1\pm\frac{N}{S}))$
$\displaystyle=-2.5Log_{10}(S)-2.5Log_{10}(1+\frac{N}{S})$
$\displaystyle=-2.5Log_{10}(S)-2.5Log_{10}(1+\frac{1}{S/N})$
$\displaystyle\delta\leavevmode\nobreak\ m_{inst}$ $\displaystyle=\mp
2.5Log_{10}(1+\frac{1}{S/N})\approx 1.0875(\frac{1}{S/N})$ (13)

Where $S$ is the signal from the source and $N$ is the noise associated with
it. We find the the error associated with the S/N is $\sim
1.0875(\frac{1}{S/N})$ using a Taylor expansion. In AutoPhOT, we define the
Signal to Noise Ratio (S/N) using the CCD equation (Mortara & Fowler, 1981;
Howell, 2006):

$\displaystyle S/N$ $\displaystyle=$
$\displaystyle\frac{\overbracket{{F_{*}\times
t_{exp}}}^{Signal}}{\sqrt{[\underbracket{(F_{*}\times t_{exp})}_{Shot\
noise}+\underbracket{(F_{sky}\times t_{exp}\times n)}_{Sky\
Noise}+\underbracket{(RN^{2}+(G^{2}/4)\times n)}_{Read\leavevmode\nobreak\
Noise}+\underbracket{(D\times n\times t_{exp})}_{Dark\ Current\ noise}]}}$
(14)

here $F_{*}$ is the count rate from the star in $e^{-}/s$, $t_{exp}$ is the
exposure time in seconds, $F_{sky}$ is the background counts in
$e^{-}/s/pixel$, $n$ is the number of pixels within an aperture, $R$ is the
read noise $e^{-}$, D is the dark current in $e^{-}/s$ and G is the Gain in
$e^{-}$. R, G, $t_{exp}$, and D are taken from the image header, if available
while the remaining terms are calculated during the photometric reduction.

Additionally we must consider the error associated with the fitting process
itself. If PSF photometry is performed, we include an error estimate from
artificial star experiments similar to those in SNOoPY. If the User desires
this additional error analysis, an artificial source with the same magnitude
as the target star, is placed in the PSF-subtracted residual image in a
position close to the real source (e.g. lower left panel of Fig. 13). The
injected sources are then recovered using an identical fitting procedure. The
standard deviation of measurements is taken as an estimate of the instrumental
magnitude error. This is combined (in quadrature) with the PSF-fit error
returned by LMFIT to give $\delta\leavevmode\nobreak\ m_{inst}$.

At the time of writing, AutoPhOT is only concerned with these terms given in
Eq. 12 as these terms are expected to dominate.

##  Appendix C Execution Example

In listing. 2 we provide a snippet of code that will execute AutoPhOT on a
dataset303030Example of AutoPhOT’s execution can be found at
https://github.com/Astro-Sean/autophot.

Listing 2: Example of AutoPhOT execution used to produce the lightcurve for SN
2016iae in Fig. 17.

⬇

# Import AutoPhoT package

import autophot

# Load command dictionary

from autophot.prep_input import load

autophot_input = load()

# location of work directory

autophot_input[’wdir’] = ’/Users/seanbrennan/Desktop/autophot_db’

# Location of fits images for SN2016iae

autophot_input[’fits_dir’] = ’/Users/seanbrennan/Desktop/SN2016iae’

# IAU name of target for TNS retrieval

autophot\_input[’target_name’] = ’2016iae’

# Name of catalog for zeropoint calibration

autophot_input[’catalog’][’use_catalog’] = ’apass’

# Import automatic photometry package

from autophot.autophot_main import run_automatic_autophot

# Run automatic phototmetry with input dictionary

run_automatic_autophot(autophot_input)

##  Appendix D Computing flux upper limits

As a transient fades to a magnitude which is comparable to the background
brightness, it is necessary to compute detection criteria to determine whether
a measured flux can be confidently associated with the transient. Detection
significance is usually defined in terms of the maximum probability of a false
positive (a spurious detection of background noise), which we define as
$\alpha$. Alpha can also be related to $\sigma$, e.g. a 3$\sigma$ upper limit
will correspond to a 0.135% probability (i.e. $\alpha$) of a false positive.

As part of AutoPhOT, we include a false negative criteria, $\beta$, which
signifies the fraction of real sources that go undetected. This $\beta$ value
can be defined in terms of a flux upper limit, $f_{UL}$, which indicates the
maximum incompleteness of a sample of sources with $f_{source}=f_{UL}$. In
other words, $100(1-\beta)\%$ of the sources with flux $f_{UL}$ will have flux
measurements with a $S/N>n\sigma$. We follow the discussion of $F_{UL}$ in
Masci (2011) and further detailed in Kashyap et al. (2010). We describe the
probability of detection as $\beta^{\prime}=1-\beta$, which we want to
maximise. The probability of detecting a source with a $f_{source}=f_{ul}$ can
be written as:

$\displaystyle\beta^{\prime}=\frac{1}{2}[1-\textit{erf}(\frac{z}{\sqrt{2}})]$
(15) $\displaystyle\rm{where}\leavevmode\nobreak\
z=\frac{n\sigma_{bkg}-f_{UL}}{\sigma_{bkg}}$

where erf is the error function, $n$ is a set detection limit (default to $3$
in AutoPhOT) and $f_{UL}$ is a flux upper-limit. Rearranging Eq. 15 gives
probabilistic criteria for detection limits:

$f_{UL}=[n+\sqrt{2}erf^{-1}(2\beta^{\prime}-1)]\sigma_{bkg}$ (16)

Using Eq. 16, we see that using the common $f_{UL}=3\sigma_{bkg}$ gives a
$\beta$’ of 50%, which means that roughly half of the sources injected at
$f_{source}=3\sigma_{bkg}$ will go undetected. For 95% percent confidence that
a source is genuine for S/N = 3, Eq. 16 gives an value for $f_{UL}\approx
5\sigma_{bkg}$.

We demonstrate the applicability of this $\beta$ criteria in Fig. 19. We
inject artificial sources in an empty part of the sky, and while noting the
injected source parameters, we assess whether or not the sources can be
recovered to an appropriated S/N, see caption of Fig. 19 for further details.

Figure 19: Demonstration of Eq. 15. We perform artificial source injection on
an empty patch of sky. Sources are injected uniformly throughout the image,
including sub-pixel placements, with random poisson noise added to the PSF
prior to injection. In the upper panel, we plot Eq. 15 versus maximum pixel
flux in units of the standard deviation of the background noise, as the red
curve. The green points show the binned S/N ratio using Eq. 14. In the lower
panel we plot the S/N ratio using Eq. 14 with the same x-axis as the upper
panel. The points are coloured blue if S/N ¿ 3 and red if S/N ¡ 3. For the
sample of sources incrementally injected, Eq. 15 can reproduce the recovered
fraction of sources. In other words, for sources measured with a
$f_{source}\approx 3\sigma_{bkg}$, roughly half of these are recovered with a
S/N ¿ 3; for injected sources with $f_{source}\approx 3.7\sigma_{bkg}$ we
detect roughly $75\%$; while virtually all sources are confidently recovered
at $f_{source}\approx 4.5\sigma_{bkg}$

AutoPhOT defaults to $\beta^{\prime}=0.75$ to provide a conservative upper
limit to any reported limiting magnitudes. The User may also opt for a more
traditional detection criteria of using the $S/N>n$ where $n$ is the level
above $\sigma_{bkg}$.

## Acknowledgements

SJB would like to acknowledge the support of Science Foundation Ireland and
the Royal Society (RS-EA/3471). MF is supported by a Royal Society - Science
Foundation Ireland University Research Fellowship. We thank Simon Prentice for
sharing data for AT 2018cow, SN 2016coi, and SN 2016iae, and comments on
AutoPhOT during its early phase of development. We thank Emma Callis, Robert
Byrne, Beth Fitzpatrick, Shane Moran, Kate Maguire, and Lluís Galbany for
their comments and feedback while AutoPhOT was under development. We thank the
Transient Name Server and their open source sample codes313131https://www.wis-
tns.org/content/tns-getting-started. This research made use of
Astropy323232http://www.astropy.org, a community-developed core Python package
for Astronomy (Astropy Collaboration et al., 2013, 2018). This research made
use of data provided by Astrometry.net333333https://astrometry.net/use.html

## References

  * Alard & Lupton (1998) Alard, C. & Lupton, R. H. 1998, ApJ, 503, 325
  * Astropy Collaboration et al. (2018) Astropy Collaboration, Price-Whelan, A. M., SipHocz, B. M., et al. 2018, aj, 156, 123
  * Astropy Collaboration et al. (2013) Astropy Collaboration, Robitaille, T. P., Tollerud, E. J., et al. 2013, A&A, 558, A33
  * Becker (2015) Becker, A. 2015, HOTPANTS: High Order Transform of PSF ANd Template Subtraction
  * Beroiz (2019) Beroiz, M. I. 2019, Astrophysics Source Code Library
  * Bertin & Arnouts (1996) Bertin, E. & Arnouts, S. 1996, A&AS, 117, 393
  * Brennan et al. (2021a) Brennan, S. J., Fraser, M., Johansson, J., et al. 2021a, arXiv e-prints, arXiv:2102.09572
  * Brennan et al. (2021b) Brennan, S. J., Fraser, M., Johansson, J., et al. 2021b, arXiv e-prints, arXiv:2102.09576
  * Chen et al. (2021) Chen, T. W., Brennan, S. J., Wesson, R., et al. 2021, arXiv e-prints, arXiv:2109.07942
  * Craig et al. (2017) Craig, M., Crawford, S., Seifert, M., et al. 2017, astropy/ccdproc: v1.3.0.post1
  * Foreman-Mackey et al. (2013) Foreman-Mackey, D., Hogg, D. W., Lang, D., & Goodman, J. 2013, Publications of the Astronomical Society of the Pacific, 125, 306–312
  * Fraser et al. (2021) Fraser, M., Stritzinger, M. D., Brennan, S. J., et al. 2021, arXiv e-prints, arXiv:2108.07278
  * Harbeck et al. (2018) Harbeck, D.-R., McCully, C., Pickles, A., et al. 2018, Long-Term Monitoring of Throughput in Las Cumbres Observatory’s Fleet of Telescopes
  * Hayes & Latham (1975) Hayes, D. S. & Latham, D. W. 1975, ApJ, 197, 593
  * Heasley (1999) Heasley, J. N. 1999, in Astronomical Society of the Pacific Conference Series, Vol. 189, Precision CCD Photometry, ed. E. R. Craine, D. L. Crawford, & R. A. Tucker, 56
  * Howell (2006) Howell, S. B. 2006, Handbook of CCD Astronomy, 2nd edn., Cambridge Observing Handbooks for Research Astronomers (Cambridge University Press)
  * Inn & Tanaka (1953) Inn, E. C. Y. & Tanaka, Y. 1953, J. Opt. Soc. Am., 43, 870
  * Kashyap et al. (2010) Kashyap, V. L., van Dyk, D. A., Connors, A., et al. 2010, The Astrophysical Journal, 719, 900–914
  * Landolt (1992) Landolt, A. U. 1992, AJ, 104, 340
  * Lang et al. (2010) Lang, D., Hogg, D. W., Mierle, K., Blanton, M., & Roweis, S. 2010, The Astronomical Journal, 139, 1782–1800
  * Lauer (1999) Lauer, T. R. 1999, Publications of the Astronomical Society of the Pacific, 111, 1434
  * Masci (2011) Masci, F. 2011, Computing flux upper-limits for non-detections
  * Massey & Davis (1992) Massey, P. & Davis, L. 1992, Pdf, 112, 211
  * McCully & Tewes (2019) McCully, C. & Tewes, M. 2019, Astro-SCRAPPY: Speedy Cosmic Ray Annihilation Package in Python
  * Merlin et al. (2019) Merlin, E., Pilo, S., Fontana, A., et al. 2019, A&A, 622, A169
  * Moffat (1969) Moffat, A. F. J. 1969, A&A, 3, 455
  * Mommert (2017) Mommert, M. 2017, Astronomy and Computing, 18, 47–53
  * Mortara & Fowler (1981) Mortara, L. & Fowler, A. 1981, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 290, Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, 28
  * Patat et al. (2011) Patat, F., Moehler, S., O’Brien, K., et al. 2011, Astronomy & Astrophysics, 527, A91
  * Perley et al. (2018) Perley, D. A., Mazzali, P. A., Yan, L., et al. 2018, Monthly Notices of the Royal Astronomical Society, 484, 1031–1049
  * Prentice et al. (2018a) Prentice, S. J., Ashall, C., Mazzali, P. A., et al. 2018a, MNRAS, 478, 4162
  * Prentice et al. (2018b) Prentice, S. J., Maguire, K., Smartt, S. J., et al. 2018b, ApJ, 865, L3
  * Prentice & Mazzali (2017) Prentice, S. J. & Mazzali, P. A. 2017, MNRAS, 469, 2672
  * Science Software Branch at STScI (2012) Science Software Branch at STScI. 2012, PyRAF: Python alternative for IRAF
  * Stetson (1987) Stetson, P. B. 1987, PASP, 99, 191
  * Stritzinger et al. (2002) Stritzinger, M., Hamuy, M., Suntzeff, N. B., et al. 2002, The Astronomical Journal, 124, 2100–2117
  * Tody (1986) Tody, D. 1986, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 627, Instrumentation in astronomy VI, ed. D. L. Crawford, 733
  * Tody (1993) Tody, D. 1993, in Astronomical Society of the Pacific Conference Series, Vol. 52, Astronomical Data Analysis Software and Systems II, ed. R. J. Hanisch, R. J. V. Brissenden, & J. Barnes, 173
  * van Dokkum et al. (2012) van Dokkum, P. G., Bloom, J., & Tewes, M. 2012, L.A.Cosmic: Laplacian Cosmic Ray Identification
  * Wildey (1992) Wildey, R. L. 1992, Publications of the Astronomical Society of the Pacific, 104, 285
  * Zackay et al. (2016) Zackay, B., Ofek, E. O., & Gal-Yam, A. 2016, The Astrophysical Journal, 830, 27