# Mask disappears after running detectCoaddSources.py

**URL:** <https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017>\
**Category:** Support\
**Created:** [July 5, 2018, 12:30pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017 "2018-07-05T12:30:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcoupon](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jcoupon/32/642_2.png) [@jcoupon](https://www.rubin.community/u/jcoupon)\
**Post date:** [July 5, 2018, 12:30pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/1 "2018-07-05T12:30:41Z")

</div>

Hi all,

I know that normally detectCoaddSources.py is run as part of coaddDriver.py, but I need to run after emulating an external image and before running the multi band process.

The problem is that after running detectCoaddSources.py on a coadd, the mask in the resulting calexp image is gone (all set to 0), even for a coadd created by the pipeline itself. Here is how I run it:

`detectCoaddSources.py $ROOTDIR --rerun=$RERUN --id tract=$TRACT patch=$PATCH filter=$FILTER`

---

<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:** [July 6, 2018, 12:18pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/2 "2018-07-06T12:18:24Z")

</div>

The only code I see to clear masks as part of `detectCoaddSources.py` is in `SourceDetectionTask`, and that only clears the `DETECTED` and `DETECTED_NEGATIVE` planes.

To run `detectCoaddSources.py` stand-alone, you should be creating a `deepCoadd` dataset to feed to it (not `deepCoadd_calexp`, which is an _output_ of `detectCoaddSources.py`). Is that what you’re doing?

---

<div class="post-metadata">

**Author:** ![jcoupon](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jcoupon/32/642_2.png) [@jcoupon](https://www.rubin.community/u/jcoupon)\
**Post date:** [July 6, 2018, 1:13pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/3 "2018-07-06T13:13:58Z")

</div>

Something weird is that when I use the `afw Display` tools to look at the image, the mask appears fine. It is only when opening the image HDU #2 with ds9 (the latest version) that the mask is zero everywhere.

(I do run `detectCoaddSources.py` from `deepCoadd`).

---

<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:** [July 6, 2018, 1:34pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/4 "2018-07-06T13:34:00Z")

</div>

Ah, that’s a known bug in ds9 support for the kind of compression we’re now using by default on our images. I believe it’s fixed in the very latest version of ds9 (but most testing has been done on OS X; I don’t know if we ever confirmed that the latest ds9 works on Linux).

---

<div class="post-metadata">

**Author:** ![jcoupon](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jcoupon/32/642_2.png) [@jcoupon](https://www.rubin.community/u/jcoupon)\
**Post date:** [July 6, 2018, 2:01pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/5 "2018-07-06T14:01:35Z")

</div>

It might be related but I don’t think it’s the explanation because 1) I do use the latest version (as I wrote previously) and 2) when I open the corresponding calexp exposure that was made by the pipeline (I assume from the run of `coaddriver.py`) I see the mask with this version of ds9.

But, try it yourself, run `detectCoaddSources.py` on a `x,x.fits` image and open the mask with ds9 on a system you’re sure it’s working with calexp images

---

<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:** [July 6, 2018, 2:31pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/6 "2018-07-06T14:31:05Z")

</div>

Ok, that is quite strange. When the mask appeared successfully with afwDisplay, was that before your code wrote it out, or was it after writing it out and reading it back in?

---

<div class="post-metadata">

**Author:** ![jcoupon](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jcoupon/32/642_2.png) [@jcoupon](https://www.rubin.community/u/jcoupon)\
**Post date:** [July 6, 2018, 2:56pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/7 "2018-07-06T14:56:20Z")

</div>

In fact the issue is not linked at all to my emulate code. The problem occurs even if I use a pipeline-produced fits image and run `detectCoaddSources.py` on it.

---

<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:** [July 6, 2018, 8:14pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/8 "2018-07-06T20:14:59Z")

</div>

It seems I can’t even get a ds9 (7.6, built for Ubuntu 17, running on Ubuntu 18.04) that will display the mask of a `deepCoadd_calexp` written by the main pipeline, if loaded directly via `ds9 -multiframe`, and I’ve confirmed that the image I’m testing does have nonzero mask values if I load it with afw. I can, however, use the same version of ds9 to read the mask of a non-coadd `calexp` (i.e. from the `CORR` directory)

That’s frustrating, but it’s also pretty clear that it’s a ds9 bug, not one of ours, though I don’t know why one kind of image works while the other doesn’t (maybe @price does?). What’s more confusing about your case is that I _think_ you’re seeing both success and failure with different instances `deepCoadd_calexp` (unless you meant "non-coadd `calexp`" above) - is there any chance the original one that does work was produced by an older version of the pipeline?

---

<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:** [July 6, 2018, 11:26pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/9 "2018-07-06T23:26:23Z")

</div>

There was a bug in cfitsio that affected reading compressed masks. Maybe that got into your ds9 build?

Can you try [the latest beta release](http://ds9.si.edu/site/Beta.html)?

---

<div class="post-metadata">

**Author:** ![jcoupon](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jcoupon/32/642_2.png) [@jcoupon](https://www.rubin.community/u/jcoupon)\
**Post date:** [July 7, 2018, 10:59pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/10 "2018-07-07T22:59:15Z")

</div>

Hi both, three things:

- following the request from Jim I tried to run `detectCoaddSources.py` with the same version of the pipeline that created the “working” (with ds9) `deepCoadd_calexp`, hscPipe 6.5.1. -\> Same problem (ds9 does not show the mask)
- I open the “failed” - made with `detectCoaddSources.py` - `deepCoadd_calexp` with astropy and confirmed that the mask is working well and has non zero values (as `afwDisplay` tests suggested)
- (a side note) the pipeline-installed astropy version does not support compressed image (did the test of the point above outside of the hscPipe environment). You may want to update astropy in future versions

The bottom line is: it’s indeed a ds9 bug, but not the one you suspected and that was already reported before (although probably related) , since I can read `deepCoadd_calexp` with the latest ds9 version.

It is still weird that it only happens when I run `detectCoaddSources.py` on my machine. The only test I can suggest to you is to try on your machines first to confirm, and then we file a bug report to ds9 developers.

---

<div class="post-metadata">

**Author:** ![isullivan](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/isullivan/32/1866_2.png) [@isullivan](https://www.rubin.community/u/isullivan)\
**Post date:** [August 24, 2018, 6:21pm UTC](https://www.rubin.community/t/mask-disappears-after-running-detectcoaddsources-py/3017/11 "2018-08-24T18:21:31Z")

</div>

I’m a bit late to this topic, but I was having this bug on my mac using ds9 version 7.6b4. The problem was fixed for me when I upgraded ds9 to v7.6
