neighboring sources such that they should be simultaneously modeled, but their segments do not touch. Hence, the size of the dilation structure should be set so that these kinds of nearby sources are correctly assigned into one group. This is most easily assessed by inspection, and tuned in successive trials.

It is important to note that morphological dilation can destroy segments nearby to larger ones. For this reason, the dilation is carried out on a copy of the segmentation image, which has been made binary such that pixels assigned to the background are set to zero, and those active pixels assigned to sources are set to 1. The segments that are already touching are now indistinguishable, and the dilation simply enlarges the footprint of contiguous regions of active pixels. The small segments remain identifiable from the segmentation image. This is important, because the group pixels belong to the group itself; no one group pixel belongs to a single source. That ownership is retained in the original segmentation only. This is essential because, while the joint likelihood maximized by *The Tractor* is computed over the group pixels, *The Farmer* can still judge the fit of individual sources from the $\chi^2$ computed over their uniquely owned pixels.

In some cases, the segments produced at detection may be too large, and so they overgroup sources. While this is not a problem scientifically, it increases the computational complexity of the fit, which can lead to poor model performance, or worse, the joint model may even fail to converge altogether. However, unlike morphological dilation, which cannot destroy groups of pixels, morphological erosion can destroy the smallest segments typically containing one source. This is a limit that must be avoided in order for *The Farmer*'s decision tree to work. More work is required to address this case.

A limitation of this approach is that groups are defined based on the detection image, its effective resolution, as well as the depths and properties of its constituent bands. A group determined from well-resolved optical images will likely miss pixels with significant flux when applied to sources in drastically lower-resolution images. This can be overcome by further dilating each group on a band-by-band basis such that all of the relevant pixels are now constraints on the model. This comes with a dilemma, however, as crowding is worse in low-resolution images of the same depth, and so the light from sources not originally included in the group may now contribute. Yet these nearby sources are not described by the existing group model, and so leaving their flux unaccounted for may instigate a bias in the photometry. The only tractable option seems to be to join these groups and perform the forced photometry in a simultaneous optimization. However, the shapes of these models were never determined together, and so it is uncertain how well the new group of models would perform. Worse, most sources in the deepest IRAC images are blended to some degree, and so strictly keeping to this philosophy of joint optimization of all overlapping sources would require every source to be simultaneously fit. While not impossible (e.g., Lang et al. 2016b), it is potentially computationally expensive. Alternative strategies will be explored in future work.

**What sets the overlap sizes for groups?** Although groups of sources are limited to their footprint whose pixels are identified by dilating source segments, the groups themselves are saved in memory as rectangular arrays whose dimensions are set by the maximum extent of the group footprint. Although the pixels inside of the rectangular array but outside the group footprint

(which can often be fractal-like in shape) do not provide any constraining power as their weight is set to zero, the models are still realized onto the larger array during the optimization. It is generally best if these models are not truncated whatsoever, and so *The Farmer* enlarges the dimensions of the group array by a set number of pixels. This is not only for numerical reasons internal to *The Tractor* but also a requirement if post-processing apertures are to measure the full extent of the joint model image. Truncation of that joint model will mean that the wings will not be realized, and so the largest apertures will underestimate the true flux. Thankfully, if the models are correctly normalized, then the truncation will *not* affect the best-fit normalization coefficient from which the source flux from *The Tractor* is derived. Nonetheless it is advisable that the group array size is large enough so that the PSF stamp would not be truncated for a source placed near the edge of main group footprint.

## A.2. Selection Functions and Image Depth

One must be cognisant regarding which band should be used to determine the models and their best-fit parameters. In fact, this is not a free choice. Using a band outside of those used in the detection image is inappropriate because there may be sources identified in the detection image that do not have flux in the chosen modeling image. If one is to maintain the selection function constructed by the detection strategy, then it must be guaranteed that a detected source has sufficient signal to constrain its model. Otherwise, the sources without models cannot be photometered, and so the selection function changes in a nontrivial way. For the same reason, it is also inadvisable to use only one band of a multiband detection image, or even the bands that define the spectral domain of the detection image. Nor is it advisable to attempt to model sources in a coadded image as the effective PSF is not easily characterized, and the FWHM of the constituent PSFs can produce additional variation in the surface brightness profiles. Therefore, it is strongly recommended that the models be produced from precisely the same bands and images that were used or combined to make the detection image.

Measuring the photometry of a source in an image that contains additional sources outside the selection function (by virtue of not being detected) presents another often encountered dilemma, although common also to aperture-based methods. This is because signal from an additional, undetected source is not described by the set of models assigned to a group. For instance, a red source that is undetected in a predominantly blue selection function may in a red band appear next to a known blue source. Although fixing model shapes helps avoid contamination, it is possible that the likelihood will be maximized by increasing the flux parameter of the blue model such that some of the flux from the new, red source is inadvertently accounted for, thus biasing the photometry for the blue source in that red band. Often times, these cases can be identified afterwards from diagnostics provided by *The Farmer*, although not guaranteed.

A similar situation is encountered when forcing photometry onto deeper bands of the same wavelength as the detection, and although such images typically can provide better photometric constraints, they may at the same time introduce bias by introducing new, undetected sources. This means that ideally all sources in a forced photometry image should be modeled, which requires that they were detected. However, identifying
these new sources automatically ahead of photometry is not
practical as lists of detected sources will differ due the blends;
the two catalogs must then somehow be reconciled and
segmentation maps merged. Doing so in limited numbers is
possible with careful supervision, typically with the assumption
that new sources are unresolved to avoid reprocessing the
decision tree (as used to photometer optically dark sources in
Jin et al. 2022). This potentially pathological issue will be
addressed in future work.

### A.3. *Models, Morphological Corrections, and Drifting*

