  We present the data reduction pipeline for CHARIS, a high-contrast
integral-field spectrograph for the Subaru Telescope. The pipeline constructs a
ramp from the raw reads using the measured nonlinear pixel response, and
reconstructs the data cube using one of three extraction algorithms: aperture
photometry, optimal extraction, or $\chi^2$ fitting. We measure and apply both
a detector flatfield and a lenslet flatfield and reconstruct the wavelength-
and position-dependent lenslet point-spread function (PSF) from images taken
with a tunable laser. We use these measured PSFs to implement a $\chi^2$-based
extraction of the data cube, with typical residuals of ~5% due to imperfect
models of the undersampled lenslet PSFs. The full two-dimensional residual of
the $\chi^2$ extraction allows us to model and remove correlated read noise,
dramatically improving CHARIS' performance. The $\chi^2$ extraction produces a
data cube that has been deconvolved with the line-spread function, and never
performs any interpolations of either the data or the individual lenslet
spectra. The extracted data cube also includes uncertainties for each spatial
and spectral measurement. CHARIS' software is parallelized, written in Python
and Cython, and freely available on github with a separate documentation page.
Astrometric and spectrophotometric calibrations of the data cubes and PSF
subtraction will be treated in a forthcoming paper.
