Skip to content

Conversation

@isullivan
Copy link
Contributor

This moves the final steps of kernel source selection from the makeKernel subtask to the _sourceSelector method of subtractImages, which allows for earlier and cleaner error handling when there are too few kernel candidates. It also allows some of the duplicated methods from the different flavors of image subtraction to be removed, since they can now directly use the methods of the base class.

Copy link
Member

@BrunoSanchez BrunoSanchez left a comment

Choose a reason for hiding this comment

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

I think I understand the changes and they improve the flow of the kernel source selection.
I asked two questions just for my better understanding but they shouldn't be a blocker on merging the code, specially if tests pass just fine.

Comment on lines 446 to 447
kernelResult = self.runMakeKernel(template, science, kernelSources,
convolveTemplate=convolveTemplate)
Copy link
Member

Choose a reason for hiding this comment

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

I have a question: here self.runMakeKernel is attempting to run the self.makeKernel.run and if it fails it checks for the same checkTemplateIsSufficient.
I see here a nested logic that is basically adding complexity but it repeats itself? I don't quite follow why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! The duplication of error handling is unnecessary. I can rearrange the new code a little to remove it, and the run method will be simpler and cleaner.

# get the img psf Noise Equivalent Area value
nea = computePSFNoiseEquivalentArea(science.psf)
self.assertFloatsAlmostEqual(stdVal, np.sqrt(2)*noiseLevel/np.sqrt(nea), rtol=0.1)
self.assertFloatsAlmostEqual(stdVal, np.sqrt(2)*noiseLevel/np.sqrt(nea), rtol=0.2)
Copy link
Member

Choose a reason for hiding this comment

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

Why is the relative tolerance now needing an adjustment? I wonder if the PSF now is less exact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that slightly more pixels are excluded near the edge during preconvolution, which I think is appropriate. That means that the background model that is calculated as part of the kernel fit is slightly different, but I think that is OK since we don't use this background model anyway - the real background subtraction is in detectAndMeasure. The change is not as large as my commit made it seem, I will reduce the tolerance to a value closer to the original.

This also prepares the selected sources to calculate the kernel by adding consistent footprints to each source.
@isullivan isullivan merged commit cdda8b9 into main Oct 3, 2025
5 checks passed
@isullivan isullivan deleted the tickets/DM-52599 branch October 3, 2025 15:30
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.

2 participants