One significant complication with *The Farmer* is that the
decision tree needs to be tuned. Because the central operation
of the decision tree is to separate resolved and unresolved
sources, its parameters are most sensitive to the resolution of
the image. A subtended size correlates strongly with apparent
brightness, and so sources in deep images typically become
unresolved around a certain magnitude threshold. In order to
succeed, the decision tree needs to be tuned such that it
correctly assigns unresolved models to essentially all sources
fainter than this limit, in addition to bright point sources. A
photometric bias can develop if instead the decision tree
assigns resolved models to unresolved sources, or vice versa.
This can be readily diagnosed from number counts, which
should be smooth and increase monotonically with decreasing
brightness. If the decision tree is not providing adequate model
type assignments, the number counts of the detection bands
will either contract toward a sharp rise or flatten into a plateau
around the resolution threshold. An unresolved model assigned
to a resolved source tends to produce an underestimated flux,
thereby moving these typically bright but comparatively rare
sources toward fainter magnitudes thus creating a plateau. In
this case, it is likely that the decision tree poorly tuned such that
PointSource models are too easily assigned, and so the $\chi^2$
penalty to the PointSource models should be lowered. A
resolved model assigned to an unresolved source tends to
produce overestimated flux, thereby moving these typically
faint but abundant sources toward brighter magnitudes thus
creating a sharp rise in counts. In this case, the $\chi^2$
penalty of PointSource models should be increased so that it is easier for
sources to be assigned an unresolved model. Number counts
are not as sensitive to which resolved model is assigned to a
resolved source (e.g., ExpGalaxy or DevGalaxy), and so the
corresponding parameters are most easily tuned by examining
residuals of bright, resolved sources.

It may not be possible to assign a simple parametric model to
a particular source. It might be that the source is actually two
blended together. Meanwhile, the brightest sources tend to be
resolved and have features such as spiral arms, bars, and
starbursts that are not described by the smooth models from
*The Tractor*. As such, model performance tends to decrease
for bright, resolved sources (e.g., spirals). While the presence
of poorly fit morphological features will be indicated in the
residual statistics (e.g., $\chi^2$), the associated photometry will
likely be biased in some way. This is especially true for space-
based imaging (e.g., HST) where the space spanned by models
from *The Tractor* are divorced from the real space spanned
by highly resolved galaxies. While aperture photometry should
be less biased, they are unable to inform about the presence of
morphological features.

Chromatic changes in morphology presents a challenge for
*The Farmer*. The model for a given source during the

modeling stage may be simultaneously constrained by multiple
bands, but *The Tractor* allows only one shape shared
between the bands. Therefore, the shapes reported by *The
Farmer* from the modeling stage are most appropriate for the
modeling bands with the largest weights. Forced photometry in
regular operation proceeds by only allowing the flux to vary
with the shape fixed, meaning that changes in morphology are
not accounted for by the model. However, *The Farmer*
makes it possible to perform forced photometry on each band
separately so that the shape parameters can be allowed to vary
in each case with or without priors, albeit at greater
computational expense and runs the danger of overfitting. It
is important to note that forcing models derived from well-
resolved bands onto images of lower resolution is typically
successful as the larger PSF of the forced photometry band
makes the photometric measurement less sensitive to morph-
ology. However, forcing models derived from low-resolution
images onto bands at high spatial resolution typically results in
a poor performance as the band of interest contains more
information than the model can describe.

As discussed in Portillo et al. (2020), flux and shape
estimates can suffer from biases introduced from inadequate
centroiding. Given the great number of multiwavelength
images and facilities involved in modern surveys, even small
astrometric offsets can impact the measurements derived from
model fitting. Hence, *The Farmer* allows the user to unfix the
centroid position of each model and introduces a Gaussian
prior on its position, on a band-by-band basis. This prior acts to
penalize the likelihood of the model fit if the model obtains a
centroid that is beyond the distance set by the prior (i.e., drifts).
This drifting can be especially prevalent in the case of a known
faint source next to an undetected bright neighbor, which
because it is not accounted for by the model will cause the
model of the faint source to move toward the bright source,
whose unaddressed presence counts against the likelihood more
than the original, fainter source. Priors can be set on the
position, although their widths are usually determined by
successive trials.

It is important to appreciate that the grouping of sources
imparts a significant advantage over fitting individual sources.
Because groups of sources are photometered separately from
other groups, a failure of the model in one group does not affect
any other group. Let us consider the unfortunate example in
which a galaxy is assigned an inaccurate model whose large
axis ratio results in wings extending well beyond the group.
While those wings will be a problem for the source in question,
and perhaps its group members as well, they will not affect any
other group in the image. Hence, while this is an issue for the
residual map, there is no reason to be concerned about the
photometry of the other group as they were fitted in an entirely
separate optimization in isolation of the problematic source.
However, this advantage effectively decouples the recon-
structed brick-level residual image from the photometry and so
complicates searches for sources in residuals. As mentioned in
Section 3.1, *The Farmer* has built-in functions to filter out
these problematic models.

### A.4. *Source Deblending*

While profile-fitting photometry can be used to deblend two
sources, they first must be identified as separate objects, which
in turn depends on the original source detection. As such,
deblending sources at the detection stage is not a problem,
these new sources automatically ahead of photometry is not
practical as lists of detected sources will differ due the blends;
the two catalogs must then somehow be reconciled and
segmentation maps merged. Doing so in limited numbers is
possible with careful supervision, typically with the assumption
that new sources are unresolved to avoid reprocessing the
decision tree (as used to photometer optically dark sources in
Jin et al. 2022). This potentially pathological issue will be
addressed in future work.

### A.3. *Models, Morphological Corrections, and Drifting*

