The Automated Photometry Of Transients (AutoPhOT) pipeline

We present the Automated Photometry Of Transients (AutoPhOT) package, a novel automated pipeline that is designed for rapid, publication-quality photometry of astronomical transients. AutoPhOT is built from the ground up using Python 3 - with no dependencies on legacy software. Capabilities of AutoPhOT include aperture and point-spread-function photometry, template subtraction, and calculation of limiting magnitudes through artificial source injection. AutoPhOT is also capable of calibrating photometry against either survey catalogues, or using a custom set of local photometric standards, and is designed primarily for ground-based optical and infrared images. We show that both aperture and point-spread-function photometry from AutoPhOT is consistent with commonly used software, for example DAOPHOT, and also demonstrate that AutoPhOT can reproduce published light curves for a selection of transients with minimal human intervention.


Introduction
For over three decades, the most commonly used packages for photometry are part of the Image Reduction and Analysis Facility (IRAF) 1 (Tody 1986(Tody , 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 PhotometryP-ipeline (Mommert 2017), that mainly perform aperture photometry on ground based images.
Photometry tools have also been developed as part of AS-TROPY (Astropy Collaboration et al. 2013, 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). Au-toPhOT 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 AS-TROPY 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 homoge-

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 wish 6 . 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 Au-toPhOT.

Target Identification
AutoPhOT implements the Transient Name Server 7 (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.

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.
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 names 8 . 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 User 9 .
AutoPhOT requires at minimum for an image to have the TELESCOPE and INSTRUME keywords. Both keywords are standard fits keywords 10 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 Au-toPhOT.

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 × 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.net 11 (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 ∼ 5s to ∼ 30s per image 12 .

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.
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, σ, then only values with within ±nσ 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: where Φ −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 ∼ 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.

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 Article number, page 3 of 16 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 0 14 In this case, the magnitude of any other star is simply related to the flux ratio of that star and Vega as follows: 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 14 In practice, the modern definition of the Vega magnitude system implies that Vega itself has a magnitude of 0.03.
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 · 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 ∼ 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 λ ) terms and aperture corrections, which we discuss in Sect. 4.

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 field 15 , 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 Au-toPhOT, 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.
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:  where counts ap is the total counts within the aperture area, ⟨counts sky ⟩ is the average counts due to the sky background and n pix is the number of pixels within our aperture.
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 16 . 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 . Histogram shows magnitude of the ratio of our large aperture size with r = 2.5 × FWHM and normal aperture size with r = 1.6 × FWHM for a single image. This is the aperture correction used when aperture photometry is employed. 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 ∼ 0.1 mag. This is not necessary if PSF photometry is used.
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 × FWHM and normal aperture size with r = 1.6 × FWHM 17 . 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.

Point Spread Function Photometry
All point sources in an image, regardless of their brightness or colour have the same shape to their PSF 18 . 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 ∼ 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: 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.
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 18 As long as the sources are unresolved and not saturated. 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.

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 ∼ 0.1 mag corrections to photometry.

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.
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.

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 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. 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 ∼ 0.1-mag. In Fig. 10, we see a shift of ∼ 0.1-mag in the zeropoint magnitude as well as smaller scatter among sources in the field.
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.
Article number, page 7 of 16  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: This is a quick method to apply a colour correction and typically converges in ∼10 iterations.

Atmospheric Extinction
We can account for the effect of atmospheric extinction using the following: where M λ is the magnitude in a given filter, λ, κ λ 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 Au-toPhOT uses in Appendix A, although for accurate photometry, the User should provide the known extinction curve for a given site.

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 1920 (Becker 2015) and PyZogy 21 (Zackay et al. 2016) for image subtraction. The User can select what package they require, with HOT-PANTS set as the default. Prior to template subtraction, Au-toPhOT aligns the science and template images using WCS alignment 22 or point source alignment 23 (Beroiz 2019). Furthermore both images are cropped to exclude any regions with no flux after alignment.

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 19 High Order Transform of PSF ANd Template Subtraction 20 https://github.com/acbecker/hotpants 21 https://github.com/dguevel/PyZOGY 22 https://reproject.readthedocs.io/en/stable/ 23 https://astroalign.readthedocs.io/en/latest/ 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. Au-toPhOT 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.
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 = π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σ, in the example shown we can see that we are unlikely to find a source with more than ∼ 3, 500 counts, and we hence adopt this as our limiting magnitude.
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 × 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σ (or some other criteria). Fig. 13 demonstrates the artificial source injection package. In this example the image is template subtracted and we use the β ′ 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 β < 0.75. We take the limiting magnitude to be the magnitude at which 80% of sources are lost.

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 ⪅ 19 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.  Fig. 11. Difference between measured magnitude versus catalog magnitude for sequence sources in an image. We adopt a 3σ threshold for source detection corresponding to δ(M) ≈ 0.31 mag using Eq. B.2.  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.
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 be-   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.

Performance
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.

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 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

MAP,Err
[mag] Fig. 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). 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   We include a match to the Paranal extinction curve using α λ = α λ,Rayleigh + α λ,Ozone + α λ,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.
We take the error from the zeropoint calibration (δ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 (δm inst ) requires more attention. The uncertainty in magnitude of a source is related to the S/N ratio as follows: 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 ∼ 1.0875( 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): 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,  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. D.1 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. B.3. In the lower panel we plot the S/N ratio using Eq. B.3 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. D.1 can reproduce the recovered fraction of sources. In other words, for sources measured with a f source ≈ 3σ bkg , roughly half of these are recovered with a S/N > 3; for injected sources with f source ≈ 3.7σ bkg we detect roughly 75%; while virtually all sources are confidently recovered at f source ≈ 4.5σ bkg We thank the Transient Name Server and their open source sample codes 28 . This research made use of Astropy 29 , a communitydeveloped core Python package for Astronomy (Astropy Collaboration et al. 2013Collaboration et al. , 2018. This research made use of data provided by Astrometry.net 30