{'fraction_non_alphanumeric': 0.028337994994847637, 'fraction_numerical': 0.008317385543942294, 'mean_word_length': 4.7694267515923565, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
The Son-Of-X-shooter (SOXS) Data-Reduction Pipeline

The Son-Of-XShooter (SOXS) is a single object spectrograph (UV-VIS&NIR) and acquisition camera scheduled to be mounted on the ESO 3.58-m New Technology Telescope at the La Silla Observatory. Although the underlying data reduction processes to convert raw detector data to fully-reduced science ready data are complex and multi-stepped, we have designed the SOXS Data Reduction pipeline with the core aims of providing end-users with a simple-to-use, well-documented command-line interface while also allowing the pipeline to be run in a fully automated state; streaming reduced data into the ESO Science Archive Facility without need for human intervention. To keep up with the stream of data coming from the instrument, there is the requirement to optimise the software to reduce each observation block of data well within the typical observation exposure time. The pipeline is written in Python 3 and has been built with an agile development philosophy that includes CI and adaptive planning.


INTRODUCTION
The SOXS (Son Of X-Shooter) instrument is a new medium resolution spectrograph (R 4500) capable of simultaneously observing 350-2000nm (U-to H-band) to a limiting magnitude of R ∼ 20 (3600sec, S/N ∼ 10). It shall be hosted at the Nasmyth focus of the New Technology Telescope (NTT) at La Silla Observatory, Chile (see 1 for an overview). This paper describes the design of the SOXS data-reduction pipeline and data-flow system. Details of each of the other SOXS subsystems can be found in a set of related.  Details of the three detectors included in the SOXS instrument, that the pipeline shall receive data from, are given in Section 2. Section 3 explains the aims and goals of the pipeline and Section 4 describes the pipeline software architecture and development environment. Finally, Section 5 outlines the data-products to be expected from the pipeline and the planned data-flow from raw data coming off the telescope through to the data owners collecting reduced data from the ESO SAF.

THE 3 SOXS DETECTORS
SOXS comprises three instruments; the UV-VIS and NIR spectrographs and an Acquisition and Imaging Camera (AC). The instruments are to be mounted on the NTT's Nasmyth focus rotator flange. It is the role of the SOXS data reduction pipeline to reduce the pixel data collected by each of these instruments into science-ready data products.

The NIR Spectrograph
The SOXS NIR spectrograph is a cross-dispersed echelle, employing "4C' (Collimator Correction of Camera Chromatism) to image spectra in 800-2000nm wavelength range, in 15 orders, onto a 2kx2k 18 micron pixel Teledyne H2RG TM array (see Figure 1). It will achieve a spectral resolution R 5000 (1 arcsec slit).

The UV-VIS Spectrograph
The UV-VIS spectrograph employs the novel design of 4 ion-etched transmission gratings in the first order (m = 1) to obtain spectra in the 350-850nm wavelength range (providing an overlap of 50nm with the NIR arm for cross-calibration). The spectral band is split into four poly-chromatic channels and sent to their specific grating. 19 Unlike the NIR arm, the UV-VIS arm will include an Atmospheric Dispersion Corrector (ADC). Each of the four dispersion orders are imaged to separate areas of the e2V CCD and aligned linearly along the direction of the CCD columns (see Figure 2).

The Acquisition and Imaging Camera
Although the primary use of the SOXS acquisition camera is to acquire spectral targets to allow for their centring on the slit, the camera's 3.5 × 3.5 FOV and 0.205 arcsec/px scale will also allow for science-grade, multi-band imaging. Observers will be able to select from 7 filters; the LSST u, g, r, i, z, y set and Johnson V .

DATA REDUCTION PIPELINE REMIT
The main purpose of the SOXS Data Reduction pipeline is to use SOXS calibration data (typically, but not necessarily, collected close in time to the science data), to remove all instrument signatures from the SOXS scientific data frames, convert this data into physical units and deliver them with their associated error bars to the ESO SAF as Phase 3 compliant science data products, all within a timescale shorter than a typical SOXS science exposure. The pipeline must also support the reduction of data taken in each of the available SOXS observation modes. The primary reduced pipeline product will be a detrended, wavelength and flux calibrated, telluric corrected 1D spectrum with UV-VIS + NIR arms stitched together (see Section 5).
Although the underlying data reduction processes to convert the raw detector data to fully-reduced, fluxand wavelength-calibrated science-ready data are complex and multi-stepped, soxspipe has been designed with Figure 3: The SOXS Spectroscopic Data Reduction Cascade. Each of the vertical lines in the map depicts a raw data frame, the specific recipe to be applied to that frame and the data product(s) output by that recipe. Horizontal lines show how those output data products are used by subsequent pipeline recipes. Time loosely proceeds from left to right (recipe order) and from top-to-bottom (recipe processing steps) on the map. a core aim of providing end-users with an easy-to-install, simple-to-use, clear, well-documented command-line interface while also allowing the pipeline to be run in a fully automated state; streaming reduced SOXS data into the ESO SAF without need for human intervention. Once users have miniconda * or anaconda † installed on their local machine, the pipeline can be installed via a single command and typically takes < 1 min to install. conda create -n soxspipe python=3.8 soxspipe -c conda-forge The static calibration files required by the pipeline are shipped alongside the code, removing the burden often * miniconda https://docs.conda.io/en/latest/miniconda.html required of pipeline users to separately download and manage these files. This has the added benefit of these files being version controlled alongside the code so the end-user will always have access to the suite of calibration files associated with the specific version of the pipeline they have installed on their machine.
The pipeline will also generate Quality Control (QC) metrics to monitor telescope, instrument and detector health. These metrics are to be read and presented by the SOXS health-monitoring system. 27

PIPELINE ARCHITECTURE AND DEVELOPMENT ENVIRONMENT
Presently, the astronomical community have overwhelmingly adopted Python as their scripting language of choice and there are a plethora of well-maintained, mature python packages to help with basic data-reduction routines, visualisation, user-interaction and data manipulation. It was a natural choice therefore to develop the SOXS pipeline in Python 3. We have implemented an object-orientated composition and the pipeline is designed to be primarily driven from the command line. The concept of 'recipes', originally employed by ESO's Common Pipeline Library (CPL), has been adopted to define the modular components of the data reduction workflow. These recipes can be connected together to create an end-to-end data-reduction cascade, taking as input raw and calibration frames from the SOXS instrument and processing them all the way through to fully reduced, calibrated, ESO Phase 3 compliant science products (see Figures 3 and 4). Recipes are named with the prefix 'soxs' followed by a succinct description of the recipe (e.g. soxs mbais for the master bias creation recipe). There are also many reusable functions designed to be called from multiple recipes; these are referred to as 'utilities' in soxspipe.
The pipeline has been built with an agile development philosophy that includes adaptive planning and evolutionary development. As with any software project, one of the greatest risks is knowledge loss due to a team member leaving before project completion. To mitigate this risk we have employed pair-programming techniques to share knowledge, both explicit and tacit, between two developers. In times of travel bans and remote working a JupterHub server with Python-based notebooks, shared screens and video conferencing tools have been essential to executing these techniques.
The SOXS End-to-End (E2E) simulator 14 is capable of producing simulated 2D images in the SOXS format that take into account the main optical behaviour of the system (grating dispersion, sampling, PSF, noises and position of various resolution elements coming from full ray-tracing). By using test-driven development throughout the development process, combined with 'extreme' mock data generated from the E2E simulator, we can verify the pipeline is not only able to reduce a typical data set but also data that is far from ideal. This extreme data helps us push the pipeline to the limits of its capabilities and allows us to defensively develop against the edge-case scenarios the pipeline will most certainly experience at some point in production mode. Figure 6 gives an indication of the quality of the reductions achieved by soxspipe when reducing E2E calibration frames. This spectrum file will also have the same 4 extensions described above.

2D Source Spectra
A 2D FITS image for each spectral arm containing wavelength and flux calibrated spectra (no other corrections applied) allowing users to perform source extraction with their tool of choice. Note that rectification of the curved orders in the NIR introduces a source of correlated noise not present in extractions performed on the unstraightened orders as done by the pipeline.
Acquisition Camera Images ugrizy astrometrically and photometrically (griz only) calibrated to Refcat2 29 The pipeline code is open-source, hosted on Github ‡ and connected to a Jenkins Continuous Integration/Continuous Deployment server via Github's webhooks. Any new push of code to a branch on the GitHub repository triggers a new 'build' of the code on the CI server where all unit tests are run. If all tests pass the branch can be merged into main development branch. If it is the main/production branch being tested, and all tests pass, then a new dot release version of the code is automatically shipped to PyPI § and conda-forge ready for deployment.

DATA PRODUCTS AND DATA FLOW
soxspipe will reduce data into a set of final data products (see Table 1 for details) which shall meet ESO Phase 3 standards 'out-of-the-box'. This has the benefit of allowing us to build an automated workflow (see Figure 7) to reduce data directly on the La Silla summit immediately after the data is acquired by the NTT and SOXS and then stream the reduced data directly into the ESO SAF 30 in Garching, Germany. Owners of the data will then be able to access the fully-reduced data alongside the raw data within minutes of the shutter closing on their observation. This low-latency, automatic reduction is possible thanks to the fixed format of SOXS (apart from exchangeable slit) allowing calibration frames to be prepared ahead of time before science data reductions. The SAF then acts as both a data distribution solution and also fulfils the SOXS consortium's legacy archive requirements.
Access to the 'open stream' method of shipping reduced data directly to the ESO SAF will initially require the ESO Archive Science Group to review and verify a moderately sized collection of soxspipe reduced data. Once the quality and content of the data produced by the pipeline have met ESO Phase 3 standards we will then be allowed to ship data products to the archive without further need of passing through a gatekeeper. The pipeline will automatically reduce on all point-source targets above an AB magnitude of r = 19 (with the stretch goal of r = 20). For sources below this magnitude, the pipeline will attempt to automatically reduce the data but may require some user interaction to optimise object extraction.

CONCLUSIONS
The SOXS Pipeline soxspipe has been designed and written in object-orientated Python 3 using an agile framework of development. Built with core aims of allowing for fast, automatic reduction of raw data, streaming reduced data into the ESO SAF without need for human intervention, while also providing end-users with a simple-to-use, well-documented command-line interface, it is our hope that the pipeline will help facilitate the success of SOXS in the years to come. Figure 6: The left panels show the NIR order-edges as identified by the SOXS data-reduction pipeline using a master-flat frame created from a set of full slit flat-lamp frames generated by the E2E simulator. On the right, the resulting final dispersion solution and residuals as fitted by the SOXS data-reduction pipeline using a simulated arc-lamp frame obscured by a multi-pinhole mask. The arc lines detected in the frame (top right image panel) are used to fit a global dispersion solution (middle right image panel). The residuals of the fits as compared to measured order-edge and arc-line locations can be found in the bottom panels. . Raw data is reduced on the summit (top centre) and transferred within minutes to the ESO SAF (Garching, Germany) where data-right owners can access it (central in blue). In parallel, the SOXS consortium will also reduce their data on a remote machine (probably cloud-based) with a leading-edge version of the pipeline (bottom in green). If at any point it is decided that new development of the pipeline has led to significantly improved data products compared to those hosted on the SAF the consortium may opt for a complete reprocessing and replacement of the data on the SAF via a dedicated Phase 3 Data Release (orange arrow).