One significant complication with *The Farmer* is that the
decision tree needs to be tuned. Because the central operation
of the decision tree is to separate resolved and unresolved
sources, its parameters are most sensitive to the resolution of
the image. A subtended size correlates strongly with apparent
brightness, and so sources in deep images typically become
unresolved around a certain magnitude threshold. In order to
succeed, the decision tree needs to be tuned such that it
correctly assigns unresolved models to essentially all sources
fainter than this limit, in addition to bright point sources. A
photometric bias can develop if instead the decision tree
assigns resolved models to unresolved sources, or vice versa.
This can be readily diagnosed from number counts, which
should be smooth and increase monotonically with decreasing
brightness. If the decision tree is not providing adequate model
type assignments, the number counts of the detection bands
will either contract toward a sharp rise or flatten into a plateau
around the resolution threshold. An unresolved model assigned
to a resolved source tends to produce an underestimated flux,
thereby moving these typically bright but comparatively rare
sources toward fainter magnitudes thus creating a plateau. In
this case, it is likely that the decision tree poorly tuned such that
PointSource models are too easily assigned, and so the $\chi^2$
penalty to the PointSource models should be lowered. A
resolved model assigned to an unresolved source tends to
produce overestimated flux, thereby moving these typically
faint but abundant sources toward brighter magnitudes thus
creating a sharp rise in counts. In this case, the $\chi^2$
penalty of PointSource models should be increased so that it is easier for
sources to be assigned an unresolved model. Number counts
are not as sensitive to which resolved model is assigned to a
resolved source (e.g., ExpGalaxy or DevGalaxy), and so the
corresponding parameters are most easily tuned by examining
residuals of bright, resolved sources.

It may not be possible to assign a simple parametric model to
a particular source. It might be that the source is actually two
blended together. Meanwhile, the brightest sources tend to be
resolved and have features such as spiral arms, bars, and
starbursts that are not described by the smooth models from
*The Tractor*. As such, model performance tends to decrease
for bright, resolved sources (e.g., spirals). While the presence
of poorly fit morphological features will be indicated in the
residual statistics (e.g., $\chi^2$), the associated photometry will
likely be biased in some way. This is especially true for space-
based imaging (e.g., HST) where the space spanned by models
from *The Tractor* are divorced from the real space spanned
by highly resolved galaxies. While aperture photometry should
be less biased, they are unable to inform about the presence of
morphological features.

Chromatic changes in morphology presents a challenge for
*The Farmer*. The model for a given source during the

modeling stage may be simultaneously constrained by multiple
bands, but *The Tractor* allows only one shape shared
between the bands. Therefore, the shapes reported by *The
Farmer* from the modeling stage are most appropriate for the
modeling bands with the largest weights. Forced photometry in
regular operation proceeds by only allowing the flux to vary
with the shape fixed, meaning that changes in morphology are
not accounted for by the model. However, *The Farmer*
makes it possible to perform forced photometry on each band
separately so that the shape parameters can be allowed to vary
in each case with or without priors, albeit at greater
computational expense and runs the danger of overfitting. It
is important to note that forcing models derived from well-
resolved bands onto images of lower resolution is typically
successful as the larger PSF of the forced photometry band
makes the photometric measurement less sensitive to morph-
ology. However, forcing models derived from low-resolution
images onto bands at high spatial resolution typically results in
a poor performance as the band of interest contains more
information than the model can describe.

As discussed in Portillo et al. (2020), flux and shape
estimates can suffer from biases introduced from inadequate
centroiding. Given the great number of multiwavelength
images and facilities involved in modern surveys, even small
astrometric offsets can impact the measurements derived from
model fitting. Hence, *The Farmer* allows the user to unfix the
centroid position of each model and introduces a Gaussian
prior on its position, on a band-by-band basis. This prior acts to
penalize the likelihood of the model fit if the model obtains a
centroid that is beyond the distance set by the prior (i.e., drifts).
This drifting can be especially prevalent in the case of a known
faint source next to an undetected bright neighbor, which
because it is not accounted for by the model will cause the
model of the faint source to move toward the bright source,
whose unaddressed presence counts against the likelihood more
than the original, fainter source. Priors can be set on the
position, although their widths are usually determined by
successive trials.

It is important to appreciate that the grouping of sources
imparts a significant advantage over fitting individual sources.
Because groups of sources are photometered separately from
other groups, a failure of the model in one group does not affect
any other group. Let us consider the unfortunate example in
which a galaxy is assigned an inaccurate model whose large
axis ratio results in wings extending well beyond the group.
While those wings will be a problem for the source in question,
and perhaps its group members as well, they will not affect any
other group in the image. Hence, while this is an issue for the
residual map, there is no reason to be concerned about the
photometry of the other group as they were fitted in an entirely
separate optimization in isolation of the problematic source.
However, this advantage effectively decouples the recon-
structed brick-level residual image from the photometry and so
complicates searches for sources in residuals. As mentioned in
Section 3.1, *The Farmer* has built-in functions to filter out
these problematic models.

### A.4. *Source Deblending*

While profile-fitting photometry can be used to deblend two
sources, they first must be identified as separate objects, which
in turn depends on the original source detection. As such,
deblending sources at the detection stage is not a problem,
<figure><img src="image_20.png" /><figcaption>**Figure 17.** A point source is simulated in the vicinity of a large, central elliptical galaxy. Models are fitted for three cases: the sources are blended and have only one centroid (mixed); the sources are blended, modeled, and then the missing source is recovered from the residual image and modeled (mixed-recovered); and lastly, both sources are a priori known and simultaneously fit (separated). Each measurement is repeated over a grid of relative brightness (0 meaning that the point source is negligible) and the distance from the central elliptical to the point source (20 means the point source is in the top left corner). While gray areas indicate successful recovery of the input (true) flux of the elliptical source, red areas indicate that the flux of the elliptical is underestimated. White areas in the middle panel indicate where the point source is not detected in the mixed residual. The model and residual of three situations are shown for each measurement strategy.</figcaption></figure>

which profile-fitting photometry can (or should) solve and instead is well-suited to address the related, but there is a distinct issue of accurately measuring the flux of two *identified* but blended sources. It is essential, therefore, to understand that, if two nearby sources are not successfully deblended at detection, then profile-fitting techniques should not be expected to reliably deblend them either.

This concept is demonstrated in Figure 17 whereby a point source is placed in the vicinity of a bright resolved galaxy, and the appropriate models are assumed to be known. Several cases are set up by varying their distance and relative brightness. Attempting to photometer both of them with only one model produces expectedly poor fits in several cases. The system is then evolved by allowing it to subtract the first source, find the brightest residual source, and refit the original using two centroids, which in turn improves the performance in cases where the residual source can be identified. However, in practice, this is dangerous if one does not know beforehand whether there is another source or whether the model for the

