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

ap_verify metrics report 0 completeness after switch to Piff

    XMLWordPrintable

    Details

      Description

      The fakes completeness metrics have dropped to zero in all ap_verify runs after DM-33857, for both ap_verify_ci_cosmos_pdr2 and ap_verify_ci_hits2015. Given that we are still detecting sources (though fewer), this may be the result of the completeness metrics making assumptions about catalog schemas and contents that are no longer true.

      Investigate and restore the metrics.

        Attachments

          Issue Links

            Activity

            No builds found.
            krzys Krzysztof Findeisen created issue -
            krzys Krzysztof Findeisen made changes -
            Field Original Value New Value
            Link This issue relates to DM-33857 [ DM-33857 ]
            krzys Krzysztof Findeisen made changes -
            Assignee Krzysztof Findeisen [ krzys ]
            krzys Krzysztof Findeisen made changes -
            Rank Ranked higher
            krzys Krzysztof Findeisen made changes -
            Summary ap_verify reports 0 completeness after switch to Piff ap_verify metrics report 0 completeness after switch to Piff
            sullivan Ian Sullivan made changes -
            Labels ap-analysis
            sullivan Ian Sullivan made changes -
            Assignee Krzysztof Findeisen [ krzys ]
            ebellm Eric Bellm made changes -
            Remote Link This issue links to "Page (Confluence)" [ 32658 ]
            Hide
            ebellm Eric Bellm added a comment - - edited

            Joshua Meyers and I worked on this a bit in pair coding today. A potential source of the problem is that Piff PSF stamps are smaller (21x21 pixels) than PSFEx. insertFakes.py uses a default calibFluxRadius=12.0, and psf.computeApertureFlux will silently return NaN values when the radius is larger than than the stamp size (which is the case now). In turn the inserted fake magnitudes are likely to be NaN, which would explain why the fakes metrics do not find them. A workaround would be to use a ten-pixel radius by default, but we should also add some additional logging.

            Show
            ebellm Eric Bellm added a comment - - edited Joshua Meyers and I worked on this a bit in pair coding today. A potential source of the problem is that Piff PSF stamps are smaller (21x21 pixels) than PSFEx. insertFakes.py uses a default calibFluxRadius=12.0 , and psf.computeApertureFlux will silently return NaN values when the radius is larger than than the stamp size (which is the case now). In turn the inserted fake magnitudes are likely to be NaN, which would explain why the fakes metrics do not find them. A workaround would be to use a ten-pixel radius by default, but we should also add some additional logging.
            ebellm Eric Bellm made changes -
            Watchers Eric Bellm, Ian Sullivan, Krzysztof Findeisen [ Eric Bellm, Ian Sullivan, Krzysztof Findeisen ] Eric Bellm, Ian Sullivan, Joshua Meyers, Krzysztof Findeisen [ Eric Bellm, Ian Sullivan, Joshua Meyers, Krzysztof Findeisen ]
            Hide
            yusra Yusra AlSayyad added a comment - - edited

            Oh my. 21 pixels is so close to being enough. I don't know anything about how PIFF chooses its stamps size. Is there a way we can ask PIFF to use at least 25x25?

            Show
            yusra Yusra AlSayyad added a comment - - edited Oh my. 21 pixels is so close to being enough. I don't know anything about how PIFF chooses its stamps size. Is there a way we can ask PIFF to use at least 25x25?
            Hide
            ebellm Eric Bellm added a comment -

            Is there anything special about calibFluxRadius=12.0? We thought maybe just using 10.0 would be a decent workaround, rather than changing the PIFF stamp sizes.

            Show
            ebellm Eric Bellm added a comment - Is there anything special about calibFluxRadius=12.0 ? We thought maybe just using 10.0 would be a decent workaround, rather than changing the PIFF stamp sizes.
            Hide
            yusra Yusra AlSayyad added a comment -

            Try 10 and see if you get an offset in the input vs output fluxes.  If not, great!

            Some more information:

            Show
            yusra Yusra AlSayyad added a comment - Try 10 and see if you get an offset in the input vs output fluxes.  If not, great! Some more information: What's special about 12 is that it's the aperture used for the CalibFlux:    https://github.com/lsst/meas_base/blob/26961ef6c7a3bd91c4b40a0307c740244fea775e/python/lsst/meas/base/baseMeasurement.py#L103 21 pixels was not motivated by anything and just what shook out with the defaults.  Through experience with the HSC data releases we progressively made the PSF models larger, and we're expecting to have to make the PIFF PSF models larger. 
            Parejkoj John Parejko made changes -
            Link This issue is triggering DM-34531 [ DM-34531 ]
            Parejkoj John Parejko made changes -
            Link This issue is blocked by DM-34531 [ DM-34531 ]
            Hide
            Parejkoj John Parejko added a comment -

            To help with debugging this, I've pushed a change to characterizeImage to make the PSF estimation there fail if sigma is NaN. I think this is behavior we'll want anyway (to prevent NaN psfs from causing failures much further downstream), and I would guess it hasn't been a problem previously because pre-PIFF PSF determiners didn't output NaN PSFs.

            Eric will comment more on better error handling and log messages in PIFF.

            Show
            Parejkoj John Parejko added a comment - To help with debugging this, I've pushed a change to characterizeImage to make the PSF estimation there fail if sigma is NaN. I think this is behavior we'll want anyway (to prevent NaN psfs from causing failures much further downstream), and I would guess it hasn't been a problem previously because pre-PIFF PSF determiners didn't output NaN PSFs. Eric will comment more on better error handling and log messages in PIFF.
            Hide
            Parejkoj John Parejko added a comment -

            The ap_verify_ci_cosmos_pdr2 branch requires DM-34531 of meas_extensions_piff; we'll want that change on each of the ap_verify datasets once we figure out why it causes piff to crash, or we'll want to default that in ap_pipe, or we'll want to default it in piff itself.

            Show
            Parejkoj John Parejko added a comment - The ap_verify_ci_cosmos_pdr2 branch requires DM-34531 of meas_extensions_piff ; we'll want that change on each of the ap_verify datasets once we figure out why it causes piff to crash, or we'll want to default that in ap_pipe, or we'll want to default it in piff itself.
            Hide
            ebellm Eric Bellm added a comment -

            Providing a bit of context for John's comments: We pair-coded on this today for a bit. We reconfigured Piff to use a 25-pixel kernelSize (via DM-34531). Unfortunately this did not resolve the "fake metrics are zero" problem, and in fact the pipeline failed to complete: it fails with the errors below:

            {{ File "/software/lsstsw/stack_20220421/stack/miniconda3-py38_4.9.2-3.0.0/Linux64/meas_algorithms/gf36ae6ace1+1d7ae49801/python/lsst/meas/algorithms/detection.py", line 688, in detectFootprints
            psf = self.getPsf(exposure, sigma=sigma)
            File "/software/lsstsw/stack_20220421/stack/miniconda3-py38_4.9.2-3.0.0/Linux64/meas_algorithms/gf36ae6ace1+1d7ae49801/python/lsst/meas/algorithms/detection.py", line 411, in getPsf
            size = self.calculateKernelSize(sigma)
            File "/software/lsstsw/stack_20220421/stack/miniconda3-py38_4.9.2-3.0.0/Linux64/meas_algorithms/gf36ae6ace1+1d7ae49801/python/lsst/meas/algorithms/detection.py", line 386, in calculateKernelSize
            return (int(sigma * self.config.nSigmaForKernel + 0.5)//2)*2 + 1 # make sure it is odd
            ValueError: cannot convert float NaN to integer}}

            As John mentions, this could have been caught earlier: characterizeImage logs

            lsst.characterizeImage INFO: iter 1; PSF sigma=nan, dimensions=(25, 25); median background=770.85

            so we should notice and catch when the PSF is providing NaNs.

            This is one of several places where the Piff log levels should be adjusted;

            lsst.characterizeImage.measurePsf.psfDeterminer INFO: Ill-conditioned matrix (rcond=2.40177e-26): result may not be accurate. might be more severe than INFO?

            and lsst.characterizeImage.measurePsf.psfDeterminer gives WARN for total chi-squared and the start of each fitting iteration.

            Show
            ebellm Eric Bellm added a comment - Providing a bit of context for John's comments: We pair-coded on this today for a bit. We reconfigured Piff to use a 25-pixel kernelSize (via DM-34531 ). Unfortunately this did not resolve the "fake metrics are zero" problem, and in fact the pipeline failed to complete: it fails with the errors below: {{ File "/software/lsstsw/stack_20220421/stack/miniconda3-py38_4.9.2-3.0.0/Linux64/meas_algorithms/gf36ae6ace1+1d7ae49801/python/lsst/meas/algorithms/detection.py", line 688, in detectFootprints psf = self.getPsf(exposure, sigma=sigma) File "/software/lsstsw/stack_20220421/stack/miniconda3-py38_4.9.2-3.0.0/Linux64/meas_algorithms/gf36ae6ace1+1d7ae49801/python/lsst/meas/algorithms/detection.py", line 411, in getPsf size = self.calculateKernelSize(sigma) File "/software/lsstsw/stack_20220421/stack/miniconda3-py38_4.9.2-3.0.0/Linux64/meas_algorithms/gf36ae6ace1+1d7ae49801/python/lsst/meas/algorithms/detection.py", line 386, in calculateKernelSize return (int(sigma * self.config.nSigmaForKernel + 0.5)//2)*2 + 1 # make sure it is odd ValueError: cannot convert float NaN to integer}} As John mentions, this could have been caught earlier: characterizeImage logs lsst.characterizeImage INFO: iter 1; PSF sigma=nan, dimensions=(25, 25); median background=770.85 so we should notice and catch when the PSF is providing NaNs. This is one of several places where the Piff log levels should be adjusted; lsst.characterizeImage.measurePsf.psfDeterminer INFO: Ill-conditioned matrix (rcond=2.40177e-26): result may not be accurate. might be more severe than INFO? and lsst.characterizeImage.measurePsf.psfDeterminer gives WARN for total chi-squared and the start of each fitting iteration.
            Hide
            ebellm Eric Bellm added a comment -

            To summarize: I think we are stuck here and need help from Joshua Meyers to understand why the Piff PSFs are returning NaNs even after we adjust the kernel size.

            Show
            ebellm Eric Bellm added a comment - To summarize: I think we are stuck here and need help from Joshua Meyers to understand why the Piff PSFs are returning NaNs even after we adjust the kernel size.
            Hide
            Parejkoj John Parejko added a comment -

            Following up here, Joshua Meyers and I created a failing test case with piff to demonstrate the error independent of Rubin code (we just pickled up the star images generated in a test) and filed an issue with Piff:

            https://github.com/rmjarvis/Piff/issues/131

            Show
            Parejkoj John Parejko added a comment - Following up here, Joshua Meyers and I created a failing test case with piff to demonstrate the error independent of Rubin code (we just pickled up the star images generated in a test) and filed an issue with Piff: https://github.com/rmjarvis/Piff/issues/131
            Parejkoj John Parejko made changes -
            Link This issue is triggering DM-34586 [ DM-34586 ]
            Parejkoj John Parejko made changes -
            Assignee John Parejko [ parejkoj ]
            Parejkoj John Parejko made changes -
            Story Points 2 4
            Hide
            Parejkoj John Parejko added a comment -

            Further followup: our psfCandidates were too small. The values of makePsfCandidates.kernelSize and psfDeterminer.kernelSize are entirely independent, and not checked against each other. PcaPsf and Psfex both force the psfCandidates to have dimensions that equal their kernelSize, but they also modify that kernelSize before fitting. I've implemented checks in piffPsfDeterminer and MeasurePsfConfig to try to prevent this. I'll put those up for review shortly, I hope.

            Running ap_verify on the modified ap_verify_ci_cosmos pipeline yaml with kernelSize=25 did not crash. I'll leave it to someone else to check that this fixes the fakes metric problem described on this ticket.

            I've updated the piff Issue linked above to reflect that piff should itself fail in this situation.

            Show
            Parejkoj John Parejko added a comment - Further followup: our psfCandidates were too small. The values of makePsfCandidates.kernelSize and psfDeterminer.kernelSize are entirely independent, and not checked against each other. PcaPsf and Psfex both force the psfCandidates to have dimensions that equal their kernelSize, but they also modify that kernelSize before fitting. I've implemented checks in piffPsfDeterminer and MeasurePsfConfig to try to prevent this. I'll put those up for review shortly, I hope. Running ap_verify on the modified ap_verify_ci_cosmos pipeline yaml with kernelSize=25 did not crash. I'll leave it to someone else to check that this fixes the fakes metric problem described on this ticket. I've updated the piff Issue linked above to reflect that piff should itself fail in this situation.
            Parejkoj John Parejko made changes -
            Status To Do [ 10001 ] In Progress [ 3 ]
            Show
            Parejkoj John Parejko added a comment - - edited Jenkins: https://ci.lsst.codes/blue/organizations/jenkins/stack-os-matrix/detail/stack-os-matrix/36498/pipeline
            Hide
            yusra Yusra AlSayyad added a comment -

            Nice detective work. 

            And we need to override the kernel configs deeper than ap_verify_ci_hsc_pdr2 too, though I get that we need to do ap_verify_ci_hsc_pdr2 ASAP, so fine if you want to do this another ticket. 

            Joshua Meyers, can we change kernelMin and kernelMax here to 25 and 45 like our other psfDeterminers?

             https://github.com/lsst/meas_extensions_piff/blob/4882acf2830983cd070aa1a906dc2fcf4ac82c04/python/lsst/meas/extensions/piff/piffPsfDeterminer.py#L75

            e.g. currrent:
            config.measurePsf.makePsfCandidates.kernelSize=21
            config.measurePsf.psfDeterminer['pca'].kernelSize=10.0
            config.measurePsf.psfDeterminer['pca'].kernelSizeMin=25
            config.measurePsf.psfDeterminer['pca'].kernelSizeMax=45
            config.measurePsf.psfDeterminer['psfex'].kernelSize=81
            config.measurePsf.psfDeterminer['psfex'].kernelSizeMin=25
            config.measurePsf.psfDeterminer['psfex'].kernelSizeMax=45 
            config.measurePsf.psfDeterminer['piff'].kernelSize=21.0
            config.measurePsf.psfDeterminer['piff'].kernelSizeMin=11 # not like the others
            config.measurePsf.psfDeterminer['piff'].kernelSizeMax=35 # not like the others

             

             

            Show
            yusra Yusra AlSayyad added a comment - Nice detective work.  And we need to override the kernel configs deeper than ap_verify_ci_hsc_pdr2 too, though I get that we need to do ap_verify_ci_hsc_pdr2 ASAP, so fine if you want to do this another ticket.  Joshua Meyers , can we change kernelMin and kernelMax here to 25 and 45 like our other psfDeterminers?   https://github.com/lsst/meas_extensions_piff/blob/4882acf2830983cd070aa1a906dc2fcf4ac82c04/python/lsst/meas/extensions/piff/piffPsfDeterminer.py#L75 e.g. currrent: config.measurePsf.makePsfCandidates.kernelSize= 21 config.measurePsf.psfDeterminer[ 'pca' ].kernelSize= 10.0 config.measurePsf.psfDeterminer[ 'pca' ].kernelSizeMin= 25 config.measurePsf.psfDeterminer[ 'pca' ].kernelSizeMax= 45 config.measurePsf.psfDeterminer[ 'psfex' ].kernelSize= 81 config.measurePsf.psfDeterminer[ 'psfex' ].kernelSizeMin= 25 config.measurePsf.psfDeterminer[ 'psfex' ].kernelSizeMax= 45 config.measurePsf.psfDeterminer[ 'piff' ].kernelSize= 21.0 config.measurePsf.psfDeterminer[ 'piff' ].kernelSizeMin= 11 # not like the others config.measurePsf.psfDeterminer[ 'piff' ].kernelSizeMax= 35 # not like the others    
            Hide
            Parejkoj John Parejko added a comment -

            The min/max kernelSize values are irrelevant for piffPsfDeterminer: see discussion on the PR for DM-34531 for details.

            Show
            Parejkoj John Parejko added a comment - The min/max kernelSize values are irrelevant for piffPsfDeterminer: see discussion on the PR for DM-34531 for details.
            Hide
            Parejkoj John Parejko added a comment -

            I think it worked? Here's what I get for one of the completeness metrics from the ap_verify metrics list with the kernelSize=25 change (it is 0 if I run on main):

            In [12]: butler.get('metricvalue_ap_pipe_ApFakesCompletenessMag20t22', instrument='HSC', detector=50, visit=59150, collections="ap_verify-output")
            Out[12]: Measurement('ap_pipe.ApFakesCompletenessMag20t22', <Quantity 0.66666667>)
            

            Show
            Parejkoj John Parejko added a comment - I think it worked? Here's what I get for one of the completeness metrics from the ap_verify metrics list with the kernelSize=25 change (it is 0 if I run on main): In [12]: butler.get('metricvalue_ap_pipe_ApFakesCompletenessMag20t22', instrument='HSC', detector=50, visit=59150, collections="ap_verify-output") Out[12]: Measurement('ap_pipe.ApFakesCompletenessMag20t22', <Quantity 0.66666667>)
            sullivan Ian Sullivan made changes -
            Story Points 4 6
            sullivan Ian Sullivan made changes -
            Sprint AP S22-5 (April) [ 1156 ] AP S22-6 (May) [ 1161 ]
            sullivan Ian Sullivan made changes -
            Rank Ranked higher
            sullivan Ian Sullivan made changes -
            Rank Ranked higher
            Hide
            Parejkoj John Parejko added a comment -

            Eric Bellm: there are three PRs to review. I think the biggest question is whether we need to make the same kernel size change to the hits2015 ap_verify datasets or whether we should make it to ap_verify or ap_pipe so it is used for all datasets.

            Show
            Parejkoj John Parejko added a comment - Eric Bellm : there are three PRs to review. I think the biggest question is whether we need to make the same kernel size change to the hits2015 ap_verify datasets or whether we should make it to ap_verify or ap_pipe so it is used for all datasets.
            Parejkoj John Parejko made changes -
            Reviewers Eric Bellm [ ebellm ]
            Status In Progress [ 3 ] In Review [ 10004 ]
            Hide
            krzys Krzysztof Findeisen added a comment -

            I think the biggest question is whether we need to make the same kernel size change to the hits2015 ap_verify datasets or whether we should make it to ap_verify or ap_pipe so it is used for all datasets.

            This kind of change does not belong in the dataset-specific configs. The only things that should go there are configurations to customize the pipeline to the contents of the datasets.

            Show
            krzys Krzysztof Findeisen added a comment - I think the biggest question is whether we need to make the same kernel size change to the hits2015 ap_verify datasets or whether we should make it to ap_verify or ap_pipe so it is used for all datasets. This kind of change does not belong in the dataset-specific configs. The only things that should go there are configurations to customize the pipeline to the contents of the datasets.
            Hide
            yusra Yusra AlSayyad added a comment -

            Ideally the change would be global in meas_extensions_piff. 

            Show
            yusra Yusra AlSayyad added a comment - Ideally the change would be global in meas_extensions_piff. 
            Hide
            Parejkoj John Parejko added a comment -

            Changing this globally in meas_extensions_piff would affect DRP, which would require DRP to do validation runs. We'd rather get the change in sooner than that, I think. We can have a follow-up ticket to make the change in meas_extensions_piff.

            Show
            Parejkoj John Parejko added a comment - Changing this globally in meas_extensions_piff would affect DRP, which would require DRP to do validation runs. We'd rather get the change in sooner than that, I think. We can have a follow-up ticket to make the change in meas_extensions_piff.
            krzys Krzysztof Findeisen made changes -
            Link This issue has to be done before DM-32694 [ DM-32694 ]
            Hide
            ebellm Eric Bellm added a comment -

            Thanks, John Parejko. DRP is going to handle changing the Piff default to 25. In the meantime we should set it for all ap pipelines. Right now you have a PR only for the HSC CI dataset; we should make the config change in ap_pipe instead, and confirm that it is inherited appropriately in CI.

            I left some other questions on the pipe_tasks and meas_extensions_piff PRs.

            Show
            ebellm Eric Bellm added a comment - Thanks, John Parejko . DRP is going to handle changing the Piff default to 25. In the meantime we should set it for all ap pipelines. Right now you have a PR only for the HSC CI dataset; we should make the config change in ap_pipe instead, and confirm that it is inherited appropriately in CI. I left some other questions on the pipe_tasks and meas_extensions_piff PRs.
            Show
            Parejkoj John Parejko added a comment - - edited New Jenkins, with change in ap_pipe: https://ci.lsst.codes/blue/organizations/jenkins/stack-os-matrix/detail/stack-os-matrix/36549/pipeline
            Hide
            ebellm Eric Bellm added a comment -

            Looks good once Jenkins is available.

            Show
            ebellm Eric Bellm added a comment - Looks good once Jenkins is available.
            ebellm Eric Bellm made changes -
            Status In Review [ 10004 ] Reviewed [ 10101 ]
            Parejkoj John Parejko made changes -
            Link This issue is triggering DM-34698 [ DM-34698 ]
            krzys Krzysztof Findeisen made changes -
            Link This issue has to be done before DM-34699 [ DM-34699 ]
            Parejkoj John Parejko made changes -
            Resolution Done [ 10000 ]
            Status Reviewed [ 10101 ] Done [ 10002 ]

              People

              Assignee:
              Parejkoj John Parejko
              Reporter:
              krzys Krzysztof Findeisen
              Reviewers:
              Eric Bellm
              Watchers:
              Eric Bellm, Ian Sullivan, John Parejko, Joshua Meyers, Krzysztof Findeisen, Lee Kelvin, Yusra AlSayyad
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Jenkins

                  No builds found.