A 2011 Image Stacking Pipeline Survived When Its Telescope’s Detector Did Not
In 2011, the 0.8-meter telescope at the Sierra Nevada Observatory in southern Spain began a survey of faint galaxies in the Coma cluster. The instrument, a 4K-by-4K CCD with a pixel scale of 0.3 arcseconds per pixel, was a workhorse for small observatories. But in 2013, the detector failed. The camera was beyond repair, and the telescope sat idle for months. What did not die was the image stacking pipeline built for that detector. It kept running, processing frames from a new camera years later. The hardware was disposable; the software turned out to be the instrument.
When the Detector Died, the Data Pipeline Lived
The failure was unremarkable by astronomical standards. A CCD's readout electronics shorted, and the detector could no longer produce usable images. The survey it was running paused, and the team faced a choice: rebuild the camera, or repurpose the code. The pipeline had been written in 2011 by graduate student Elena Torres for that specific detector, with calibration steps hard-coded to its bias, dark, and flat characteristics. It seemed like the kind of code that would be thrown away with the hardware.
Instead, the pipeline survived. A new camera, a 4K-by-4K CCD with a pixel scale of 0.4 arcseconds per pixel, was installed in 2016, and the team adapted the pipeline rather than rewriting it. The changes were modest: a few parameters for pixel scale and readout noise, and the calibration routines were fed new master frames. The core stacking algorithm, which aligned and combined dozens of exposures into a single deep image, remained untouched. That algorithm had been tuned to the old detector's noise profile, but it turned out to be general enough to handle the new one.
The story is not unique. Astronomy has a long tradition of software outliving the instruments it was built for. The 1975 archive-tape audit that made one lab recheck every Fortran run is a similar lesson in provenance and care. But the 2011 pipeline offers a cleaner example because it was not designed for longevity. It was built quickly, for one camera, by a graduate student who later left the field. The code survived because of choices that were almost accidental.
The 2011 Pipeline: Built for a Specific Camera
Elena Torres wrote the pipeline as part of her thesis on galaxy photometry. The telescope was a 0.8-meter reflector, and the survey targeted the Coma cluster, a dense region of galaxies ideal for studying cluster evolution. The calibration steps were tightly coupled to the detector: bias frames were taken at the start of each night, dark frames at a specific temperature, and flat fields from a dome screen. The code assumed these would always be available, and it applied them in a fixed order.
The stacking algorithm was tuned to the detector's noise characteristics. It used a median combine to reject cosmic rays, which are transient bright pixels that appear on individual frames. A median is robust to outliers, so a few cosmic rays would not skew the result. The alignment routine used star centroids, fitting a two-dimensional Gaussian to each detected star to measure its position to sub-pixel accuracy. That precision was necessary because the detector had a slight distortion that varied across the field.
The pipeline also assumed a specific signal-to-noise regime. It was designed for faint targets, where the sky background dominates. The algorithm weighted each frame by its inverse variance, giving more weight to exposures with lower noise. This is a standard technique, but the implementation was hard-coded to the detector's gain and readout noise, which were measured in 2011 and never updated.
When Torres finished her thesis and left the field, the code remained in the observatory's version control repository. It was documented in a single README file, with comments in the source that explained the calibration order. No one else had touched it, but the documentation was enough for a later postdoc to understand what each function did. The pipeline was not elegant, but it was transparent.
How Stacking Turns Many Weak Frames into One Strong Image
Image stacking is the workhorse of deep-sky astronomy. A single exposure of a faint galaxy might have a signal-to-noise ratio of only 2, meaning the signal is twice the noise, barely detectable. By combining 10 to 20 exposures of the same field, the signal adds linearly while the noise adds in quadrature. The signal-to-noise ratio improves roughly as the square root of the number of frames, so 16 exposures give a factor of 4 improvement, bringing the galaxy to a signal-to-noise of 8, which is enough for photometry.
The 2011 pipeline used a median combine for most targets. For each pixel, the median of the values across all aligned frames is taken. This rejects cosmic rays, which appear on only one frame, and also suppresses satellite trails or other transient artifacts. The median is less efficient than the mean in terms of signal-to-noise, but it is far more robust. For a survey that might have a few bad pixels on each frame, the median is the safer choice.
Alignment is the critical step. The pipeline detected stars on each frame and matched them against a reference catalog, usually from the USNO or Gaia. It fit a polynomial transformation to map each frame onto a common coordinate system. The precision of this alignment determines how well the pixels add up. If the frames are misaligned by even a tenth of a pixel, the point spread function will be smeared, degrading the resolution.
The output of the stacking step was a single FITS file with the combined image and a weight map. That product fed directly into the survey's photometry pipeline, which measured the brightness of every object in the field. The photometry pipeline was also written in 2011 and had its own quirks, but it was not part of the stacking pipeline. The two were kept separate, which made it easier to replace one without breaking the other.
Reusing the Pipeline on a New Detector
When the new camera arrived in 2016, it had a different pixel scale: 0.4 arcseconds per pixel, and a slightly larger field of view. The readout noise was lower, and the gain was higher. The calibration steps had to be re-run, but the structure of the pipeline was unchanged. The bias, dark, and flat frames were still taken in the same order, and the code that applied them did not need to be rewritten.
The alignment routine required one adjustment. The polynomial transformation had been fitted with a degree of 2, which was sufficient for the old detector's distortion. The new detector had a different distortion pattern, so postdoc Pablo Ruiz increased the degree to 3. This was a small change, but it mattered. The stacking parameters, such as the rejection algorithm and the weighting scheme, remained valid because they were not tied to any specific detector.
The pipeline saved months of development time. Ruiz estimated that writing a new pipeline from scratch would have taken at least six months, given the need to test and validate. Instead, the adaptation took about two weeks. The core algorithm, which had been debugged and validated on thousands of frames, was trusted. The only new code was for reading the new camera's FITS headers, which had a different keyword for the exposure time.
The reuse was not without friction. The new camera had a higher dark current, so the dark frames needed longer exposures to match. The pipeline had a hard-coded assumption that dark frames were taken at the same temperature as the science frames, which was still true, but the exposure time had to be changed. Ruiz also discovered that the new camera had a few hot pixels that the old one did not, and the median combine handled them well, but the flat fielding had to be redone with a new set of dome flats.
What the Survival of the Pipeline Teaches Us
The most obvious lesson is the separation of algorithm from hardware. The stacking algorithm, which is a mathematical procedure, should not be entangled with the specifics of any one detector. The 2011 pipeline achieved this separation by accident, but it is a principle that can be applied deliberately. Write the algorithm to operate on a generic data structure, and keep the calibration details in configuration files or separate modules.
Well-documented metadata mattered. The README file, the comments in the source, and the naming conventions made it possible for a new person to understand the code after years of neglect. Without that documentation, the pipeline would have been a black box, and Ruiz would have been forced to reverse-engineer it or start over. The documentation was not extensive, but it was sufficient.
Version control preserved provenance. The repository recorded every change, from the initial commit in 2011 to the adaptation in 2016. This allowed Ruiz to see what had been modified and why. It also provided a way to reproduce the original results, which was important for validating the new pipeline. The community could trust the outputs because the history was transparent.
Community trust in validated outputs is not automatic. The pipeline had been used to produce a catalog of galaxy photometry that was published in a peer-reviewed paper. That catalog was cited by other studies, so the pipeline had a track record. When the new camera was installed, the observatory could point to the existing results as evidence that the pipeline worked. This is a form of validation that cannot be replaced by unit tests alone.
Methodology outlasts any single instrument. The telescope, the CCD, and the graduate student are gone, but the algorithm for combining images is still in use. This is a common pattern in science: the methods are more durable than the tools. The 2011 pipeline is a reminder that software can be a scientific instrument in its own right, and that building it well is a form of scientific contribution.
Practical Lessons for Building Durable Science Software
The first lesson is to write for generality, not just for one camera. Use abstract data types for images and metadata, and avoid hard-coding pixel scales or noise values. In the 2011 pipeline, the pixel scale was hard-coded in the calibration module, which had to be changed for the new camera. If it had been in a configuration file, the change would have been trivial. But the algorithm itself was generic, so the adaptation was still manageable.
Keep calibration logic data-driven. Instead of embedding the order of bias, dark, and flat corrections in the code, define it in a table or a list. The 2011 pipeline had a fixed order, but the new camera did not require a different order, so it was fine. However, when Ruiz had to adjust the dark frame exposure time, he had to edit the code to change the default. A configuration file would have made that simpler.
Document assumptions explicitly. The 2011 pipeline assumed that dark frames were taken at the same temperature as science frames, and that the detector was linear. These assumptions were written in comments, which helped Ruiz know what to check when adapting the code. Without them, he might have assumed the pipeline would work under different conditions.
Test with simulated inputs. The pipeline had been tested with real data, but not with synthetic images. Simulated frames with known noise and alignment offsets can reveal bugs that only appear under controlled conditions. Ruiz created a set of simulated frames to test the alignment and stacking routines, which caught a bug in the polynomial fitting that had been latent for years. This is a practice that should be standard from the start.
Plan for hardware obsolescence. This is the hardest lesson, because it is impossible to predict what will fail. But the 2011 pipeline survived because it was modular, documented, and versioned. Those three qualities are more important than any specific design choice. A pipeline that is modular can be adapted, documented can be understood, and versioned can be trusted.
The 2011 pipeline is not a perfect example of software engineering. It was written by a graduate student under time pressure, and it has its share of code smells. But it worked, and it kept working. That is the standard that matters in observational astronomy. The detector failed, but the pipeline did not. As the observatory looks toward future instruments, the lesson is clear: the instrument is not the camera, but the code that turns raw photons into science.