one source was simply a poor fit. Lastly, the two sources are fit by two appropriate models, which results in accurate photometry at all distances and relative brightness. Hence, deblending with profile-fitting photometry requires the correct number of models (and centroids) to optimize for a given group of sources.

What is little appreciated, however, is that this behavior is undoubtedly an advantage. While aperture techniques do not make any assumption about source morphology and are hence extremely powerful in the face of resolved structural features in galaxies, their ability to identify cases of sources blended at detection or quantify contamination in photometry of photometrically blended sources is severely limited. Parametric profile-fitting techniques suffer from neither of these drawbacks. So long as intrinsically blended sources are not well-described also by a single profile,<fnref n="23" /> then the optimized model

<footnote n="23">²³ In such cases, sources cannot be identified as separate objects without higher-resolution ancillary data anyways.</footnote>
<figure><img src="image_20.png" /><figcaption>**Figure 17.** A point source is simulated in the vicinity of a large, central elliptical galaxy. Models are fitted for three cases: the sources are blended and have only one centroid (mixed); the sources are blended, modeled, and then the missing source is recovered from the residual image and modeled (mixed-recovered); and lastly, both sources are a priori known and simultaneously fit (separated). Each measurement is repeated over a grid of relative brightness (0 meaning that the point source is negligible) and the distance from the central elliptical to the point source (20 means the point source is in the top left corner). While gray areas indicate successful recovery of the input (true) flux of the elliptical source, red areas indicate that the flux of the elliptical is underestimated. White areas in the middle panel indicate where the point source is not detected in the mixed residual. The model and residual of three situations are shown for each measurement strategy.</figcaption></figure>

which profile-fitting photometry can (or should) solve and instead is well-suited to address the related, but there is a distinct issue of accurately measuring the flux of two *identified* but blended sources. It is essential, therefore, to understand that, if two nearby sources are not successfully deblended at detection, then profile-fitting techniques should not be expected to reliably deblend them either.

This concept is demonstrated in Figure 17 whereby a point source is placed in the vicinity of a bright resolved galaxy, and the appropriate models are assumed to be known. Several cases are set up by varying their distance and relative brightness. Attempting to photometer both of them with only one model produces expectedly poor fits in several cases. The system is then evolved by allowing it to subtract the first source, find the brightest residual source, and refit the original using two centroids, which in turn improves the performance in cases where the residual source can be identified. However, in practice, this is dangerous if one does not know beforehand whether there is another source or whether the model for the

one source was simply a poor fit. Lastly, the two sources are fit by two appropriate models, which results in accurate photometry at all distances and relative brightness. Hence, deblending with profile-fitting photometry requires the correct number of models (and centroids) to optimize for a given group of sources.

What is little appreciated, however, is that this behavior is undoubtedly an advantage. While aperture techniques do not make any assumption about source morphology and are hence extremely powerful in the face of resolved structural features in galaxies, their ability to identify cases of sources blended at detection or quantify contamination in photometry of photometrically blended sources is severely limited. Parametric profile-fitting techniques suffer from neither of these drawbacks. So long as intrinsically blended sources are not well-described also by a single profile,<fnref n="23" /> then the optimized model

<footnote n="23">²³ In such cases, sources cannot be identified as separate objects without higher-resolution ancillary data anyways.</footnote>
will not achieve a satisfactory fit. These cases may be
confidently identified a posteriori using statistics such as those
discussed in Section 3.4.2.

A.5. Comparison to Similar Methods

These advantages and limitations hold mainly for purely
parametric models. There exists another, related class, which uses
a high-resolution cutout of a given source as its model that can be
used to photometer other bands by first convolving it with an
appropriate kernel to translate its native PSF to that of the band of
interest, and then scaling the unit-normalized model to match the
source in that band. These stamps have a distinct advantage over
parametric models in that they can exploit the resolution of the
cutout image to capture structural features not describable by
typically smooth parametric models. Without shape parameters to
constrain, these stamps can be extremely efficient in measuring
fluxes as essentially a scaling factor between the PSF-transformed
stamp and the source in question. While simpler than purely
parametric models, this approach requires a deep high-resolution
image, which contains every detected source (if not the same
image as that used for detection). More so, the PSF must be well-
understood to provide kernels to map the original PSF to those of
the lower-resolution images, a drawback not shared by parametric
models. The stamp must also be resampled to match the pixel
scale of the image to be photometered. For example, an HST-
derived stamp of a marginally resolved source applied to Spitzer
provides no significant advantage over a parametric model.
Worse, the morphology described by the stamp is assumed to be
constant, and so there can arise significant effects between the
wavelength of the stamp image and that of the image to be
photometered. Such stamp-based profile-fitting software includes
TFIT (Laidler et al. 2007), T-PHOT (Merlin et al. 2015, 2016),
PyGFIT (Mancone et al. 2013), Morfometryka (Ferrari et al.
2015), LAMBDAR (Wright et al. 2016), and GOLFIR (Kokorev
et al. 2022). Each one takes its own approach to the problem of
flux estimation in terms of available models, parameterization,
algorithm speed, flexibility, and accessibility. As discussed in
Appendix A.3, purely parametric models can overcome the
limitations of these stamp-based codes by freely fitting the shape
of the model, possibly with some prior constraints (e.g., GALFIT,
Peng et al. 2002, 2010, ProFit, Robotham et al. 2017;
SExtractor++, Bertin et al. 2020; Kümmel et al. 2020;
GALAPAGOS-2, Häußler et al. 2022).

One of the most similar photometry frameworks to The
Farmer is HSCPipe, in part because they both inherit the
profile-fitting approach of SDSS (Stoughton et al. 2002). As
discussed in Aihara et al. (2019), HSCPipe provides model-
based photometry by fitting both point-source (PSF) and
composite galaxy (cModel) profiles to each galaxy individu-
ally. Even though both resolved and pointlike models are tried,
unlike The Farmer, they are tried for each source
independent of their neighbors, which for blended sources
can lead to inconsistencies (as demonstrated in Figure 1).
Furthermore, HSCPipe does not choose a best-fit model type
for each source and instead provides fluxes measured from each
profile assuming independence from neighbors. While this is
computationally faster than a decision tree, it is also inefficient
to fit unresolved sources with highly parameterized composite
models (which risk overfitting). As of version 8 of
HSCPipe,<fnref n="24" /> only the likelihood of the CModel fits are

