  We present a new open-source data-reduction pipeline to reconstruct spectral
data cubes from raw SPHERE integral-field spectrograph (IFS) data. The pipeline
is written in Python and based on the pipeline that was developed for the
CHARIS IFS. It introduces several improvements to SPHERE data analysis that
ultimately produce significant improvements in postprocessing sensitivity. We
first used new data to measure SPHERE lenslet point spread functions (PSFs) at
the four laser calibration wavelengths. These lenslet PSFs enabled us to
forward-model SPHERE data, to extract spectra using a least-squares fit, and to
remove spectral crosstalk using the measured lenslet PSFs. Our approach also
reduces the number of required interpolations, both spectral and spatial, and
can preserve the original hexagonal lenslet geometry in the SPHERE IFS. In the
case of least-squares extraction, no interpolation of the data is performed. We
demonstrate this new pipeline on the directly imaged exoplanet 51 Eri b and on
observations of the hot white dwarf companion to HD 2133. The extracted
spectrum of HD 2133B matches theoretical models, demonstrating
spectrophotometric calibration that is good to a few percent. Postprocessing on
two 51 Eri b data sets demonstrates a median improvement in sensitivity of 80%
and 30% for the 2015 and 2017 data, respectively, compared to the use of cubes
reconstructed by the SPHERE Data Center. The largest improvements are seen for
poorer observing conditions. The new SPHERE pipeline takes less than three
minutes to produce a data cube on a modern laptop, making it practical to
reprocess all SPHERE IFS data.
