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

makeWcs() chokes on decam images in 10.1

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: afw, obs_decam
    • Labels:
      None

      Description

      In 10.0, processCcdDecam.py could process decam images to completion (whether the WCS was read correctly is a different question). Now it fails on makeWcs() (see traceback below), and I suspect this change in behavior is related to DM-2883 and DM-2967.

      Repository with both data and code to reproduce:
      http://www.astro.washington.edu/users/yusra/reproduce/reproduceMakeWcsErr.tar.gz
      (apologies for the size)

      The attachment is a document describing the WCS representation in the images from the community pipeline, courtesy of Francisco Forster.

      Please advise. This ticket captures any changes made to afw.

      D-108-179-166-118:decam yusra$ processCcdDecam.py newTestRepo/ --id visit=0232847 ccdnum=10 --config calibrate.doPhotoCal=False calibrate.doAstrometry=False calibrate.measurePsf.starSelector.name="secondMoment" doWriteCalibrateMatches=False --clobber-config
      : Loading config overrride file '/Users/yusra/lsst_devel/LSST/repos/obs_decam_ya/config/processCcdDecam.py'
      : Config override file does not exist: '/Users/yusra/lsst_devel/LSST/repos/obs_decam_ya/config/decam/processCcdDecam.py'
      : input=/Users/yusra/decam/newTestRepo
      : calib=None
      : output=None
      CameraMapper: Loading registry registry from /Users/yusra/decam/newTestRepo/registry.sqlite3
      processCcdDecam: Processing {'visit': 232847, 'ccdnum': 10}
      makeWcs WARNING: Stripping PVi_j keys from projection RA---TPV/DEC--TPV
      processCcdDecam FATAL: Failed on dataId={'visit': 232847, 'ccdnum': 10}: 
        File "src/image/Wcs.cc", line 130, in void lsst::afw::image::Wcs::_initWcs()
          Failed to setup wcs structure with wcsset. Status 5: Invalid parameter value {0}
      lsst::pex::exceptions::RuntimeError: 'Failed to setup wcs structure with wcsset. Status 5: Invalid parameter value'
       
      Traceback (most recent call last):
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/pipe_base/10.1-3-g18c2ba7+49/python/lsst/pipe/base/cmdLineTask.py", line 320, in __call__
          result = task.run(dataRef, **kwargs)
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/pipe_base/10.1-3-g18c2ba7+49/python/lsst/pipe/base/timer.py", line 118, in wrapper
          res = func(self, *args, **keyArgs)
        File "/Users/yusra/lsst_devel/LSST/repos/obs_decam_ya/python/lsst/obs/decam/processCcdDecam.py", line 77, in run
          mi = exp.getMaskedImage()
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/daf_persistence/10.1-1-g6edbc00+28/python/lsst/daf/persistence/readProxy.py", line 41, in __getattribute__
          subject = oga(self, '__subject__')
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/daf_persistence/10.1-1-g6edbc00+28/python/lsst/daf/persistence/readProxy.py", line 136, in __subject__
          set_cache(self, get_callback(self)())
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/daf_persistence/10.1-1-g6edbc00+28/python/lsst/daf/persistence/butler.py", line 242, in <lambda>
          innerCallback(), dataId)
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/daf_persistence/10.1-1-g6edbc00+28/python/lsst/daf/persistence/butler.py", line 236, in <lambda>
          location, dataId)
        File "/Users/yusra/lsst_devel/LSST/repos/obs_decam_ya/python/lsst/obs/decam/decamMapper.py", line 118, in bypass_instcal
          wcs         = afwImage.makeWcs(md)
        File "/Users/yusra/lsst_devel/LSST/DMS5/DarwinX86/afw/10.1-26-g9124caf+1/python/lsst/afw/image/imageLib.py", line 8706, in makeWcs
          return _imageLib.makeWcs(*args)
      RuntimeError: 
        File "src/image/Wcs.cc", line 130, in void lsst::afw::image::Wcs::_initWcs()
          Failed to setup wcs structure with wcsset. Status 5: Invalid parameter value {0}
      lsst::pex::exceptions::RuntimeError: 'Failed to setup wcs structure with wcsset. Status 5: Invalid parameter value'
      

        Attachments

          Issue Links

            Activity

            Hide
            hchiang2 Hsin-Fang Chiang added a comment -

            There seems a problem with the tar.gz file?

            Show
            hchiang2 Hsin-Fang Chiang added a comment - There seems a problem with the tar.gz file?
            Hide
            ktl Kian-Tat Lim added a comment -

            At a first glance through the document, it does look like we need to implement TPV correctly to process these. Note from the earlier ticket: "TPV is not (yet) supported by LSST software so TPV is then converted back to --TAN."

            Show
            ktl Kian-Tat Lim added a comment - At a first glance through the document, it does look like we need to implement TPV correctly to process these. Note from the earlier ticket: "TPV is not (yet) supported by LSST software so TPV is then converted back to --TAN."
            Hide
            tjenness Tim Jenness added a comment -

            I was just going to say that, but it seems the fallback to TAN isn't happening, otherwise it wouldn't choke on the header.

            Show
            tjenness Tim Jenness added a comment - I was just going to say that, but it seems the fallback to TAN isn't happening, otherwise it wouldn't choke on the header.
            Hide
            yusra Yusra AlSayyad added a comment -

            Hsin-Fang Chiang, Try the tarball again. (The first one got corrupted when I uploaded it)

            Show
            yusra Yusra AlSayyad added a comment - Hsin-Fang Chiang , Try the tarball again. (The first one got corrupted when I uploaded it)
            Hide
            yusra Yusra AlSayyad added a comment -

            For now u/yusra/DM-3196 reverts the commit in DM-2967: af906a8f28afeeb7b665bb08bd543c281e718f2c

            Show
            yusra Yusra AlSayyad added a comment - For now u/yusra/ DM-3196 reverts the commit in DM-2967 : af906a8f28afeeb7b665bb08bd543c281e718f2c
            Hide
            rhl Robert Lupton added a comment -

            Has anyone analysed these DECAM headers for legality? And the headers post the DM-2967 change?

            Show
            rhl Robert Lupton added a comment - Has anyone analysed these DECAM headers for legality? And the headers post the DM-2967 change?
            Hide
            yusra Yusra AlSayyad added a comment -

            Are you asking what changes DM-2967 makes to the headers?

            Show
            yusra Yusra AlSayyad added a comment - Are you asking what changes DM-2967 makes to the headers?
            Hide
            tjenness Tim Jenness added a comment -

            My understanding is that these are TPV headers. The new code is meant to spot the TPV-ness, change the projection to TAN and remove all except the first four PV headers. The header is then processed as a TAN header (so isn't technically correct). Something is going wrong though when the newly modified header is sent to wcsLib.

            Show
            tjenness Tim Jenness added a comment - My understanding is that these are TPV headers. The new code is meant to spot the TPV-ness, change the projection to TAN and remove all except the first four PV headers. The header is then processed as a TAN header (so isn't technically correct). Something is going wrong though when the newly modified header is sent to wcsLib.
            Hide
            tjenness Tim Jenness added a comment -

            Robert Lupton might be asking for a dump of the headers after AFW has hacked them all up to turn them into TAN.

            Show
            tjenness Tim Jenness added a comment - Robert Lupton might be asking for a dump of the headers after AFW has hacked them all up to turn them into TAN.
            Hide
            hchiang2 Hsin-Fang Chiang added a comment -

            Here is an example of the header after afw changed it into TAN. The WCS projection type of the input file is TPV.

            XTENSION= 'IMAGE   '           / IMAGE extension
            BITPIX  =                  -32 / number of bits per data pixel
            NAXIS   =                    2 / number of data axes
            NAXIS1  =                 2046 / length of data axis 1
            NAXIS2  =                 4094 / length of data axis 2
            PCOUNT  =                    0 / required keyword; must = 0
            GCOUNT  =                    1 / required keyword; must = 1
            EQUINOX =      9.87654321E+107 / Equinox of coordinates
            RADESYS = 'ICRS    '           / Coordinate system for equinox
            CRPIX1  =               8914.4 / WCS Coordinate reference pixel
            CRPIX2  =                2048. / WCS Coordinate reference pixel
            CD1_1   =  -2.863583082783E-07 / WCS Coordinate scale matrix
            CD1_2   =   7.285161023394E-05 / WCS Coordinate scale matrix
            CD2_1   =  -7.285152832571E-05 / WCS Coordinate scale matrix
            CD2_2   =  -2.881919867864E-07 / WCS Coordinate scale matrix
            CRVAL1  =       300.6567689437 / WCS Ref value (RA in decimal degrees)
            CRVAL2  =      -57.45059962179 / WCS Ref value (DEC in decimal degrees)
            CUNIT1  = 'deg     '
            CUNIT2  = 'deg     '
            CTYPE1  = 'RA---TAN'           / WCS Coordinate type
            CTYPE2  = 'DEC--TAN'           / WCS Coordinate type
            LTV1    =                    0
            LTV2    =                    0
            INHERIT =                    T
            EXTTYPE = 'IMAGE   '
            CRVAL1A =                    0 / Column pixel of Reference Pixel
            CRVAL2A =                    0 / Row pixel of Reference Pixel
            CRPIX1A =                    1 / Column Pixel Coordinate of Reference
            CRPIX2A =                    1 / Row Pixel Coordinate of Reference
            CTYPE1A = 'LINEAR  '           / Type of projection
            CTYPE2A = 'LINEAR  '           / Type of projection
            CUNIT1A = 'PIXEL   '           / Column unit
            CUNIT2A = 'PIXEL   '           / Row unit
            

            Show
            hchiang2 Hsin-Fang Chiang added a comment - Here is an example of the header after afw changed it into TAN. The WCS projection type of the input file is TPV. XTENSION= 'IMAGE ' / IMAGE extension BITPIX = - 32 / number of bits per data pixel NAXIS = 2 / number of data axes NAXIS1 = 2046 / length of data axis 1 NAXIS2 = 4094 / length of data axis 2 PCOUNT = 0 / required keyword; must = 0 GCOUNT = 1 / required keyword; must = 1 EQUINOX = 9 .87654321E+ 107 / Equinox of coordinates RADESYS = 'ICRS ' / Coordinate system for equinox CRPIX1 = 8914.4 / WCS Coordinate reference pixel CRPIX2 = 2048 . / WCS Coordinate reference pixel CD1_1 = - 2 .863583082783E- 07 / WCS Coordinate scale matrix CD1_2 = 7 .285161023394E- 05 / WCS Coordinate scale matrix CD2_1 = - 7 .285152832571E- 05 / WCS Coordinate scale matrix CD2_2 = - 2 .881919867864E- 07 / WCS Coordinate scale matrix CRVAL1 = 300.6567689437 / WCS Ref value (RA in decimal degrees) CRVAL2 = - 57.45059962179 / WCS Ref value (DEC in decimal degrees) CUNIT1 = 'deg ' CUNIT2 = 'deg ' CTYPE1 = 'RA---TAN' / WCS Coordinate type CTYPE2 = 'DEC--TAN' / WCS Coordinate type LTV1 = 0 LTV2 = 0 INHERIT = T EXTTYPE = 'IMAGE ' CRVAL1A = 0 / Column pixel of Reference Pixel CRVAL2A = 0 / Row pixel of Reference Pixel CRPIX1A = 1 / Column Pixel Coordinate of Reference CRPIX2A = 1 / Row Pixel Coordinate of Reference CTYPE1A = 'LINEAR ' / Type of projection CTYPE2A = 'LINEAR ' / Type of projection CUNIT1A = 'PIXEL ' / Column unit CUNIT2A = 'PIXEL ' / Row unit
            Hide
            tjenness Tim Jenness added a comment -

            There aren't any PV headers at all there. Just CD. Did all the PV headers get stripped?

            The EQUINOX header is really fun. Good thing that it's ignored for ICRS.

            Show
            tjenness Tim Jenness added a comment - There aren't any PV headers at all there. Just CD . Did all the PV headers get stripped? The EQUINOX header is really fun. Good thing that it's ignored for ICRS.
            Hide
            hchiang2 Hsin-Fang Chiang added a comment - - edited

            I used u/yusra/DM-3196, otherwise makeWcs() failed as in the description. This was what I did:

            >>> md = afwImage.readMetadata('file.fits.fz[10]')
            >>> wcs = afwImage.makeWcs(md)
            makeWcs WARNING: Stripping PVi_j keys from projection RA---TPV/DEC--TPV
            >>> wcs.getFitsMetadata().toList()
            [('NAXIS', 2, 'number of data axes'), ('EQUINOX', 2000.0, 'Equinox of coordinates'), ('RADESYS', 'ICRS', 'Coordinate system for equinox'), ('CRPIX1', 8914.4, 'WCS Coordinate reference pixel'), ('CRPIX2', 2048.0, 'WCS Coordinate reference pixel'), ('CD1_1', -2.863583082783e-07, 'WCS Coordinate scale matrix'), ('CD1_2', 7.285161023394e-05, 'WCS Coordinate scale matrix'), ('CD2_1', -7.285152832571e-05, 'WCS Coordinate scale matrix'), ('CD2_2', -2.881919867864e-07, 'WCS Coordinate scale matrix'), ('CRVAL1', 300.6567689437, 'WCS Ref value (RA in decimal degrees)'), ('CRVAL2', -57.45059962179, 'WCS Ref value (DEC in decimal degrees)'), ('CUNIT1', 'deg', ''), ('CUNIT2', 'deg', ''), ('CTYPE1', 'RA---TAN', 'WCS Coordinate type'), ('CTYPE2', 'DEC--TAN', 'WCS Coordinate type')]
            
            

            In the header of the input file, there were PV keywords of PVi_j, i=1-2, j=0-10

            Show
            hchiang2 Hsin-Fang Chiang added a comment - - edited I used u/yusra/ DM-3196 , otherwise makeWcs() failed as in the description. This was what I did: >>> md = afwImage.readMetadata( 'file.fits.fz[10]' ) >>> wcs = afwImage.makeWcs(md) makeWcs WARNING: Stripping PVi_j keys from projection RA---TPV/DEC--TPV >>> wcs.getFitsMetadata().toList() [( 'NAXIS' , 2 , 'number of data axes' ), ( 'EQUINOX' , 2000.0 , 'Equinox of coordinates' ), ( 'RADESYS' , 'ICRS' , 'Coordinate system for equinox' ), ( 'CRPIX1' , 8914.4 , 'WCS Coordinate reference pixel' ), ( 'CRPIX2' , 2048.0 , 'WCS Coordinate reference pixel' ), ( 'CD1_1' , - 2 .863583082783e- 07 , 'WCS Coordinate scale matrix' ), ( 'CD1_2' , 7 .285161023394e- 05 , 'WCS Coordinate scale matrix' ), ( 'CD2_1' , - 7 .285152832571e- 05 , 'WCS Coordinate scale matrix' ), ( 'CD2_2' , - 2 .881919867864e- 07 , 'WCS Coordinate scale matrix' ), ( 'CRVAL1' , 300.6567689437 , 'WCS Ref value (RA in decimal degrees)' ), ( 'CRVAL2' , - 57.45059962179 , 'WCS Ref value (DEC in decimal degrees)' ), ( 'CUNIT1' , 'deg' , '' ), ( 'CUNIT2' , 'deg' , '' ), ( 'CTYPE1' , 'RA---TAN' , 'WCS Coordinate type' ), ( 'CTYPE2' , 'DEC--TAN' , 'WCS Coordinate type' )] In the header of the input file, there were PV keywords of PVi_j, i=1-2, j=0-10
            Hide
            hchiang2 Hsin-Fang Chiang added a comment -

            I tried two ways to read the header and makeWcs: (1) the quick route as in my last comment, I was thinking it might be an easier way to debug , and (2) retrieving the image using obs_decam, and writing the result into a fits file using ExposureF.writeFits(). In the header of this output fits file, HDU 0 has CTYPE1 = 'RA---TPV' and all PVi_j cards. The header I posted earlier in https://jira.lsstcorp.org/browse/DM-3196?focusedCommentId=37871&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-37871

            is from HDU 1 and it does have a funny EQUINOX header. Don't know where it got messed up.

            Show
            hchiang2 Hsin-Fang Chiang added a comment - I tried two ways to read the header and makeWcs: (1) the quick route as in my last comment, I was thinking it might be an easier way to debug , and (2) retrieving the image using obs_decam, and writing the result into a fits file using ExposureF.writeFits(). In the header of this output fits file, HDU 0 has CTYPE1 = 'RA---TPV' and all PVi_j cards. The header I posted earlier in https://jira.lsstcorp.org/browse/DM-3196?focusedCommentId=37871&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-37871 is from HDU 1 and it does have a funny EQUINOX header. Don't know where it got messed up.
            Hide
            swinbank John Swinbank added a comment -

            David Nidever [X] has asked me what the DRP/Princeton team can do to help with this issue. Scanning the discussion above, I'm confused as to what's required – is this a request for full support for the TPV WCS in the LSST stack, or simply a bug report that the fallback to TAN isn't working as advertised?

            Show
            swinbank John Swinbank added a comment - David Nidever [X] has asked me what the DRP/Princeton team can do to help with this issue. Scanning the discussion above, I'm confused as to what's required – is this a request for full support for the TPV WCS in the LSST stack, or simply a bug report that the fallback to TAN isn't working as advertised?
            Hide
            tjenness Tim Jenness added a comment -

            Ideally we would support TPV. In the interim this bug is blocking obs_decam work because the code is documented to convert TPV to TAN and that fallback does not seem to be working. Yusra AlSayyad works around that by simply reverting the commit that broke it (see DM-2967) and usign an AFW branch, but AFW master will not work (which prevents obs_decam from being integrated into the LSST CI).

            Supporting TPV natively is a whole other discussion not related to this ticket.

            Show
            tjenness Tim Jenness added a comment - Ideally we would support TPV. In the interim this bug is blocking obs_decam work because the code is documented to convert TPV to TAN and that fallback does not seem to be working. Yusra AlSayyad works around that by simply reverting the commit that broke it (see DM-2967 ) and usign an AFW branch, but AFW master will not work (which prevents obs_decam from being integrated into the LSST CI). Supporting TPV natively is a whole other discussion not related to this ticket.
            Hide
            yusra Yusra AlSayyad added a comment -

            Moving forward on this ticket requires getting a hold of the scamp output images that Robert Lupton used to test DM-2883 and editing the commit in DM-2967 that broke the fallback so that it works on both the scamp images and decam images.

            Show
            yusra Yusra AlSayyad added a comment - Moving forward on this ticket requires getting a hold of the scamp output images that Robert Lupton used to test DM-2883 and editing the commit in DM-2967 that broke the fallback so that it works on both the scamp images and decam images.
            Hide
            rhl Robert Lupton added a comment -

            Agreed. I'll find the file and attach it here later today in some timezone – have to dash now.

            Show
            rhl Robert Lupton added a comment - Agreed. I'll find the file and attach it here later today in some timezone – have to dash now.
            Hide
            rhl Robert Lupton added a comment -

            I pushed a fix to tickets/DM-3196

            The cleanup to the TPV headers was over-zealous and caused problems for PTF as well as DECam. I've verified that this branch works with PTF and am pulling the DECam example from this ticket, but if someone would like to check at UW that would be OK with me...

            Show
            rhl Robert Lupton added a comment - I pushed a fix to tickets/ DM-3196 The cleanup to the TPV headers was over-zealous and caused problems for PTF as well as DECam. I've verified that this branch works with PTF and am pulling the DECam example from this ticket, but if someone would like to check at UW that would be OK with me...
            Hide
            rhl Robert Lupton added a comment -

            OK, I have that tarball downloaded and I still see the problem. I take back the review request...

            Show
            rhl Robert Lupton added a comment - OK, I have that tarball downloaded and I still see the problem. I take back the review request...
            Hide
            rhl Robert Lupton added a comment -

            Let's try again. I have pushed a patch that successfully processes PTF data and works with the tarball that you attached to this ticket.

            $ git push
            [...]
            To git@github.com:lsst/afw
               2cc2aaf..7ccd5fb  tickets/DM-3196 -> tickets/DM-3196
            $ git diff --stat origin/master
             src/image/makeWcs.cc | 18 ++++++++----------
             1 file changed, 8 insertions(+), 10 deletions(-)
            

            Show
            rhl Robert Lupton added a comment - Let's try again. I have pushed a patch that successfully processes PTF data and works with the tarball that you attached to this ticket. $ git push [...] To git@github.com:lsst/afw 2cc2aaf..7ccd5fb tickets/DM-3196 -> tickets/DM-3196 $ git diff --stat origin/master src/image/makeWcs.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
            Hide
            yusra Yusra AlSayyad added a comment -

            OK to merge.

            Show
            yusra Yusra AlSayyad added a comment - OK to merge.
            Hide
            rhl Robert Lupton added a comment - - edited

            Merged to master and pushed

            (that took too many edits!)

            Show
            rhl Robert Lupton added a comment - - edited Merged to master and pushed (that took too many edits!)

              People

              Assignee:
              rhl Robert Lupton
              Reporter:
              yusra Yusra AlSayyad
              Reviewers:
              Yusra AlSayyad
              Watchers:
              Colin Slater, David Nidever [X] (Inactive), Hsin-Fang Chiang, John Swinbank, Kian-Tat Lim, Robert Lupton, Russell Owen, Simon Krughoff, Tim Jenness, Yusra AlSayyad
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Jenkins

                  No builds found.