reported, and so a consistent statistical comparison with the
PSF models is not possible, which leaves only a binary
extendedness flag to indicate a resolved source. The Farmer
provides not only a best-fit model type for each source but also
a suite of statistics from which the reliability of that model can
be assessed.

Although limited to low-resolution IRAC images, the IRACLEAN software (Hsieh et al. 2012) measures photometry by iteratively subtracting PSFs at detected source centroids until the residual is clean of signal to some user-defined level. Although broadly similar to The Farmer, IRACLEAN does not perform model-fitting in a classical sense as an unbounded iterative subtraction of the PSF is equivalent to a model with effectively unlimited parameters. Furthermore, the order in which sources are processed can introduce hysteresis in crowded regions. There is also the danger of overfitting, as IRACLEAN will continue subtracting a scaled PSF stamp until a given segment has no more signal, which in the case of a blend will combine the flux of the two sources into one photometric measurement. The Farmer’s parametric models act as a prior, which can, in some cases, ignore the flux of a neighbor, which is left in the residual, and report statistics flagging the problem to the user. Further discussions and comparisons with IRACLEAN are presented in Weaver et al. (2022).

A.6. Computational Considerations

The computation of sources scales with the number of
sources fit simultaneously as well as the number of free
parameters, meaning that these techniques require significantly
longer runtimes compared to aperture photometry. In the
context of modern deep surveys containing millions of sources
(many of which are resolved), fitting all sources simultaneously
would be enormously complex requiring significant computa-
tional resources. However, a high degree of parallelization can
be achieved so long as the source density and resolution allow
for distinct groups of sources to be identified and fit separately.
A practical approach is to process each brick independently.
Source groups are constructed at a runtime and kept in memory
only, so they are ideal for being run in parallel, e.g., across
many CPUs of a given cluster node.

However, computational time still increases with the number
of free parameters. As such, the modeling stage is not only
more complicated than forced photometry because of the
several trials of the decision tree but also because shapes are
left to vary in some stages. It is for this reason that the decision
tree starts with simple models and moves toward complexity,
or in other words, computational expense. If the conditions of
the decision tree are satisfied for every source, then the models
are assigned without moving to the next stage. For example, an
isolated point source should only be tried out with a
PointSource and SimpleGalaxy model whereupon it should
satisfy the PointSource criterion and stop. Each of these model
types have three parameters (two for position and one for flux)
and so are incredibly quick compared to a CompositeGalaxy
with ten parameters.

Unfortunately, computational time also increases with source
crowding given the stronger covariance between neighboring
models. Many separate sources can be modeled independently
and in parallel without a loss of accuracy. However, because
deep images of crowded fields are best photometered when
groups of nearby sources are simultaneously modeled, the

<footnote n="24">²⁴ https://hsc.mtk.nao.ac.jp/pipedoc/pipedoc_8_e/index.html</footnote>
will not achieve a satisfactory fit. These cases may be
confidently identified a posteriori using statistics such as those
discussed in Section 3.4.2.

A.5. *Comparison to Similar Methods*

These advantages and limitations hold mainly for purely
parametric models. There exists another, related class, which uses
a high-resolution cutout of a given source as its model that can be
used to photometer other bands by first convolving it with an
appropriate kernel to translate its native PSF to that of the band of
interest, and then scaling the unit-normalized model to match the
source in that band. These stamps have a distinct advantage over
parametric models in that they can exploit the resolution of the
cutout image to capture structural features not describable by
typically smooth parametric models. Without shape parameters to
constrain, these stamps can be extremely efficient in measuring
fluxes as essentially a scaling factor between the PSF-transformed
stamp and the source in question. While simpler than purely
parametric models, this approach requires a deep high-resolution
image, which contains every detected source (if not the same
image as that used for detection). More so, the PSF must be well-
understood to provide kernels to map the original PSF to those of
the lower-resolution images, a drawback not shared by parametric
models. The stamp must also be resampled to match the pixel
scale of the image to be photometered. For example, an HST-
derived stamp of a marginally resolved source applied to Spitzer
provides no significant advantage over a parametric model.
Worse, the morphology described by the stamp is assumed to be
constant, and so there can arise significant effects between the
wavelength of the stamp image and that of the image to be
photometered. Such stamp-based profile-fitting software includes
TFIT (Laidler et al. 2007), T-PHOT (Merlin et al. 2015, 2016),
PyGFIT (Mancone et al. 2013), Morfometryka (Ferrari et al.
2015), LAMBDAR (Wright et al. 2016), and GOLFIR (Kokorev
et al. 2022). Each one takes its own approach to the problem of
flux estimation in terms of available models, parameterization,
algorithm speed, flexibility, and accessibility. As discussed in
Appendix A.3, purely parametric models can overcome the
limitations of these stamp-based codes by freely fitting the shape
of the model, possibly with some prior constraints (e.g., GALFIT,
Peng et al. 2002, 2010, ProFit, Robotham et al. 2017;
SExtractor++, Bertin et al. 2020; Kümmel et al. 2020;
GALAPAGOS-2, Häußler et al. 2022).

One of the most similar photometry frameworks to The
Farmer is HSCPipe, in part because they both inherit the
profile-fitting approach of SDSS (Stoughton et al. 2002). As
discussed in Aihara et al. (2019), HSCPipe provides model-
based photometry by fitting both point-source (PSF) and
composite galaxy (cModel) profiles to each galaxy individu-
ally. Even though both resolved and pointlike models are tried,
unlike The Farmer, they are tried for each source
independent of their neighbors, which for blended sources
can lead to inconsistencies (as demonstrated in Figure 1).
Furthermore, HSCPipe does not choose a best-fit model type
for each source and instead provides fluxes measured from each
profile assuming independence from neighbors. While this is
computationally faster than a decision tree, it is also inefficient
to fit unresolved sources with highly parameterized composite
models (which risk overfitting). As of version 8 of
HSCPipe,<fnref n="24" /> only the likelihood of the CModel fits are

