Skip to content

Conversation

@isullivan
Copy link
Contributor

Adds a new subtask to calibrateImage that masks regions containing diffraction spikes near bright stars drawn from the photometric reference catalog.

@isullivan isullivan force-pushed the tickets/DM-52541 branch 4 times, most recently from 52035ea to aeef4a3 Compare October 22, 2025 18:07
@isullivan isullivan changed the title DM-52541: Add new BRIGHT mask plane DM-52541: Add new SPIKE mask plane Oct 22, 2025
)
doMaskDiffractionSpikes = pexConfig.Field(
dtype=bool,
default=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense to default to True? Do we need an override then in all non-LSSTCam obs packages to turn this off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These settings are correct for ComCam as well, and the task is useful for HSC and DECam. Those instruments ideally would have tweaked magSlope and magOffset parameters, but the task should be run for them.

dtype=float,
default=60.,
doc="Margin outside the exposure bounding box to include bright "
"sources. In arcseconds.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these the quotes should line with quotes.

default="phot_g_mean",
doc="Fallback flux field in the reference catalog to use for sources"
" that don't have measurements in the science image's band."
"The default uses Gaia g-band.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's what this config means. Also don't put the default in the doc string! Also also it's Gaia G not gaia g.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the code below, I guess that's what this is doing ... even though that's not what this config means in other contexts. I would recommend renaming this config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to fallbackFluxField to remove the false similarity to other contexts.

default=10,
doc="Ratio of the length of a diffraction spike to it's width in the"
" core of the star.",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any of these vary per band? Is that something that may be added in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bruno's analysis did not show a dependence on band, so we decided to keep this simple for now. I would like to update the calculations to be based on counts in the future, so that it would properly scale with exposure time.

Returns
-------
brightCat : `lsst.afw.table.SourceCatalog`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> spikeCat

Returns
-------
brightCat : `lsst.afw.table.SourceCatalog`
The entries from the reference catalog selected as bright stars.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> stars with diffraction spikes.

-------
brightCat : `lsst.afw.table.SourceCatalog`
The entries from the reference catalog selected as bright stars.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to check if self.refObjLoader is not None and specifically raise otherwise (must be initialized or set...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a check, but it was not the first line. I'll move it up so the check runs before any other code.

self.config.magnitudeThreshold)
self.maskSources(xvals, yvals, radii[bright], mask)
else:
self.log.info("No bright stars found in the reference catalog; not masking bright sources.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bright -> spike here. Maybe not everywhere, but at least "no masking diffraction spikes"

radii = [10**(self.config.magSlope*magnitude + self.config.magOffset) for magnitude in magnitudes]
return np.array(radii)

def extractMagnitudes(self, refCat, filterLabel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate that this code needs to be duplicated from elsewhere, but I'm not sure what else to do.

nBright = np.count_nonzero(bright)

mask = exposure.mask
mask.addMaskPlane(self.config.spikeMask)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only run if it's on, right? If this is off do other tasks downstream crash (e.g. in the detectAndMeasure with HSC). Or do we trust that this should be the default for everyone? That seems ... surprising.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downstream tasks should currently be fine whether this task is run or not, and the SPIKE mask is only added if it is.

dtype=float,
default=15,
doc="Threshold magnitude for treating a star from the reference catalog"
" as bright.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format here

@isullivan isullivan force-pushed the tickets/DM-52541 branch 2 times, most recently from 39ad916 to 28ccb3d Compare October 23, 2025 03:55
@isullivan isullivan force-pushed the tickets/DM-52541 branch 2 times, most recently from 2e71603 to c2ad7d1 Compare October 23, 2025 22:16
Bright sources off the image will also have diffraction spikes calculated and masked if they overlap the image.
@isullivan isullivan merged commit 5a60e81 into main Oct 24, 2025
4 checks passed
@isullivan isullivan deleted the tickets/DM-52541 branch October 24, 2025 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants