Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-12943: Add utilities for detection when noise is correlated. #96

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TallJimbo
Copy link
Member

No description provided.

if ((*mi.getMask())(x1, y1) & badBitMask) {
continue;
}
float z = (*mi.getImage())(x1, y1) / (*mi.getVariance())(x1, y1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to subtract the mean here and below from the image values?

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking was that because this should only be running noise pixels, we could assume the mean was zero. I suppose I should at least add a comment noting that we should check that assumption if we ever use this code in a pipeline setting.

Copy link
Contributor

Choose a reason for hiding this comment

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

I found that there were many regions where this was not the case in the HSC wide data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course, they may just get filtered out when taking the median over a tract.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just started thinking about fixing this, and I realized that I don't understand what you're proposing - the "mean" we need to subtract is a correction to the background estimate, right? How do we estimate that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, depending on how large the image is the background estimate may be off. Can't you just compute the mean of the image and subtract that off?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, if you think just subtracting off the image mean would be an improvement (I was imagining something more local), that's definitely something I can do.

if (miIter.mask() & badBitMask) {
continue;
}
*outIter += z*miIter.image();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you dividing the variance value from only the first pixel? Shouldn't be something like sqrt(var(x1,y1))*sqrt(var(x2,y2))?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you're right - I was originally thinking of this as part of the stationarity assumption, but I don't need to assume the variance is stationary to assume that the correlations are.

class CorrelatedNoiseDetectionTestCase(lsst.utils.tests.TestCase):
"""Test utilities for dealing with correlated noise when running detection."""

def testMeasureCorrelatationKernel(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Your test here doesn't use correlated values. I'm wondering if this is a useful test? I could imagine getting the correlation values correct for this simple case, but missing a bug that would get the correlation wrong when there actually is correlation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, this was just laziness, because I didn't want to work out how to add correlated stationary noise with NumPy. If you happen to have a recipe for that on hand, I'd love to have it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I gave this a shot, and unfortunately the naive way to do it with NumPy (constructing a full covariance matrix) is totally impractical - if we want enough pixels in the noise image to be able to estimate the kernel, the covariance matrix is too big to even allocate. I could imagine working around that with sparse matrices, and I'm sure there's a way to do this with an FFT, but at this point it's not looking like it's worth the effort.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, FFT is the way to go. I could potentially give this a shot today. It is conceptually simple, but it always takes me a while to get all the factors correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

That'd be great. I'm not in any hurry to merge this, so please don't feel like you need to get it done today.

Would it make sense to just make that a separate ticket (maybe to add more reusable functionality to afw::math::Random), and block the merge of this ticket on that one?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that sounds like a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

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