reported, and so a consistent statistical comparison with the
PSF models is not possible, which leaves only a binary
extendedness flag to indicate a resolved source. The Farmer
provides not only a best-fit model type for each source but also
a suite of statistics from which the reliability of that model can
be assessed.

Although limited to low-resolution IRAC images, the IRACLEAN software (Hsieh et al. 2012) measures photometry by iteratively subtracting PSFs at detected source centroids until the residual is clean of signal to some user-defined level. Although broadly similar to The Farmer, IRACLEAN does not perform model-fitting in a classical sense as an unbounded iterative subtraction of the PSF is equivalent to a model with effectively unlimited parameters. Furthermore, the order in which sources are processed can introduce hysteresis in crowded regions. There is also the danger of overfitting, as IRACLEAN will continue subtracting a scaled PSF stamp until a given segment has no more signal, which in the case of a blend will combine the flux of the two sources into one photometric measurement. The Farmer’s parametric models act as a prior, which can, in some cases, ignore the flux of a neighbor, which is left in the residual, and report statistics flagging the problem to the user. Further discussions and comparisons with IRACLEAN are presented in Weaver et al. (2022).

A.6. *Computational Considerations*

The computation of sources scales with the number of
sources fit simultaneously as well as the number of free
parameters, meaning that these techniques require significantly
longer runtimes compared to aperture photometry. In the
context of modern deep surveys containing millions of sources
(many of which are resolved), fitting all sources simultaneously
would be enormously complex requiring significant computa-
tional resources. However, a high degree of parallelization can
be achieved so long as the source density and resolution allow
for distinct groups of sources to be identified and fit separately.
A practical approach is to process each brick independently.
Source groups are constructed at a runtime and kept in memory
only, so they are ideal for being run in parallel, e.g., across
many CPUs of a given cluster node.

However, computational time still increases with the number
of free parameters. As such, the modeling stage is not only
more complicated than forced photometry because of the
several trials of the decision tree but also because shapes are
left to vary in some stages. It is for this reason that the decision
tree starts with simple models and moves toward complexity,
or in other words, computational expense. If the conditions of
the decision tree are satisfied for every source, then the models
are assigned without moving to the next stage. For example, an
isolated point source should only be tried out with a
PointSource and SimpleGalaxy model whereupon it should
satisfy the PointSource criterion and stop. Each of these model
types have three parameters (two for position and one for flux)
and so are incredibly quick compared to a CompositeGalaxy
with ten parameters.

Unfortunately, computational time also increases with source
crowding given the stronger covariance between neighboring
models. Many separate sources can be modeled independently
and in parallel without a loss of accuracy. However, because
deep images of crowded fields are best photometered when
groups of nearby sources are simultaneously modeled, the

<footnote n="24">²⁴ https://hsc.mtk.nao.ac.jp/pipedoc/pipedoc_8_e/index.html</footnote>
complexity and computational expense is greater than if the
same number of sources were fit separately. As such, it is
strongly advised that typical source groups contain as few
members as possible without breaking across two blended
sources. Unfortunately, the situation of source crowding will
only become more difficult as surveys grow deeper. While
apertures will eventually hit a limit, profile-fitting photometry
can forge ahead, albeit with a greater computational cost.

ORCID iDs

J. R. Weaver https://orcid.org/0000-0003-1614-196X

L. Zalesky https://orcid.org/0000-0001-5680-2326

V. Kokorev https://orcid.org/0000-0002-5588-9156

C. J. R. McPartland https://orcid.org/0000-0003-0639-025X

N. Chartab https://orcid.org/0000-0003-3691-937X

K. M. L. Gould https://orcid.org/0000-0003-4196-5960

M. Shuntov https://orcid.org/0000-0002-7087-0701

I. Davidzon https://orcid.org/0000-0002-2951-7519

A. Faisst https://orcid.org/0000-0002-9382-9832

P. L. Capak https://orcid.org/0000-0003-3578-6843

S. Toft https://orcid.org/0000-0003-3631-7176

B. Mobasher https://orcid.org/0000-0001-5846-4404

D. B. Sanders https://orcid.org/0000-0002-1233-9998

O. B. Kauffmann https://orcid.org/0000-0001-5283-4662

H. J. McCracken https://orcid.org/0000-0002-9489-7765

O. Ilbert https://orcid.org/0000-0002-7303-4397

G. Brammer https://orcid.org/0000-0003-2680-005X

References

Aihara, H., AlSayyad, Y., Ando, M., et al. 2019, PASJ, 71, 114

Astropy Collaboration, Price-Whelan, A. M., Sipőcz, B. M., et al. 2018, AJ,
156, 123

Astropy Collaboration, Robitaille, T. P., Tollerud, E. J., et al. 2013, A&A,
558, A33

Barbary, K. 2016, JOSS, 1, 58

Bertin, E., 2010 SWarp: Resampling and Co-adding FITS Images Together, Astrophysics Source Code Library, ascl:1010.068

Bertin, E. 2013, PSFEx: Point Spread Function Extractor, Astrophysics Source
Code Library, ascl:1301.001

Bertin, E., & Arnouts, S. 1996, A&AS, 117, 393

Bertin, E., Schefer, M., Apostolakos, N., et al. 2020, in ASP Conf. Ser. 527, Astronomical Data Analysis Software and Systems XXIX, ed. R. Pizzo et al. (San Francisco, CA: ASP), 461

Bigourdan, G. 1888, BuAsI, 5, 303

Cramer, H. 1946, Mathematical Methods of Statistics (Princeton, NJ: Princeton Univ. Press)

D'Agostino, R. B. 1970, *Biometrika*, 57, 679

D'Agostino, R. B., & Belanger, A. 1990, Am. Stat., 44, 316
de Vaucouleurs, G. 1948, AnAp, 11, 247

