Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-24371

Implement fixed correction fixed PSF support decorrelation afterburner

    Details

    • Type: Story
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: ip_diffim, pipe_tasks
    • Labels:
      None
    • Story Points:
      20
    • Epic Link:
    • Sprint:
      AP S20-6 (May)
    • Team:
      Alert Production
    • Urgent?:
      No

      Description

      This is the first code piece in the decorrelation afterburner rewrite.

      For helping the review, the whitening concept and the whitening kernel are demonstrated in DM-24316.

       

        Attachments

          Issue Links

            Activity

            Hide
            swinbank John Swinbank added a comment -

            Hey Gabor — could you please add a story point estimate when you get a moment? Thanks!

            Show
            swinbank John Swinbank added a comment - Hey Gabor — could you please add a story point estimate when you get a moment? Thanks!
            Hide
            gkovacs Gabor Kovacs added a comment -

            John Swinbank : "Moved" 20 points from the parent issue.

            Show
            gkovacs Gabor Kovacs added a comment - John Swinbank : "Moved" 20 points from the parent issue.
            Hide
            sullivan Ian Sullivan added a comment -

            The notebook looks great, and suggests that the new code is calculating the decorrelation correctly. Please see the additional comments on the pull requests.

            Show
            sullivan Ian Sullivan added a comment - The notebook looks great, and suggests that the new code is calculating the decorrelation correctly. Please see the additional comments on the pull requests.
            Hide
            gkovacs Gabor Kovacs added a comment - - edited

            Some points to note here copy pasted from my github response:

            When you return a Struct with only one element, you should think about whether you really want the Struct at all.

            This is a result of dropping the correction kernel from the return. I am not 100% sure that we don't want to return any additional information; I'll postpone the removal of the Struct for the spatially varying correction implementation DM-23857. Added TODO comment to the task description and to the return statement.
            Considerations: It'd be logical to return something about the correction kernel itself, but...

            • returning the Fourier space correction needs the freqSpaceShape and may not suit for any outside operation.
            • Returning the image space correction (full image size) needs one additional, otherwise unnecessary, IFT. Also where the origin is placed would need detailed description or additional, otherwise unnecessary, copying (re-centering) of the array.
            • If a matchingKernel size cropped version is returned then we throw away the main lesson from this whole change i.e. that the correction can be larger than the original matching kernel in general so should not be used.

            Please add a comment describing why 1e8 was chosen. Also, since this is only a warning, you might want to consider lowering the threshold. Finally, I'm a bit surprised by this check: isn't the template variance usually smaller than the science image, rather than the other way around?

            As the matching kernel high frequency components go to zero, the correction factor converges to sqrt(tvar/svar) i.e. this is a warning when high frequency pixels of the difference image is multiplied by more than 4 orders of magnitude as correction. Yes, in the regular case, the template variance is the smaller one and this is no concern; tvar>svar can happen if we convolve the science image thus the arguments are swapped for this task.
            I don't have a really good justification for the value itself at the moment, just wanted an indicator to watch for diverging solutions. We won't coadd ~1e8 images, so I don't expect that any realistic coadd variance will be this small (i.e. this large when swapped in science exposure convolution mode) but this scaling is still acceptable at double precision (I mean assuming within one Fourier space image to have order ~1. values at low frequency and ~1e4 values at high frequencies and having ~1e7 pixels still fits in the double precision conveniently for any calculation/transformation. )


            Re taking the real part in DecorrelateALKernelTask.computeCorrection:

            kft2 and mk2 (below) should both be real based on their calculation, but I suspect they will still be stored as complex. I think you want to explicitly take the real part of both to force them to be used as floats.

            My original consideration here was that converting them to real then back to complex when applying the returned correction may take more time. But this is not the case, np.real creates a view and taking the sqrt of reals is much faster.

             

            See lsst-dm/diffimTests : tickets/DM-24371_decorr_afterburner_tests/DM-24371_real_complex_conversion_timing.ipynb

            Show
            gkovacs Gabor Kovacs added a comment - - edited Some points to note here copy pasted from my github response: When you return a Struct with only one element, you should think about whether you really want the Struct at all. This is a result of dropping the correction kernel from the return. I am not 100% sure that we don't want to return any additional information; I'll postpone the removal of the Struct for the spatially varying correction implementation DM-23857 . Added TODO comment to the task description and to the return statement. Considerations: It'd be logical to return something about the correction kernel itself, but... returning the Fourier space correction needs the freqSpaceShape and may not suit for any outside operation. Returning the image space correction (full image size) needs one additional, otherwise unnecessary, IFT. Also where the origin is placed would need detailed description or additional, otherwise unnecessary, copying (re-centering) of the array. If a matchingKernel size cropped version is returned then we throw away the main lesson from this whole change i.e. that the correction can be larger than the original matching kernel in general so should not be used. Please add a comment describing why 1e8 was chosen. Also, since this is only a warning, you might want to consider lowering the threshold. Finally, I'm a bit surprised by this check: isn't the template variance usually smaller than the science image, rather than the other way around? As the matching kernel high frequency components go to zero, the correction factor converges to sqrt(tvar/svar) i.e. this is a warning when high frequency pixels of the difference image is multiplied by more than 4 orders of magnitude as correction. Yes, in the regular case, the template variance is the smaller one and this is no concern; tvar>svar can happen if we convolve the science image thus the arguments are swapped for this task . I don't have a really good justification for the value itself at the moment, just wanted an indicator to watch for diverging solutions. We won't coadd ~1e8 images, so I don't expect that any realistic coadd variance will be this small (i.e. this large when swapped in science exposure convolution mode) but this scaling is still acceptable at double precision (I mean assuming within one Fourier space image to have order ~1. values at low frequency and ~1e4 values at high frequencies and having ~1e7 pixels still fits in the double precision conveniently for any calculation/transformation. ) Re taking the real part in DecorrelateALKernelTask.computeCorrection: kft2 and mk2 (below) should both be real based on their calculation, but I suspect they will still be stored as complex. I think you want to explicitly take the real part of both to force them to be used as floats. My original consideration here was that converting them to real then back to complex when applying the returned correction may take more time. But this is not the case, np.real creates a view and taking the sqrt of reals is much faster.   See lsst-dm/diffimTests : tickets/DM-24371_decorr_afterburner_tests/DM-24371_real_complex_conversion_timing.ipynb
            Hide
            gkovacs Gabor Kovacs added a comment - - edited

            Re in-place modification, computeCorrectedDiffimPsf actually did not do in-place modification but this was indeed a bug in computeCorrectedImage. Added making of a copy internally; we can remove it later if this becomes a performance bottleneck. Thanks Ian Sullivan for spotting this!

            Show
            gkovacs Gabor Kovacs added a comment - - edited Re in-place modification, computeCorrectedDiffimPsf actually did not do in-place modification but this was indeed a bug in computeCorrectedImage . Added making of a copy internally; we can remove it later if this becomes a performance bottleneck. Thanks Ian Sullivan for spotting this!
            Hide
            sullivan Ian Sullivan added a comment -

            If you haven't already, can you file a bug ticket describing the problem in computeCorrectedImage?

            Show
            sullivan Ian Sullivan added a comment - If you haven't already, can you file a bug ticket describing the problem in computeCorrectedImage ?

              People

              • Assignee:
                gkovacs Gabor Kovacs
                Reporter:
                gkovacs Gabor Kovacs
                Reviewers:
                Ian Sullivan
                Watchers:
                Gabor Kovacs, Ian Sullivan, John Swinbank
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel