ProFit: Bayesian Profile Fitting of Galaxy Images



\[firstpage\]

galaxies: statistics – galaxies: structure – methods: statistical – techniques: photometric – galaxies: fundamental parameters – methods: data analysis

Introduction {#section_introduction}
============

Galaxy modelling can be broadly separated into two categories: light profile fitting and kinematic dynamical modelling. In dynamical modelling, part or all of the six-dimensional phase space structure is constrained by kinematic data and dynamical constraints such as the Poisson and/or Jeans' equations. By contrast, profile fitting (or profiling) quantifies the *projected* structure of a galaxy on the sky, usually by fitting radially-varying density profiles to one-dimensional, azimuthally-averaged profiles or two-dimensional images. Both methods have been used to infer the presence of distinct structural components in galaxies, such as discs, bulges, bars and spiral arms (so-called decomposition).

@hubb26 is credited as the first to develop a galaxy classification scheme including distinct features or components, including spiral arms and a concentrated central component. As early as @de-v58 it had been quantitatively demonstrated, using photoelectric measurements along the major and minor axes, that M31 comprised a distinct bulge and disc component. In the modern era, large samples of thousands of galaxies have been decomposed quantitatively into distinct components [@alle06; @gado09; @sima11; @lang16; @kenn16]. Such data sets have been used to infer distinct evolutionary pathways and mechanisms [@korm04] for galaxies of different types and compositions and to develop galaxy formation models [@zava08; @driv13; @lace16]. Improving these theories requires both better data (by volume, depth and quality) and analysis methods. This paper offers a new route to reliably divide galaxies into their constituent parts using a new publicly released library and interface (<span>`libprofit`</span>and <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>respectively) for galaxy profile modelling and decomposition. These will be used by the authors for near future large-scale studies, and are being made available to the wider community along with the prospect of practical support and future updates.

The earliest efforts of galaxy structural characterization concentrated on simple one-dimensional intensity profile fitting, leading to the early discovery of the de-Vaucouleurs profile [@de-v48] for describing early-type galaxies and the realization that disc galaxies had close to exponential profiles [@de-v59]. @sers63 generalized these profiles into the $r^{1/n}$ law that remains widely popular today, commonly referred to as the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile [@grah05]. Increasingly complicated one-dimensional component fitting came in work by @korm77 and @kent85, where galaxies were decomposed into distinct components rather than treated as having a single light profile.

The earliest efforts at two-dimensional galaxy profiling came with the work of @andr95, @byun95, @de-j96, @scha95 and @wada99. The latter four approaches are broadly similar in application, and are recognizably similar to modern two-dimensional galaxy fitting efforts. The basic philosophy was the same as for previous one-dimensional work, the aim being to find the distinct light components of galaxies, but here the analysis was made using image pixels directly rather than by fitting azimuthally averaged ellipses of light.

A large number of key insights into galaxy properties have been uncovered through both one-dimensional and two-dimensional structural analysis. Early work found that the disc component of galaxies is very well represented by an exponential drop-off in light [e.g. @free70; @korm77]. Of recent interest in the astronomy literature is the relationship between galaxy mass and size, both globally [@shen03; @lang15] and for individual components [@lang16]. There is also a large body of work investigating the luminosity-surface brightness relation for different classes of galaxy [see reviews by @ferg94; @grah13], as well as investigating the distribution of mass for different types of structure [e.g. @dres87; @bens07; @driv07; @kelv14; @kenn16; @moff16a; @moff16b].

Such global morphological properties of galaxies are finally being utilized and predicted by the newest theoretical work, both in the regime of semi-analytic models [@lace16] and cosmological hydrodynamic simulations [@voge14; @scha15]. Given the constraints that galaxy morphology can offer theory, it will be increasingly important that well quantified structural measurements for galaxy properties are extracted from current and future large-area, deep, high-resolution photometric surveys [e.g. Kilo Degree Survey (KiDS), Dark Energy Survey (DES), Hyper Suprime Camera (HSC) and Large Synoptic Survey Telescope (LSST): @kuij15; @des05; @miya13; @abel09 respectively].

There remains some debate regarding the relative merits of one-dimensional and two-dimensional image analysis [e.g. @savo16]. This introduction will not serve as a thorough discussion of the various issues, but we will discuss a few key points. One-dimensional fitting relies heavily on an additional step in the analysis: the galaxy must be collapsed into a one-dimensional profile in some manner, usually using software such as IRAF's ELLIPSE task. It is impossible to do this in an entirely model independent manner when the galaxy is anything other than smoothly changing isophotes; however, such an approach can easily cope with a smoothly varying orientation in the isophotes. A caveat to this is that it is unclear formally how the atmospheric point-spread function (PSF) should be treated in one-dimensional fitting [note that there are analytic solutions for the specific case of face-on convolution, see @prit81]. Even a galaxy constructed from perfect concentric ellipses will become artificially circular towards the profile centre when convolved with a circular PSF. Whilst this effect is captured from the one-dimensional profile information, it is non-trivial to properly propagate this information such that you measure the intrinsic two-dimensional profile properties of the galaxy. Collapsing two-dimensional information into a one-dimensional form is almost always a lossy process (it can be no better than lossless), and real azimuthal profile fluctuations may be lost entirely. Correctly propagating errors is also non-trivial, and in practice these are often not used at all [an approach advocated in @savo16].

There are two other critical aspects of this collapsing process that can have a dramatic effect on galaxy profiling: the centre of the galaxy must be fixed exactly a-priori and the components must share the same centre. The freedom to fit for the galaxy centre is often important for capturing the steepest inner parts of a galaxy properly (especially if the centre is sub-pixel) and galaxy components sometimes do not share exactly the same centres [@lang15].

Two-dimensional fitting is closer in spirit to Bayesian generative model fitting, e.g. creating a two-dimensional distribution of flux that is then propagated through the atmospheric PSF. As such it is an attractive approach to quantifying image components. However, the isophotes of popular galaxy profile functions are poorly behaved when integrating over two-dimensional pixels, requiring relatively expensive numerical estimation, while complex geometry (like rotating isophotes) is more difficult to capture fully, with most codes ignoring this issue entirely. In the regime where the true galaxy is well represented by the two-dimensional model being used a two-dimensional fit <span>*should*</span> be preferable. In principle, effects such as twisting isophotes can be incorporated into a two-dimensional generative model technique [see @peng10], but this is rarely attempted in practice.

Because of these relative advantages and disadvantages between one-dimensional and two-dimensional approaches, their application to galaxy profiling has pragmatically diverged. One-dimensional codes are more popular in the regime of highly resolved galaxies where complex geometric effects (such as twisting isophotes) are clearly visible and the issue of PSF convolution is less significant. Because of the more automated nature of two-dimensional codes (they do not require a carefully controlled collapse of the data to one-dimensional), they have tended to be more popular for large samples of galaxies where the fitting is made with little user interaction [e.g. @sima02; @alle06; @haus07; @kelv12; @haus13]. Our long-term ambition is to decompose galaxy structures from a large number of imaging data sources for many millions of galaxies, so our use-case is squarely in the highly-automated regime. For this reason in particular, we focused our efforts on two-dimensional decomposition codes.

Current publicly-available two-dimensional galaxy profile fitting codes include <span><span style="font-variant:small-caps;">B</span>UDDA</span> [@de-s04], <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>[@peng10], <span><span style="font-variant:small-caps;">G</span>ALMORPH</span> [@hydephd], <span><span style="font-variant:small-caps;">G</span>IM2D</span> [@sima02], and <span><span style="font-variant:small-caps;">I</span>MFIT</span> [@erwi15] — all of which support the commonly-used <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile. These codes share their origins in the early two-dimensional profiling efforts of @wada99 and @bens02 and have been utilized in a number of notable large-scale galaxy studies: @alle06 [@gado09; @hyde09; @sima11; @kelv12; @haus13; @meer15; @lang16; @kenn15; @kenn16]. Notable alternatives include <span><span style="font-variant:small-caps;">G</span>ASPHOT</span> [@pign06], which is a one-dimensional fitting code, and <span><span style="font-variant:small-caps;">M</span>GE</span> [@capp02], which abandons traditional <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile bulge-disc decomposition for more flexible (but arguably less physical) concentric Gaussians. In all of the other codes, the model is treated generatively by numerically integrating a radially-varying profile over a rectangular pixel grid; in practice, most codes improve integration accuracy by oversampling the native pixel grid, particularly near the centre of the galaxy. Once this idealized model is integrated, it can be convolved with a target PSF, either via brute-force or fast Fourier transform (FFT) techniques. These codes all have their positive features and weaknesses, and differ in fine aspects such as how the likelihood is computed and maximized. However, no existing code achieves the desired design requirements that our new code, <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, aims to address, namely that it:

-   should be legally open source under a GPL, BSD, MIT license, or similar;

-   should be practically collaborative and hosted in a publicly available location such as GitHub or BitBucket;

-   should be written in a low-level modern object-oriented language, aiding modularity, extensions and robustness for complex software,

-   has the core image generation code clearly separated from the optimization code, available as a shared library, and accessible via an easy-to-use API;

-   offers a useful range of built-in models and have a well documented mechanism for adding more;

-   supports sub $\sim$1% flux weighted error model image generation for built-in models, and be testable in this regard;

-   should be fast at generating these model images;

-   has a range of options to define likelihoods; i.e. Normal, Poisson, Chi-Squared and Student-T statistics;

-   should be able to fit a large number of components in a flexible manner, e.g. components being fixed, free or locked together with other components;

-   should be untied to a specific optimizer, i.e. able to use a range of (user-selectable) optimization engines;

-   should be able to accept prior distributions of an arbitrary type for model parameters (vital for Bayesian model evaluation);

-   has the ability to fit parameters in linear or log space as deemed appropriate by the user for the problem (vital for Bayesian model evaluation);

-   should be able to handle parameter limits and constraints in flexible manner (e.g. prevent some parameters getting larger than other etc);

-   has a core interface that does not require the use of text file inputs, i.e. there is a completely functional interactive interface to the software (though scripting with files should be allowable);

-   is simple to parallelize.

The reasons for desiring the above features are multifaceted, but broadly it is to aid the structural analysis of large amounts of data obtained from new and future imaging surveys such as KiDS, DES, HSC and LSST. Also, the addition of optional priors and log or linear parameter scaling is paramount for proper Bayesian model evaluation. Automating a historic code is a complicated affair [@kelv12; @haus13], and there are in practice many subtle issues with trying to bootstrap a new code from legacy software. Starting from scratch with a new code offers full flexibility in language choice, design flexibility and low-level choice regarding pixel integration and likelihood calculations. Our estimation was it would be at least as much effort to adapt any available open-source code to meet the above requirements that <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>delivers.

This paper discusses the development and application of the core image generation code (<span>`libprofit`</span>, Section \[sec:imgen\]) and the fitting code (<span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, Section \[sec:fit\]). The <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>code is then applied to various examples (Section \[sec:examples\]), spanning a detailed case study (Section \[sec:example1\]) and the analysis of 10 exemplar bulge-disc galaxies that are included with the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package (Section \[sec:example2\]). Estimations of decomposition fidelity is then made for current and future data sets (Section \[sec:future\]). Finally, we discuss and summarize the results of this paper (Section \[sec:discuss\]).

Image Generation with <span>`libprofit`</span> {#sec:imgen}
==============================================

The image generation code is contained in a shared library written in <span><span style="font-variant:small-caps;">c</span>++</span> called <span>`libprofit`</span>. <span>`libprofit`</span> enables the user to construct a *model* to which *profiles* are appended. Each profile can be fine-tuned, and fully describes a component of the resulting image. After profiles are appended the model is evaluated, and the resulting image can be retrieved. <span>`libprofit`</span> cycles through each of the profiles generating individual images for each of them, which are optionally convolved and finally added. Hence, it is trivial to describe a one-, two-, or multi-component system. This external interface, internal organization and execution of the <span>`libprofit`</span>library are depicted in Fig. \[fig:libprofit\] using the Unified Modelling Language.

Galaxy Profiles {#sec:profiles}
---------------

<span>`libprofit`</span> includes a default set of popular profiles: <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, broken-exponential, Moffat, Ferrer, modified empirical King, PSF and sky (see Fig. \[fig:profiles\]). The first six share some key similarities: they can be fully described by an analytic radial profile that is then evaluated in two-dimensions over pseudo-elliptical isophotes. They also share similarities in terms of how they must be evaluated in a given pixel: if the gradient of the model image is varying rapidly over the scale of a pixel then using a simple trapezoidal integration scheme (effectively taking the flux value predicted at the centre and assuming this to reflect the average for the pixel) can be error prone.

For this reason the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, broken-exponential, Moffat, Ferrer and King profiles all share the same core c++ code that evaluates the flux in a pixel and determines whether more accuracy is required. This means new profiles can be defined quite simply within <span>`libprofit`</span>, effectively reducing to the one-dimensional form of the radial profile and a scheme to calculate the total flux within the profile. For <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, Moffat and Ferrer, the total integration is known (or has been calculated by the authors) analytically, so this makes them particularly simple cases.

All eight profiles are discussed in more detail below, with the caveat that the detail of the integration scheme discussed with respect to the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile also applies to the Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, broken-exponential, Moffat, Ferrer, and King.

![image](Figures/types.pdf){width="12cm"}

### <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>Profile

For galaxy fitting purposes the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile [@sers63] is a modern day work-horse, having enough flexibility in profile characteristics to fit a large variety of galaxy types [see e.g. @kelv12]. The intensity profile is usually parameterized as:

$$I(R)=I_e \exp \left\{ -b_n \left[ \left( \frac{R_m}{R_e} \right)^{1/n}-1 \right] \right\},$$

where $I_e$ is the intensity of the profile at $R_e$ (the radius containing half of the flux), $n$ is the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index (which has special cases of Normal / Gaussian with $n=0.5$, exponential with $n=1$ and de-Vaucouleurs with $n=4$) and $b_n$ is a derived parameter that ensures the correct integration properties at $R_e$ and is the quantile at which the Gamma probability distribution function integrates to 0.5 given a shape parameter of $2n$. This can be computed directly using high-level interfaces to statical distribution libraries (e.g. in <span><span><span style="font-variant:small-caps;">R</span></span></span>$b_n=$ <span>qgamma(0.5, 2\*n)</span>). $R_m$ is the modified radius where we want to make the evaluation, which in one dimension is simply the radius from the profile centre. In two dimensions $R_m$ has a more complex form

$$R_m=\sqrt{(x-x_{cen})^2 + (y-y_{cen})^2},$$

where $x,y$ is the two-dimensional location where we wish to make the evaluation and $x_{cen},y_{cen}$ is the location of the profile centre. When the two-dimensional profile is non-circular, the isophotal contours become elliptical annuli, so calculating $R_m$ becomes a series of computations that rotate and circularize the annuli. When the major-axis angle $\theta$ is defined such that it is 0$^{\circ}$ vertically and increases positively as the galaxy is rotated counter-clockwise (as per <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>) these steps become

$$\begin{aligned}
R_t&=&\sqrt{(x-x_{cen})^2 + (y-y_{cen})^2},\\
\theta_t&=&\arctan{\frac{x-x_{cen}}{y-y_{cen}}}+\theta,\\
R_m&=&\sqrt{(R_t\sin(\theta_t) A_{rat})^2 + (R_t\cos(\theta_t))^2},\end{aligned}$$

where $A_{rat}$ is the minor to major axis ratio (so always a number between 0 and 1, where 0 is an infinitely thin line and 1 is a circle or disc). The final modifier to the standard one-dimensional <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile intensity is to allow for apparent 'boxiness'. Boxiness is often used to create the more rectangular visual appearance of galaxy bulges or elliptical galaxies. It effectively modifies the unit circle (or ellipse) away from the standard $L^2$ norm and either towards a diamond/kite appearance ($L^1$ norm) or a boxy appearance ($L^\infty$ norm). This is achieved though a small manipulation of the final $R_m$ calculation above

$$\label{eq:Rmod}
R_m=\left[(R_t\sin(\theta_{t})A)^{(2+B)} + (R_t\cos(\theta_{t}))^{(2+B)}\right]^\frac{1}{2+B},$$

where $B$ is the boxiness, which for practical (as opposed to mathematical) purposes is usually allowed to vary between $-1$ and 1 (thus covering the full range of apparent visual boxiness). Fig. \[fig:boxiness\] shows the effect of different negative and positive values of boxiness. A consideration for the user is the relative expense of computing the boxiness. Powers that differ from the $L^2$ norm are much more expensive to compute, in particular non-integer values might be a factor of a couple slower when computing a model image. In most standard C math libraries (<span>libm</span>) it is faster to make successive calls to <span>sqrt</span> and <span>csqrt</span> rather than a single call to <span>pow</span>. <span>`libprofit`</span> acknowledges this fact and calls the most efficient set of functions as appropriate for certain exponents.

Whilst the above is an accurate description of the computations that need to be made to calculate an arbitrary two-dimensional <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, they are not optimal. <span>`libprofit`</span> uses rotation matrix arithmetic internally to achieve the above steps efficiently, projecting pixel coordinates on to the major and minor axes of the ellipse. This can be a factor of a few faster than explicitly computing rotations with expensive calls to trigonometric functions.

![image](Figures/ExampleBox-0p5.pdf){width="5.8cm"} ![image](Figures/ExampleBox0.pdf){width="5.8cm"} ![image](Figures/ExampleBox0p5.pdf){width="5.8cm"}

It is not necessary to parameterize the profile using $I_e$ to define the normalization, as this is rarely intuitive. Instead, the user can specify the total flux contained within a profile in magnitudes ($m$) given a magnitude zero-point ($m_{zero}$), and calculations are made internally to convert this to the correct value of $I_e$. These include appropriate modifications for the axis ratio ($A_{rat}$) and boxiness ($B$):

$$\begin{aligned}
\label{eq:sersnorm}
R_{box}&=&\frac{\pi(2+B)}{2\beta\left(\frac{1}{2+B},\frac{1}{2+B}\right)},\\
L_{tot} &=& \frac{2 \pi A_{rat} R_e^2 n \Gamma(2n) \exp(b_n)}{R_{box}b_n^{2n}},\\
I_e&=&\frac{10^{-0.4(m-m_{zero})}}{L_{tot}},\end{aligned}$$

where $\beta$ is the Beta function defined as $\beta(a,b)=\Gamma(a)\Gamma(b)/\Gamma(a+b)$, and $\Gamma$ is the standard Gamma function. If the profile has no boxiness, then the above is simplified by noting that $R_{box}(B=0)=1$ and therefore the denominator term for $L_{tot}$ disappears. To aid flexibility, it is also possible in <span>`libprofit`</span> to define the profile normalisation using the mean surface brightness within $R_e$ ($<\mu>$), where:

$$<\mu>=m+2.5\log_{10}(\pi Re^2 A_{rat})-2.5\log_{10}(0.5).$$

<span>`libprofit`</span> follows the convention that $<\mu>$ is determined for an elliptical radius containing half of the objects flux, i.e. it is not modified for boxiness. This can be useful when parameterizing a galaxy where the galaxy magnitude is entirely unknown since galaxies span a much smaller dynamic range in surface brightness than total magnitude [@driv05].

In conclusion, the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile is specified fully through the provision of eight parameters that are parsed into the <span>`libprofit`</span> image building routine as a list structure of equal length vectors. Below is an example specification of a two-component <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>model in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>that directly calls the <span>`libprofit`</span>API to generate model images, where $x_{cen}=$

xcen, $y_{cen}=$

ycen, $m=$

mag, $R_e=$

re, $n=$

nser, $\theta=$

ang, $A_{rat}=$

axrat, and $B=$

box:

This model is shown in Fig. \[fig:examplesersicmodel\]. As expected, the high <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index bulge component dominates the flux near the galaxy centre as well as at very large radii, due to the shallow slope of an $n=8$ <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile. This is visible as side lobes in the surface brightness contours jutting out from the visually dominant disc component running diagonally across the image.

![Example <span>`libprofit`</span> model image with no convolution by the PSF.<span data-label="fig:examplesersicmodel"></span>](Figures/ExampleSersicModel.pdf){width="\columnwidth"}

### Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>

Closely related to the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile is the Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile introduced by @grah03. This was designed to parameterize the strong inner core (i.e. suppression compared to pure <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>) profile of well-resolved elliptical galaxies. The inner components of such galaxies had previously been parameterized well with the Nuker profile [@laue95], at least in the inner parts of the profile. However, the Nuker profile fits poorly at large radii and does not have a well behaved integral to infinite radius for typical parameters. The Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>addresses these issue by allowing the inner component to behave in a Nuker-like manner, with the outer parts being described by a standard <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile. The intensity profile can be parameterised as

$$I(R_m)=I_r\left[1+\left(\frac{R_m}{R_b}\right)^{-a}\right]^\frac{b}{a} \exp \left[-b_n \left(\frac{R_m^a+R_b^a}{R_e^a}\right)^\frac{1}{n a}\right],$$

where $I_r$ is the intensity at a parameter dependent reference point (the centre if $R_b=0$), $R_b$ is the break radius that controls the point where the outer <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>-like profile transitions to become an inner Nuker-like profile, $R_e$ is the standard <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>half light radius (and $b_n$ has the same meaning as for the pure <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile) and $a$ controls the strength of transition (large value is a sharper transition) and $b$ controls the inner power law. $R_m$ is the modified radius where we want to make the evaluation, which in one dimension is simply the radius from the profile centre. In two dimensions $R_m$ has a more complex form where, as with the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, we can use this basic form and compute annuli that are modified from pure circular ellipses by introducing geometric transformations that compute an effective $R_m$, as per Equation \[eq:Rmod\].

Accounting for the allowed geometric distortions of axial ratio and boxiness, the value of $I_r$ for a given magnitude can be calculated numerically with

$$\begin{aligned}
L_{tot} &=& \frac{2 \pi A_{rat} \int_0^\infty R_m I(R_m; I_r=1) dR_m}{R_{box}},\\
I_r&=&\frac{10^{-0.4(m-m_{zero})}}{L_{tot}},\end{aligned}$$

The integral above has no simple analytic solution, so it is instead calculated numerically inside <span>`libprofit`</span> using either the <span><span><span style="font-variant:small-caps;">R</span></span></span>or GSL implementation of the <span><span style="font-variant:small-caps;">Q</span>UADPACK</span> library (specifically adaptive Gauss-Kronrod quadrature integration). This is a much better solution than attempting to re-normalize the generated image since much of the flux could exist beyond the confines of the image pixels, especially for large values of $n$.

Below is an example of a Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>model in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>that directly calls the <span>`libprofit`</span>API to generate model images, where $x_{cen}=$

xcen, $y_{cen}=$

ycen, $m=$

mag, $R_{b}=$

rb, $R_{e}=$

re, $n=$

nser, $a=$

a, $b=$

b, $\theta=$

ang, $A_{rat}=$

axrat, and $B=$

box:

### Broken-Exponential Profile

The broken-exponential profile is a popular means to parameterise rolling or sharp truncations in the surface profiles of discs, which are usually close to exponential in profile until they enter the moderate- to low-surface brightness regime. @erwi08 introduced a simple modification to the standard exponential profile (which is itself a subset of possible <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profiles) in order to capture the range of truncations observed. The intensity profile can be parameterized as

$$\begin{aligned}
S&=&(1 + e^{ - a R_b } )^{-\frac{1}{a}\left(\frac{1}{h_1}-\frac{1}{h_2}\right)},\\
I(R_m)&=&I_0 S e^{ \left(\frac{-R_m}{h_1}\right)} \left[ 1+ e^{a (R_m - R_b)} \right]^{\frac{1}{a}\left(\frac{1}{h_1}-\frac{1}{h_2}\right)},\end{aligned}$$

where $I_0$ is the intensity at the centre of the profile, $h_1$ is the scale length of the inner exponential profile, $h_2$ is the scale length of the outer exponential profile, $R_b$ is the radius at which the profile transitions from the inner to outer part and $a$ controls the sharpness of this transition. $R_m$ is the modified radius where we want to make the evaluation, which in one dimension is simply the radius from the profile centre. In two dimensions $R_m$ has a more complex form where, as with the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, we can use this basic form and compute annuli that are modified from pure circular ellipses by introducing geometric transformations that compute an effective $R_m$, as per Equation \[eq:Rmod\].

Accounting for the allowed geometric distortions of axial ratio and boxiness, the value of $I_0$ for a given magnitude can be calculated analytically with

$$\begin{aligned}
L_{tot} &=& \frac{2 \pi A_{rat} \int_0^{R_t} R_m I(R_m; I_0=1) dR_m}{R_{box}},\\
I_0&=&\frac{10^{-0.4(m-m_{zero})}}{L_{tot}},\end{aligned}$$

where $m$, $m_{zero}$ and $R_{box}$ have the same meanings as per Equation \[eq:sersnorm\].

An example specification of a broken exponential model in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>that directly calls the <span>`libprofit`</span>API to generate model images, where $x_{cen}=$

xcen, $y_{cen}=$

ycen, $m=$

mag, $h_1=$

h1, $h_2=$

h2, ${{\textsc R}\xspace}_b=$

rb, $a=$

a, $\theta=$

ang, $A_{rat}=$

axrat, and $B=$

box, is

### Moffat Profile {#subsubsec:moffat}

The Moffat function was designed as a means to parameterize a telescope PSF [@moff69], and is often used on occasions when the PSF is predicable and when you might not have many point sources within the field of view to estimate it empirically (e.g. for space telescopes with small fields-of-view like the <span>*Hubble Space Telescope*</span>). Whilst this was the purpose behind its design, in practice in modern applications, it is rare to see analytic approximations of the PSF (such as the Moffat) used, the modern preference being for empirically derived estimates. Regardless, for reasons of flexibility, it is included as a profile option in <span>`libprofit`</span>. The Moffat is a re-parameterization of the bivariate Student-T distribution, meaning it creates a Normal-like core with Lorentzian-like wings. The intensity profile can be parameterized as

$$I(R_m)=I_0 \left[1+\left(\frac{R_m}{R_d}\right)^2 \right]^{-c},$$

where

$$R_d=\frac{FWHM}{2\sqrt{2^\frac{1}{c}-1}},$$

where $I_0$ is the intensity at the centre of the profile, $c$ is the profile concentration ($c=1$ is pure Lorentzian, $c=\infty$ is pure Normal), and $FWHM$ is the full-width half max of the profile across the major-axis of the intensity profile. $R_m$ is the modified radius where we want to make the evaluation, which in one dimension is simply the radius from the profile centre. In two dimensions, $R_m$ has a more complex form where, as with the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, we can use this basic form and compute annuli that are modified from pure circular ellipses by introducing geometric transformations that compute an effective $R_m$, as per Equation \[eq:Rmod\]. Thus in <span>`libprofit`</span> the Moffat function need not be circular, which is often the case for the PSF of a wide-field telescope where corner distortions tend to be radial or tangentially aligned with respect to the field centre.

Accounting for the allowed geometric distortions of axial ratio and boxiness, the value of $I_0$ for a given magnitude can be calculated analytically with:

$$\begin{aligned}
L_{tot} &=& \frac{\pi A_{rat} {R_d}^2}{(c-1) R_{box}},\\
I_0&=&\frac{10^{-0.4(m-m_{zero})}}{L_{tot}},\end{aligned}$$

where $m$, $m_{zero}$ and $R_{box}$ have the same meanings as per Equation \[eq:sersnorm\].

An example specification of three Moffat models in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>that directly calls the <span>`libprofit`</span>API to generate model images, where $x_{cen}=$

xcen, $y_{cen}=$

ycen, $m=$

mag, $FWHM=$

fwhm, $c=$

con, $\theta=$

ang, $A_{rat}=$

axrat, and $B=$

box, is

Since the Moffat profile is almost exclusively used to model the image PSF, <span>`libprofit`</span> is hard-coded to never convolve the profile with another PSF, even if this is provided. This is to help eliminate potential user error.

### Modified Ferrer/s Profile

The modified Ferrer profile (a type of projected potential derived from Ferrers' functions, as discussed in @laur05) is a useful parameterization of galaxy features that have very strong drop-offs, most typically bar structures. Whilst it should formally be called the Ferrers profile, it is very common for it to be written as Ferrer (the assumption is that authors have erroneously attributed the final 's' as possessive, but the name derives from Norman Macleod Ferrers). For convenience, the profile can be named as Ferrer or Ferrers in <span>`libprofit`</span>and in higher level interfaces. The intensity can be parameterized as

$$I(R_m)=I_0 \left[1-\left(\frac{R_m}{R_{out}}\right)^{(2-b)}\right]^{a},$$

where $I_0$ is the intensity at the centre of the profile, $R_{out}$ is the outer truncation radius (the profile is 0 beyond this radius), $a$ controls the global power-law slope to the profile centre, and $b$ controls the strength of truncation as $R_M$ approaches $R_{out}$. $R_m$ is the modified radius where we want to make the evaluation, which in one dimension is simply the radius from the profile centre. In two dimensions $R_m$ has a more complex form where, as with the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, we can use this basic form and compute annuli that are modified from pure circular ellipses by introducing geometric transformations that compute an effective $R_m$, as per Equation \[eq:Rmod\]. For the Ferrer profile it is common to introduce some positive boxiness to reflect the visually rectangular isophotes of galaxy bars.

Accounting for the allowed geometric distortions of axial ratio and boxiness, the value of $I_0$ for a given magnitude can be calculated analytically with

$$\begin{aligned}
L_{tot} &=& \frac{\pi A_{rat} {R_{out}}^2 a \beta\left(a, 1+\frac{2}{2-b}\right)}{R_{box}},\\
I_0&=&\frac{10^{-0.4(m-m_{zero})}}{L_{tot}},\end{aligned}$$

Below is a sample specification of a Ferrer model in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>that directly calls the <span>`libprofit`</span>API to generate model images, where $x_{cen}=$

xcen, $y_{cen}=$

ycen, $m=$

mag, $R_{out}=$

rout, $a=$

a, $b=$

b, $\theta=$

ang, $A_{rat}=$

axrat and $B=$

box:

### Modified Empirical King profile

The modified King profile in <span>`libprofit`</span> shares its origins with the empirically motivated two-dimensional profile presented in @king62, and remains a popular function for parameterizing globular cluster light profiles. It should be emphasized that it is <span>*not*</span> the same as the equally popular profile presented in @king66, the latter being parameterized in three dimensions, theoretical in origin and non-trivial to project. <span>`libprofit`</span> uses the same basic modification to the @king62 as used in <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, where the intensity can be parameterized as

$$I(R_m)=I_r \left\{\frac{1}{\left[1+\left(\frac{R_m}{R_c}\right)^2\right]^\frac{1}{a}}-\frac{1}{\left[1+\left(\frac{R_t}{R_c}\right)^2\right]^\frac{1}{a}}\right\}^a,$$

where $I_r$ is the intensity at a parameter-dependent reference point (the centre if $R_t=\infty$), $R_c$ is the core radius, $R_t$ is the outer truncation radius (the profile is 0 beyond this radius) and $a$ controls the global power-law. When $a=2$, this parameterisation is identical to the one presented originally in @king62. $R_m$ is the modified radius where we want to make the evaluation, which in one dimension is simply the radius from the profile centre. In two dimensions $R_m$ has a more complex form where, as with the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, we can use this basic form and compute annuli that are modified from pure circular ellipses by introducing geometric transformations that compute an effective $R_m$, as per Equation \[eq:Rmod\].

Accounting for the allowed geometric distortions of axial ratio and boxiness, the value of $I_0$ for a given magnitude can be calculated analytically with:

$$\begin{aligned}
L_{tot} &=& \frac{2 \pi A_{rat} \int_0^{R_t} R_m I(R_m; I_r=1) dR_m}{R_{box}},\\
I_r&=&\frac{10^{-0.4(m-m_{zero})}}{L_{tot}},\end{aligned}$$

An example specification of a modified King profile in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>that directly calls the <span>`libprofit`</span>API to generate model images, where $x_{cen}=$

xcen, $y_{cen}=$

ycen, $m=$

mag, $R_{c}=$

rc, $R_{t}=$

rt $a=$

a, $\theta=$

ang, $A_{rat}=$

axrat and $B=$

box, is

### Point Spread Function Profile {#subsubsec:psf}

The PSF profile for an unresolved point source (referred to as a <span>pointsource</span> within <span>`libprofit`</span>and <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>to distinguish it from the PSF) is a simple prescription requiring the $x_{cen},y_{cen}$ location of the desired point source, the total flux contained in magnitudes $m$ and either an empirical PSF image or analytic PSF model. In the former case, the PSF image is linearly interpolated on to the specified location in the image (thus fractional pixel values can be provided) and is renormalized to ensure the flux contained is correct given the magnitude zero-point ($m_{zero}$); otherwise, the point source is accurately integrated with the specified PSF model using an analytic profile (e.g. the Moffat, as discussed in Section \[subsubsec:moffat\]). An example of a model containing three point sources in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, where $x_{cen}=$

xcen, $y_{cen}=$

ycen and $m=$

mag, is

Numerical integration of an analytic PSF is considerably more accurate than interpolation of an empirical PSF image, so we generally recommend using the former approach if it is at all possible. As mentioned in Section \[subsubsec:moffat\], it is more typical to see astronomers using empirical PSFs. Since the intrinsic PSF is unknown, using such a description will result in a simple linear interpolation to fractional pixel locations. To accommodate this fact, <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>allow for the specification of an oversampled empirical PSF. If PSF modelling is required, this offers both a pragmatic and accurate solution.

### Sky Profile

The simplest profile of all is the sky. In <span>`libprofit`</span>, this is specified as the flux per pixel without any adjustment made for the magnitude zero-point ($m_{zero}$), i.e. it is the flat sky level pedestal directly measured from the image in its native flux units (any subsequent conversions must be made explicitly by the user). An example sky model in the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>requires only the background level bg:

Currently only flat sky profiles are available in <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, with the assumption that in typical <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>use cases the sky is a pedestal term, with no gradient of curvature. Depending on community feedback additional complexity for the sky profile could be added in future. However, it is clear that the majority of modern survey image processing involves an explicit sky-subtraction stage that reduces the data to a pedestal-only sky profile [e.g. see @kuij15]. Like any other profile type, it is possible to fit for the sky profile background within <span>`libprofit`</span>; however, in many use cases, the background will be known a-priori and should not be fit. A common issue with the leaving the sky as a fitted parameter is how degenerately it behaves with <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>-index outer profiles, which also appear close to flat at many multiples of $R_e$. To guard against this effect, it is wise to fit using pixels that are dominated by galaxy flux.

### A Combined Model

Combining models in <span>`libprofit`</span> is simple given the nested list nature of object specification. A structure containing the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, Ferrer bar, point-source and sky models is given by

This is the list structure used in <span><span><span style="font-variant:small-caps;">R</span></span></span> <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>to specify models, and in principle an unlimited number of profiles can be provided to create complex model images. In practice, for galaxy image fitting simple models are made of the region of direct interest. This structure is also the mechanism for providing initial conditions for galaxy image fitting. This structure can be easily manipulated from outside of the <span><span><span style="font-variant:small-caps;">R</span></span></span>environment, or directly within <span><span><span style="font-variant:small-caps;">R</span></span></span>.

Fig. \[fig:examplecombmodel\] shows the image generated by the example model above. This is very similar to Fig. \[fig:examplesersicmodel\] but with the addition of a Ferrer bar profile, three bright point sources and a sky background (which is not visible due to the image scaling). More details on how <span>`libprofit`</span> generates these images is provided in the following section.

![Example <span>`libprofit`</span> model image with convolution by the PSF, which is an idealised Gaussian PSF with full width half max (FWHM) of 1.3 pixels. For clarity no surface brightness contours are over-drawn. This image has the same two-component <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>model as shown in Figure \[fig:examplesersicmodel\], but with the addition of a Ferrer bar profile, three PSFs and a sky background.<span data-label="fig:examplecombmodel"></span>](Figures/ExampleCombModel.pdf){width="\columnwidth"}

Accurate and Fast Pixel Integration {#sec:profit-acc}
-----------------------------------

The main focus of development effort in <span>`libprofit`</span> was optimizing model image generation for speed <span>*and*</span> accuracy, particularly for the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile (since this is by some margin the most popular general purpose profile for galaxy modelling). The first requirement to achieve rapid image generation was that the core code should be written in a fast low-level language. <span><span style="font-variant:small-caps;">c</span>++</span> was chosen for these purposes, with the idea that <span>`libprofit`</span> should provide a generic low-level library that higher level languages (e.g. <span><span><span style="font-variant:small-caps;">R</span></span></span>and <span><span><span style="font-variant:small-caps;">P</span>YTHON</span></span>) can access easily.

With <span><span style="font-variant:small-caps;">c</span>++</span> chosen as the implementation language, the main considerations left were how to best approach the problem of model image generation algorithmically. Two-dimensional modelling routines are circumspect in how they achieve pixel integration, with most published references stating that inner pixels are 'oversampled' in order to achieve reasonable accuracy in the pixel flux (note this is different to the type of oversampling required to ensure accurate image convolution, as discussed in Section \[subsec:convolution\]). Depending on the profile being created the degree of oversampling can vary by many orders of magnitude. Getting accurate solutions for the flux in a pixel containing the peak of a steep (high $n$) <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile is clearly a very different prospect to estimating the flux of a pixel a large distance from the centre, where the profile is very flat. To combat this problem, <span>`libprofit`</span> uses a unified oversampling scheme (inspired by adaptive quadrature) for all profiles that have an analytic radial intensity profile — initially the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, Core-<span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>, broken-exponential, Moffat, Ferrer, and King profiles discussed above. Here, we concentrate on the evaluation of the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile, but the basic principles hold true for all radially varying profiles. In <span>`libprofit`</span> all such profiles inherit from a generic class of radial type profiles (see Fig. \[fig:profiles\]), where the pixel integration scheme is shared in a common method. The profiles are specified by their radial intensity and total luminosity (as per Section \[sec:profiles\]). This minimizes code duplication and simplifies the addition of new profiles to <span>`libprofit`</span>, where the user only needs to be able to express the one-dimensional form of the profile shape and a method to integrate it to get the total luminosity (which can simply be a numerical integration if there is no convenient analytic solution).

![image](Figures/pixint_mod.png){width="13cm"}

The qualitative version of the pixel integration scheme is that an oversampling resolution, a recursion depth, and an accuracy level is specified for a given pixel. The grid is initially oversampled by the integer factor provided, for each sub-pixel the gradient along the minor axis (this being the steepest descent) is computed and when it is over a tolerance specified by the accuracy value this pixel is selected for recursive oversampling. In this situation, the sub-pixel becomes redefined as the parent pixel and the scheme above is repeated. Fig. \[fig:pixint\] is a simple schematic of the central $3\times3$ pixels being recursively oversampled by a factor $5\times5$ to achieve an accurate numerical integration in the regime where the profile is rising steeply in the core of the galaxy.

The default allowed maximum depth for sub-pixel recursion is 2, but it can be user-specified. The default oversampling factor is 8, meaning at most sub-regions of pixels would be oversampled by a factor $(8^2)^2=8^4$. A special case is made for the central pixel in the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile (containing the flux peak). To ensure accurate results even for extreme examples of very steep profiles of barely resolved galaxies, the maximum recursion depth is increased to 10, giving potential oversampling of $(8^{10})^2\sim10^{9}$. In extreme cases, where deep recursion is triggered on the very central pixel of each layer, the practical worst case scenario is that $(8^2) \times 10=640$ calculations are actually required because only the sub-pixels containing the profile peak require deeper recursion.

This combination of accuracy and speed means <span>`libprofit`</span> performs well in model image generation bench-marking whilst maintaining user-definable accuracy with sensible defaults. Detailed comparisons were made with reference to <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, where the target was to achieve similar or better pixel level accuracy whilst ensuring the model image computation time was no longer for typical values of the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index ($n$). For these comparisons, a modified build of <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>was used that did not read or write to disk and instead took arguments and produced outputs in memory (ensuring this relatively large I/O bottleneck was not a factor).

The exact pixel fluxes were computed using the <span><span style="font-variant:small-caps;">R</span>2CUBA</span> <span><span><span style="font-variant:small-caps;">R</span></span></span>package that is an interface to the <span><span style="font-variant:small-caps;">C</span>UBA</span> <span><span style="font-variant:small-caps;">c</span>++</span> library that offers deterministic algorithms for multidimensional numerical integration. The algorithm used was <span><span style="font-variant:small-caps;">C</span>UHRE</span>, which offers a user-definable level of integration accuracy. For these tests, it was set to be better than 0.1 per cent pixel accuracy (in practice achieving an order of magnitude better accuracy in most pixels), so at most this amount of inaccuracy may come from the reference <span>*exact*</span> pixel fluxes. It is worth highlighting why this approach cannot be used in general: to create a typical $20\times20$ pixel image (a very small image by galaxy fitting standards) with this level of accuracy takes $\sim$3 s (and much longer for some profiles). In comparison, <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>can both create similar image in less than 0.01 s, i.e. they are both at least 300 times faster than using a multidimensional integration library, even a fast one written in <span><span style="font-variant:small-caps;">c</span>++</span>. It is not clear why using this specialized library is so slow, but it ruled out using it within <span>`libprofit`</span>for general application.

Fig. \[fig:fluxweighterror\] compares the flux-weighted pixel error of <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>as a function of <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index for <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profiles (again, <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profiles have been high-lighted due to their popularity in the galaxy profiling community) with $R_e=2$pixels, $\theta=60^\circ$ and $A/B=0.3$. Two things are immediately clear: <span>`libprofit`</span> has a lower flux-weighted error per pixel (typically 0.1 per cent), and this error does not vary significantly with <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index. <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>achieves a flux weighted error per pixel of 0.3 per cent for low values of the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index, but this inflates to $>1$ per cent for larger values of $n$.

![<span>`libprofit`</span> versus <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>flux weighted model image error for <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>indices 0.5–16 for $R_e=2$pixels, $\theta=60^\circ$, and $A/B=0.3$ in a $20 \times 20$ pixel image. A subset of these results (for $n=1, 4, 8, 16$) are shown in detail in Fig. \[fig:pixelaccuracy\].<span data-label="fig:fluxweighterror"></span>](Figures/FluxWeightedError.pdf){width="\columnwidth"}

The image generation is shown in more detail for these example profiles in Fig. \[fig:pixelaccuracy\]. This shows the actual error as a function of pixel location on the two-dimensional image for the target model for both <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>. Fig. \[fig:pixelaccuracydiag\] shows the one-dimensional pixel error across the central portion of pixels that incorporate the peak pixel (which is usually the hardest to integrate accurately for the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile). There are specific regions of pixels where <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>has smaller errors, but the general trend is that <span>`libprofit`</span> is more accurate over a large range of pixels, and never experiences large integration error in pixels that contain significant fractions of the profile flux. In the case of both <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>outer pixels might often have large relative error, but in these cases the pixels contain almost no flux and do not drive the overall model image to a large flux-weighted error.

Exact Image Generated with Cubic Quadrature Routine via Cuba\
![image](Figures/Exact2DN1.pdf){width="4.3cm"} ![image](Figures/Exact2DN4.pdf){width="4.3cm"} ![image](Figures/Exact2DN8.pdf){width="4.3cm"} ![image](Figures/Exact2DN16.pdf){width="4.3cm"}\
Error in Approximate <span>`libprofit`</span> Image\
![image](Figures/ProFit2DErrorN1.pdf){width="4.3cm"} ![image](Figures/ProFit2DErrorN4.pdf){width="4.3cm"} ![image](Figures/ProFit2DErrorN8.pdf){width="4.3cm"} ![image](Figures/ProFit2DErrorN16.pdf){width="4.3cm"}\
Error in Approximate <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>Image\
![image](Figures/GALFIT2DErrorN1.pdf){width="4.3cm"} ![image](Figures/GALFIT2DErrorN4.pdf){width="4.3cm"} ![image](Figures/GALFIT2DErrorN8.pdf){width="4.3cm"} ![image](Figures/GALFIT2DErrorN16.pdf){width="4.3cm"}\

Error Across Central Diagonal Pixels\
![image](Figures/Comb1DErrorN1.pdf){width="\columnwidth"} ![image](Figures/Comb1DErrorN4.pdf){width="\columnwidth"}\
![image](Figures/Comb1DErrorN8.pdf){width="\columnwidth"} ![image](Figures/Comb1DErrorN16.pdf){width="\columnwidth"}\

As established in the design goals of <span>`libprofit`</span>, generating images accurately is important, but there is a trade-off to be made with the required computation time. It is unavoidable that some pixels will be harder to evaluate due to the rapid change in flux within a pixel (especially true for the central pixel containing the peak of the <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profile flux), and more computing time will be needed for correctly evaluating the pixel flux. <span>`libprofit`</span> uses adaptive recursion to adjust the integration resources as required in order to maintain a relatively constant level of pixel integration accuracy. This is evident from Figure \[fig:imagetime\], which compares the image generation times for <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>for the same <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profiles as presented in Figure \[fig:fluxweighterror\]. It is clear that <span>`libprofit`</span> varies the integration time (which is akin to more resources spent evaluating <span>*hard*</span> pixels) more in order to maintain relatively constant flux weighted errors (see Figure \[fig:fluxweighterror\]), whereas <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>maintains nearly constant integration times.

![<span>`libprofit`</span> versus <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>model image generation time for <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>indices 0.5 to 16 for $R_e=2$pixels, $\theta=60^\circ$ and $A/B=0.3$ in a $20 \times 20$ pixel image.<span data-label="fig:imagetime"></span>](Figures/ImageTime.pdf){width="\columnwidth"}

The computation times of <span>`libprofit`</span> and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>for <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profiles are investigated in more detail in Fig. \[fig:TimevTime\] and Figure \[fig:paramtime\]. For all these tests the same MacBook Pro running El-Capitan with 2.6 GHz i7 processors and 16 GB of RAM was used. In Figure \[fig:TimevTime\] we see that <span>`libprofit`</span> is factors of a few faster compared to <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>for most combinations of model parameters. In Fig. \[fig:paramtime\] we see there is weak dependence of computation time on $R_e$ and $n$, and a strong dependence on axial ratio (in all three cases larger means longer computation time for <span>`libprofit`</span>). For reasons not immediately clear, <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>actually takes longer to compute compact models — perhaps because its integration scheme is not sufficiently adaptive.

In general, we find a wide range of potential computation times, spanning a factor of $\sim$10 for <span>`libprofit`</span> versus $\sim$3 for <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>even though the target image is $200 \times 200$ pixels in all cases. This makes it hard to predict in general how long a particular fit might take given the image size. In a pathological situation of the target galaxy having large $R_e$, large $n$, and being circular in projection, the computation could be a factor 10 longer than for the case of a compact galaxy with low $n$ and fairly elongated projection.

![<span>`libprofit`</span> versus <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>model image generation times for a large grid of $200 \times 200$ pixel images. Galaxy size (10 $R_e$), <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index (11 $n$), rotation angle (10 $\theta$) and axial ratio (10 $A/B$) were sampled on a grid, with 11,000 model images generated in total. The red lines show 1:1, 1:2, 1:3, 1:4 and 1:5 relative speeds for the same target model image, <span>`libprofit`</span> being substantially faster in almost all situations.<span data-label="fig:TimevTime"></span>](Figures/TimeVersusTime.png){width="\columnwidth"}

Time to create $200\times200$ pixel images\
![image](Figures/TimeVersusRe.pdf){width="\columnwidth"} ![image](Figures/TimeVersusNser.pdf){width="\columnwidth"}\
![image](Figures/TimeVersusAng.pdf){width="\columnwidth"} ![image](Figures/TimeVersusAxrat.pdf){width="\columnwidth"}\

It is possible to configure <span>`libprofit`</span> to exceed $\sim$0.1 per cent flux-weighted image accuracy. This default was deemed appropriate for typical (and certainly our) uses of <span>`libprofit`</span> since it equates to 0.001 mag accuracy which in practice far exceeds the systematic and random measurement uncertainties for even relatively high fidelity photometric images. It also allows for rapid image fitting since small gains in accuracy begin to take factors longer to compute. However, a combination of increasing the oversampling and recursion depth allows for arbitrarily high levels of integration accuracy should this be required by the user. By including a simple interface to the Cuba library in the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package for all six radial profile types, it is possible to tune these parameters in order to achieve the desired level of accuracy and speed.

Image Convolution {#subsec:convolution}
-----------------

ProFit supports both brute-force convolution and FFT-based convolution using the FFTW library. In the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation, both methods are benchmarked and the optimal method for the given image and PSF size is chosen. Brute-force convolution is often significantly faster than FFT-based methods but scales directly with image *and* PSF size, being $\mathcal{O}(n_{image}n_{PSF})$, whereas FFT convolution is $\mathcal{O}(4n_{image}\log{4n_{image}})$, accounting for necessary zero-padding. Testing shows that both methods give nearly identical answers, with fractional differences of less than $10^{-12}$.

One important consideration is that the accuracy of convolution depends on the resolution of the PSF relative to the pixel scale. A poorly resolved PSF with a FWHM $\le 3$ pixels may give flux errors on the order of a few percent for the innermost pixels. <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>allows for model and PSF oversampling for more accurate convolution, whereby the model pixel grid is subdivided by an integer factor (preferably odd). This is independent of the oversampling for the purposes of accurate model convolution, and requires either an analytic PSF or prior interpolation of the empirical PSF. Interpolating a noisy empirical PSF offers a limited gain in accuracy, so for this reason (and as mentioned in Section \[subsubsec:psf\]), analytic PSFs are generally preferred. When this process is attempted empirically it is usually via stacking or drizzling of the data (e.g. with the use of a program like MultiDrizzle[^1]). Accounting for pixel covariance when drizzling is a complex problem, and best handled by fitting the native resolution images simultaneously rather than attempting to combine them in an information-lossy process. Simultaneous image fitting of multi-exposure data and covariance likelihoods are high on the list of future extensions to <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, but are not present in v1.0 (although experimental covariance likelihoods are already being tested).

Image Fitting with <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span> {#sec:fit}
=================================================================================================

Having demonstrated that <span>`libprofit`</span> integrates and convolves analytic profiles quickly and accurately, the remaining ingredients for model fitting are the likelihood function and optimization and/or likelihood sampling method. This logic is implemented in the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span> <span><span><span style="font-variant:small-caps;">R</span></span></span>package. <span><span><span style="font-variant:small-caps;">R</span></span></span>is becoming increasingly widely used in astronomy and other fields of advanced data analysis, and since it features a large number of statistics packages and optimization methods (maximum-likelihood and Bayesian), it is ideally suited for the purpose of Bayesian galaxy image fitting.

Having easy access to a wealth of optimizers was a key design goal of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>. A large subdivision of statistical data science and computer science has invested huge efforts into describing and implementing a multitude of optimizers that have a range of strengths and weaknesses. Depending on the specific problem at hand, one optimizer might be preferred over another for reasons that are very hard for us to intuit. Since this is such a key component of galaxy modelling, where a typical use case might involve fitting dozens of partly degenerate parameters, giving the user flexibility to experiment with optimization engines was deemed critical.

In practice an initial global parameter search might be made using a fast but biased downhill gradient optimizer, or one which is known to get easily trapped in local minima. From this point a more expensive but robust Markov Chain Mote Carlo (MCMC) optimizer could be used to accurately refine the parameter posteriors (this is the typical mode of operation recommended by the authors and described in detailed vignettes included with the <span><span><span style="font-variant:small-caps;">R</span></span></span>package version of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>). In the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation alone the user has easy plug-and-play access to hundreds of optimizers accessible though the Central R Archive Network (CRAN) with hundreds more served from online repositories (e.g. GitHub). We do not wish to be overly prescriptive in how samplers are used to model data, but some typical applications will be discussed in the following sections.

Required Observational Data
---------------------------

A number of inputs are required to meaningfully fit a profile to a target galaxy observation. For good-quality data where the whole image is to be used for fitting, the bare minimum is strictly an image where pixels contain integer photoelectron counts and an analytical description of the PSF.

In practice, a more complete set of inputs can include the flux image ($D$, in whatever linear units are appropriate), a segmentation map (that is pixel matched to $D$, where distinct integer values represent different detected structures in the image as per SExtractor), a binary mask (that is pixel matched to $D$, where TRUE means mask out and ignore for analysis, and FALSE means do not mask), and the $\sigma$ image ($\sigma$, that is pixel matched to $D$, where values represent Normal errors in the same units as for $D$).

The PSF can be specified in two main ways: either via an analytical description using any of the available radial profiles (in practice, the Moffat function is a good profile for this task), or with an image of the PSF that is on the same pixel scale as $D$. <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>has a high-level setup function (<span>profitSetupData</span>) that can take these basic inputs and create an internal object that is appropriate for fitting a <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>model.

Image Likelihood
----------------

There is a wealth of routes to compute meaningful image versus model likelihoods, depending on the data regime. If many (i.e. hundreds of) photo-electrons are registered in pixels for the observed galaxy then the data are likely to be operating in the Normal statistics regime, where <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>likelihoods can be computed with

$$\begin{aligned}
x_{i,j}&=&\frac{(D_{i,j}-M_{i,j})^2}{2\sigma_{i,j}^2},\\
\ln\mathcal{L}&=& \frac{\ln{2\pi}}{2} - \sum_{i=1}^{N_i}\sum_{j=1}^{N_j} x_{i,j} -\ln{\sigma_{i,j}}.
$$

Here, $D_{i,j}$ represents the observed pixel data at pixel $i, j$, $M_{i,j}$ represents a computed <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>model at pixel ${i, j}$ and $\sigma_{i,j}$ represents the estimated Normal uncertainty at pixel $i,j$.

An alternative view is that cumulative sum of squared residuals should follow a $\chi^2$ distribution, with a <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>likelihood computed by

$$\begin{aligned}
\chi^2&=&\sum_{i=1}^{N_i} \sum_{j=1}^{N_j} \frac{(D_{i,j}-M_{i,j})^2}{\sigma_{i,j}^2},\\
\ln\mathcal{L}&=& - \frac{k}{2} \ln{2} - \ln{\Gamma{(k/2)}} + \left(\frac{k}{2}-1 \right) \ln{\chi^2} - \frac{\chi^2}{2}.\end{aligned}$$

Here $k$ represents the degrees of freedom of the $\chi^2$ distribution. For fitting of this type this will usually be determined by the number of pixels containing galaxy flux (here, $N_i N_j$) minus the number of parameters being used to fit the model to the data (up to eight in the case of a single component <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>model). In the regime of the statistics being truly Normal and the model fitting well (i.e. a reduced $\chi^2$ near unity), the Normal and $\chi^2$ distribution likelihoods converge to similar results. The chief distinction is that the $\chi^2$ statistic penalizes overfitting, since extremely small residuals across all pixels are highly unlikely. Both statistics are sensitive to residuals significantly above the shot noise ($\chi^2$ somewhat more so), such as non-axisymmetric features such as bars, spiral arms, and dust lanes. Nonetheless, if the dominant source of uncertainty in the image is truly shot noise rather than systematics, and the signal to noise is high, the $\chi^2$ statistic is appropriate.

However, if the count rates are relatively low, then the Poisson statistics must be used. In this case, <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>likelihoods are computed with

$$\begin{aligned}
\ln\mathcal{L}=\sum_{i=1}^{N_i} \sum_{j=1}^{N_j} D_{i,j} \ln{\lambda_{i,j}} -\lambda_{i,j} -D_{i,j}!.\end{aligned}$$

Here, $\lambda_{i,j}$ is the expectation for the number of photoelectrons counted in at pixel $i,j$, and $D_{i,j}$ is the integer number of photoelectrons recorded. Dropping the $D_{i,j}!$ term (since it depends only on the data) applies a global offset to log-likelihood, which makes no difference to any posterior inference since this is all computed in a relative manner. Expressed in this form and multiplied by a factor of $-2$ we recover the 'Cash' statistic $C$ [@cash79], which is similar to $\chi^2$ but for Poisson statistics. In the same manner that $-2 \ln\mathcal{L} = \chi^2 + a$ for Normal statistics, $-2 \ln\mathcal{L} = C + a$ for Poisson statistics.

It is worth highlighting that returning images to true photo-electron counts is non-trivial and in our experience many published data sets do not produce enough ancillary information to return the images to true counts to better than an accuracy of a few factors. A particularly pernicious issue is that counts must be known within the CCD itself, not for photons at the top of the atmosphere. The latter is relatively trivial to compute after the fact if we know intrinsic properties of the source spectral energy distribution; however, the former requires estimates of atmospheric transmission, instrumental losses, detector gain and quantum efficiency, etc. Sometimes this information is easy to obtain at least approximately [e.g. for the Sloan Digital Sky Survey, SDSS: @ahn14], but this level of ancillary meta-data is in general rare. Added to this is the fact that optical survey data generally have copious counts per pixel: typically thousands of photoelectric counts. For these reasons, Poisson likelihoods should seldom be used for optical survey data, even if quite shallow. It is more appropriate for fitting X-ray data, where the counts are low and have the required meaning for Poisson statistics. Indeed, X-ray astronomy is the main subdivision that uses Poisson (usually in the guise of Cash) statistics.

If the data are nominally in the Normal statistics regime (i.e. many photoelectron counts per pixel), but in practice have a significant number of data points that are poorly represented by our attempted model (typical when trying to fit smooth two-dimensional <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>profiles to well-resolved galaxies with asymmetries) then more robust Student-T distribution statistics might be appropriate. These distributions are approximately Normal in the core but have broad Lorentzian wings, which puts more likelihood mass at large distances from the Normal core. This behaviour is controlled by the 'degrees-of-freedom', which in practice is not free and is instead estimated via maximum-likelihood from the data directly. The <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>Student-T likelihood is computed by

$$\begin{aligned}
x_{i,j}&=&\frac{(D_{i,j}-M_{i,j})^2}{\sigma_{i,j}^2},\\
\ln\mathcal{L}&=&-\ln \left( \sum_{i=1}^{N_i}\sum_{j=1}^{N_j} \frac{\Gamma{(\frac{\nu+1}{2})}}{\sqrt{\nu \pi}\Gamma{\frac{\nu}{2}}}\left(1+ \frac{x_{i,j}}{\nu} \right)^{-\frac{\nu+1}{2}} \right).\end{aligned}$$

<span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>gives the users easy access to all four types of commonly used likelihood statistics, and it is for the user to decide the most appropriate given the quality and type of kadkins@example.net. For high $S/N$ images of galaxies, the Student-T statistic behaves well over a broad regime given its robustness to outlier flux values. For this reason, it is selected as the default option when setting <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>up for fitting. In future, we will add covariance likelihoods [more appropriate for data that exhibits large amounts of pixel correlation, e.g. NIR, see @andr14], but these are not present in v1.0.

Parameter Optimization
----------------------

Once the observational data have been correctly assembled and the most appropriate type of likelihood statistic has been chosen, the user is free to fit a model image. <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>requires the user to suggest an initial parameterization of the model, which need not be close to the optimal parameters with robust optimizers. The user is free to fix some components and fit others (e.g. they might wish to fix the disc <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index to 1). They are also free to provide prior distributions for each parameter (important for formal Bayesian analysis), hard limits and/or constraints on the allowed fitting region, to specify whether parameters are optimized in log or linear space and to specify additional constraints between parameters (e.g. pair parameters together). The detailed process for specifying these options is provided in the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>manual and example vignettes, so we will not repeat the full description here.

Once the fitting structure has been specified within <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>(<span>profitSetupData</span>, as mentioned above) the user can interface with a number of popular optimization routines. The <span><span><span style="font-variant:small-caps;">R</span></span></span> <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package provides examples of using the base <span>optim</span> function, the open source <span><span style="font-variant:small-caps;">L</span>aplacesDemon</span> package that gives access to gradient optimizers via <span>LaplaceApproximation</span> and a large suite of Markov Chain Monte Carlo (MCMC) samplers via <span>LaplacesDemon</span>, and the genetic algorithm <span><span style="font-variant:small-caps;">C</span>MA-ES</span> package[^2]. These four routes to optimisation offer over a hundred distinct optimisers. The CRAN collates packages that tackle particular problems types: optimization[^3] and Bayesian[^4] analysis task views suggest over a hundred additional packages that themselves potentially contain multiple algorithms.

To the uninitiated this can seem daunting, but the reality is that a core few packages and optimizers give the user a solid foundation for a diverse range of fitting problems. Sample vignettes provided in the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package goes through some example fitting problems in detail, but we will summarize the approach here. The basic strategy for preparing the inputs for galaxy fitting is

-   REQUIRED: read in an <span>**image**</span> of an observed galaxy (in principle any format, but e.g. FITS).

-   OPTIONAL: read in a <span>**mask**</span> with the same size, pixel scale, and astrometry as the <span>**image**</span>.

-   OPTIONAL: read in a <span>**sigma**</span> image with the same size, pixel scale, and astrometry as the <span>**image**</span>.

-   OPTIONAL: read in a <span>**segmentation**</span> map with the same size, pixel scale, and astrometry as the <span>**image**</span>.

-   OPTIONAL: read in a <span>**PSF**</span> image with the same pixel scale as the <span>**image**</span>.

-   REQUIRED: read in an <span>**initial**</span> model list (as detailed above).

-   OPTIONAL: read in a list with the same structure as <span>**initial**</span> detailing which parameters <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>will <span>**fit**</span> (the others will be fixed at their <span>**initial**</span> values).

-   OPTIONAL: read in a list with the same structure as <span>**initial**</span> detailing which parameters <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>will fit in <span>**log**</span> space (the others will be fitted in linear space).

-   OPTIONAL: read in a function detailing the calculation of the <span>**prior**</span> log-likelihood.

-   OPTIONAL: read in a list with the same structure as <span>**initial**</span> detailing the allowed <span>**limits**</span> for each parameter when fitting.

-   OPTIONAL: read in a function detailing the calculation of additional <span>**constraints**</span> to apply to parameters, e.g. pairing parameters together or making them scale relative to each other in a fixed manner.

-   REQUIRED: all of the above two-dimensional matrix images, list structures, and functions are provided to the high-level <span>profitSetupData</span> function that organises the information into an object of class <span>**profit.data**</span> ready for fitting with third-party optimization engines.

Once the user has created the <span>**profit.data**</span> object, which includes some additional options for choosing the type of likelihood and setting the verbosity of the fitting process, a basic strategy for fitting might look like as follows:

-   Initially find a maximum likelihood galaxy model solution using the base <span><span><span style="font-variant:small-caps;">R</span></span></span> <span>optim</span> function using the Broyden, Fletcher, Goldfarb, and Shanno [BFGS: @flet70] algorithm (which is fairly robust to spurious minima).

-   Take the solution from the BFGS optimization as a starting point and use <span>LaplacesDemon</span> component-wise hit-and-run metropolis (CHARM) to make MCMC samples of the likelihood space (this is very robust to local minima, and can move large distances from poor solutions; hence hit-and-run),

-   Use diagnostic tools provided with the <span><span style="font-variant:small-caps;">L</span>aplacesDemon</span> package to test for the quality and convergence of the model fit, including tests for auto-correlation between parameters, the number of effective stationary samples and traditional parameter triangle plots.

-   Assuming the fit is flagged as being well converged and well behaved, the log marginal likelihood (LML) can be computed to aid comparisons between models.

The above fitting process can be carried out for models of varying complexity. If they are well-converged then the LML computed can be used to calculate Bayes factors between simpler and more complex models, offering an objective route for deciding how complex the model needs to be.

<span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>in Practice {#sec:examples}
=========================================================================================

Single galaxy case-study of G266033 {#sec:example1}
-----------------------------------

The <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package includes 10 example data sets with all the required inputs for fitting. These examples use public Sloan Digital Sky Survey [SDSS; @ahn14] and the Kilo Degree Survey [KiDS; @kuij15] data for galaxies selected from the Galaxy And Mass Assembly [GAMA; @driv11; @lisk15] survey that are at reasonably low redshift and are deemed to have multiple components [as found in @lang16]. The vignettes included with the software give examples of fitting these data using high-level <span><span><span style="font-variant:small-caps;">R</span></span></span>and <span><span><span style="font-variant:small-caps;">P</span>YTHON</span></span>interfaces.

Bulge component of galaxy fit:\
\
Disc component of galaxy fit:\
\
Bulge+Disc components of galaxy fit:\
\

As a case study, Fig. \[fig:modelfit\] shows the quality of MCMC fit and residuals that are possible using <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>for G266033. A qualitative assessment of the residuals shows that we are able to remove the major bulge and disc structural components, but that non-axisymmetric components remain (the spiral arms in particular). The three rows of panels show the bulge (top), disc (middle) and combined (bottom) components. The outputs of the CHARM MCMC sampling are shown in Fig. \[fig:modeltriangle\]. Here only stationary samples are shown (i.e. there is no 'burn-in' of the sampling), and whilst there is evidence of some weak covariance between some parameters (e.g. disc magnitude (Dmag) and effective radius (Dre)), in general the posteriors look well sampled and consistent with multivariate Normal distributions. This latter characteristic is useful when estimating marginalized parameter errors.

Using the <span><span><span style="font-variant:small-caps;">R</span></span></span>interface to <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, more quantitative information can be extracted from the fit. Fig. \[fig:modelfitchisq\] shows the output of the <span>profitMakePlots</span> function, which as well as producing the standard residuals, also outputs how they compare to a reference Normal and Student-T distribution. The $\chi^2$ excess is also demonstrated with respect to a $\chi^2$ distribution with one degree-of-freedom. Finally, a residual image scaled by the pixel error $\sigma$ is provided. This shows that there are some significant residual spiral arm structures that are highly unlikely from the point of view of the idealized generative model we are fitting.

As discussed in the Introduction, it is common in the field of galaxy modelling to collapse two-dimensional data into a one-dimensional form. Whilst <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>does not evaluate likelihood using this one-dimensional form, it does provide functions for producing such isophotal data and the associated plots ( <span>profitEllipse</span> and <span>profitEllipsePlot</span>). In brief these functions use the geometric parameters of the disk and bulge components of a simple two-component model to extract isophotal annuli, allowing for the standard geometric distortions such as ellipticity and boxiness (if present). The one-dimensional profile of G266033 with overlaid model fits is shown in Fig. \[fig:modelfitoned\].

![The approximate projected one-dimensional profile for G266033. The grey shaded region shows the 1$\sigma$ error region for the data pixels, and ideally the total model (green line) should sum to follow this distribution quite closely. At a few radii the data and model are in some tension (at the 0.1 mag level in surface brightness), but for the majority of the profile they agree very well.<span data-label="fig:modelfitoned"></span>](Figures/G266033KiDSFit1D.png){width="\columnwidth"}

Given the residual flux not replicated by the model, the question remains how representative any posterior error distributions might be. To estimate the impact an imperfect model can have on the returned posterior error estimates, the residual is subtracted from the initial image. Fig. \[fig:modelfitchisqmod\] shows the effect of fitting such an input where the image noise has been added back via Poisson sampling of the convolved model image. The residuals almost entirely disappear, and the $\sigma$ scaled residuals show no radial kadkins@example.net. Comparing the posteriors to the original input data and the residual-removed input data, the former has typical marginalized posterior errors for each parameter that are a factor of $\sim$2 <span>*larger*</span> (spanning the range 1.3–3) with best-fitting values that agree to within 1%. This is encouraging, since it suggests in this particular case, where <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>is correctly identifying the major structural components, the presence of non-axisymmetric components creates posteriors with larger errors. How such fitting behaves will depend on the data at hand (i.e. this should not be assumed to be true in general), but such a test is easy to implement, and should be part of a standard <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>workflow.

Running <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>on a small sample from SDSS and KiDS {#sec:example2}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

As mentioned above, the <span><span><span style="font-variant:small-caps;">R</span></span></span> <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package comes with 10 fairly isolated example galaxies included that have imaging from SDSS and KiDS. All of these are well resolved galaxies taken from the GAMA survey where we already have well converged bulge and disc fits from @lang16. To create this sample, 40 galaxies from @lang16 were randomly sampled and these were ranked in terms of fit-ability (removing galaxies with more complex backgrounds and nearby sources). Of these, the 10 largest were chosen as example galaxies. As such this sample, whilst small, is broadly representative of how common different classes of bulge-disc systems are (e.g. we are dominated by lower $B/T$ systems). Consistent sky subtractions were made using LAMBDAR [@wrig16], and segmentation maps and PSFs were created using an updated version of SIGMA [@kelv12]. We then proceeded to fit these 10 galaxies using both SDSS and KiDS inputs, and using <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>. The free parameters used throughout were $x$ and $y$ centres, bulge mag, $R_e$ and $n$ ($A/B$ for the bulge was fixed to be 1), and disc mag, $R_e$, $A/B$ and $\theta$ ($n$ for the disc was fixed to be 1, i.e. exponential).

The input parameters were taken from the fits in @lang16, although it should be noted that <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>(used in full MCMC mode) is largely insensitive to the inputs used, as long as the total input magnitude is approximately correct (i.e. within a couple of magnitudes of the correct value). Used in pure downhill gradient mode <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>suffers from similar local minima issue to <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>[see the discussion of <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>convergence in @lang16].

The full range of comparison Figures A1–A6 are included in Appendix \[app:consist\]. Here we compare how well these different combinations of decomposition codes and data sources affect the returned values for bulge and disc magnitudes.

### Comparison of bulge magnitudes

Fig. \[fig:compmagB\] compares the agreement between estimated bulge magnitudes. The one major disagreement between codes is the faintest bulge measured. In <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>the decomposition preferred removing the bulge entirely, often hitting our specified lower limit of 30 mag. Using <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, the code does not allow the solution to move huge distances from the initial estimates unless the likelihood terrain is very smooth, which occurs only when the model reproduces the data with no clear residuals. Fig. \[fig:sdssdecomp\] shows the fit and residuals for the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>fit for this galaxy, suggesting there is little need for any kadkins@example.net.

Otherwise the main conclusion that can be drawn is that the codes correlate tightly, and so do the data sets, but in all cases the scatter is much larger than the errors suggested by <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>or <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>. Although the errors returned by <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>were consistently larger for these galaxies, they are still smaller than the points in the panels.

A general remark is that we find more consistency between codes than between data sets. Removing the outlier galaxy G266035, we measured the intrinsic scatter using the <span><span style="font-variant:small-caps;">hyper-fit</span></span>code of @robo15 and find it to be reduced by more than a factor of two. It is at a minimum for the SDSS data (0.14 dex versus 0.20 dex scatter orthogonal to the 1–1 line), suggesting that some aspect of our data processing is more internally consistent for the SDSS data. This might be the background subtraction or the PSF determination.

### Comparison of disc magnitudes

Fig. \[fig:compmagD\] compares the agreement between estimated disc magnitudes. In general we find more self-consistent fits for discs both between codes and between data. Whilst the smallest intrinsic scatter is again found for SDSS using <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, the results for <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>using SDSS and KiDS are not far behind. The intrinsic scatter for KiDS using <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>using SDSS and KiDS are notably worse (the latter showing the most scatter).

For all these fits we find that the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>MCMC solution provides a <span>*more likely*</span> fit both when forcing the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>parameters through <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, and when forcing the <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>parameters through <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>. Usually the increases in likelihood when using <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>are substantial, suggesting the difference is due to local convergence issues with the Levenberg-Marquardt [@marq63] algorithm built into <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, rather than issues to do with model accuracy that we explored in Section \[sec:profit-acc\].

A general conclusion is that we appear to be able to recover more self-consistent results for disc properties compared to bulge properties. Further evidence for this is shown in Appendix \[app:consist\], where disc $R_e$ is found to be more reliably measured than bulge $R_e$. Bulge $n$ is notably the hardest property to measure consistently, a finding in agreement with recent work by @savo16. We investigate in more detail how well we expect to be able to recover various bulge-disc properties for different quality and depth data in the next section.

Applying <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>to Simulated Current and Future Imaging Surveys {#sec:future}
======================================================================================================================================

Having described and tested our new <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>decomposition code in some detail, we finally investigate how it performs on data of different depth and quality. For the purposes of these tests we create and fit bulge-disc systems in $40 \times 40$ arcsec image stamps. We investigate three sources of survey imaging that are indicative of the types of data that <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>will be used on en-masse in future: SDSS, KiDS and LSST. Since these results are purely indicative we make some simplifying assumptions for the three surveys. Table \[tab:surveys\] presents the assumptions made when simulating and fitting the galaxies. These are not precisely the values advertised for the various surveys, but are indicative given the inevitable variations in data quality. For LSST these estimates are for the stacked 5-yr survey. Since we know the precise PSF used to convolve the model and the images themselves are precisely background subtracted, the following results are the upper-limits on the decomposition performance we can hope to expect.

The simulations themselves sample 10,000 profiles from a uniform grid of total magnitude ($15 \le m_{T} \le 22$), bulge fraction ($0 \le B/T \le 1$), logarithmic bulge effective radius ($0 \le \log_{10}(R_e) \le 1$), logarithmic disc effective radius ($0 \le \log_{10}(R_e) \le 1$), logarithmic bulge <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index ($0 \le \log_{10}(n) \le 1$) and disc axial ratio ($0 \le A/B \le 1$). The bulge axial ratio was assumed to have $A/B=1$ and the disc <span><span><span style="font-variant:small-caps;">S</span>érsic</span></span>index was fixed to $n=1$. <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>never appears to struggle to find the correct disc angle $\theta$, so we only simulated galaxies with the minor axis varying on the $x$-axis of the image. Note we do not impose internal correlations between parameters, so these results span an overly generous range of structural parameter space.

  Survey   Scale ("/pix) & PSF FWHM (")   $1 \sigma$ $r$-band depth   
  -------- ------------------------------ --------------------------- ----
  SDSS     0.4                            1.4                         24
  KIDS     0.2                            0.6                         26
  LSST     0.2                            0.6                         28

  : Assumed image quality parameters for different surveys.

\[tab:surveys\]

![Comparisons of 10,000 random simulations for SDSS, KiDS and LSST quality data. Top panel shows the fraction of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>fits that converge on a solution that is not a hard limit of the fit as a function of total magnitude. Bottom panel shows the mean Euclidian logarithmic distance between the six input parameters and the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>fit for the galaxies that have converged fits taken from the top panel (where the distance in flux is $\log_{10}(flux)$ rather than magnitude, i.e. $m/2.5$). The solid lines show the median of the results, and the dotted show the $14^{th}$ and $86^{th}$ percentile ranges (akin to the $1\sigma$ range if the distributions are Normal). In simple terms, larger value are better in the top panel and lower values are better in the bottom panel.<span data-label="fig:converge_frac"></span>](Figures/magTvFitDist.pdf){width="\columnwidth"}

Fig. \[fig:converge\_frac\] shows the results of these simulations in a compact manner, comparing the fraction of fits that are found to converge (which means they find solutions that are not hard limits imposed within <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>) and the typical average separation between all input and output parameters in log-space. These properties are plotted in Figures B1–B7 for all major observables in Appendix \[app:sims\], but here we show the results versus the most observable input parameter: the total magnitude of the galaxy. Unsurprisingly, all the results are best when the galaxy is intrinsically bright and the source signal dominates over the sky background. Of perhaps more surprise is that we see a large improvement in decomposition performance when moving from SDSS to KiDS quality data, but a relatively minor improvement when we move from KiDS to LSST. This appears to be due to the major improvement being limited to surface brightness depth, the pixel scale and the typical PSF FWHM is not expected to be much (if at all) improved between KiDS and LSST (one caveat being the latter has a much larger field-of-view, so further un-simulated sky-subtraction gains could be expected).

To briefly summarize the other trends presented in Appendix \[app:sims\]: lower bulge and disc $R_e$, lower disc $A/B$, lower bulge $n$ and a moderate $B/T\sim0.5$ all lead to improved fitting results. For $R_e$, this is simply because lower $R_e$ means high surface brightness for a given magnitude, and the components become easier to distinguish against the background. We start our simulations at an $R_e$ of 1 arcsec, so the caveat to make is that much below this ($R_e$ less than half the PSF FWHM), and the parameters become indistinguishable structurally. Even in this regime we can still expect the component magnitude to be well recovered, it is just hard to resolve structure inside the PSF scale.

It is clear from these results that only in the most favourable regimes can we expect complete <span>*and*</span> robust bulge-disc decompositions, even using the best current and next generation deep survey data. This is true even when we are operating in the regime of moderately low redshift galaxies extracted from surveys such as GAMA. A future low-redshift focused WAVES-Wide survey [@driv16], being inherently lower redshift due to its photo-$z$ pre-selection (with typical redshift likely to be similar to SDSS DR10) is the best prospect for such future studies given the target of high redshift completeness, and a guarantee it will have deep good quality imaging data (since KiDS will act as the primary input source for targets).

Discussion and Conclusions {#sec:discuss}
==========================

In this paper we have presented our new publicly available galaxy modelling and decomposition code <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>. The core code comes in a standalone <span><span style="font-variant:small-caps;">c</span>++</span> library (<span>`libprofit`</span>) that allows for easy access to higher level languages (e.g. <span><span><span style="font-variant:small-caps;">R</span></span></span>and <span><span><span style="font-variant:small-caps;">P</span>YTHON</span></span>) through a simple API.

The core advances that <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>offers over currently available software are that it:

-   is fully open-source with multiple active developers,

-   offers a standalone library (<span>`libprofit`</span>) for accurate and fast pixel integrations when generating a model,

-   can be extended with new profiles in a simple well-documented manner,

-   allows for simple or complex priors on parameters (an important aspect of Bayesian analysis),

-   offers a range of likelihood calculations,

-   is untied to any specific optimizers but has easy access to downhill minimization, genetic algorithm, and MCMC routines,

-   can fit parameters in log or linear space,

-   allows for simple or complex additional constraints between parameters,

-   offers brute-force and FFT PSF convolution options, with automatic benchmarking to select the fastest strategy.

Initially <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>comes in three varieties: a fully featured <span><span><span style="font-variant:small-caps;">R</span></span></span>package (<span>ProFit</span>, discussed in detail in this paper), a basic <span><span><span style="font-variant:small-caps;">P</span>YTHON</span></span>wrapper (<span>pyprofit</span>) and a command line terminal interface (<span>profit-cli</span>). The <span><span><span style="font-variant:small-caps;">R</span></span></span>package is the most advanced in terms of features, and we have a longer term aim to bring the <span><span><span style="font-variant:small-caps;">P</span>YTHON</span></span>package up to the same level of sophistication. The command line interface only exists for the easy generation of model images via calling the underlying <span>`libprofit`</span>library, so it does not provide any built-in optimisation. By separating the model image generation (which should be an objective black-box task achieved through an API) into a separate <span>`libprofit`</span>library, users are not tied to our high-level solution for the much more subjective problem of galaxy fitting (with many caveats over masking, convolution, likelihoods etc). We are aware of at least one community fork of <span>`libprofit`</span>already that uses diffusive nested sampling [DNEST; @brew11] in order to overcome sampling of highly multimodal data (Huijser et al., in preparation). Extensions to other languages using the library API are encouraged, but simpler workarounds using the command line interface are also possible for less programming-savvy users. To avoid community confusion, we request that any forks that are released append the name in some manner (e.g. <span><span style="font-variant:small-caps;">P</span>roFit\_STAN</span>). The aim would be to pull any substantial and useful changes into the main <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>branch in the longer term.

The first versions of the <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>code stemmed from preliminary work by ASGR. Following this, DST and RT have added many new features and have heavily modified and expanded the functionality of the software. From the early stages, <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>has been designed in a highly modular manner. This is important to prevent the user becoming limited to our default choice of profile, likelihood evaluation, or optimization method. The core <span>`libprofit`</span>library is designed to be fast and accurate at integrating and convolving target model images, where the likelihood function to compute, and optimization engine to use, are largely choices for the user via higher level interfaces. The <span><span><span style="font-variant:small-caps;">R</span></span></span>package version of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>contains a large number of examples using simple downhill gradient schemes, more complex genetic algorithms and more computationally expensive MCMC techniques. Users are encouraged to build from these examples to use more or less sophisticated engines as appropriate.

The various libraries and higher level interfaces are all available on GitHub, and future support and functionality will be added through these repositories. This paper necessarily refers to a static v1.0 of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, as such specifics regarding operation and options should be derived from the public repositories and documentation found there, rather than this text. The most reliable longterm location for the base <span>`libprofit`</span>library is <https://github.com/ICRAR/libprofit>. The higher-level <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>is available at <https://github.com/ICRAR/ProFit> and the <span><span><span style="font-variant:small-caps;">P</span>YTHON</span></span>variant is maintained at <https://github.com/ICRAR/pyprofit>. This paper was written using the <span><span><span style="font-variant:small-caps;">R</span></span></span>implementation exclusively.

Community use and feedback is encouraged, especially via raising <span>*issues*</span> and <span>*pull*</span> requests through GitHub. In particular, the requirements outlined in Section \[section\_introduction\] are not an exhaustive list, so users are encouraged to submit feature proposals and requests. Currently planned extensions include built-in support for Monte Carlo image generation, simultaneous fitting of multiple images (in the same band) and/or multiple bands, zero-point calibration, covariance likelihoods and PSF fitting. Indeed, the <span><span><span style="font-variant:small-caps;">R</span></span></span>package already includes a vignette with PSF fitting examples, a full description of which is omitted here for brevity.

In this paper, we have investigated the application of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>to both SDSS and KiDS data, using <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>reference runs as a comparison. In pragmatic terms, <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>and <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>achieve consistent results given the same input data, with at least as much scatter being produced by changes between data source (in this case, SDSS versus KiDS). This is encouraging in that it validates the broad findings of recent work that made exclusive use of <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, and lends credibility to our future applications of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>to a number of different data sources. The main difference is a large degree of intervention was required when running GALFIT via running on a large grid of initial conditions and post-processing the results [see @lang16], whereas <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>was run by AM with just a basic wrapper using one of the many available MCMC routines in <span><span><span style="font-variant:small-caps;">R</span></span></span>and converged to reasonable global solutions with little user intervention.

Acknowledgements
================

Much of the work presented here was made possible by the free and open <span><span><span style="font-variant:small-caps;">R</span></span></span>software environment [@rcor16]. All figures in this paper were made using the <span><span><span style="font-variant:small-caps;">R</span></span></span> <span>magicaxis</span> package [@robo16]. Data from the KiDS [@kuij15] and SDSS [@ahn14] surveys were used for this work. Funding for SDSS-III has been provided by the Alfred P. Sloan Foundation, the Participating Institutions, the National Science Foundation, and the U.S. Department of Energy Office of Science. The SDSS-III web site is http://www.sdss3.org/. Parts of this research were conducted by the Australian Research Council Centre of Excellence for All-sky Astrophysics (CAASTRO), through project number CE110001020. Credit to E. Mannering for Fig. \[fig:pixint\], she was inspired by the lamentable initial efforts of ASGR. Thank you to the anonymous referee, whose comments particularly assisted in clarifying complex parts of the paper.

<span>1</span>

Comparisons of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>Example Galaxies {#app:consist}
=============================================================================================================

To supplement Figs \[fig:compmagB\] and \[fig:compmagD\], below are the various other <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>, <span><span><span style="font-variant:small-caps;">G</span>ALFIT</span></span>, SDSS and KiDS comparisons for the 10 galaxies that are included in the standard <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>installation for demonstration and testing purposes.

![Panels comparing the measured bulge $R_e$ for the 10 well resolved galaxies included with the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package. See Fig. \[fig:compmagB\] for details.](Figures/CompAllreB.pdf){width="\columnwidth"}

![Panels comparing the measured disc $R_e$ for the 10 well resolved galaxies included with the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package. See Fig. \[fig:compmagB\] for details.](Figures/CompAllreD.pdf){width="\columnwidth"}

![Figures comparing the measured bulge $n$ for the 10 well resolved galaxies included with the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package. See Fig. \[fig:compmagB\] for details.](Figures/CompAllnB.pdf){width="\columnwidth"}

![Figures comparing the measured disc $A/B$ for the 10 well resolved galaxies included with the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package. See Fig. \[fig:compmagB\] for details.](Figures/CompAllaxratD.pdf){width="\columnwidth"}

![Figures comparing the measured disc $\theta$ for the 10 well resolved galaxies included with the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package. See Fig. \[fig:compmagB\] for details.](Figures/CompAllangD.pdf){width="\columnwidth"}

![Figures comparing the measured $B/T$ for the 10 well resolved galaxies included with the <span><span><span style="font-variant:small-caps;">R</span></span></span><span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>package. See Fig. \[fig:compmagB\] for details.](Figures/CompAllB2T.pdf){width="\columnwidth"}

Comparisons of <span><span><span style="font-variant:small-caps;">P</span>roFit</span></span>Simulations for SDSS, KiDS, and LSST Type Data {#app:sims}
===========================================================================================================================================

![As per Fig. \[fig:converge\_frac\] but for bulge magnitude on the x-axis.](Figures/magBvFitDist.pdf){width="\columnwidth"}

![As per Fig. \[fig:converge\_frac\] but for disc magnitude on the x-axis.](Figures/magDvFitDist.pdf){width="\columnwidth"}

![As per Fig. \[fig:converge\_frac\] but for bulge $R_e$ on the x-axis.](Figures/reBvFitDist.pdf){width="\columnwidth"}

![As per Fig. \[fig:converge\_frac\] but for disc $R_e$ on the x-axis.](Figures/reDvFitDist.pdf){width="\columnwidth"}

![As per Fig. \[fig:converge\_frac\] but for bulge $n$ on the x-axis.](Figures/nserBvFitDist.pdf){width="\columnwidth"}

![As per Fig. \[fig:converge\_frac\] but for disc $A/B$ on the x-axis.](Figures/axratDvFitDist.pdf){width="\columnwidth"}

![As per Fig. \[fig:converge\_frac\] but for $B/T$ on the x-axis.](Figures/BoTvFitDist.pdf){width="\columnwidth"}

[^1]: http://stsdas.stsci.edu/multidrizzle/

[^2]: Versions of <span>LaplacesDemon</span> and <span><span style="font-variant:small-caps;">C</span>MA-ES</span> implementing runtime limits for use on shared (super)computers are available at <https://github.com/taranu/LaplacesDemon> and <https://github.com/taranu/cmaeshpc>, respectively.

[^3]: cran.r-project.org/web/views/Optimization.html

[^4]: cran.r-project.org/web/views/Bayesian.html

{'source': 'arXiv_out/1611'}