Dey, A., Schlegel, D. J., Lang, D., et al. 2019, AJ, 157, 168

Ding, X., Birrer, S., Treu, T., & Silverman, J. D. 2021, arXiv:2111.08721

Faisst, A. L., Chary, R. R., Fajardo-Acosta, S., et al. 2022, ApJ, 929, 66

Ferrari, F., de Carvalho, R. R., & Trevisan, M. 2015, ApJ, 814, 55

Girelli, G., Pozzetti, L., Bolzonella, M., et al. 2020, A&A, 634, A135

Haigh, C., Chamba, N., Venhola, A., et al. 2021, A&A, 645, A107

Häußler, B., Vika, M., Bamford, S. P., et al. 2022, A&A, 664, A92

Holwerda, B. W. 2005, arXiv:astro-ph/0512139

Hsieh, B.-C., Wang, W.-H., Hsieh, C.-C., et al. 2012, ApJS, 203, 23

Hubble, E. 1929, *PNAS*, 15, 168

Hubble, E. P. 1926, ApJ, 64, 321

Hunter, J. D. 2007, CSE, 9, 90

Jin, S., Daddi, E., Magdis, G. E., et al. 2022, A&A, 665, A3

Kauffmann, O. B., Ilbert, O., Weaver, J. R., et al. 2022, A&A, 667, A65

Kokorev, V., Brammer, G., Fujimoto, S., et al. 2022, ApJS, 263, 38

Kümmel, M., Bertin, E., Schefer, M., et al. 2020, in ASP Conf. Ser. 527, Working With the SourceXtractor++ Software, ed. R. Pizzo et al. (San Francisco, CA: ASP), 29

Laidler, V. G., Papovich, C., Grogin, N. A., et al. 2007, PASP, 119, 1325

Laigle, C., McCracken, H. J., Ilbert, O., et al. 2016, ApJS, 224, 24

Lang, D., Hogg, D. W., Mykytyn, D., et al., 2016a The Tractor: Probabilistic astronomical source detection and measurement, Astrophysics Source Code Library, ascl:1604.008

Lang, D., Hogg, D. W., & Schlegel, D. J. 2016b, AJ, 151, 36

Lesser, M. 2015, PASP, 127, 1097

Mancone, C. L., Gonzalez, A. H., Moustakas, L. A., & Price, A. 2013, PASP, 125, 1514

McCracken, H. J., Milvang-Jensen, B., Dunlop, J., et al. 2012, A&A,
544, A156

Merlin, E., Bourne, N., Castellano, M., et al. 2016, A&A, 595, A97

Merlin, E., Fontana, A., Ferguson, H. C., et al. 2015, A&A, 582, A15

Nyland, K., Lacy, M., Sajina, A., et al. 2017, ApJS, 230, 9

Oke, J. B. 1974, ApJS, 27, 21

Peng, C. Y., Ho, L. C., Impey, C. D., & Rix, H.-W. 2002, AJ, 124, 266

Peng, C. Y., Ho, L. C., Impey, C. D., & Rix, H.-W. 2010, AJ, 139, 2097

Portillo, S. K. N., Speagle, J. S., & Finkbeiner, D. P. 2020, AJ, 159, 165

Rao, C. R. 1945, Bull. Calcutta Math. Soc., 37, 81

Robotham, A. S. G., Taranu, D. S., Tobar, R., Moffett, A., & Driver, S. P. 2017, MNRAS, 466, 1513

Rowe, B. T. P., Jarvis, M., Mandelbaum, R., et al. 2015, A&C, 10, 121

Sérsic, J. L. 1963, BAAA, 6, 41

Stetson, P. B. 1987, PASP, 99, 191

Stevans, M. L., Finkelstein, S. L., Kawinwanichakij, L., et al. 2021, ApJ,
921, 58

Stoughton, C., Lupton, R. H., Bernardi, M., et al. 2002, AJ, 123, 485

Szalay, A. S., Connolly, A. J., & Szokoly, G. P. 1999, AJ, 117, 68

van der Walt, S., Colbert, S. C., & Varoquaux, G. 2011, CSE, 13, 22

Weaver, J., & Zalesky, L. 2023, astroweaver/the_farmer: v1.0.0-beta, Zenodo,
doi:10.5281/zenodo.8205817

Weaver, J. R., Kauffmann, O. B., Ilbert, O., et al. 2022, ApJS, 258, 11

Whitaker, K. E., Labbé, I., van Dokkum, P. G., et al. 2011, ApJ, 735, 86

Wright, A. H., Robotham, A. S. G., Bourne, N., et al. 2016, MNRAS, 460, 765
complexity and computational expense is greater than if the
same number of sources were fit separately. As such, it is
strongly advised that typical source groups contain as few
members as possible without breaking across two blended
sources. Unfortunately, the situation of source crowding will
only become more difficult as surveys grow deeper. While
apertures will eventually hit a limit, profile-fitting photometry
can forge ahead, albeit with a greater computational cost.

ORCID iDs

J. R. Weaver https://orcid.org/0000-0003-1614-196X

L. Zalesky https://orcid.org/0000-0001-5680-2326

V. Kokorev https://orcid.org/0000-0002-5588-9156

C. J. R. McPartland https://orcid.org/0000-0003-0639-025X

N. Chartab https://orcid.org/0000-0003-3691-937X

K. M. L. Gould https://orcid.org/0000-0003-4196-5960

M. Shuntov https://orcid.org/0000-0002-7087-0701

I. Davidzon https://orcid.org/0000-0002-2951-7519

A. Faisst https://orcid.org/0000-0002-9382-9832

P. L. Capak https://orcid.org/0000-0003-3578-6843

S. Toft https://orcid.org/0000-0003-3631-7176

B. Mobasher https://orcid.org/0000-0001-5846-4404

D. B. Sanders https://orcid.org/0000-0002-1233-9998

O. B. Kauffmann https://orcid.org/0000-0001-5283-4662

H. J. McCracken https://orcid.org/0000-0002-9489-7765

O. Ilbert https://orcid.org/0000-0002-7303-4397

