Astrometric and photometric accuracies in high contrast imaging: The SPHERE speckle calibration tool (SpeCal)

The consortium of the Spectro-Polarimetric High-contrast Exoplanet REsearch installed at the Very Large Telescope (SPHERE/VLT) has been operating its guaranteed observation time (260 nights over five years) since February 2015. The main part of this time (200 nights) is dedicated to the detection and characterization of young and giant exoplanets on wide orbits. The large amount of data must be uniformly processed so that accurate and homogeneous measurements of photometry and astrometry can be obtained for any source in the field. To complement the European Southern Observatory pipeline, the SPHERE consortium developed a dedicated piece of software to process the data. First, the software corrects for instrumental artifacts. Then, it uses the speckle calibration tool (SpeCal) to minimize the stellar light halo that prevents us from detecting faint sources like exoplanets or circumstellar disks. SpeCal is meant to extract the astrometry and photometry of detected point-like sources (exoplanets, brown dwarfs, or background sources). SpeCal was intensively tested to ensure the consistency of all reduced images (cADI, Loci, TLoci, PCA, and others) for any SPHERE observing strategy (ADI, SDI, ASDI as well as the accuracy of the astrometry and photometry of detected point-like sources. SpeCal is robust, user friendly, and efficient at detecting and characterizing point-like sources in high contrast images. It is used to process all SPHERE data systematically, and its outputs have been used for most of the SPHERE consortium papers to date. SpeCal is also a useful framework to compare different algorithms using various sets of data (different observing modes and conditions). Finally, our tests show that the extracted astrometry and photometry are accurate and not biased.


Introduction
The Spectro-Polarimetric High-contrast Exoplanet REsearch (SPHERE) (Beuzit et al. 2008) is a facility-class instrument at the Very Large Telescope (VLT) dedicated to directly imaging and spectroscopically characterizing exoplanets and circumstellar disks. It combines a high-order adaptive-optics system with diverse coronagraphs. Three instruments are available: an infrared dual-band imager (IRDIS, Dohlen et al. 2008), an infrared Based on observations collected at the European Organisation for Astronomical Research in the Southern Hemisphere under ESO programme 097.C-0865. integral field spectrometer (IFS, Claudi et al. 2008), and a visible imaging polarimeter (Zimpol, Thalmann et al. 2008).
Since first light in May 2014, SPHERE has been performing well in all observational modes, enabling numerous follow-up studies of known sub-stellar companions to stars and circumstellar disks as well as new discoveries (e.g., Boccaletti et al. 2015;de Boer et al. 2016;Ginski et al. 2016;Lagrange et al. 2016;Maire et al. 2016a;Mesa et al. 2016;Perrot et al. 2016;Vigan et al. 2016;Zurlo et al. 2016;Chauvin et al. 2017;Bonnefoy et al. 2017;Feldt et al. 2017;Maire et al. 2017;Mesa et al. 2017;Samland et al. 2017). The good performance to date results from the stability of the instrument over time and a dedicated and sophisticated software for data reduction.
The SPHERE reduction software uses the data reduction handling pipeline (DRH, Pavlov et al. 2008) that was delivered to ESO with the instrument as well as upgraded tools optimized using the first SPHERE data to derive accurate spectrophotometric and astrometric calibrations (Mesa et al. 2015;Maire et al. 2016b). The software that is implemented at the SPHERE data center (Delorme et al. 2017b) first assembles tens to thousands of images or spectra into calibrated datacubes, removing or correcting for instrumental artifacts. This includes image processing steps such as flat-fielding, bad pixels, background, frame selection, anamorphism correction, true north alignment, frame centring, and spectral transmission. The outputs of these first steps are temporal and spectral sequences of images organized in datacubes with four dimensions hereafter: coronagraphic images and the associated point-spread functions (PSF). Then, the software uses the speckle calibration tool (SpeCal) written in the IDL language and described in this paper. SpeCal was developed in the context of the SpHere INfrared survey of Exoplanets (SHINE), which is the main part of the SPHERE guaranteed observation time (GTO) and is now used to process all SPHERE data obtained with IRDIS and IFS systematically. SpeCal uses data processing algorithms proposed in the literature. Data from the Zurich imaging polarimeter (ZIMPOL) will be implemented in the future.
In section 2, we describe the algorithms that SpeCal uses to optimize the exoplanet detection, while in section 3 we explain how SpeCal algorithms estimate the astrometry and photometry of point-like sources like exoplanets or brown dwarfs. To address the accuracies of the data reduction in terms of astrometry and photometry we use SpeCal to reduce two sequences recorded with IRDIS (section 4) and IFS (section 5) during the SPHERE guaranteed time observations.

Differential imaging strategies
Current high contrast imaging instruments dedicated to exoplanet detection combine an adaptive optics system to compensate for the atmospheric turbulence and coronagraphs to attenuate the flux of the central bright source (i.e. the star). Because the adaptive optics system is not perfect and because of aberrations in the optics of the telescope and instrument, part of the stellar light reaches the science detector, creating spatial interference patterns called speckles. The speckles mimic images of offaxis point-like sources, especially in narrow band filters. Other factors let stellar light go through the coronagraph preventing the detection of faint sources in the raw data: chromatism of the coronagraph, atmospheric dispersion, diffraction effects from the secondary mirror and from spiders, low wind effect, and so on. Hereafter, for convenience, the stellar speckle pattern will refer to any type of stellar light that reaches the detector even if it is not in the form of speckles.
Strategies that are routinely used to discriminate exoplanet images from the stellar speckle pattern include angular differential imaging (ADI, Marois et al. 2006), dual-band imaging, and spectral differential imaging (SDI, Rosenthal et al. 1996;Racine et al. 1999;Marois et al. 2004;Thatte et al. 2007), reference differential imaging (RDI, Beuzit et al. 1997), and polarization differential imaging (PDI, Baba & Murakami 2003;Baba et al. 2005). Each strategy relies on specific assumptions about the speckle pattern, and the efficiency of extracting the planet signal from the speckle pattern is directly related to the strengths and limitations of these assumptions. When using ADI, we as-ADI Angular differential imaging SDI Spectral differential imaging PDI Polarization differential imaging RDI Reference differential imaging ASDI Simultaneous ADI and SDI Table 1. Acronyms of the strategies of observation.
sume most of the optical aberrations come from planes that are optically conjugated to the pupil plane and remain static in the course of the observation. Keeping the pupil orientation fixed (pupil tracking mode), we record a sequence of images that show a stable speckle pattern while the field of view, including an offaxis exoplanet image, rotates around the central star. Using dualband imaging, we assume the spectrum of the star (and so, the speckles) is different from the exoplanet spectrum. Using SDI, we assume the speckles are induced by an achromatic optical path difference in a pupil plane so that we can predict the evolution of the phase aberrations that induce the speckles with wavelength. Using RDI, we observe several similar stars with a similar instrumental set-up assuming the speckle pattern is stable in time. Finally, the PDI technique assumes that, unlike the star light, the light coming from the planet is polarized. For each strategy, several algorithms exist to process the data.
The SPHERE instrument can record coronagraphic images simultaneously in two spectral filters using the IRDIS subsystem for dual-band imaging (Vigan et al. 2010) or in 39 narrow spectral channels using the IFS for SDI (Zurlo et al. 2014;Mesa et al. 2015). During the observations, ADI, dual-band imaging, and SDI can be used so that the SPHERE instrument records four-dimensional datacubes, called I(x, y, θ, λ): two spatial dimensions (x, y, sky coordinates), one angular dimension (θ, orientation with respect to the north direction, which evolves with time in pupil tracking mode), and one spectral dimension (λ, wavelength). In the rest of the paper, we use "spectral channel" to refer to the spectral dimension, and "angular channel" to refer to the angular dimension. Also, we use SDI for both SDI and dual-band imaging.
The SpeCal tool was developed so that all the SHINE SPHERE GTO data can be uniformly processed. We remind readers that this tool uses data processing techniques that were previously proposed in the literature. The interest of the tool is that all these techniques have been tested on several datasets to ensure that all the products are consistent (contrast curves, measurements of astrometry, and photometry of detected pointlike sources). SpeCal can process data recorded using ADI, SDI, RDI, or the combination of ADI and SDI that is called ASDI hereafter (see Table 1). When SDI or ASDI is chosen, the frames I(x, y, θ, λ) are spatially scaled with wavelength to compensate for the spectral dispersion of the speckle position and size, the reference wavelength being the shortest one. The resulting frames are called I s (x, y, θ, λ). The scaling changes the spatial sampling. An inverse scaling is performed at the end of the data processing. The ASDI option usually minimizes the speckle pattern more efficiently but it can strongly bias the photometry of the objects that are detected, as demonstrated in Maire et al. (2014) and Rameau et al. (2015).
Numerous algorithms were proposed to minimize the speckle pattern in coronagraphic images so that point-like sources (e.g., exoplanets) or extended sources (e.g., circumstellar disks) can be detected. SpeCal offers several algorithms depending on the observing strategy: classical ADI (cADI, Marois et al. 2006), classical reference differential imaging (cRDI), sub-  Table 2. Acronyms and names of algorithms used to process the data recorded using a given strategy of observation (third column). If the third column shows 'all', it means the algorithm can be used on ADI, or SDI, or ASDI data.
In the ADI cases, once the A pattern is subtracted, all frames of R are rotated to align their north axis. In the SDI case, the R frames are spatially scaled to recover the initial sampling. In the ASDI case, the R frames are both spatially scaled and rotated. Then, the frames are mean-combined to sum up the offaxis source signal. The result is a datacube I final (x, y, λ). SpeCal also uses a median combination of the R frames. Hence, there are two final images for each spectral channel.
The following sections describe how SpeCal calculates the A pattern for each algorithm, the acronyms for which are given in Table 2.

Classical averaging
SpeCal can provide the average and median combinations of the rotated R frames using A = 0. This algorithm (ClasIm) can be useful to optimize the signal-to-noise ratio of detections in parts of the image that are dominated by background instead of speckles.
(2) Equation 1 is applied and the R frames are rotated and then averaged to produce one final image I final,a per spectral channel. SpeCal can also remove the median of the frames instead of the average: A m (x, y, λ) = (median(I(x, y, θ, λ)) θ .
( 3) Then, it uses A m in Eq. 1, rotates the R frames, and then applies a median combination. The final image I final,m is less sensitive than I final,a to uncorrected hot or bad pixels. It is however harder to accurately retrieve the photometry of a detected off-axis source from I final,m than from I final,a (section 3).

cRDI
The reference differential imaging (RDI) is especially useful to obtain images of extended sources like circumstellar disks or to probe small angular separations to the star because it is not subject to self-subtraction unlike the other algorithms. The classical RDI (cRDI) is similar to cADI but it uses N reference frames I R (x, y, n, λ) to derive the speckle pattern A, where n = 1..N. These reference frames are images of stars other than the one of interest (I R I). The resulting A pattern is

Subtraction of a radial profile
For detecting and studying extended sources, SpeCal proposes the radPro algorithm that first works out the average of the datacube over the angular dimension (Eq. 2). Then, it calculates the azimuthally averaged profile in rings of one pixel width. Finally, the A pattern is the centro-symmetrical image that is derived from this profile.

Loci
The SpeCal Loci algorithm is described in Lafrenière et al. (2007). For a given θ, a given λ, and a given region in the field (blue in Fig. 1), the algorithm calculates the linear combination of the other frames I s (x, y, θ , λ ) (θ θ and λ λ in ASDI) to build A(x, y, θ, λ) that minimizes |R| (Eq. 1) in the region of interest. In addition to the algorithm of Lafrenière et al. (2007), we impose the coefficients of the linear combination to be positive. Conversely to Lafrenière et al. (2007), the region of interest where A is applied and the region of optimization from which A is derived are the same in SpeCal. They are defined using: the radial width of the region (dr in Lafrenière et al. 2007); the number of PSFs inside the region (N A in Lafrenière et al. 2007).
We use different parameters to Lafrenière et al. (2007) to select the frames that are used in the linear combination. Consider the frame I s (x, y, θ, λ) (ASDI case, section 2.1). First, we assume the image I p of a putative off-axis source in I s is the two-dimensional Gaussian function with the full width halfmaximum (fwhm) estimated from the recorded PSF (see section 2.10.1). If the source is in the region centered on (x 0 , y 0 ) in I s (x, y, θ, λ), it is angularly shifted by s θ = r 0 (θ i − θ) and radially shifted by s r = r 0 (1 − λ/λ j ) in I s (x, y, θ i , λ j ), where r 0 = x 2 0 + y 2 0 is the angular separation from the star in fwhm unit. If only I s (x, y, θ i , λ j ) was used to build A, the normalized intensity of the off-axis source integrated within a disk of onefwhm diameter in the frame R would be Using the radial and angular shifts s r and s θ of I s (x, y, θ i , λ j ), we find where α equals 2 √ ln 2, and erf is the error function, and Here, we assume the angular motion is linear, which is a good assumption because E(s) quickly decreases. The function τ goes from 0 (θ = θ i and λ = λ j , total self-subtraction) to 1 (no self-subtraction). In SpeCal, we set a parameter τ that can be linked to the minimum motion δ min of the putative off-axis source in Lafrenière et al. (2007). If τ is smaller than τ, the frame I s (x, y, θ i , λ j ) is rejected. Doing so for each θ i and λ j , we obtain a series of frames {I s } that individually leave at least τ times the initial flux of the putative source in the R(x, y, θ, λ). Then, we select from {I s } the N most correlated frames (N is adjustable) to I s (x, y, θ, λ) in the considered region. We obtain the linear combination of the N frames (i.e., the A pattern) that minimizes the residual energy in this region using the boundedvariables least-squares algorithm by Lawson & Hanson (1995). Finally, as the coefficients of the linear combination are positive, the flux of the putative source in the final image I final is at least τ times the initial flux for any region. The Loci algorithm can be used to reduce ADI, SDI, or ASDI data. In the ADI case, the Loci A pattern that is worked out for a given frame I(x, y, θ, λ) uses the other frames taken in the same spectral channel only. In the SDI case, it uses the frames taken with the same angle θ only. Finally, in the ASDI case, all frames are spatially scaled with wavelength, and they are all used to determine the A pattern.

TLoci
The SpeCal TLoci algorithm is derived from the one described in Galicher & Marois (2011) and Marois et al. (2014) assuming a flat planet spectrum in contrast. The parameters that are used to select the frames (τ and N) and to describe the regions of interest (dr and N A ) where the A pattern is applied (blue region in Fig. 1) are the same as for the Loci case (section 2.6). The difference from Loci is the region where A is optimized (red region). In SpeCal, the gap between this region and the region of interest is set to 0.5 fwhm. Hence, the optimizing region is close enough to the region of interest so that A is efficiently optimized, and the optimizing region is far enough from the region of interest so that the flux of a source in the latter does not bias the linear combination. Moreover, the internal radii of the two regions are the same in SpeCal. Finally, an additional parameter sets the radial width of the optimizing region. As for Loci, TLoci can be associated to ADI, SDI, and ASDI.

LociRDI
A reference differential imaging algorithm using Loci is also implemented in SpeCal. It works as described in section 2.6 but the frames that are used to build A are reference frames as in the cRDI case (section 2.4).

PCA
For historical reasons, two PCA algorithms are implemented in SpeCal. The first version can be applied on IRDIS or IFS data using the ADI or ASDI options. This algorithm follows the equation of Soummer et al. (2012). For each frame I(x, y, θ, λ), we subtract its average over the field of view: In the ADI case, the principal components are calculated for each spectral channel independently. Each frame I z (x, y, θ, λ) is then projected onto the N first components to obtain the A pattern that is used in Eq. 1, replacing I with I z . The N parameter is called "number of modes" hereafter. Finally, the averages that were removed (Eq. 9) are added back to obtain the R frames of Eq. 1. In the ASDI case, the algorithm is the same but it works on I s instead of I. We note that here there is no frame selection to minimize the self-subtraction of point-like sources when deriving the principal components. The second version of PCA that is implemented in SpeCal is very similar to the first one but it can be applied on IFS data using the ASDI option only (Mesa et al. 2015). The two PCA versions were tested on a large amount of SPHERE data and they provide a very similar performance.

Model of unsaturated PSF
SpeCal produces common outputs whatever the chosen algorithm. First, it records the final images I final normalized to the estimated maximum of an unsaturated non-coronagraphic stellar image with the same exposure time. Hence, the values of the pixels in I final give the contrast ratio to the star maximum. For each spectral channel, the maximum β of the stellar noncoronagraphic image is derived from the best fit of the input PSFs by the function where α is the background level, β is the star maximum, γ and η are related to the spatial extension of the PSF (and to fwhm), and (x PSF , y PSF ) give the center of the PSF. All these parameters are fitted accounting for the photon noise in the provided PSF images. The SPHERE PSFs are usually close to two-dimensional Gaussian functions (η = 2) but can deviate from them. In the context of SHINE, PSFs are usually recorded before and after the coronagraphic sequence. SpeCal calculates the best fit to each of the PSFs (∼ 50x50 pixels) and runs two tests on the time series of fitted parameters. First, it works out the average and standard deviation of the normalization factor β over time, records the two values, and sends a warning if the flux of the star β varies by more than 20 % between distinct PSF observations of the target. Then, it sends a warning if the background level α is larger than 10 % of β. These values (10 % and 20 %) were defined as quality requirements based on our experience with the instrument and the analysis of hundreds of datasets. Finally, SpeCal estimates and records the PSF fwhm.

Calibration of photometry
For algorithms that bias the photometry of off-axis sources, SpeCal estimates the throughput of the technique at each position in the field. For cADI, radPro, and PCA, SpeCal creates a datacube of fake planets that are on a linear spiral centered on the star (one planet per 2 fwhm). For each planet, we use the recorded PSF and its flux equals ten times the local residual flux in I final . The fake planet datacube is added to the datacube I(x, y, θ, λ). Then, SpeCal combines the frames as the I(x, y, θ, λ) were combined to get I final . For each planet, the ratio of the flux in the resulting image to the flux of the fake planet is calculated to obtain the 1D-throughput as a function of the angular separation. For Loci and TLoci, the throughput τ R is estimated in each frame R as the average of all τ of Eq. 7, weighting E(s θ ) and E(s r ) by the coefficients used to obtain I final . We average all τ R to obtain the 1D-throughput as a function of the angular separation. Finally, the throughput map T is the centro-symmetrical image created from the 1D-throughput. SpeCal also calculates the throughput-corrected final image I final /T .

Signal-to-noise and detection maps
For each spectral channel, the image I final /T is divided into annulii of 0.5 fwhm width. Then, in each annulus (i.e., at each angular separation), we calculate the standard deviation that is set to be the 1 σ contrast. Signal-to-noise maps are also created. Each pixel gives the ratio of the flux in I final /T to the standard deviation of I final /T calculated in annulii of 1 fwhm centered on the star. This correction is valid only for point-like sources. For example, this correction is not valid for an extended source like a disk. Finally, SpeCal also provides local detection maps giving the local standard deviation in boxes of 2 fwhm radial size and of a total area of 5 fwhm 2 .

Planet image
Say there is a planet whose intensity is described by I p (x, y, θ, λ) whereas the stellar intensity is I * (x, y, θ, λ). The A pattern is derived from the cube I(x, y, θ, λ) = I * (x, y, θ, λ) + I p (x, y, θ, λ) and part of the A pattern is composed of planet signal. For example, when using cADI, Loci, TLoci, or radPro on ADI, SDI, or ASDI data, the A pattern can be expressed as A(x, y, θ, λ) = i j c i, j I * (x, y, θ i , λ j ) + c i, j I p (x, y, θ i , λ j ) , (13) where coefficients c i, j are real numbers that can be a function of (x, y), and Hence, the A pattern is contaminated by planet signal and, when subtracting the A pattern from the initial frames I, part of the planet signal self-subtracts. The R frames is then where all terms depend on x, y, θ, and λ. A perfect algorithmthat does not exist -would be such that A * = I * and A p = 0. As the planet image moves in the field from one frame to another (radially for SDI or azimuthally for ADI), the subtracted signal is shifted with respect to the astrophysical position of the planet. This results in a positive-negative pattern of the planet in each frame of R and as a consequence in the final image I final (left in Fig. 2). This pattern is not always centered on the planet position. The distortions of the planet image can be minimized by carefully selecting the frames that are used to build A (so that A p → 0) but it usually reduces the efficiency of the speckle attenuation at the same time (increasing |I * − A * |). In the case of PCA algorithms, I(x, y, θ i , λ i ) in Eq. 12 is replaced by the principal components, which are also contaminated by the planet signal.

Model of planet images
The first way of extracting the astrometry and the photometry of an off-axis point-like source like a planet in an ADI, SDI, or ASDI reduced image consists of building a model of the planet image (Galicher & Marois 2011). First, we estimate the position of the detected source in I final with a pixel accuracy. Then, we use the measured stellar PSF to build a sequence of frames I f p (x, y, θ, λ) with only one fake planet image at the rough position accounting for the field-of-view rotation. We do not account for the smearing that affects images. This effect may be nonnegligible at the edges of the IRDIS images if the field-of-view rotation is fast and the exposures are long, which is rare. We combine the frames I f p in the same way the frames I were combined using the same c i, j and we get an estimation of A p (Eq. 15). Rotating (ADI case), spatially scaling (SDI case), and averaging the frames result in a model of the planet image (right in Fig. 2). The planet image has negative wings due to the self-subtraction of the planet flux (section 3.1). Then, the flux and the position of this synthetic image are adjusted to best fit the real planet image within a disk of diameter 3 fwhm so that it includes the positive and the negative parts of the image. The optimization is done using I final , which is derived from the average of the R frames after rotation and spatial scaling (and not the one obtained using the median-combination that does not preserve linearity). Rigorously, we should calculate the synthetic image each time we test a new planet position. To optimize computation time, we shift the synthetic planet image that was obtained with the rough position. We noticed no significant difference as long as the shifts are smaller than ∼ 1 fwhm.
Once the optimization is done, we look for the excursion of each parameter that increases the minimum residual level by a factor of 1.15. We set these excursions to be the 1 σ accuracies due to the fitting errors in the SpeCal outputs. The value of 1.15 is empirical but it was tested on numerous cases (high or low signal-to-noise detection, strong or weak negative wings, Loci, TLoci, PCA, and others). Another SpeCal output is the standard deviation in time of the averaged flux in the coronagraphic images. To avoid saturated parts of the images and background dominated parts, the averaged flux is calculated inside an annulus centered on the star and going from 30 pixels to 50 pixels in radius.
SpeCal can use this technique to extract astrometry and spectro-photometry in images obtained with any algorithm (cADI/radPro/Loci/TLoci/PCA/averaging) and any of ADI, SDI, or ASDI. It can also be used on cRDI, LociRDI, and ClasImg final images. In these cases, the planet image model is the stellar PSF shifted at the position of the detection with no negative wings as the A p pattern is null (classical fit of a noncoronagraphic image).

Negative planets
Another technique -the fake negative planet - (Lagrange et al. 2010;Chauvin et al. 2012) is implemented in SpeCal to retrieve the photometry and astrometry of point-like sources. First, we build the sequence of frames I f p with the fake planet only, as done in section 3.2. Then, we subtract this datacube from the initial data I. We apply the algorithm and get the final image from the I − I f p frames. In this final image, we measure the standard deviation of the residual intensity inside a disk of 3 fwhm diameter centered on the rough position of the detected planet. Modifying the fake planet position and flux, we minimize the residual intensity. The uncertainties on the best values are estimated as the ones in section 3.2. The negative planet technique is more time-consuming than the model of planet image technique because it calculates the c i, j for all the tested fake planet positions and fluxes. It is, however, needed in some cases for which the model of planet image technique is biased (section 4.2).  Table 3. Separations to the central star in pixels towards east (∆RA) and north (∆DEC), angular separations in mas and flux ratio with respect to the star (C) for each fake planet added to the IRDIS data.

Reduction of IRDIS data
In section 4 and 5, we use SpeCal to reduce two datasets as examples. In section 4, we consider one sequence recorded during the SPHERE GTO on 2016 September 16 observing HIP2578 in IRDIS H2/H3 mode. There are 80 images of 64 s exposure time and the field of view rotates by 31.5 degrees. The seeing was about 0.5 arcsec and the average wind speed was 7.4 m.s −1 . All algorithms are applied on the same datacube provided by the first part of the SPHERE pipeline (background, flat-fielding, bad pixels, registration, wavelength calibration, astrometric calibration; Pavlov et al. 2008;Zurlo et al. 2014;Maire et al. 2016b). The datacube is a 1024 × 1024 × 80 × 2 array. The last dimension stands for the two spectral channels (H2 and H3). We also added three fake planets to the data (see Table 3) using the recorded stellar PSFs. We chose the position and the flux to have three typical cases. Planets 1 and 2 are in the speckle dominated part of the image, planet 2 being surrounded by brighter speckles. Planet 3 is in a region dominated by the background and not by speckles.

Calibration of the speckle pattern
We apply several algorithms to the two spectral channels independently (no use of SDI) and we show the average of the two final images in Fig. 3 for cADI, TLoci, Loci, and two PCA (5 and 10 modes). Images are corrected from the technique throughput T (self-subtraction of a putative planet, section 2.10.2) and from the coronagraph transmission. All images provide similar sensitivities except for cADI, which is less efficient inside the AO correction area that is dominated by speckles. The three fake planets are well detected in all images. The corresponding 5σ contrast curves are plotted in Figs. 4 (H2) and 5 (H3), where the three planets are represented by plus symbols. The curves are corrected for the throughput T of each technique and from the coronagraph transmission (Guerri et al. 2011). The latter is a function of angular separation and it was calibrated at the telescope and via numerical simulations. We also overplot the contrast before any a posteriori speckle minimization with a dotted line (ClasImg). The utility of a speckle calibration during the data processing is obvious since none of the planets are detected in the images with no subtraction (ClasImg). In this example, all the algorithms except cADI give similar performances in terms of contrast level. For some sequences, one algorithm reaches better contrast levels but there is no algorithm in SpeCal that is always better than the others.
The small sample statistic bias (Mawet et al. 2014) that mainly affects separations at less than 0.2 will be implemented in the next version of the tool. This correction will affect all the algorithm reductions the same way.   4. Contrast curves at 5 σ before (ClasImg) and after minimization of the stellar light using different algorithms (cADI, Tloci, Loci, PCA 5 modes) on H2 data. The curves are corrected from the technique attenuation and from the coronagraph transmission. The fake planets are represented by plus symbols.

Measurements of astrometry and photometry
We extract the astrometry and photometry for each detected point-like source using the technique of the model of planet image (section 3.2). The estimated contrasts to the star are gathered in Table 4 with the associated 1 σ uncertainties. Each measurement C is compared to the true value C R using with Err the estimated 1 σ uncertainty on C.
All the astrometric measurements are at less than 1 σ from the true values (Table 3), which corresponds to an accuracy of ∼ 0.2 pixel (i.e., ∼ 2 mas); and all photometric measurements  Table 4. Measured astrometry and photometry in IRDIS images for each planet (same Id as in Table 3) using the model of planet image technique (section 3.2). Measurements are given with their 1 σ uncertainties. For each measurement, we compare it to the true value using the E criteria that is given in Eq. 17.
are at less than 1.8 σ from the true value C R . In the case of PCA images, the model of planet image technique can be biased in the current version of SpeCal, especially when using more than approximately ten modes. We are still investigating to understand why. To overcome this bias, we use the negative planet technique (section 3.3) that can be time-consuming but which provides more accurate measurements as showed in Table 5: the measurements are at less than 1.5 σ from the true values whereas they were at 6 σ using the planet image technique.
To conclude, SpeCal meets the requirements in terms of extracted astrophysical signals because the measured astrometry and photometry of point-like sources (e.g., exoplanets or brown dwarfs) are accurate and unbiased. This is essential to correctly interpret the observations (fit of the planet orbits or of their spectra). Moreover, SpeCal enables the use of several algorithms to provide a global dispersion of these measurements and a crosscheck between measurements to prevent any systematic errors.

Reduction of IFS data
We now use SpeCal to reduce one sequence recorded during the SPHERE GTO on 2016 September 16 observing HD206893 in IFS YJH mode. There are 80 images of 64 s exposure time and the field of view rotates by 75.6 degrees. The seeing was about 0.7 arcsec and the average wind speed was 8.4 m.s −1 .
As for the IRDIS data, all algorithms are applied on the same datacube provided by the first part of the SPHERE pipeline (Pavlov et al. 2008;Mesa et al. 2015;Maire et al. 2016b). The datacube is a 290 × 290 × 80 × 39 array. The last dimension is the number of IFS spectral channels. We also added three fake planets to the data (see Table 6) using the recorded stellar PSFs. As for IRDIS, we chose the position and spectra to be representative of three common cases. The spectra of planets 1 and 2 show strong variations between 0.9 µm and 1.7 µm. Planet 1 is closer to the star and its image is located in a region with bright speck-les. Planet 3 is located in a region with very bright speckles and its spectrum in contrast is flatter than the others.

Calibration of the speckle pattern
First, we apply ASDI PCA to detect point-like sources as it efficiently minimizes the speckle pattern (Fig. 6). We detect four point-like sources: the three fake planets (1, 2, and 3) and one real object HD 206893 B that we do not study in this paper (see Delorme et al. 2017;Milli et al. 2017). It is hard to accurately retrieve the planet photometry from ASDI images when the planet spectrum is unknown, as demonstrated in Maire et al. (2014) and Rameau et al. (2015). Therefore, we also apply several algorithms using ADI resulting in 39 final images I final (x, y, λ) for each algorithm. The averages over the 39 channels are shown in Fig. 6 for PCA/ADI (5 and 20 modes) and TLoci/ADI. We clearly detect the four objects in all images.

Measurements of photometry
For TLoci and PCA/ADI 5 mode images, we use the model of planet image technique (section 3.2) to extract the photometry and the astrometry of the three fake planets. For the PCA/ADI 20 mode image, we use the negative planet technique (section 3.3) to avoid the photometry underestimation that was noticed in sectio 4.2. When considering the spectral channels where the planet is detected, the astrometry measurements are accurate with 1 σ uncertainties of 0.6, 0.3, and 0.5 pixel for planets 1, 2, and 3 respectively. These values correspond to 4.5, 2.3, and 3.8 mas respectively.
We plot the extracted spectrophotometry in Figs. 7, 8, and 9 for the TLoci/ADI (blue), the PCA/ADI 5 modes (red), and the PCA/ADI 20 modes (green) cases, as well as the true spectra that we used for the fake planets (full line). The arrows give the 1 σ  Table 6. Fake planets injected in the IFS data: separation from the central star in pixels toward east (∆RA) and toward north (∆DEC), angular separation in mas, and averaged contrast over the 39 spectral channels.
upper limits when the planet is not detected, and the error bars correspond to the estimated 1 σ uncertainties.
All algorithms retrieve the spectra of the three fake planets with similar uncertainties and no bias. In the case of planet 3, which is in a region with bright speckles, there are spectral channels below 1 µm for which TLoci give an upper limit only (no detection). For the same planet, the PCA algorithm using 5-modes does not detect the object between 1.3 µm and 1.5 µm, whereas it does below 1 µm. Such a situation often happens: several algorithms detect the planet in different spectral channels. Thus, it Fig. 7. Spectra of planet-to-star contrast extracted from the PCA/ADI 5 modes (red), PCA/ADI 20 modes (green), and TLoci/ADI (blue) images compared to the true spectrum that was used for fake planet 1 (black full line). Error bars and upper limits are given at 1 σ. is essential to use several algorithms in parallel to optimize the detection and the measured spectrum.

Conclusion
The Speckle Calibration tool (SpeCal) was developed by the SPHERE/VLT consortium in the context of a large survey (SHINE), the main objective of which is to search for and measure the astrometry and spectrophotometry of exoplanets at large separations (> 5 au). SpeCal provides high contrast images using a variety of algorithms (cADI, PCA, Loci, TLoci) enabling the study of exoplanets, brown dwarfs, and circumstellar disks. SpeCal has been intensively tested on SPHERE guaranteed time observations (GTO) and calibration data since 2013. It is implemented in the SPHERE data center (Delorme et al. 2017b) to produce the final reduction for public data releases. The final reductions will be available in the SPHERE target database (TDB). Finally, SpeCal and the DC are able to process all GTO data obtained with IRDIS/SPHERE (dual-band imaging) and IFS/SPHERE (integral field spectrometer) automatically. SpeCal delivers major outputs for the survey and feeds the SPHERE database with final images, contrast curves, signal to noise maps, astrometry, and photometry of detected pointlike sources in the field (exoplanets, brown dwarfs, background sources, and all sub-stellar or stellar candidates). This material has been used for the study of exoplanets and circumstellar disks primarily based on SPHERE data (de Boer et al. 2016;Ginski et al. 2016;Lagrange et al. 2016;Maire et al. 2016a;Mesa et al. 2016;Perrot et al. 2016;Vigan et al. 2016;Zurlo et al. 2016;Benisty et al. 2017;Bonavita et al. 2017;Bonnefoy et al. 2017;Feldt et al. 2017;Maire et al. 2017;Mesa et al. 2017;Pohl et al. 2017;Samland et al. 2017).
In this paper, we investigated the astrometric and photometric performance for point-like sources considering objects at a contrast of ∼ 3 × 10 −6 in the separation range of 3 to 26 fwhm. Using the techniques of positive and negative fake planets, we demonstrated the ability to achieve a measurement of the astrometry with an accuracy of ∼ 0.2 pixel (i.e., ∼ 2 mas) for IRDIS and 0.5 pixel (i.e., ∼ 4 mas) for IFS. Similarly the photometric accuracy reaches ∼ 10%.
We are planning to upgrade SpeCal with other algorithms like Andromeda (Cantalloube et al. 2015) or inverse approaches (Devaney & Thiébaut 2017), and other observing modes (polarimetry, ZIMPOL). Finally, a specific tool to model the ADI self-subtraction of circumstellar disks with simple geometries will also be implemented.