A selection function toolbox for subsets of astronomical catalogues
  Large catalogues are ubiquitous throughout astronomy, but most scientific
analyses are carried out on smaller samples selected from these catalogues by
chosen cuts on catalogued quantities. The selection function of that scientific
sample - the probability that a star in the catalogue will satisfy these cuts
and so make it into the sample - is thus unique to each scientific analysis. We
have created a general framework that can flexibly estimate the selection
function of a sample drawn from a catalogue in terms of position, magnitude and
colour. Our method is unique in using the binomial likelihood and accounting
for correlations in the selection function across position, magnitude and
colour using Gaussian processes and spherical harmonics. We have created a new
open-source Python package selectionfunctiontoolbox that implements this
framework and used it to make three different estimates of the APOGEE DR16 red
giant sample selection function, as a subset of 2MASS, with each estimate using
an increasing amount of technical knowledge of the APOGEE targeting. In a
companion paper we applied our methodology to derive estimates of the
astrometric and spectroscopic selection functions of Gaia EDR3. Our framework
will make it trivial for astrophysicists to estimate the selection function
that they should be using with the custom sample of stars that they have chosen
to answer their scientific question.