G. Brammer https://orcid.org/0000-0003-2680-005X

References

Aihara, H., AlSayyad, Y., Ando, M., et al. 2019, PASJ, 71, 114

Astropy Collaboration, Price-Whelan, A. M., Sipőcz, B. M., et al. 2018, AJ,
156, 123

Astropy Collaboration, Robitaille, T. P., Tollerud, E. J., et al. 2013, A&A,
558, A33

Barbary, K. 2016, JOSS, 1, 58

Bertin, E., 2010 SWarp: Resampling and Co-adding FITS Images Together, Astrophysics Source Code Library, ascl:1010.068

Bertin, E. 2013, PSFEx: Point Spread Function Extractor, Astrophysics Source
Code Library, ascl:1301.001

Bertin, E., & Arnouts, S. 1996, A&AS, 117, 393

Bertin, E., Schefer, M., Apostolakos, N., et al. 2020, in ASP Conf. Ser. 527, Astronomical Data Analysis Software and Systems XXIX, ed. R. Pizzo et al. (San Francisco, CA: ASP), 461

Bigourdan, G. 1888, BuAsI, 5, 303

Cramer, H. 1946, Mathematical Methods of Statistics (Princeton, NJ: Princeton Univ. Press)

D'Agostino, R. B. 1970, Biometrika, 57, 679

D'Agostino, R. B., & Belanger, A. 1990, Am. Stat., 44, 316
de Vaucouleurs, G. 1948, AnAp, 11, 247

Dey, A., Schlegel, D. J., Lang, D., et al. 2019, AJ, 157, 168

Ding, X., Birrer, S., Treu, T., & Silverman, J. D. 2021, arXiv:2111.08721

Faisst, A. L., Chary, R. R., Fajardo-Acosta, S., et al. 2022, ApJ, 929, 66

Ferrari, F., de Carvalho, R. R., & Trevisan, M. 2015, ApJ, 814, 55

Girelli, G., Pozzetti, L., Bolzonella, M., et al. 2020, A&A, 634, A135

Haigh, C., Chamba, N., Venhola, A., et al. 2021, A&A, 645, A107

Häußler, B., Vika, M., Bamford, S. P., et al. 2022, A&A, 664, A92

Holwerda, B. W. 2005, arXiv:astro-ph/0512139

Hsieh, B.-C., Wang, W.-H., Hsieh, C.-C., et al. 2012, ApJS, 203, 23

Hubble, E. 1929, PNAS, 15, 168

Hubble, E. P. 1926, ApJ, 64, 321

Hunter, J. D. 2007, CSE, 9, 90

Jin, S., Daddi, E., Magdis, G. E., et al. 2022, A&A, 665, A3

Kauffmann, O. B., Ilbert, O., Weaver, J. R., et al. 2022, A&A, 667, A65

Kokorev, V., Brammer, G., Fujimoto, S., et al. 2022, ApJS, 263, 38

Kümmel, M., Bertin, E., Schefer, M., et al. 2020, in ASP Conf. Ser. 527, Working With the SourceXtractor++ Software, ed. R. Pizzo et al. (San Francisco, CA: ASP), 29

Laidler, V. G., Papovich, C., Grogin, N. A., et al. 2007, PASP, 119, 1325

Laigle, C., McCracken, H. J., Ilbert, O., et al. 2016, ApJS, 224, 24

Lang, D., Hogg, D. W., Mykytyn, D., et al., 2016a The Tractor: Probabilistic astronomical source detection and measurement, Astrophysics Source Code Library, ascl:1604.008

Lang, D., Hogg, D. W., & Schlegel, D. J. 2016b, AJ, 151, 36

Lesser, M. 2015, PASP, 127, 1097

Mancone, C. L., Gonzalez, A. H., Moustakas, L. A., & Price, A. 2013, PASP, 125, 1514

McCracken, H. J., Milvang-Jensen, B., Dunlop, J., et al. 2012, A&A,
544, A156

Merlin, E., Bourne, N., Castellano, M., et al. 2016, A&A, 595, A97

Merlin, E., Fontana, A., Ferguson, H. C., et al. 2015, A&A, 582, A15

Nyland, K., Lacy, M., Sajina, A., et al. 2017, ApJS, 230, 9

Oke, J. B. 1974, ApJS, 27, 21

Peng, C. Y., Ho, L. C., Impey, C. D., & Rix, H.-W. 2002, AJ, 124, 266

Peng, C. Y., Ho, L. C., Impey, C. D., & Rix, H.-W. 2010, AJ, 139, 2097

Portillo, S. K. N., Speagle, J. S., & Finkbeiner, D. P. 2020, AJ, 159, 165

Rao, C. R. 1945, Bull. Calcutta Math. Soc., 37, 81

Robotham, A. S. G., Taranu, D. S., Tobar, R., Moffett, A., & Driver, S. P. 2017, MNRAS, 466, 1513

Rowe, B. T. P., Jarvis, M., Mandelbaum, R., et al. 2015, A&C, 10, 121

Sérsic, J. L. 1963, BAAA, 6, 41

Stetson, P. B. 1987, PASP, 99, 191

Stevans, M. L., Finkelstein, S. L., Kawinwanichakij, L., et al. 2021, ApJ,
921, 58

Stoughton, C., Lupton, R. H., Bernardi, M., et al. 2002, AJ, 123, 485

Szalay, A. S., Connolly, A. J., & Szokoly, G. P. 1999, AJ, 117, 68

van der Walt, S., Colbert, S. C., & Varoquaux, G. 2011, CSE, 13, 22

Weaver, J., & Zalesky, L. 2023, astroweaver/the_farmer: v1.0.0-beta, Zenodo,
doi:10.5281/zenodo.8205817

Weaver, J. R., Kauffmann, O. B., Ilbert, O., et al. 2022, ApJS, 258, 11

Whitaker, K. E., Labbé, I., van Dokkum, P. G., et al. 2011, ApJ, 735, 86

Wright, A. H., Robotham, A. S. G., Bourne, N., et al. 2016, MNRAS, 460, 765