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

testPsfSelectTest fails when run with via "pytest *.py"

    Details

    • Templates:
    • Story Points:
      1
    • Sprint:
      Alert Production F17 - 8
    • Team:
      Alert Production

      Description

      testPsfSelectTest fails when run via pytest *.py in meas_algorithms/tests, but passes if run with python testPsfSelectTest.py or pytest testPsfSelectTest.py. Sample failing run shown below. I'm betting this is a badly-initialized random seed (e.g. the one on line 45).

      Including Vishal Kasliwal [X] since it looks like he did the pytest port, and Ian Sullivan because he added the new-style test boilerplate at the bottom.

      $ pytest *.py
      ============================= test session starts ==============================
      platform linux2 -- Python 2.7.12, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
      rootdir: /home/parejkoj/lsst/lsstsw/build/meas_algorithms/tests, inifile: 
      plugins: cov-2.4.0
      collected 147 items 
       
      testAstrometrySourceSelector.py ..........
      testBinnedWcs.py ...
      testCoaddApCorrMap.py ...
      testCoaddBoundedField.py ....
      testCoaddPsf.py ...........
      testCr.py ....
      testDetection.py ...
      testExecutables.py .....
      testGaussianPsf.py ...........
      testGaussianPsfFactory.py .....
      testHtmIndex.py .........
      testInstallGaussianPsf.py ......
      testInterp.py ......
      testLoadReferenceObjects.py ....
      testMeasure.py .....
      testMeasureApCorr.py ..........
      testNegative.py ...
      testPsfAttributes.py ...
      testPsfCandidate.py .....
      testPsfDetermination.py .........
      testPsfIO.py .......
      testPsfSelectTest.py F...
      testReadFitsCatalog.py ........
      testReadTextCatalog.py ......
      testTicket-2986.py ...
       
      =================================== FAILURES ===================================
      ___________________ PsfSelectionTestCase.testDistortedImage ____________________
       
      self = <testPsfSelectTest.PsfSelectionTestCase testMethod=testDistortedImage>
       
          def testDistortedImage(self):
          
              detector = self.detector
          
              psfSigma = 1.5
              stars = plantSources(self.x0, self.y0, self.nx, self.ny, self.sky, self.nObj, psfSigma, detector)
              expos, starXy = stars[0], stars[1]
          
              # add some faint round galaxies ... only slightly bigger than the psf
              gxy = plantSources(self.x0, self.y0, self.nx, self.ny, self.sky, 10, 1.07*psfSigma, detector)
              mi = expos.getMaskedImage()
              mi += gxy[0].getMaskedImage()
              gxyXy = gxy[1]
          
              kwid = 15  # int(10*psfSigma) + 1
              psf = measAlg.SingleGaussianPsf(kwid, kwid, psfSigma)
              expos.setPsf(psf)
          
              expos.setDetector(detector)
          
              ########################
              # try without distorter
              expos.setDetector(self.flatDetector)
              print("Testing PSF selection *without* distortion")
              sourceList = self.detectAndMeasure(expos)
              psfCandidateList = self.starSelector.run(expos, sourceList).psfCandidates
          
              ########################
              # try with distorter
              expos.setDetector(self.detector)
              print("Testing PSF selection *with* distortion")
              sourceList = self.detectAndMeasure(expos)
              psfCandidateListCorrected = self.starSelector.run(expos, sourceList).psfCandidates
          
              def countObjects(candList):
                  nStar, nGxy = 0, 0
                  for c in candList:
                      s = c.getSource()
                      x, y = s.getX(), s.getY()
                      for xs, ys in starXy:
                          if abs(x-xs) < 2.0 and abs(y-ys) < 2.0:
                              nStar += 1
                      for xg, yg in gxyXy:
                          if abs(x-xg) < 2.0 and abs(y-yg) < 2.0:
                              nGxy += 1
                  return nStar, nGxy
          
              nstar, ngxy = countObjects(psfCandidateList)
              nstarC, ngxyC = countObjects(psfCandidateListCorrected)
          
              print("uncorrected nStar, nGxy: ", nstar, "/", len(starXy), "   ", ngxy, '/', len(gxyXy))
              print("dist-corrected nStar, nGxy: ", nstarC, '/', len(starXy), "   ", ngxyC, '/', len(gxyXy))
          
              ########################
              # display
              if display:
                  iDisp = 1
                  ds9.mtv(expos, frame=iDisp)
                  size = 40
                  for c in psfCandidateList:
                      s = c.getSource()
                      ixx, iyy, ixy = size*s.getIxx(), size*s.getIyy(), size*s.getIxy()
                      ds9.dot("@:%g,%g,%g" % (ixx, ixy, iyy), s.getX(), s.getY(),
                              frame=iDisp, ctype=ds9.RED)
                  size *= 2.0
                  for c in psfCandidateListCorrected:
                      s = c.getSource()
                      ixx, iyy, ixy = size*s.getIxx(), size*s.getIyy(), size*s.getIxy()
                      ds9.dot("@:%g,%g,%g" % (ixx, ixy, iyy), s.getX(), s.getY(),
                              frame=iDisp, ctype=ds9.GREEN)
          
              # we shouldn't expect to get all available stars without distortion correcting
      >       self.assertLess(nstar, len(starXy))
      E       AssertionError: 64 not less than 64
       
      testPsfSelectTest.py:452: AssertionError
      ----------------------------- Captured stdout call -----------------------------
      Testing PSF selection *without* distortion
      Testing PSF selection *with* distortion
      uncorrected nStar, nGxy:  64 / 64     0 / 9
      dist-corrected nStar, nGxy:  64 / 64     0 / 9
      ----------------------------- Captured stderr call -----------------------------
      sourceDetection INFO: Detected 70 positive sources to 5 sigma.
      sourceDetection INFO: Resubtracting the background after object detection
      measurement INFO: Measuring 70 sources (70 parents, 0 children) 
      measurement INFO: Measuring 1 sources (1 parents, 0 children) 
      sourceDetection INFO: Detected 70 positive sources to 5 sigma.
      sourceDetection INFO: Resubtracting the background after object detection
      measurement INFO: Measuring 70 sources (70 parents, 0 children) 
      measurement INFO: Measuring 1 sources (1 parents, 0 children) 
      ============================ pytest-warning summary ============================
      WC1 /home/parejkoj/lsst/lsstsw/build/meas_algorithms/tests/testGaussianPsfFactory.py cannot collect test class 'TestConfig' because it has a __new__ constructor
      =========== 1 failed, 146 passed, 1 pytest-warnings in 28.33 seconds ===========
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rowen Russell Owen
                Reporter:
                Parejkoj John Parejko
                Reviewers:
                Tim Jenness
                Watchers:
                Ian Sullivan, John Parejko, John Swinbank, Russell Owen, Simon Krughoff, Tim Jenness
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel