(17)

Another advantage of using two pairs of exposures is that one can calculate
the null polarization (NULL1 and NULL2) as in equations 20 and 26 of Bagnulo
et al. (2009), which provides a way to quantify the amount of spurious
polarization. The null polarization for the Difference method is given by

$NULL_{X}=\frac{1}{4}\sum_{k=1}^{2}{\left[(-1)^{k-1}\left(\frac{r_{2k-1}-1}{r_{2k-1}+1}-\frac{r_{2k}-1}{r_{2k}+1}\right)\right]},$
(18)

and for the Ratio method the null polarization is given by

$NULL_{X}=\frac{\left(\prod_{k=1}^{2}{r_{2k-1}/r_{2k}}\right)^{\frac{(-1)^{k-1}}{4}}-1}{\left(\prod_{k=1}^{2}{r_{2k-1}/r_{2k}}\right)^{\frac{(-1)^{k-1}}{4}}+1}.$
(19)

Finally, the uncertainties of polarimetric measurements can be calculated from
the extracted fluxes and their uncertainties (denoted here by $\sigma$) by
equations A3 and A10 of Bagnulo et al. (2009). In the Difference method, the
variance for each spectral element is given by

$\sigma_{X}^{2}=\frac{1}{16}\sum_{i=1}^{4}{\left\\{\left[\frac{2f_{i\parallel}f_{i\perp}}{(f_{i\parallel}+f_{i\perp})^{2}}\right]^{2}\left[\frac{\sigma_{i\parallel}^{2}}{f_{i\parallel}^{2}}+\frac{\sigma_{i\perp}^{2}}{f_{i\perp}^{2}}\right]\right\\}},$
(20)

and in the Ratio method the variance is given in terms of the flux ratio
$r_{i}$ as defined in Equation 14, i.e.,

$\sigma_{X}^{2}=\frac{\left(\frac{r_{1}}{r_{2}}\frac{r_{4}}{r_{3}}\right)^{1/2}}{4\left[\left(\frac{r_{1}}{r_{2}}\frac{r_{4}}{r_{3}}\right)^{1/4}+1\right]^{4}}\sum_{i=1}^{4}{\left[\frac{\sigma_{i\parallel}^{2}}{f_{i\parallel}^{2}}+\frac{\sigma_{i\perp}^{2}}{f_{i\perp}^{2}}\right]}.$
(21)

Applying this formalism to SPIRou spectra, we obtain values that vary
continuously throughout the spectrum and are systematically above or below
zero for each spectrum, which we refer to here as the ‘continuum
polarization’. For general scientific applications with SPIRou, this continuum
polarization is actually spurious as it reflects small differences in the
injection between beams, and must therefore be fitted and removed. This step
is mandatory before performing measurements in spectral lines. apero applies
an iterative sigma-clip algorithm to fit either a polynomial or a spline to
model the continuum polarization.

###  10.2 Least-Squares Deconvolution

The least-squares deconvolution method (LSD) is an efficient technique that
combines the signal from thousands of spectral lines retaining the same line
profile information to obtain a mean velocity profile for the intensity,
polarization, and null spectra. A common application of this technique
concerns the measurement of the Zeeman split into Stokes V (circularly
polarized) profiles. The Zeeman split is a physical process where electronic
transitions occurring in the presence of a magnetic field have their main
energy transition level split into two additional levels, forming a double
line in the intensity spectrum. An interesting feature of these lines is that
they are circularly polarized and their polarizations have opposite signs.
Therefore, by observing the circularly polarized spectrum one can obtain a
characteristic Stokes V profile that provides a way to detect and characterize
the magnetism in stellar photospheres with great sensitivity.

apero implements the LSD calculations using the formalism introduced by Donati
et al. (1997), summarized as follows. Let us first consider the weight of a
given spectral line $i$, $w_{i}=g_{i}\lambda_{i}d_{i}$, where $g$ is the Landé
factor (magnetic sensitivity), $\lambda$ is the central wavelength, and $d$ is
the line depth. Then one can construct the line pattern function,

$M(v)=\sum_{i=1}^{N_{l}}{w\delta(v-v_{i})},$ (22)

where $N_{l}$ is the number of spectral lines considered in the analysis,
$\delta$ is the Dirac function, and $v$ is the velocity. The transformation
from wavelength ($\lambda$) to velocity space is performed by the relation
$dv/d\lambda=c/\lambda$, where $c$ is the speed of light. The LSD profile is
calculated by the following matrix equation:

$\rm{\bf Z}=\left(\rm{\bf M}^{t}.\rm{\bf S}^{2}.\rm{\bf M}\right)^{-1}\rm{\bf
M}^{t}.\rm{\bf S}^{2}.\rm{\bf P},$ (23)

where $\rm{\bf P}$ is the polarimetric spectrum calculated from Equation 16 or
17, and $\rm{\bf S}$ is the covariance matrix, a diagonal matrix where each
element in the diagonal is given by $S_{jj}=1/\sigma_{j}$, with $\sigma_{j}$
being the uncertainty in the polarimetric spectrum calculated from Equation 20
or 21.

Note that one can also calculate the null polarization LSD profile by
substituting the polarimetric spectrum $\rm{\bf P}$ by the null spectrum
$\rm{\bf N}$ in Equation 23. The intensity LSD is also possible, by using the
flux spectrum $\rm{\bf F}$, but in this case the line weight in Equation 22 is
simply given by the line depth, i.e, $w_{i}=d_{i}$.

In practice, LSD requires a few important steps to be executed by apero.
First, each individual spectrum is cleaned using a sigma-clip rejection
algorithm to minimize the impact of outliers in the LSD profile. Then we set a
grid of velocities to calculate the LSD profile, where the grid is defined by
the following parameters: an initial velocity, $v_{0}$, a final velocity,
$v_{f}$, and the total number of points in the grid, $N_{v}$. Next, a fast and
accurate method is necessary to project the spectral values onto the velocity
grid. Finally, an appropriate catalog of spectral lines (line mask) needs to
be adopted for the LSD calculations. apero selects the line mask from a
repository of masks, where the selection is based on the proximity to the
effective temperature of the star observed. The apero masks are computed using
the VALD catalog (Piskunov et al., 1995) and a MARCS model atmosphere
(Gustafsson et al., 2008) with an effective temperature ranging from 2500 to
5000 K in steps of 500 K, and the same surface gravity of $\log g=5.0$ dex.
The lines that are effectively used in the LSD analysis are selected with line
depths above a given threshold, which is set to 3% by default and with a Landé
factor of $g_{\rm eff}>0$, resulting in a total of approximately 2500 atomic
lines that cover the full spectral range of SPIRou. Figure 27 shows an example
of an LSD analysis performed on a 4-exposure Stokes-V sequence of the bright
Ap star Gamma Equulei, which has a strong magnetic field (e.g., Bychkov et
al., 2006) and therefore shows an obvious Zeeman feature in the SPIRou data.

Figure 27: LSD analysis performed on the polarimetric data reduced with APERO
and obtained from a 4-exposure Stokes-V sequence of the bright Ap star Gamma
Equulei. Panels from top to bottom show Stokes I, Stokes V, and null profiles.

In practice, the LSD analysis is not computed in a standard automated run of
apero but the module is supplied and can be activated with the use of a single
keyword in the apero profiles or run after processing.

Figure 28: Polarimetric sequence

##  11 Post processing

The final data products that go to PIs are composite files of many of the
outputs of apero. For SPIRou, these are sent to the Canadian Data Astronomy
Center (CADC)161616accessible from https://www.cadc-ccda.hia-iha.nrc-
cnrc.gc.ca/ but are only produced for science targets and hot stars (i.e.,
obj_fp, obj_dark, polar_fp, and polar_dark) and not for calibrations by
default. There are currently five post-processing files each linked to a
single odometer code. These are the 2D extracted output (e.fits, Section
11.1), the 2D telluric corrected output (t.fits, Section 11.3), the 1D output
(s.fits, Section 11.2), the velocity output (v.fits, Section 11.4), and the
polarimetric outputs (p.fits 11.5). A summary of the CADC output files is
available in table 4 and the post-process sequence is shown in Figure 29.

File |  Description
---|---
(odometer)e.fits |  2D extracted spectrum for fibers AB, A, B, C, wavelength solution, and blaze
(odometer)s.fits |  1D extracted spectrum for fibers AB, A, B, C, and telluric corrected spectrum if available
(odometer)t.fits |  2D telluric corrected spectrum for fiber AB, A, B, wavelength solution, blaze, and reconstructed atmospheric transmission
(odometer)v.fits |  combined and per order CCFs for fitting the radial velocity of the star
(odometer)p.fits |  polarimetric products (Polarimetric flux, Stokes I, Null vectors, wavelength solution, and blaze)
Table 4: Science ready outputs sent to the Canadian Data Astronomy Center,
CADC).

###  11.1 2D extraction product (e.fits)

These are the combined extracted products. All extensions are two-dimensional
spectra of size $4088\times 49$. The ‘e.fits’ file contains the extracted
spectrum for each order for each fiber and the matching wavelength and blaze
solution for each order and each fiber. The files are identified with a single
odometer generated at the time of observation followed by an ‘e.fits’ suffix.

###  11.2 2D telluric corrected product (t.fits)

These are the combined telluric-corrected products. All extensions are two-
dimensional spectra of size $4088\times 49$. The ‘t.fits’ file contains the
telluric corrected spectrum for each order and each fiber and the matching
wavelength and blaze solution for each order and each fiber. The files are
identified with a single odometer code at the time of observation followed by
a ‘t.fits’ suffix.

###  11.3 1D extraction and 1D telluric corrected product (s.fits)

These are the combined 1D spectrum products and consist of two tables. The two
tables consist of the 1D spectrum in 1. velocity units and 2. wavelength
units. They each consist of the following columns: the wavelength solution,
the extracted flux in AB, A, B, and C, the telluric corrected flux in fibers
AB, A, and B (if available), and the associated uncertainties for each flux
column. The files are identified with a single odometer code at the time of
observation followed by an ‘s.fits’ suffix.

###  11.4 Velocity product (v.fits)

The velocity products are packaged into the ‘v.fits’ file. Currently, only the
CCF values (Section 9.1) are added as an extension as the LBL products are
computed separately. The CCF file consists of the CCF generated for each
radial velocity element (by default this is between $\pm$300 $\text{ms}^{-1}$
in steps of 0.5 $\text{ms}^{-1}$) for each order and a combined CCF for the
same radial velocity elements. The files are identified with a single odometer
code at the time of observation followed by a ‘v.fits’ suffix. Once the LBL
module is able to be used with apero it will add an extension to the ‘v.fits’
(the ‘rdb’ extension described in the LBL
documentation${}^{\ref{footnote:lbl_docs}}$).

