Include fakes on non-masked/flaged positions

Hello,
I want to add fakes to exposures with random positions, is there a way to be sure that the fakes will not be placed on some masked/flagged regions?
How can I exclude all flag/masked regions in a patch, and so help the fakes to be placed in non flagged regions?
Thank you in advance

As far as I know, the pipeline uses a MultilevelParquetTable of sources (the deepCoadd_fakeSourceCat dataset) as the basis for inserting fake sources, but does not include code to generate that catalog. That means that you can add fakes wherever you want, with whatever characteristics you want.

I use some custom code, ingestFakeStars.py, to convert a colleague’s FITS file (with RA, Dec, gMag, rMag, iMag columns) to the appropriate format and put it in the right place. Perhaps you can adapt it to your needs (sorry for the lack of documentation!).

1 Like

Currently there isn’t. The way to do it at the moment would be for you to look at the image and pick the positions that you want to add fakes at. Then stick those locations into your input catalogue. Then you can choose which mask planes you want to avoid and which ones you don’t care about. If this is a popular request we could see how easy it would be to implement but I suspect that people will have to wide a range of opinions about what criteria they care about to make it easy to add.

1 Like

Hello @price, thank you for your answer. Yes indeed I include fakes around positions of galaxies of the coadd catalog (excluding psffluxFalg, Pixelflux_flag), but then some of my fakes are placed in some flagged regions. Thank you for your code, I will adapt it for what I need! Thank you

Thank you @sophiereed. Yes, in addition to the galaxy positions that I am looking for, I should look to the fakes positions before including them. Thank you

In the old version of synpipe, I converted the mask plane to avoid into a collection of polygon shapes and filter the input fake catalogs through it.

I extract different mask planes for each Patch, then use the find_contours and approximate_polygon functions from skimage.measure to convert these masked regions into multiple polygon shapes. After converting the coordinates into (RA, Dec) using the WCS, you can save it as ds9 region files and use the venice tool developed by Jean Coupon to filter coordinate or you can use a package like Shapely to handle it. You can eventually combine these polygons from all the Patch or Tract you want to test.

This is a clumpy method relying on a lot of stuff outside lsstPipe, and you have to do this Patch by Patch. But it is also quite flexible. I use this method to make sure my fake objects don’t overlap any bad pixels or sometimes I actually use it to put fake objects on top of a detection to force a blending scenario.

I have some really old code to do this here. It was for the original synpipe and works only for hscPipe v4, but the scikit-image and shapely parts should be the same.

I wish there are better ways to do this as it is quite useful for serious mock tests. If you find it, please let me know! :slightly_smiling_face: