# What's a good way of debugging poor PSF estimation

**URL:** <https://www.rubin.community/t/whats-a-good-way-of-debugging-poor-psf-estimation/1023>\
**Category:** Support\
**Tags:** psf, cosmicray\
**Created:** [August 12, 2016, 5:28pm UTC](https://www.rubin.community/t/whats-a-good-way-of-debugging-poor-psf-estimation/1023 "2016-08-12T17:28:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwv](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mwv](https://www.rubin.community/u/mwv)\
**Post date:** [August 12, 2016, 5:28pm UTC](https://www.rubin.community/t/whats-a-good-way-of-debugging-poor-psf-estimation/1023/1 "2016-08-12T17:28:30Z")

</div>

The image processing, and particularly the key first step of CR rejection, relies on a rough estimate of the PSF. This step often can go wrong and is confusing for new users. What’s a good way of debugging the PSF estimation stage?

---

<div class="post-metadata">

**Author:** ![rowen](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/rowen/32/52_2.png) [@rowen](https://www.rubin.community/u/rowen)\
**Post date:** [August 12, 2016, 5:46pm UTC](https://www.rubin.community/t/whats-a-good-way-of-debugging-poor-psf-estimation/1023/2 "2016-08-12T17:46:24Z")

</div>

To what extent have you observed that this is a problem? The PSF estimation should not be very sensitive to the initial estimate (this was improved in the recent rewrite of ProcessCcdTask). If further improvements are indeed needed, some data showing the problem would be very useful (e.g. images and some idea of what initial PSF worked and did not work).

---

<div class="post-metadata">

**Author:** ![price](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/price/32/488_2.png) [@price](https://www.rubin.community/u/price)\
**Post date:** [August 12, 2016, 6:54pm UTC](https://www.rubin.community/t/whats-a-good-way-of-debugging-poor-psf-estimation/1023/3 "2016-08-12T18:54:37Z")

</div>

Put the following in a file called `debug.py` somewhere on your `PYTHONPATH`, and run your `CmdLineTask` with the `--debug` command-line option. This should result in images and plots being displayed as you go through.

```
try:
    import lsstDebug

    print "Importing debug settings..."
    def DebugInfo(name):
        di = lsstDebug.getInfo(name) # N.b. lsstDebug.Info(name) would call us recursively
        if name in (
# "lsst.meas.algorithms.secondMomentStarSelector",
# "lsst.meas.algorithms.pcaPsfDeterminer",
            "lsst.meas.extensions.psfex.psfexPsfDeterminer",
            ):
            di.display = True
            di.displayExposure = True
            di.displayPsfCandidates = True
            di.displayIterations = True
            di.displayPsfComponents = True
            di.displayPsfMosaic = True
            di.displayPsfSpatialModel = True
            di.matchKernelAmplitudes = False
            di.keepMatplotlibPlots = True
            di.showBadCandidates = True
            di.normaliseResiduals = True
            di.pause = True
        elif name in (
            "lsst.meas.algorithms.objectSizeStarSelector"
            ):
            di.display = True
            di.displayExposure = True
            di.plotMagSize = True
        return di

    lsstDebug.Info = DebugInfo

except ImportError:
    print >> sys.stderr, "Unable to import lsstDebug; not setting display intelligently"
```

---

<div class="post-metadata">

**Author:** ![jbosch](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jbosch/32/12_2.png) [@jbosch](https://www.rubin.community/u/jbosch)\
**Post date:** [August 18, 2016, 8:24pm UTC](https://www.rubin.community/t/whats-a-good-way-of-debugging-poor-psf-estimation/1023/4 "2016-08-18T20:24:34Z")

</div>

As a follow up: if you want to use this functionality elsewhere, or you’re not running a `CmdLineTask`, there’s more documentation on this debug mechanism here:

[https://lsst-web.ncsa.illinois.edu/doxygen/x\_masterDoxyDoc/base\_debug.html](https://lsst-web.ncsa.illinois.edu/doxygen/x_masterDoxyDoc/base_debug.html)
