Source detection over injected DP1 difference images

Dears,

As mentioned in a previous topic, we are working on a pipeline for searching for optical counterparts to high-energy transients.

Because image subtraction is not easily achieved with DP1 data, we have been injecting sources directly into visit and difference images fetched by the butler, following a suggestion by @MelissaGraham Unfortunately, lsst.ip.diffim.DetectAndMeasureTask requires a template image to run, in addition to the science and difference images. With DP0.2, these templates were provided visit-by-visit through the goodSeeingDiff_templateExp dataset. DP1 provides no direct analogue for this dataset, and warping existing coadds into a new template has proven difficult before.

We found that DetectAndMeasureTask completes without problems when the same visit is used for both the science and template parameters of DetectAndMeasureTask.run. Below is a sketch of the code we are using to detect and measure sources on a DP1 difference image:

from lsst.ip.diffim.detectAndMeasure import DetectAndMeasureTask, DetectAndMeasureConfig

visit = fetch_visit(..)
difference = fetch_difference(..)
visit_injected = inject_exposure(visit)
difference_injected = inject_exposure(difference)
config: DetectAndMeasureConfig = custom_configuration() 

results = DetectAndMeasureTask(config=config).run(
    visit_injected,
    visit_injected,  # here we would have a coadd template
    diff_injected
)

I have a few questions:

  1. Why does DetectAndMeasureTask require both the science and template images to run, in addition to the difference image?
  2. What consequences should we expect from calling DetectAndMeasureTask.run with both the template and science parameters set to the same visit image? What benefits would we gain from calling the method with a proper coadd template instead?
  3. Is our approach reasonable? What are the best practices for measuring sources in DP1 difference images? Is anyone else doing this, and if so, how are you approaching it?

As always, thank you!

Hi Giuseppe,

The science and template images are used for measurements of sources that get classified as dipoles. For dipoles, we measure the source on the science and the template image to compute the position, separation, and direction, for example. These measurements will be incorrect if the same image is used for both the science and template. However, you have enough to make it work: you can subtract the difference image from the science to get something useable as the template. The difference is that it will be the template convolved to match the science image, but that should be OK for the dipole measurements. The variance plane will also be higher than it would be for the real template, but again that will only affect the dipole measurements slightly and should not affect the majority that are made on the difference image.

@isullivan Ian, thank you a lot for you clear reply and pointers! I should have thought about reconstructing the template from the difference and science :sweat_smile:. Will follow this suggestion from now on. Bests!