Figure 29: Post-process sequence

###  11.5 Polarimetric product (p.fits)

These are the combined polarimetric products. The ‘p.fits‘ file consists of
eight image extensions and three table extensions. The first two tables are
the 1D representations of the 2D polarimetric products (listed in the
extensions above) in 1. velocity units and 2. wavelength units. They each
consist of the following columns: the wavelength solution, the polarimetric
flux, the Stokes I flux, the Null 1 and 2 fluxes, and the associated
uncertainties on each flux column. The third table lists the configuration
parameters used to run apero. Although polarimetric products are the
combination of at least 4 odometer codes, files are associated with a single
odometer code (the first in the sequence at the time of observation) followed
by a ‘p.fits’ suffix.

##  12 Discussion

apero has been an ongoing effort since its conception in October 2017 (see
Appendix D and table D1). With the first light of SPIRou in April 2018, it
took nearly 2 years for apero to start producing precise science results and
has been used in publications since 2020 (see Appendix E and table E1). Here
we discuss current performances and limitations and planned future work.

###  12.1 Performance and limitations

Throughout development, we have tried to optimize the speed of all recipes
(e.g., through the use of SQL databases, numba, bottleneck, etc.). With the
most current version (v0.7.256), using 35 CPU cores (on a single node), we can
reduce all available data (all SPIRou legacy survey data and all PI data to
which we have access, covering $\sim$430 nights and $\sim$45000 science
observations) in 7 days; table 5 shows a breakdown of the various steps using
a 35 core machine. These timings are for all data we have access to, which are
equivalent to $\sim$90% of all data taken with SPIRou between April 2018 and
June 2022.

Sequence |  Recipes | Number | Time taken | Efficiency
---|---|---|---|---
Pre-processing |  apero_preprocess | 75761 files | 34.5 hours | 0.89
|  |  |  |
Reference Calibrations |  apero_dark_ref, apero_badpix, apero_loc_spirou, apero_shape_ref, apero_shape, apero_flat, apero_thermal, apero_leak_ref, apero_wave_ref | 1 night | 1.5 hours | -
|  |  |  |
Nightly Calibrations |  apero_badpix, apero_loc_spirou, apero_shape, apero_flat, apero_thermal, apero_wave_night | 432 nights | 7.4 hours | 0.87
|  |  |  |
Extraction |  apero_extract | 46836 files | 63.3 hours | 0.63
|  |  |  |
Telluric (hot star) |  apero_mk_tellu, apero_mk_model, apero_fit_tellu, apero_mk_template | 1043 files | 1.1 hours | 0.70
|  |  |  |
Telluric (science) |  apero_fit_tellu, apero_mk_template | 45524 files | 34.6 hours | 0.75
|  |  |  |
CCF |  apero_ccf | 45524 files | 7.0 hours | 0.89
|  |  |  |
Polarimetry |  apero_polar | 9880 groups | 2.1 hours | 0.90
|  |  |  |
Post-process |  apero_processing | 48472 files | 18.4 hours | 0.93
Total |  |  | 170.1 hours | 0.76
|  |  | 7.1 days | 0.76
Table 5: Example full run reducing all SPIRou legacy survey (and some PI) data
from April 2018 to April 2022. This was processed on one machine using 35
cores. Note preprocessing is done on both science and calibration
observations, reference calibrations are only run on a single night, and each
nightly calibration depends on the availability of specific calibrations thus
leading to a range of nights (from 366 to 401). Polarimetric groups consist of
4 individual exposures in different rhomb positions and are only processed for
polar_fp and polar_dark files. The number of specific steps may depend on
previous steps (i.e., quality control failures, engineering nights that were
excluded, and odometer codes that were present in a list to not be processed).
The efficiency is defined in Equation 24.

We find that with 35 CPU cores we reach a point where we start to see input-
output bottlenecks, most probably caused by writing to disk and/or writing to
the various databases. This manifests as an individual slowdown of each recipe
run which limits the efficiency of using more CPU cores (i.e., more recipes
run at the same time mean more files being written to disk at the same time
and more writing to the various database at the same time causing queuing to
occur). We define efficiency in table 5 as the total CPU time taken divided by
the total time taken to run multiplied by the number of cores (Equation 24). A
perfectly efficient code would give a value of 1.

$\text{Efficiency}=\frac{\text{totalCPUtime}}{\text{totaltimetaken}\times
N_{cores}}$ (24)

We see that on average we have an efficiency between 0.7 and 0.93. We find
that recipes that run quickly but save several files have lower efficiency,
i.e., that a bottleneck of writing to disk may be occurring; however, these
recipes also run quickly and write frequently to the various databases, and as
such it is hard to distinguish between the disk and database bottlenecks.
Also, recipes that run slow are rated as more efficient due to the amount of
time spent using the CPUs (i.e., science algorithms) against reading/writing
to and from disk/databases, thus our metric is far from perfect. Another
factor is other processes using the machine at that specific time that cannot
be easily taken into account when measuring how efficient we are. We will
continue to review the performances, speed up the science algorithms and find
ways to make the individual recipes faster.

Currently, apero is optimized to run on a single node (i.e., a single machine)
with access to many CPU cores on this single node. It is possible to run
batches of apero in a manual way using multiple runs of apero_processing and
controlling (manually) when to run the next step (i.e., making sure all pre-
processing is done before reference calibrations, that all reference
calibrations are done before any night calibrations, etc.). One can also run
recipes one-by-one bypassing the use of the apero_processing recipe
completely. apero is optimized to reduce a full data set, this implies many
terabytes of raw and reduced data. Currently to reduce a single night of data
one requires at the very least a full reference calibration night (i.e., the
calibration data from 2020-08-31) and the full set of calibrations for the
night to be reduced (and preferably a few nights surrounding it in case any
calibrations fail quality control) and the full telluric database of hot stars
(from every night processed). This obviously means a large amount of data is
required for even a single night or single observation. We plan to release a
full calibration database and full telluric database of hot stars with a way
to get and install this data, in order to allow any user to reduce a small set
of data. We do however always recommend using data reduced with a full data
set done in a uniform way. This is currently available at data centers at
CFHT, Université de Montréal, and the Laboratoire d’Astrophysique de
Marseille.

###  12.2 Future work

As with most pipelines, improvements are always ongoing. With the LBL RV
analysis code, we have seen RV accuracy down to 2$\text{ms}^{-1}$ with SPIRou,
which is an indication that apero is at least this precise. However, there are
several features we plan to add:

  * •

The apero recipes do not currently propagate uncertainties throughout the data
reduction process, which can be problematic when trying to understand the
limiting factors in the data analysis. Full error propagation is important as
feedback to the engineering team; for example, quantifying the impact of the
thermal background from the optical train on the measurement of $K$-band
spectroscopic features such as the 2.29 $\mu$m CO band-head could justify
efforts to cool parts of the optical train or not.

  * •

In parallel to the propagation of uncertainties, we plan to propagate quality
flags on pixel values, for example, whether a given invalid pixel is due to a
cosmic ray hit or a hot pixel. In the current framework, pixels are either
deemed valid or invalid and flagged as a nan, which does not allow one to
back-trace the origin of missing data. This is done for JWST data
products171717https://jwst-reffiles.stsci.edu/source/data_quality.html with a
pixel-level data quality encoded with 32-bit integers.

  * •

As the SPIRou fibers are multi-mode, one expects a certain level of noise to
arise from the time-varying weight of modes injected in each of the science
fibers. This is minimized through the use of a pupil slicer and fiber
scrambler at the injection. As the pupil slicer image provides more
information on the flux distribution at the fiber exit than a simple fiber
(e.g., the bottom-center panel in Figure 19), one could decorrelate this
spatially-resolved information against the modal noise.

  * •

Persistence in infrared arrays is a non-trivial problem for faint-target
observations Artigau et al. (2018). For any given image, one sees a decaying
remnant image of all previous observations with decreasing amplitude. The
amplitude of any given observation falls with an amplitude that is
proportional to the inverse of the delay since the last illumination. One
notable feature of persistence in infrared arrays is that it is not only the
previous frame that matters but the entire history of illumination over the
last few hours. A bright target observed for a long time at the beginning of a
night (a common example being a multi-hour sequence to monitor a transiting
planet) will affect all fainter targets observed later during the night. To
add further complexity to the matter, the persistence response varies at the
pixel-to-pixel level. Work has begun to construct a persistence model for
SPIRou. Furthermore, the algorithms need to be run at the observatory level as
data obtained earlier in the night may be proprietary and not accessible to
all apero users.

  * •

The main limitation for faint object observations with SPIRou or any near-
infrared pRV spectrograph, particularly bluer of the $K$ band, is detector
readout noise. As has been demonstrated by Payeur et al. (2022), machine-
learning algorithms can reduce readout noise in long sequences (100 readouts
of $\sim$10 minutes) from $\sim$6 e- to $<2$ e- (see Table 2 therein). This
needs to be performed before the current apero steps, as it requires handling
the data cubes rather than the 2-D images used here. As long as the output
format is maintained, the machine-learning images should be used as inputs to
apero.

  * •

Energetic particles regularly hit infrared arrays and deposit electrons in
pixels, leading to spurious signals. These hits happen basically
instantaneously (on the time scales relevant to the readout) and manifest
themselves as discontinuities in the time series of non-destructive readouts.
Efficient algorithms have been proposed to handle cosmic ray hits in ramp-
fitting frameworks (Anderson & Gordon, 2011) but have yet to be implemented
for SPIRou.

  * •

The LBL recipes have been designed to use apero byproducts, but they have not
yet been implemented within the automated apero framework. Steps that are
currently done manually, such as the association of an appropriate stellar
template, will be included within apero in the near future.

There are also various planned improvements, they are the optimal extraction
(better characterization of extraction weights), the database architecture
(currently throttling the maximum number of connections with a large number of
cores), some minor memory leaks when parallel processing, handling the thermal
contribution at bluer wavelength domains and completing all
documentation${}^{\ref{footnote:apero_docs}}$.

##  13 Conclusion

We present apero (A PipelinE to Reduce Observations) and highlight its use as
the official pipeline for SPIRou. We walk through the steps going from raw
data to science-ready products. We detail the pre-processing of raw data to
correct detector issues, the production of reference calibrations and nightly
calibrations, and the use of these calibrations to correct and extract hot
stars and science observations in a consistent, controlled manner. We
summarize telluric correction (which will be detailed in a future publication,
Artigau et al. in prep), RV analysis, polarimetric analysis, and our post-
processing recipes delivering telluric corrected 2D and 1D spectra as well as
polarimetry products and enabling precise stable radial velocity calculations
(via the LBL algorithm, Artigau et al. 2022), good to at least $\sim 2$
$\text{ms}^{-1}$ over the timescale of the current lifetime of SPIRou (5
years).

We would like to thank the anonymous referee for the valuable comments that
improved the quality of the paper. The authors wish to thank everyone involved
with writing, maintaining, and updating all Python packages. Specifically,
apero has made extensive use of: (2) astropy, (Astropy Collaboration et al.,
2018, 2013) astroquery (Ginsburg et al., 2019) barycorrpy (Kanodia & Wright,
2018; Wright & Kanodia, 2020) matplotlib (Hunter, J. D., 2007) numpy (Harris
et al., 2020) pandas (McKinney, 2010, 2011) scipy (Virtanen et al., 2020) As
well as the python packages bottleneck (Goodman & et al., 2019), gitchangelog
(Lab, 2018), ipdb (Chapelle, 2021), IPython package (Pérez & Granger, 2007),
mysql-connector-python (Mariz, 2021), numba (Lam et al., 2015), pandastable
(Farrell, 2016), Pillow (Murray, 2021), pyyaml (Simonov, 2021), sphinx (Komiya
& Brandl, 2021), sqlalchemy (Bayer, 2021), Scikit-learn (Pedregosa et al.,
2011), tqdm (da Costa-Luis et al., 2021), yagmail (van Kooten, 2021), and xlrd
(Withers, 2021). This research made use of ds9, a tool for data visualization
supported by the Chandra X-ray Science Center (CXC) and the High Energy
Astrophysics Science Archive Center (HEASARC) with support from the JWST
Mission office at the Space Telescope Science Institute for 3D visualization.
This research made use of TOPCAT, an interactive graphical viewer and editor
for tabular data (Taylor, 2005). apero would have been impossible without the
use of PyCharm, Git, and GitHub. This work has made use of data from the
European Space Agency (ESA) mission Gaia (https://www.cosmos.esa.int/gaia),
processed by the Gaia Data Processing and Analysis Consortium (DPAC,
https://www.cosmos.esa.int/web/gaia/dpac/consortium). Funding for the DPAC has
been provided by national institutions, in particular, the institutions
participating in the Gaia Multilateral Agreement. apero has made use of the
SIMBAD database, operated at CDS, Strasbourg, France. This research has made
use of NASA’s Astrophysics Data System. apero has made use of the VizieR
catalog access tool, CDS, Strasbourg, France. The acknowledgments were
compiled using the Astronomy Acknowledgment Generator. The authors wish to
recognize and acknowledge the very significant cultural role and reverence
that the summit of MaunaKea has always had within the indigenous Hawaiian
community. We are most fortunate to have the opportunity to conduct
observations from this mountain. This work was financially supported by the
Natural Sciences and Engineering Research Council of Canada and the Fonds
Québécois de Recherche - Nature et Technologies. Observatoire du Mont-Mégantic
and the Institute for Research on Exoplanets acknowledge funding from
Développement Économique Canada, Quebec’s Ministère de l’Éducation et de
l’Innovation, the Trottier Family Foundation and the Canadian Space Agency.
M.H. and I.B acknowledge support from ANID – Millennium Science Initiative –
ICN12_009. C.M., A.C., P.F., X.D., I.B., and J.F.D. acknowledges funding from
the French ANR under contract number ANR18CE310019 (SPlaSH) and the Programme
National de Planétologie (PNP). This work is supported by the French National
Research Agency in the framework of the Investissements d’Avenir program
(ANR-15-IDEX-02), through the funding of the “Origin of Life” project of the
Grenoble-Alpes University. J.F.D. acknowledges funding from the European
Research Council (ERC) under the H2020 research & innovation programme (grant
agreement #740651 NewWorlds). T.V. would like to acknowledge funding from the
Fonds de Recherche du Québec - Nature et Technologies (FRQNT, scholarship
number 320056), and the Institute for Research on Exoplanets (iREx).

## References

  * Aceituno et al. (2013) Aceituno, J., Sánchez, S. F., Grupp, F., et al. 2013, A&A, 552, A31, doi: 10.1051/0004-6361/201220361
  * Allart et al. (2022) Allart, R., Lovis, C., Faria, J., et al. 2022, arXiv e-prints, arXiv:2209.01296.  https://arxiv.org/abs/2209.01296
  * Anderson & Gordon (2011) Anderson, R. E., & Gordon, K. D. 2011, Publications of the Astronomical Society of the Pacific, 123, 1237, doi: 10.1086/662593
  * Artigau et al. (2018) Artigau, É., Saint-Antoine, J., Lévesque, P.-L., et al. 2018, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 10709, High Energy, Optical, and Infrared Detectors for Astronomy VIII, ed. A. D. Holland & J. Beletic, 107091P, doi: 10.1117/12.2314475
  * Artigau et al. (2014) Artigau, É., Astudillo-Defru, N., Delfosse, X., et al. 2014, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9149, Observatory Operations: Strategies, Processes, and Systems V, ed. A. B. Peck, C. R. Benn, & R. L. Seaman, 914905, doi: 10.1117/12.2056385
  * Artigau et al. (2021) Artigau, É., Hébrard, G., Cadieux, C., et al. 2021, AJ, 162, 144, doi: 10.3847/1538-3881/ac096d
  * Artigau et al. (2022) Artigau, É., Cadieux, C., Cook, N. J., et al. 2022, The Astronomical Journal, 164, 84, doi: 10.3847/1538-3881/ac7ce6
  * Astropy Collaboration et al. (2013) Astropy Collaboration, Robitaille, T. P., Tollerud, E. J., et al. 2013, A&A, 558, A33, doi: 10.1051/0004-6361/201322068
  * Astropy Collaboration et al. (2018) Astropy Collaboration, Price-Whelan, A. M., Sipőcz, B. M., et al. 2018, AJ, 156, 123, doi: 10.3847/1538-3881/aabc4f
  * Bagnulo et al. (2009) Bagnulo, S., Landolfi, M., Landstreet, J. D., et al. 2009, PASP, 121, 993, doi: 10.1086/605654
  * Bayer (2021) Bayer, M. e. a. 2021, sqlalchemy, https://github.com/sqlalchemy/sqlalchemy, GitHub
  * Bedell et al. (2019) Bedell, M., Hogg, D. W., Foreman-Mackey, D., Montet, B. T., & Luger, R. 2019, AJ, 158, 164, doi: 10.3847/1538-3881/ab40a7
  * Bertaux et al. (2014) Bertaux, J. L., Lallement, R., Ferron, S., Boonne, C., & Bodichon, R. 2014, A&A, 564, A46, doi: 10.1051/0004-6361/201322383
  * Boisse et al. (2016) Boisse, I., Perruchot, S., Bouchy, F., et al. 2016, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9908, Ground-based and Airborne Instrumentation for Astronomy VI, ed. C. J. Evans, L. Simard, & H. Takami, 990868, doi: 10.1117/12.2231678
  * Borgman & Wofford (2021) Borgman, C. L., & Wofford, M. F. 2021, arXiv e-prints, arXiv:2109.01707.  https://arxiv.org/abs/2109.01707
  * Boucher et al. (2021) Boucher, A., Darveau-Bernier, A., Pelletier, S., et al. 2021, AJ, 162, 233, doi: 10.3847/1538-3881/ac1f8e
  * Bouchy et al. (2001) Bouchy, F., Pepe, F., & Queloz, D. 2001, A&A, 374, 733, doi: 10.1051/0004-6361:20010730
  * Bouchy et al. (2009) Bouchy, F., Hébrard, G., Udry, S., et al. 2009, A&A, 505, 853, doi: 10.1051/0004-6361/200912427
  * Bouchy et al. (2011) Bouchy, F., Hébrard, G., Delfosse, X., et al. 2011, in EPSC-DPS Joint Meeting 2011, Vol. 2011, 240
  * Bychkov et al. (2006) Bychkov, V. D., Bychkova, L. V., & Madej, J. 2006, MNRAS, 365, 585, doi: 10.1111/j.1365-2966.2005.09738.x
  * Caballero et al. (2016) Caballero, J. A., Guàrdia, J., López del Fresno, M., et al. 2016, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9910, Observatory Operations: Strategies, Processes, and Systems VI, ed. A. B. Peck, R. L. Seaman, & C. R. Benn, 99100E, doi: 10.1117/12.2233574
  * Cadieux et al. (2022) Cadieux, C., Doyon, R., Plotnykov, M., et al. 2022, The Astronomical Journal, 164, 96, doi: 10.3847/1538-3881/ac7cea
  * Chapelle (2021) Chapelle, G. e. a. 2021, ipdb, https://github.com/gotcha/ipdb, GitHub
  * Chené et al. (2021) Chené, A.-N., Mao, S., Lundquist, M., et al. 2021, AJ, 161, 109, doi: 10.3847/1538-3881/abd411
  * Collins et al. (2017) Collins, K. A., Kielkopf, J. F., Stassun, K. G., & Hessman, F. V. 2017, The Astronomical Journal, 153, 77, doi: 10.3847/1538-3881/153/2/77
  * Cosentino et al. (2012) Cosentino, R., Lovis, C., Pepe, F., et al. 2012, in Ground-based and Airborne Instrumentation for Astronomy IV, ed. I. S. McLean, S. K. Ramsay, & H. Takami, Vol. 8446, International Society for Optics and Photonics (SPIE), 657 – 676, doi: 10.1117/12.925738
  * Cristofari et al. (2022a) Cristofari, P. I., Donati, J. F., Masseron, T., et al. 2022a, MNRAS, 511, 1893, doi: 10.1093/mnras/stab3679
  * Cristofari et al. (2022b) —. 2022b, arXiv e-prints, arXiv:2208.10340.  https://arxiv.org/abs/2208.10340
  * Cushing et al. (2004) Cushing, M. C., Vacca, W. D., & Rayner, J. T. 2004, PASP, 116, 362, doi: 10.1086/382907
  * da Costa-Luis et al. (2021) da Costa-Luis, C., Larroque, S. K., Altendorf, K., et al. 2021, tqdm: A fast, Extensible Progress Bar for Python and CLI, v4.62.3, Zenodo, doi: 10.5281/zenodo.5517697
  * Donati (2003) Donati, J. F. 2003, in Astronomical Society of the Pacific Conference Series, Vol. 307, Solar Polarization, ed. J. Trujillo-Bueno & J. Sanchez Almeida, 41
  * Donati et al. (1997) Donati, J. F., Semel, M., Carter, B. D., Rees, D. E., & Collier Cameron, A. 1997, MNRAS, 291, 658, doi: 10.1093/mnras/291.4.658
  * Donati et al. (2018) Donati, J.-F., Kouach, D., Lacombe, M., et al. 2018, SPIRou: A NIR Spectropolarimeter/High-Precision Velocimeter for the CFHT (Springer International Publishing), 107, doi: 10.1007/978-3-319-55333-7_107
  * Donati et al. (2020) Donati, J. F., Kouach, D., Moutou, C., et al. 2020, MNRAS, 498, 5684, doi: 10.1093/mnras/staa2569
  * Dumusque, X. (2018) Dumusque, X. 2018, A&A, 620, A47, doi: 10.1051/0004-6361/201833795
  * Earl et al. (2022) Earl, N., Tollerud, E., Jones, C., et al. 2022, Zenodo, doi: 10.5281/zenodo.6207491
  * Errmann et al. (2020) Errmann, R., Cook, N. J., Anglada-Escudé, G., et al. 2020, Publications of the Astronomical Society of the Pacific, 132, 064504, doi: 10.1088/1538-3873/ab8783
  * Farrell (2016) Farrell, D. 2016, Journal of Open Research Software, 4, doi: 10.5334/jors.94
  * Fiorio & Gustedt (1996) Fiorio, C., & Gustedt, J. 1996, Theoretical Computer Science, 154, 165, doi: https://doi.org/10.1016/0304-3975(94)00262-2
  * Follert et al. (2014) Follert, R., Dorn, R. J., Oliva, E., et al. 2014, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9147, Ground-based and Airborne Instrumentation for Astronomy V, ed. S. K. Ramsay, I. S. McLean, & H. Takami, 914719, doi: 10.1117/12.2054197
  * Gaia Collaboration et al. (2016) Gaia Collaboration, Brown, A. G. A., Vallenari, A., et al. 2016, A&A, 595, A2, doi: 10.1051/0004-6361/201629512
  * Gaia Collaboration et al. (2018) —. 2018, A&A, 616, A1, doi: 10.1051/0004-6361/201833051
  * Gaia Collaboration et al. (2021) —. 2021, A&A, 649, A1, doi: 10.1051/0004-6361/202039657
  * Gan et al. (2022a) Gan, T., Soubkiou, A., Wang, S. X., et al. 2022a, MNRAS, 514, 4120, doi: 10.1093/mnras/stac1448
  * Gan et al. (2022b) Gan, T., Lin, Z., Wang, S. X., et al. 2022b, MNRAS, 511, 83, doi: 10.1093/mnras/stab3708
  * Giardino et al. (2019) Giardino, G., Birkmann, S., Robberto, M., et al. 2019, PASP, 131, 094503, doi: 10.1088/1538-3873/ab2fd6
  * Ginsburg et al. (2019) Ginsburg, A., Sipőcz, B. M., Brasseur, C. E., et al. 2019, AJ, 157, 98, doi: 10.3847/1538-3881/aafc33
  * Goldoni et al. (2006) Goldoni, P., Royer, F., François, P., et al. 2006, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 6269, Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, ed. I. S. McLean & M. Iye, 62692K, doi: 10.1117/12.669986
  * Gonzalez & Woods (2008) Gonzalez, R. C., & Woods, R. E. 2008, Digital image processing (Upper Saddle River, N.J.: Prentice Hall).  http://www.amazon.com/Digital-Image-Processing-3rd-Edition/dp/013168728X
  * Goodman & et al. (2019) Goodman, K. W., & et al., W. C. 2019, Bottleneck, https://github.com/pydata/bottleneck, GitHub
  * Gustafsson et al. (2008) Gustafsson, B., Edvardsson, B., Eriksson, K., et al. 2008, A&A, 486, 951, doi: 10.1051/0004-6361:200809724
  * Harris et al. (2020) Harris, C. R., Millman, K. J., van der Walt, S. J., et al. 2020, Nature, 585, 357, doi: 10.1038/s41586-020-2649-2
  * Hobson et al. (2021) Hobson, M. J., Bouchy, F., Cook, N. J., et al. 2021, A&A, 648, A48, doi: 10.1051/0004-6361/202038413
  * Hodapp et al. (2019) Hodapp, K. W., Hall, D., Jacobson, S., et al. 2019, in American Astronomical Society Meeting Abstracts, Vol. 234, American Astronomical Society Meeting Abstracts #234, 103.02
  * Hodapp et al. (1996) Hodapp, K. W., Hora, J. L., Hall, D. N. B., et al. 1996, New A, 1, 177, doi: 10.1016/S1384-1076(96)00013-9
  * Horne (1986) Horne, K. 1986, PASP, 98, 609, doi: 10.1086/131801
  * Hunter, J. D. (2007) Hunter, J. D. 2007, Computing In Science & Engineering, 9, 90
  * Kanodia & Wright (2018) Kanodia, S., & Wright, J. 2018, Research Notes of the AAS, 2, 4, doi: 10.3847/2515-5172/aaa4b7
  * Komiya & Brandl (2021) Komiya, T., & Brandl, G. e. a. 2021, sphinx, https://github.com/sphinx-doc/sphinx, GitHub
  * Kotani et al. (2018) Kotani, T., Tamura, M., Nishikawa, J., et al. 2018, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 10702, Ground-based and Airborne Instrumentation for Astronomy VII, ed. C. J. Evans, L. Simard, & H. Takami, 1070211, doi: 10.1117/12.2311836
  * Lab (2018) Lab, V. e. a. 2018, gitchangelog, https://github.com/vaab/gitchangelog, GitHub
  * Labrie et al. (2019) Labrie, K., Anderson, K., Cárdenes, R., Simpson, C., & Turner, J. E. H. 2019, in Astronomical Society of the Pacific Conference Series, Vol. 523, Astronomical Data Analysis Software and Systems XXVII, ed. P. J. Teuben, M. W. Pound, B. A. Thomas, & E. M. Warner, 321
  * Lam et al. (2015) Lam, S. K., Pitrou, A., & Seibert, S. 2015, in Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in HPC, 1–6
  * Lillo-Box et al. (2020) Lillo-Box, J., Aceituno, J., Pedraz, S., et al. 2020, MNRAS, 491, 4496, doi: 10.1093/mnras/stz3283
  * Mahadevan et al. (2010) Mahadevan, S., Ramsey, L., Wright, J., et al. 2010, Proceedings of SPIE - The International Society for Optical Engineering, 7735, doi: 10.1117/12.857551
  * Mahadevan et al. (2012) Mahadevan, S., Ramsey, L., Bender, C., et al. 2012, in Ground-based and Airborne Instrumentation for Astronomy IV, ed. I. S. McLean, S. K. Ramsay, & H. Takami, Vol. 8446, International Society for Optics and Photonics (SPIE), 624 – 637, doi: 10.1117/12.926102
  * Marconi et al. (2021) Marconi, A., Abreu, M., Adibekyan, V., et al. 2021, The Messenger, 182, 27, doi: 10.18727/0722-6691/5219
  * Mariz (2021) Mariz, N. e. a. 2021, mysql-connector-python, https://github.com/mysql/mysql-connector-python, GitHub
  * Martioli et al. (2012) Martioli, E., Teeple, D., Manset, N., et al. 2012, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 8451, Software and Cyberinfrastructure for Astronomy II, ed. N. M. Radziwill & G. Chiozzi, 84512B, doi: 10.1117/12.926627
  * Martioli et al. (2020) Martioli, E., Hébrard, G., Moutou, C., et al. 2020, A&A, 641, L1, doi: 10.1051/0004-6361/202038695
  * Martioli et al. (2022) Martioli, E., Hébrard, G., Fouqué, P., et al. 2022, A&A, 660, A86, doi: 10.1051/0004-6361/202142540
  * Mayor et al. (2003) Mayor, M., Pepe, F., Queloz, D., et al. 2003, The Messenger, 114, 20
  * McCray (2014) McCray, W. 2014, Technology and Culture, 55, 908, doi: 10.1353/tech.2014.0102
  * McCray (2004) McCray, W. P. 2004, Giant telescopes : astronomical ambition and the promise of technology (Harvard University Press)
  * McKay et al. (2004) McKay, D. J., Ballester, P., Banse, K., et al. 2004, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 5493, Optimizing Scientific Return for Astronomy through Information Technologies, ed. P. J. Quinn & A. Bridger, 444–452, doi: 10.1117/12.551214
  * McKinney (2010) McKinney, W. 2010, in Proceedings of the 9th Python in Science Conference, Vol. 445, Austin, TX, 51–56
  * McKinney (2011) McKinney, W. 2011, Python for High Performance and Scientific Computing, 14
  * Micheau et al. (2018) Micheau, Y., Kouach, D., Donati, J.-F., et al. 2018, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 10702, Ground-based and Airborne Instrumentation for Astronomy VII, ed. C. J. Evans, L. Simard, & H. Takami, 107025R, doi: 10.1117/12.2305937
  * Modigliani et al. (2010) Modigliani, A., Goldoni, P., Royer, F., et al. 2010, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 7737, Observatory Operations: Strategies, Processes, and Systems III, ed. D. R. Silva, A. B. Peck, & B. T. Soifer, 773728, doi: 10.1117/12.857211
  * Moutou et al. (2020) Moutou, C., Dalal, S., Donati, J. F., et al. 2020, A&A, 642, A72, doi: 10.1051/0004-6361/202038108
  * Murray (2021) Murray, A. e. a. 2021, Pillow, https://github.com/python-pillow/Pillow, GitHub
  * Oliva et al. (2006) Oliva, E., Origlia, L., Baffa, C., et al. 2006, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 6269, Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, ed. I. S. McLean & M. Iye, 626919, doi: 10.1117/12.670006
  * Payeur et al. (2022) Payeur, G., Artigau, É., Levasseur, L. P., & Doyon, R. 2022, AJ, 163, 292, doi: 10.3847/1538-3881/ac69d2
  * Pedregosa et al. (2011) Pedregosa, F., Varoquaux, G., Gramfort, A., et al. 2011, Journal of Machine Learning Research, 12, 2825
  * Pelletier et al. (2021) Pelletier, S., Benneke, B., Darveau-Bernier, A., et al. 2021, AJ, 162, 73, doi: 10.3847/1538-3881/ac0428
  * Pepe et al. (2002) Pepe, F., Mayor, M., Galland, F., et al. 2002, A&A, 388, 632, doi: 10.1051/0004-6361:20020433
  * Pepe et al. (2021) Pepe, F., Cristiani, S., Rebolo, R., et al. 2021, A&A, 645, A96, doi: 10.1051/0004-6361/202038306
  * Pérez & Granger (2007) Pérez, F., & Granger, B. E. 2007, Computing in Science and Engineering, 9, 21, doi: 10.1109/MCSE.2007.53
  * Perryman et al. (1997) Perryman, M. A. C., Lindegren, L., Kovalevsky, J., et al. 1997, A&A, 323, L49
  * Piskunov et al. (2021) Piskunov, N., Wehrhahn, A., & Marquart, T. 2021, A&A, 646, A32, doi: 10.1051/0004-6361/202038293
  * Piskunov et al. (1995) Piskunov, N. E., Kupka, F., Ryabchikova, T. A., Weiss, W. W., & Jeffery, C. S. 1995, A&AS, 112, 525
  * Piskunov & Valenti (2002) Piskunov, N. E., & Valenti, J. A. 2002, A&A, 385, 1095, doi: 10.1051/0004-6361:20020175
  * Quirrenbach et al. (2014) Quirrenbach, A., Amado, P. J., Caballero, J. A., et al. 2014, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9147, Ground-based and Airborne Instrumentation for Astronomy V, ed. S. K. Ramsay, I. S. McLean, & H. Takami, 91471F, doi: 10.1117/12.2056453
  * Rasband (2011) Rasband, W. S. 2011, http://imagej. nih. gov/ij/
  * Rupprecht et al. (2004) Rupprecht, G., Pepe, F., Mayor, M., et al. 2004, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 5492, Ground-based Instrumentation for Astronomy, ed. A. F. M. Moorwood & M. Iye, 148–159, doi: 10.1117/12.551267
  * Seemann et al. (2014) Seemann, U., Anglada-Escude, G., Baade, D., et al. 2014, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9147, Ground-based and Airborne Instrumentation for Astronomy V, ed. S. K. Ramsay, I. S. McLean, & H. Takami, 91475G, doi: 10.1117/12.2056668
  * Seifahrt et al. (2020) Seifahrt, A., Bean, J. L., Stürmer, J., et al. 2020, in Ground-based and Airborne Instrumentation for Astronomy VIII, ed. C. J. Evans, J. J. Bryant, & K. Motohara (SPIE), doi: 10.1117/12.2561564
  * Simonov (2021) Simonov, K. e. a. 2021, pyyaml, https://github.com/yaml/pyyaml, GitHub
  * Smette et al. (2015) Smette, A., Sana, H., Noll, S., et al. 2015, A&A, 576, A77, doi: 10.1051/0004-6361/201423932
  * Sousa et al. (2021) Sousa, A. P., Bouvier, J., Alencar, S. H. P., et al. 2021, A&A, 649, A68, doi: 10.1051/0004-6361/202140346
  * Taylor (2005) Taylor, M. B. 2005, in Astronomical Society of the Pacific Conference Series, Vol. 347, Astronomical Data Analysis Software and Systems XIV, ed. P. Shopbell, M. Britton, & R. Ebert, 29
  * Tody (1986) Tody, D. 1986, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 627, Instrumentation in astronomy VI, ed. D. L. Crawford, 733, doi: 10.1117/12.968154
  * Tran et al. (2016) Tran, H. D., Cohen, R., Colson, A., et al. 2016, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9910, Observatory Operations: Strategies, Processes, and Systems VI, ed. A. B. Peck, R. L. Seaman, & C. R. Benn, 99102E, doi: 10.1117/12.2230963
  * van Kooten (2021) van Kooten, P. e. a. 2021, yagmail, https://github.com/kootenpv/yagmail, GitHub
  * Vernet et al. (2011) Vernet, J., Dekker, H., D’Odorico, S., et al. 2011, A&A, 536, A105, doi: 10.1051/0004-6361/201117752
  * Virtanen et al. (2020) Virtanen, P., Gommers, R., Oliphant, T. E., et al. 2020, Nature Methods, 17, 261, doi: https://doi.org/10.1038/s41592-019-0686-2
  * Vogt et al. (1994) Vogt, S. S., Allen, S. L., Bigelow, B. C., et al. 1994, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 2198, Instrumentation in Astronomy VIII, ed. D. L. Crawford & E. R. Craine, 362, doi: 10.1117/12.176725
  * Wenger et al. (2000) Wenger, M., Ochsenbein, F., Egret, D., et al. 2000, Astronomy and Astrophysics Supplement Series, 143, 9–22, doi: 10.1051/aas:2000332
  * Wildi et al. (2017) Wildi, F., Blind, N., Reshetov, V., et al. 2017, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 10400, Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, 1040018, doi: 10.1117/12.2275660
  * Withers (2021) Withers, C. e. a. 2021, xlrd, https://github.com/python-excel/xlrd, GitHub
  * Wright & Eastman (2014) Wright, J. T., & Eastman, J. D. 2014, PASP, 126, 838, doi: 10.1086/678541
  * Wright & Kanodia (2020) Wright, J. T., & Kanodia, S. 2020, The Planetary Science Journal, 1, 38, doi: 10.3847/PSJ/ababa4
  * Wu et al. (2005) Wu, K., Otoo, E., & Shoshani, A. 2005, in Medical Imaging 2005: Image Processing, ed. J. M. Fitzpatrick & J. M. Reinhardt, Vol. 5747, International Society for Optics and Photonics (SPIE), 1965 – 1976, doi: 10.1117/12.596105
  * Zacharias et al. (2013) Zacharias, N., Finch, C. T., Girard, T. M., et al. 2013, AJ, 145, 44, doi: 10.1088/0004-6256/145/2/44
  * Zandian et al. (2016) Zandian, M., Farris, M., McLevige, W., et al. 2016, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9915, High Energy, Optical, and Infrared Detectors for Astronomy VII, ed. A. D. Holland & J. Beletic, 99150F, doi: 10.1117/12.2233664

##  Appendix A Creating a raw SPIRou ramp image

The SPIRou detector control software reads the detector continuously every
5.57 s and produces a 2D image ($4096\times 4096$) constructed from the linear
fit of the pixel value versus time (as well as a slope, intercept, error, and
number of frames used for quality checks). The construction of the 2D image
from individual readouts being handled at the acquisition step is not included
as part of apero but as software maintained and used at CFHT. The construction
of the 2D frame is performed through the following steps.

Individual detector frames are obtained from the detector control software
every 5.57 s (at time $j$, $t[j]$). A flagging of pixel saturation is
performed, and pixels with a non-linearity that would be larger than $\sim 10$
% are considered unreliable and rejected for all future readouts (binary mask
$m[i,j]$ for pixel $i$ at time $j$). A non-linearity correction is applied to
pixel fluxes (flux at pixel $i$ and at time $j$ is $f[i,j]$). As individual
readouts are in computer memory, intermediate quantities necessary for the
computation of the total pixel-level slope are computed. The advantage of
preserving these quantities in memory is that one can perform a pixel-level
ramp-fitting over an arbitrarily large number of frames without being required
to have all pixel values in memory at the same time or without having to
access files multiple times.

  * •

$\sigma_{x}[i]=\sum_{j}m[i,j]*f[i,j]$

  * •

$\sigma_{y}[i]=\sum_{j}m[i,j]*t[j]$

  * •

$\sigma_{xy}[i]=\sum_{j}m[i,j]*f[i,j]*t[j]$

  * •

$\sigma_{x^{2}}[i]=\sum_{j}m[i,j]*f[i,j]^{2}$

  * •

$n[i]=\sum_{j}m[i,j]$

Among these intermediate quantities, the only one that has a clear
signification is $n[i]$: it corresponds to the number of valid (i.e., below
the predefined flux level for saturation) readouts obtained over the entire
sequence. For normal scientific exposures, $n[i]$ is equal to the total number
of readouts for the vast majority of pixels; pixels with a very large dark
current being the exception.

From simple linear algebra, one can show that the per-pixel intercept is

$b[i]=\frac{\sigma_{x}[i]\sigma_{xy}[i]-\sigma_{x^{2}}[i]*\sigma_{y}[i]}{\sigma_{x}[i]^{2}-n\sigma_{x^{2}}}$
(A1)

and correspondingly, the per-pixel slope is:

$a[i]=\frac{\sigma_{y}-n[i]b[i]}{\sigma_{x}[i]}$ (A2)

Once the slope image $a[i]$ has been computed, it is corrected for correlated
amplifier noise using the side reference pixels (along the fast readout axis),
and amplifier offset is corrected using the top and bottom reference pixels
(both extremities of the slow readout axis).

As a quality check of pixel-level value, we further compute the error on the
slope to identify pixels having a suspiciously large dispersion of their
values around the slope. This is used to flag pixels that have a large slope
that is inconsistent with their frame-to-frame accumulation rate. To compute
the slope, one has to re-read all frames once (though it is not required to
keep them all at once in memory) and compute the following values

  * •

$x_{p}[i]=sx[i]/n[i]$

  * •

$y_{p}[i,j]=b[i]+a[i]*t[j]$

  * •

$\varrho_{x^{2}}[i]=\sum_{j}(t[j]-x_{p}[i])m[i,j]$

  * •

$\varrho_{y^{2}}[i]=\sum_{j}(f[i,j]-y_{p}[i,j])m[i,j]$

From which the slope error is

$\varrho(i)=\sqrt{\frac{\varrho_{y^{2}}[i]/(n[i]-2)}{\varrho_{x^{2}}[i]}}$
(A3)

##  Appendix B Standard image calibration

After pre-processing (Section 4), the reference dark calculation (Section 5.1)
and the bad pixel correction (Section 6.1), all images that are used in apero
need to be calibrated in a standard way (using both the dark reference and bad
pixel recipe outputs). This is not a separate recipe but a set of functions
that are used in all recipes that use pre-processed files as inputs.

The standard calibration is ordered as follows:

  1. 1.

dark reference correction (Section B.1).

  2. 2.

flip, resize and re-scale the image (Section B.2).

  3. 3.

flag bad pixels (Section B.3).

  4. 4.

correct background flux (Section B.4).

  5. 5.

clean hot pixels (Section B.5).

  6. 6.

flag pixels that are out of bounds (Section B.6).

###  B.1 Dark reference correction

The first step of the standard calibration of pre-processed files is to
correct the input image for the dark signal.

$IM_{\text{corr}i,j}=IM_{\text{uncorr}i,j}-N(DARK_{i,j})$ (B1)

where $IM_{\text{corr}i,j}$ and $IM_{\text{uncorr}i,j}$ are the flux in the
$i^{th}$ row $j^{th}$ column of the corrected image and uncorrected image
respectively, $N$ is the number of raw images that went into $IM$ and
$DARK_{i,j}$ is flux in the $i^{th}$ row $j^{th}$ column of the reference dark
(see Section 5.1).

The dark reference is taken from the calibration database. If more than one
dark reference exists the closest in time to $IM$ is used (using the header
key mjdmid from the header).

###  B.2 Flipping, resizing, and re-scaling the image

For legacy reasons, the image is flipped in the vertical and horizontal
directions (see Figure 4). After this the image is converted from $ADU/s$ to
electrons using Equation B2.

$IM_{\text{electrons}i,j}=IM_{\text{ADU}/\text{s}i,j}\times\text{Gain}\times
t_{\rm exp}$ (B2)

where $IM_{\text{electons}i,j}$ is the flux in electrons for the $i^{th}$ row
$j^{th}$ column, $IM_{\text{ADU}/\text{s}i,j}$ is the flux in $ADU/s$ for the
$i^{th}$ row $j^{th}$ column, the gain is taken from the header key gain
(although it has remained constant over the lifetime of SPIRou), and $exptime$
is the exposure time in seconds (taken from the header key exptime).

Once the image is in electrons it is then resized. The image is cut in the
cross-order direction to start from pixel 250 and end at pixel 3350 (removing
a partial blue order and the whole unilluminated dark amplifier region) and in
the along-order direction to start from pixel 4 and end at pixel 4092
(removing just the H4RG reference pixels). Thus after this resizing the image
is of size 3100$\times$4088 (see Figure 4).

###  B.3 Flagging the bad pixels

The closest bad pixel map (badpix, see Section 6.1) in time to the image
(using the header key mjdmid from the header) is loaded from the calibration
database and all pixels that are flagged as bad pixels are set to nan, this is
shown in Equation B3.

$IM_{\text{corr}i,j}=\left\\{\begin{array}[]{cl}NaN:&BADPIX_{i,j}\equiv 1\\\
IM_{i,j}:&\text{otherwise}\\\ \end{array}\right.$ (B3)

where $IM_{\text{corr}i,j}$ and $IM_{i,j}$ are the flux in the $i^{th}$ row
$j^{th}$ column of the corrected image and the input image respectively.
$BADPIX_{i,j}$ is a bad pixel flag (1 or 0) in the $i^{th}$ row $j^{th}$
column from the bad pixel map.

###  B.4 Correcting the background flux

Within each science image, we take the median of ‘background’ pixels
(identified using the backmap, see Section 6.1) within a region and create a
map of large-scale background features (middle panel, Figure 14). This map is
then splined into a $4088\times 4088$ image and subtracted from the science
frame.

###  B.5 Additional cleaning of hot pixels

Hot pixels are flagged by finding pixels that are 10$\sigma$ (positive or
negative) outliers compared to their immediate neighbors. This is in addition
to the cosmic ray rejection applied in Section 4.5 and the bad pixel flagging
(Section 6.1) which removes most of the hot pixels. In this additional
cleaning of hot pixels, we first construct a flattened image and perform a
low-pass filter in the along-order direction, filtering the image so that only
pixel-to-pixel structures remain. We then apply median filtering, which
removes these big outliers, and then we smooth the image to avoid big regions
filled with zeros. We apply a 5-pixel median boxcar and a 5-pixel smoothing in
the along-order direction, which blurs along the dispersion over a scale of
$\sim$7 pixels. Bad pixels are interpolated with a 2D surface fit by using
valid pixels within a $3\times 3$ pixel box centered on the bad pixel.

###  B.6 Flagging out of bound pixels

Pixel values need to be within reasonable bounds considering the physics of
the H4RG detector. If they are not in bounds we set them to nan. The upper
bound is the saturation per frame time, but as the flux is expressed as a
slope (in the fits2ramp.py), a pixel with a value greater than the saturation
point can be recorded by the detector and is nonphysical. The lower bound is
set to the negative value of ten times the readout noise, these bounds are
shown in Equation B4.

$IM_{\text{corr}i,j}=\left\\{\begin{array}[]{cl}NaN:&IM_{i,j}>\text{saturation}/t_{\text{frame}}\\\
NaN:&IM_{i,j}<-10\times\text{readoutnoise}\\\ IM_{i,j}:&\text{otherwise}\\\
\end{array}\right.$ (B4)

where $IM_{\text{corr}i,j}$ and $IM_{i,j}$ are the flux in the $i^{th}$ row
$j^{th}$ column of the corrected image and the input image respectively,
$saturation$ is taken from the header keyword saturate and is converted to
electrons via B2, $t_{\rm frame}$ is the individual frame time (from header
keyword frmtime), and readout noise is taken from the header keyword rdnoise.

##  Appendix C Shape transformation

The shape transform algorithm allows three different transformations, that may
or may not be used. Here we define $x$ as the direction along the order, $y$
as the direction across the order.

  1. 1.

a linear transform: defined by $dx$, $dy$, $A$, $B$, $C$, $D$, where $dx$ and
$dy$ are shifts $x$ and $y$ respectively and $A$, $B$, $C$, $D$ form the
transform matrix:

$\left[\begin{array}[]{cl}A&B\\\ C&D\\\ \end{array}\right]$ (C1)

This combines with $dx$ and $dy$ in order to form a 3$\times$3 matrix:

$\left[\begin{array}[]{ccc}A&B&dx\\\ C&D&dy\\\ 0&0&1\\\ \end{array}\right]$
(C2)

This $3\times 3$ linear transformation matrix allows for scaling, rotation,
reflection (not used in our case) and shearing (Gonzalez & Woods, 2008).

  2. 2.

a shift in $x$ position, where a shift is defined for each pixel.

  3. 3.

a shift in $y$ position, where a shift is defined for each pixel.

##  Appendix D Version history of APERO

apero has been in development since October 2017. Here we list a few of the
major versions to give the reader an idea of how long the development of a
full pipeline can take.

First version | Last version | Date of first version |  Main improvements
---|---|---|---
0.0.000 | 0.0.048 | 2017-10-12 |  First python version of apero
0.1.000 | 0.1.037 | 2018-01-10 |  First version to run on SPIRou engineering data (H2RG detector)
0.2.000 | 0.2.128 | 2018-04-17 |  First version for SPIRou commissioning (H4RG upgrade)
0.3.000 | 0.3.077 | 2018-09-06 |  First implementation of telluric correction
0.4.000 | 0.4.123 | 2018-12-08 |  Re-work wave solution and BERV calculation
0.5.000 | 0.5.124 | 2019-05-10 |  Implementation of reference calibrations/recipes
0.6.000 | 0.6.132 | 2019-12-06 |  Complete re-ordering of apero file structure, first use on NIRPS
0.7.000 | 0.7.255 | 2020-10-16 |  Implementation of SQL databases, Telluric pre-cleaning, upgrade calibration recipes, integration of spirou-polar
0.8.000 | active | 2022-09-11 |  Currently in development: uncertainty propagation, nan pixel quality flags, optimal extraction weights, database architecture
1.0.000 | - | - |  After 0.8, full documentation, including adding new instruments
Table D1: History of the major versions of apero

##  Appendix E Current science publications using APERO

In table E1 we list some science publications using apero for science. This
list is not complete but gives an idea of the range of science enabled by
apero with SPIRou.

Title | Citation
---|---
Spin-orbit alignment and magnetic activity in the young planetary system AU Mic | Martioli et al. 2020
Early science with SPIRou: near-infrared radial velocity and spectropolarimetry of the planet-hosting star HD 189733 | Moutou et al. 2020
SPIRou: NIR velocimetry and spectropolarimetry at the CFHT | Donati et al. 2020
Star-disk interaction in the T Tauri star V2129 Ophiuchi: An evolving accretion-ejection structure | Sousa et al. 2021
Where Is the Water? Jupiter-like C/H Ratio but Strong H2O Depletion Found on Tau Bootis b Using SPIRou | Pelletier et al. 2021
TOI-1278 B: SPIRou Unveils a Rare Brown Dwarf Companion in Close-in Orbit around an M Dwarf | Artigau et al. 2021
Characterizing Exoplanetary Atmospheres at High Resolution with SPIRou: Detection of Water on HD 189733 b | Boucher et al. 2021
TOI-530b: a giant planet transiting an M-dwarf detected by TESS | Gan et al. 2022b
TOI-1759 b: A transiting sub-Neptune around a low mass star characterized with SPIRou and TESS | Martioli et al. 2022
TESS discovery of a sub-Neptune orbiting a mid-M dwarf TOI-2136 | Gan et al. 2022a
Estimating fundamental parameters of nearby M dwarfs from SPIRou spectra | Cristofari et al. 2022a
Line-by-line velocity measurements, an outlier-resistant method for precision velocimetry | Artigau et al. 2022
TOI-1452 b: SPIRou and TESS reveal a super-Earth in a temperate orbit transiting an M4 dwarf | Cadieux et al. 2022
Estimating the atmospheric properties of 44 M dwarfs from SPIRou spectra | Cristofari et al. 2022b
CO or no CO? Narrowing the CO abundance constraint and recovering the H2O detection in the atmosphere of WASP-127b using SPIRou | Boucher et al. (accepted 2022)
Near-IR and optical radial velocities of the active M-dwarf star Gl 388 (AD Leo) with SPIRou at CFHT and SOPHIE at OHP | Carmona et al. (submitted 2022)
New insights on the near-infrared veiling of young stars using CFHT/SPIRou data | Sousa et al. (submitted 2022)
A sub-Neptune planet around TOI-1695 discovered and characterized with TESS and SPIRou | Kiefer et al. (submitted 2022)
The rotation period of 43 quiet M dwarfs from spectropolarimetry in the near-infrared: I. The SPIRou APERO analysis | Fouqué et al. (in prep)
Optical and near-infrared stellar activity characterization of the early M dwarf Gl 205 with SOPHIE and SPIRou | Cortés-Zuleta et al. (in prep)
High-resolution Chemical Spectroscopy of Barnard’s Star with SPIRou | Jahanadar et al. (in prep)
New methods to correct for systematics in near-infrared radial velocity measurements: Application to GL725B with SPIRou data | Ould-Elhkim et al. (in prep)
Characterizing planetary systems with SPIRou: the M-dwarf Planet Search survey and the system of GJ 251 | Moutou et al. (in prep)
Table E1: List of some publications using apero for science.

##  Appendix F Inputs

The currently allowed raw file inputs are listed in table F1. The name becomes
the apero header key dprtype. All other columns are header keys found in the
raw input files or are added/modified when first processed (in
apero_preprocess and apero_processing).

Although all SPIRou raw files have suffixes: [style=itemize](2) a.fits
(obstype = align) c.fits (obstype = comparison) d.fits (obstype = dark) f.fits
(obstype = flat) o.fits (obstype = object)

apero does not rely on the filenames to assign a dprtype to a raw input file.
Instead, we use header keys to identify file types (Table F1).

name | OBSTYPE | SBCCAS_P | SBCREF_P | SBCALI_P | INSTRUME | TRG_TYPE$\ast$ | DRSMODE$\ast$
---|---|---|---|---|---|---|---
dark_dark_int | DARK | pos_pk | pos_pk | P4 | SPIRou | - | -
dark_dark_tel | DARK | pos_pk | pos_pk | P5 | SPIRou | - | -
dark_dark_sky | OBJECT | pos_pk | pos_pk | - | SPIRou | SKY | -
dark_fp_sky | OBJECT | pos_pk | pos_fp | - | SPIRou | SKY | -
dark_flat | FLAT | pos_pk | pos_wl | - | SPIRou | - | -
flat_dark | FLAT | pos_wl | pos_pk | - | SPIRou | - | -
flat_flat | FLAT | pos_wl | pos_wl | - | SPIRou | - | -
flat_fp | FLAT | pos_wl | pos_fp | - | SPIRou | - | -
dark_fp | ALIGN | pos_pk | pos_fp | - | SPIRou | - | -
fp_dark | ALIGN | pos_fp | pos_pk | - | SPIRou | - | -
fp_flat | ALIGN | pos_fp | pos_wl | - | SPIRou | - | -
fp_fp | ALIGN | pos_fp | pos_fp | - | SPIRou | - | -
lfc_lfc | ALIGN | pos_rs | pos_rs | - | SPIRou | - | -
lfc_fp | ALIGN | pos_rs | pos_fp | - | SPIRou | - | -
fp_lfc | ALIGN | pos_fp | pos_rs | - | SPIRou | - | -
obj_dark | OBJECT | pos_pk | pos_pk | - | SPIRou | TARGET | SPECTROSCOPY
obj_fp | OBJECT | pos_pk | pos_fp | - | SPIRou | TARGET | SPECTROSCOPY
obj_hcone | OBJECT | pos_pk | pos_hc1 | - | SPIRou | TARGET | -
obj_hctwo | OBJECT | pos_pk | pos_hc2 | - | SPIRou | TARGET | -
polar_dark | OBJECT | pos_pk | pos_pk | - | SPIRou | TARGET | POLAR
polar_fp | OBJECT | pos_pk | pos_fp | - | SPIRou | TARGET | POLAR
dark_hcone | COMPARISON | pos_pk | pos_hc1 | - | SPIRou | - | -
dark_hctwo | COMPARISON | pos_pk | pos_hc2 | - | SPIRou | - | -
fp_hcone | COMPARISON | pos_fp | pos_hc1 | - | SPIRou | - | -
fp_hctwo | COMPARISON | pos_fp | pos_hc2 | - | SPIRou | - | -
hcone_fp | COMPARISON | pos_hc1 | pos_fp | - | SPIRou | - | -
hctwo_fp | COMPARISON | pos_hc2 | pos_fp | - | SPIRou | - | -
hcone_hcone | COMPARISON | pos_hc1 | pos_hc1 | - | SPIRou | - | -
hctwo_hctwo | COMPARISON | pos_hc2 | pos_hc2 | - | SPIRou | - | -
hcone_dark | COMPARISON | pos_hc1 | pos_pk | - | SPIRou | - | -
hctwo_dark | COMPARISON | pos_hc2 | pos_pk | - | SPIRou | - | -
Table F1: All possible inputs currently accepted by apero. HDR denotes that a
keyword is required from an input file header. $\ast$ denotes header key is
added or modified by apero before internal use.

##  Appendix G APERO Products

apero produces outputs after every recipe. These are saved to the reduced
directory (except for the apero_preprocess recipe that saves outputs into the
working directory). These are intermediary products and are used to create the
CADC outputs in post-processing (see Section 11).

File |  Recipe |  Frequency |  Description
---|---|---|---
(id)_pp.fits |  apero_preprocess |  every file |  preprocessed file
(HASH)_pp_dark_ref.fits |  apero_dark_ref |  ref night |  reference dark file
(HASH)_pp_badpixel.fits |  apero_badpix |  every night |  bad pixel map file
(HASH)_pp_order_profile_{AB,C}.fits |  apero_loc_spirou |  every night |  order profile file
(HASH)_pp_loco_{AB,C}.fits |  apero_loc_spirou |  every night |  localization center map file
(HASH)_pp_shapex.fits |  apero_shape_ref |  ref night |  dx shape map file
(HASH)_pp_shapey.fits |  apero_shape_ref |  ref night |  dy shape map file
(HASH)_pp_fpref.fits |  apero_shape_ref |  ref night |  FP reference file
(HASH)_pp_shapel.fits |  apero_shape |  every night |  local shape map file
(HASH)_pp_blaze_{AB,A,B,C}.fits |  apero_flat |  every night |  blaze correction file
(HASH)_pp_flat_{AB,A,B,C}.fits |  apero_flat |  every night |  flat correction file
(HASH)_pp_e2ds_{AB,A,B,C}.fits |  apero_thermal |  every night |  2D Extracted dark_dark_int and/or dark_dark_tel file [49x4088]
(HASH)_pp_e2dsff_{AB,A,B,C}.fits |  apero_thermal |  every night |  2D extracted + flat fielded dark_dark_int and/or dark_dark_tel file [49x4088]
(HASH)_pp_s1d_v_{AB,A,B,C}.fits |  apero_thermal |  every night |  1D extracted + flat fielded dark_dark_int and/or dark_dark_tel file with constants velocity bins
(HASH)_pp_s1d_w_{AB,A,B,C}.fits |  apero_thermal |  every night |  1D extracted + flat fielded dark_dark_int and/or dark_dark_tel with constants wavelength bins
(HASH)_pp_thermal_e2ds_int_{AB,A,B,C}.fits |  apero_thermal |  every night |  extracted thermal internal dark calibration file
(HASH)_pp_thermal_e2ds_tel_{AB,A,B,C}.fits |  apero_thermal |  every night |  extracted thermal telescope dark calibration file
(id)_pp_e2ds_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  2D Extracted dark_fp file [49x4088]
(id)_pp_e2dsff_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  2D extracted + flat fielded dark_dark_int and/or dark_dark_tel file [49x4088]
(id)_pp_s1d_v_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  1D extracted + flat fielded dark_dark_int and/or dark_dark_tel file with constants velocity bins
(id)_pp_s1d_w_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  1D extracted + flat fielded dark_dark_int and/or dark_dark_tel with constants wavelength bins
(HASH)_pp_leak_ref_{AB,A,B,C}.fits |  apero_leak_ref |  ref night |  leak correction reference file
(HASH)_pp_e2ds_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  2D extracted fp_fp and hcone_hconefile [49x4088]
(HASH)_pp_e2dsff_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  2D extracted + flat fielded fp_fp and hcone_hconefile [49x4088]
(HASH)_pp_s1d_v_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  1D extracted + flat fielded fp_fp and hcone_hconefile] with constants velocity bins
(HASH)_pp_s1d_w_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  1D extracted + flat fielded fp_fp and hcone_hconefile] with constants wavelength bins
(HASH)_pp_wavesol_ref_{AB,A,B,C}.fits |  apero_wave_ref |  ref night |  reference 2D wavelength solution [49x4088]
(HASH)_pp_wavecav_AB.fits |  apero_wave_ref |  ref night |  Cavity width measurement file
(HASH)_pp_e2ds_{AB,A,B,C}.fits |  apero_wave_night |  every night |  2D extracted fp_fp and hcone_hconefile [49x4088]
(HASH)_pp_e2dsff_{AB,A,B,C}.fits |  apero_wave_night |  every night |  2D extracted + flat fielded fp_fp and hcone_hconefile [49x4088]
(HASH)_pp_s1d_v_{AB,A,B,C}.fits |  apero_wave_night |  every night |  1D extracted + flat fielded fp_fp and hcone_hconefile] with constants velocity bins
(HASH)_pp_s1d_w_{AB,A,B,C}.fits |  apero_wave_night |  every night |  1D extracted + flat fielded fp_fp and hcone_hconefile] with constants wavelength bins
(HASH)_pp_wave_night_ref_{AB,A,B,C}.fits |  apero_wave_night |  every night |  reference 2D wavelength solution [49x4088]
Table G1: Main apero products, where id for SPIRou is the odometer code and the HASH is a checksum created by multiple inputs (of the same data type) to the given recipe. A full list of data products for each recipe can be found in the documentation. Continued in table G2. File |  Recipe |  Frequency |  Description
---|---|---|---
(id)_pp_e2ds_{AB,A,B,C}.fits |  apero_extract |  every file |  2D extracted science/hot star file [49x4088]
(id)_pp_e2dsff_{AB,A,B,C}.fits |  apero_extract |  every file |  2D extracted + flat fielded science/hot star file [49x4088]
(id)_pp_s1d_v_{AB,A,B,C}.fits |  apero_extract |  every file |  1D extracted + flat fielded science/hot star file with constants velocity bins
(id)_pp_s1d_w_{AB,A,B,C}.fits |  apero_extract |  every file |  1D extracted + flat fielded science/hot star file with constants wavelength bins
(id)_pp_tellu_trans{AB,A,B}.fits |  apero_mk_tellu |  every hot star file |  Measured telluric transmission file [49x4088]
(id)_pp_tellu_pclean{AB,A,B}.fits |  apero_mk_tellu |  every hot star file |  Telluric pre-cleaning (corrected, transmission mask, measured absorption, sky model) [49x4088]
trans_model_AB.fits |  apero_mk_model |  one |  Model of all telluric transmission files (residuals in water, dry and a dc level).
(id)_pp_e2dsff_tcorr{AB,A,B}.fits |  apero_fit_tellu |  every hot star/science file |  2D telluric corrected extracted flat fielded file [49x4088]
(id)_pp_s1d_w_tcorr_{AB,A,B}.fits |  apero_fit_tellu |  every hot star/science file |  1D Telluric corrected extracted flat fielded file with constants velocity bins
(id)_pp_s1d_v_tcorr_{AB,A,B}.fits |  apero_fit_tellu |  every hot star/science file |  1D telluric corrected extracted flat fielded file with constants velocity bins
(id)_pp_e2dsff_recon{AB,A,B}.fits |  apero_fit_tellu |  every hot star/science file |  2D telluric reconstructed absorption file [49x4088]
(id)_pp_s1d_w_recon_{AB,A,B}.fits |  apero_fit_tellu |  every hot star/science file |  1D telluric reconstructed absorption file with constants wavelength bins
(id)_pp_s1d_v_recon_{AB,A,B}.fits |  apero_fit_tellu |  every hot star/science file |  1D telluric reconstructed absorption file with constants velocity bins
(id)_pp_tellu_pclean{AB,A,B}.fits |  apero_mk_tellu |  every hot star/science file |  Telluric pre-cleaning (corrected, transmission mask, measured absorption, sky model) [49x4088]
Template_{object}_tellu_obj_AB.fits |  apero_mk_template |  once per object |  2D telluric corrected template of a hot star or science object [49x4088]
Template_s1d_{object}_sc1d_w_file_AB.fits |  apero_mk_template |  once per object |  1D telluric corrected template of a hot star or science object with constants wavelength bins
Template_s1d_{object}_sc1d_v_file_AB.fits |  apero_mk_template |  once per object |  1D telluric corrected template of a hot star or science object with constants velocity bins
(id)_pp_e2dsff_tcorr{AB,A,B}_ccf _{mask}_{AB,A,B,C}.fits |  apero_ccf |  every hot star/science file |  The CCF output file (CCFs per order and fitted parameters)
(HASH)_pp_e2dsff_tcorr_pol_deg.fits |  apero_polar |  every polarimetric group |  2D polar file [49x4088]
(HASH)_pp_e2dsff_tcorr_null1_pol.fits |  apero_polar |  every polarimetric group |  2D Null 1 file [49x4088]
(HASH)_pp_e2dsff_tcorr_null2_pol.fits |  apero_polar |  every polarimetric group |  2D Null 2 file [49x4088]
(HASH)_pp_e2dsff_tcorr_StokesI.fits |  apero_polar |  every polarimetric group |  2D Stokes I file [49x4088]
(HASH)_pp_e2dsff_tcorr_s1d_w_pol.fits |  apero_polar |  every polarimetric group |  1D polarimetry, null 1, null 2 and stokes I file with constants wavelength bins
(HASH)_pp_e2dsff_tcorr_s1d_v_pol.fits |  apero_polar |  every polarimetric group |  1D polarimetry, null 1, null 2 and stokes I file with constants velocity bins
Table G2: Main apero products, where id for SPIRou is the odometer code and
the HASH is a checksum created by multiple inputs (of the same data type) to
the given recipe. A full list of data products for each recipe can be found in
the documentation. Continued from table G1.

##  Appendix H Preliminary usage with NIRPS

One of our main goals with apero was to keep the code generic enough that
adding new instruments is possible. To document this we detail here the
changes required to add NIRPS_HE and NIRPS_HA modes to apero. This work is
preliminary as commissioning of NIRPS is currently underway and we expect
additional changes will be required when larger data set over longer periods
of time exist (including long science sequences); however apero with NIRPS has
already demonstrated precision equivalent to SPIRou. The specific details of
all changes are not in the scope of this paper and will be part of a future
publication. Currently, after extraction, there are no code differences
between NIRPS and SPIRou reductions.

###  H.1 NIRPS: A comparison with SPIRou

NIRPS is very similar to SPIRou but differs in several ways. We list key
differences that apero must handle:

  * •

there are two modes, high efficiency (NIRPS_HE) and high accuracy (NIRPS_HA).

  * •

there is only one science fiber and one calibration fiber.

  * •

wavelength domain of 980 nm to 1800 nm (negligible thermal emission)

  * •

missing order(s) around 1400 nm

  * •

the resolution is higher $\sim$100 000 and $\sim$ 80 000 for NIRPS_HE and
NIRPS_HA modes respectively.

  * •

there is no slicer and NIRPS_HE and NIRPS_HA have differing fiber geometry.

  * •

there are 73 echelle orders extracted by apero.

  * •

there are no dark unilluminated amplifiers.

###  H.2 APERO changes for NIRPS

We use Figure 1 as our reference to changes within apero sub-packages. It is
worth noting that adapting apero for use with NIRPS did change some code used
for SPIRou, as having a second instrument with some unique characteristics
informed us of code that could be improved for both instruments. These changes
are not mentioned in this section. apero is designed to have each of these
instruments in the same code base thus there is no separate installation, nor
download of additional code is required for apero for usage with NIRPS.

No code was changed in the following apero sub-packages: apero.core: with the
exception of apero.core.instruments, apero.documentation, apero.io,
apero.lang, apero.plotting, apero.setup, and apero.tools. Minimal code (adding
3 or fewer changes) was changed in the following apero sub-package:
apero.base: adding of NIRPS_HE and NIRPS_HA to the supported instruments list.
Some code changes were added to the following apero sub-packages:

  * •

apero.data: data files were copied from SPIRou and updated for NIRPS_HE and
NIRPS_HA. A few FITS files had to be updated using external scripts. We plan
that these scripts will be ingested into apero as tools to be used on other
instruments directly with sufficient documentation to do so.

  * •

apero.recipes: recipe scripts were copied from SPIRou (mostly unchanged other
than filename). One recipe was added that did not exist before (a reference
flat done before the preprocessing recipe), which was added to the
preprocessing sequence for NIRPS_HE and NIRPS_HA.

  * •

apero.science: some science algorithms were added (and called from the
recipes) in addition to or to replace SPIRou science algorithms. For example,
as NIRPS does not have an unilluminated region similar to SPIRou we have to
handle the detector corrections in preprocessing slightly differently,
building a background image from the between-order regions.

Substantial code was added to the following apero sub-package:
apero.core.instruments: configuration, constants, keywords, file definitions,
pseudo constants and recipe definitions were copied from SPIRou and updated
for NIRPS_HE and NIRPS_HA. We also removed the polarimetry recipes as there is
no polarimetry mode for NIRPS.

Note that pseudo constants are constants and variables that cannot be
described by a single number or string of characters, such as a decision
between science and reference fibers for a specific step of apero, or a
specific fix to a FITS header key for a specific instrument. These pseudo
constants are python functions designed to keep these instrument-specific
options separate from the rest of the code.

##  Appendix I Glossary

In Table I1 we present a list of terms used throughout this paper.

Term |  Description
---|---
apero |  A PipelinE to Reduce Observations.
apero profile |  A specific setup of apero (i.e. with a certain set of constants, reduction directories, database setups, etc).
amplifier |  Independent electronic readout circuits operating in parallel and used to minimize the total readout time.
CCF |  Cross-correlation function
CADC |  Canadian Data Astronomy Center.
CFHT |  The Canada, France, Hawaii Telescope, situated on Maunakea, Hawaii, US.
dprtype |  Data product type - this describes what is in the science and reference fibers and distinguishes different calibrations and observations from each other.
drsmode |  Data product mode - for SPIRou this is spectroscopy data or polarimetry data.
e2ds |  An extracted order-by-order spectrum.
e2dsff |  An extracted order-by-order spectrum that has been flat fielded.
fast-axis (long-axis) |  Axis parallel to the amplifier direction on the detector. For SPIRou this is 4096 pixels per amplifier.
FITS file |  A Flexible Image Transport System file to hold images, tables, and metadata in the form of a FITS header.
FITS header |  A Flexible Image Transport System metadata holder. Consists of 8 character ‘keys‘, a value, and a comment.
FP |  A Fabry Perot etalon used for calibration.
hash |  A short unique hexadecimal string of characters generated from a long string of characters.
HC |  A hollow cathode lamp used for calibration.
hot star |  Bright, fast rotators of B or A spectral type that are spectrally featureless under $\sim$100$\text{kms}^{-1}$.
LBL |  Line-by-line method for measuring radial velocity, presented in Artigau et al. (2022).
NIRPS |  Near Infra Red Planet Searcher, a spectrograph on the 3.6m telescope in La Silla, Chile.
odometer |  A unique sequential number used by CFHT to identify individual observations.
order |  A domain on the detector at specific wavelengths generated by light passing through a diffraction grating.
PI |  Principal investigator.
pipeline |  Software that takes data from the origin to a destination.
post-processed data |  Data that is given to PIs after apero has been completed.
pre-processed data |  Data that has been corrected for detector issues - the first step for handling raw data.
pRV |  Precision radial velocity, measurements at the order of $\text{ms}^{-1}$ accuracy.
raw data |  For the purposes of apero this is the RAMPS from CFHT.
recipe |  A top-level script similar to a cookbook recipe where simple steps follow one another; most calculations and algorithms are hidden from these recipes.
reduced data |  Data that has been created from the raw data using a pipeline.
rhomb |  An ensemble of prisms used to rotate polarization states.
run.ini file |  A configuration file used for a specific reduction sequence i.e. a science sequence or a calibration sequence.
reduction sequence |  A set of recipes run in a certain order with specific filters on which files to reduce for a specific purpose.
reference calibration |  A calibration done once (not on a nightly basis).
science observation |  Any observation that is taken by the telescope specifically for the purposes of science i.e. SLS data and PI data.
slicer |  Device that is used to split an image into narrower images to increase spectral resolution.
slow-axis (short-axis) |  Axis perpendicular to the amplifier direction on the detector. For SPIRou this is 128 pixels per amplifier.
SPIRou |  Spectro Polarimètre Infra ROUge, a spectrograph for CFHT.
SLS |  The SPIRou Legacy Survey.
Wollaston prism |  A device that allows the incoming beam (either from the telescope or the calibration unit) to be split into two lyorthogonal polarized beams.
1/f noise |  A noise component arising from the detector readout electronics that has a low-frequency component that is common to all amplifiers and sampled by the reference pixels.
Table I1: Glossary of terms