[PIPE2D-512] ReduceArc.py fails on Subaru data using recent bootstrapped detectormap Created: 08/Feb/20  Updated: 05/Jan/21  Resolved: 07/Apr/20

Status: Done
Project: DRP 2-D Pipeline
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Story Priority: Normal
Reporter: hassan Assignee: hassan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2020-03-04-08-37-49-809.png     PNG File quiver-visit-436.png    
Issue Links:
Relates
relates to PIPE2D-536 Correct header info for ReduceArc and... Done
relates to PIPE2D-507 ConstructFiberFlat.py hangs against S... Done
Story Points: 6
Sprint: 2DDRP-2020 A, 2DDRP-2021 A

 Description   

Following a bootstrapDetectorMap run based on the July 2019 detectormap 'r' file available at
https://github.com/Subaru-PFS/drp_pfs_data/blob/master/detectorMap/detectorMap-2019Jul-r1.fits using Dec 2019 Subaru data

bootstrapDetectorMap.py ${repo} --calib ${repo}/CALIB --rerun ${rerunDir} --flatId visit=108 --arcId visit=436 arm=r

Followed by a run of reduceArc.py using the same Dec 2019 Subaru arc data

reduceArc.py ${repo} --calib ${repo}/CALIB --rerun calib/arc --id visit=436 arm=r

results in an error in fitContinuum.py:

reduceArc.identifyLines INFO: Matched 11 from 29 observed and 60 reference lines
reduceArc.identifyLines INFO: Matched 9 from 23 observed and 60 reference lines
reduceArc.identifyLines INFO: Matched 8 from 22 observed and 60 reference lines
reduceArc.identifyLines INFO: Matched 10 from 29 observed and 60 reference lines
reduceArc.identifyLines INFO: Matched 10 from 28 observed and 60 reference lines
reduceArc.identifyLines INFO: Matched 10 from 27 observed and 60 reference lines
reduceArc.identifyLines INFO: Matched 10 from 29 observed and 60 reference lines
reduceArc FATAL: Failed on dataId={'visit': 436, 'arm': 'r', 'dateObs': '2019-12-17', 'site': 'S', 'category': 'A', 'spectrograph': 1, 'field': 'ARC', 'ccd': 1, 'filter': 'r', 'expTime': 2.998, 'dataType': 'arc', 'taiObs': '2019-12-17', 'pfsDesignId': 1099528409104, 'slitOffset': 0.0}: AssertionError: Monotonic
Traceback (most recent call last):
  File "/tigress/HSC/PFS/stack/20190925/stack/miniconda3-4.5.12-1172c30/Linux64/pipe_base/18.1.0/python/lsst/pipe/base/cmdLineTask.py", line 388, in __call__
    result = self.runTask(task, dataRef, kwargs)
  File "/tigress/HSC/PFS/stack/20190925/stack/miniconda3-4.5.12-1172c30/Linux64/pipe_base/18.1.0/python/lsst/pipe/base/cmdLineTask.py", line 447, in runTask
    return task.runDataRef(dataRef, **kwargs)
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/reduceArcTask.py", line 165, in runDataRef
    self.identifyLines.run(results.spectraList[0], results.detectorMapList[0], lines)
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/identifyLines.py", line 49, in run
    self.identifyLines(spec, detectorMap, lines)
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/identifyLines.py", line 84, in identifyLines
    obsLines = self.findLines.runCentroids(spectrum).centroids
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/findLines.py", line 89, in runCentroids
    result = self.run(spectrum)
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/findLines.py", line 63, in run
    continuum = self.fitContinuum.fitContinuum(spectrum) if self.config.doSubtractContinuum else None
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/fitContinuum.py", line 85, in fitContinuum
    good = self.maskLines(spectrum)
  File "/tigress/hassans/software/drp_stella/python/pfs/drp/stella/fitContinuum.py", line 186, in maskLines
    assert np.all(delta >= 0) or np.all(delta <= 0), "Monotonic"
AssertionError: Monotonic
reduceArc FATAL: Failed to process at least one of the components for {'visit': 436, 'arm': 'r', 'dateObs': '2019-12-17', 'site': 'S', 'category': 'A', 'spectrograph': 1, 'field': 'ARC', 'ccd': 1, 'filter': 'r', 'expTime': 2.998, 'dataType': 'arc', 'taiObs': '2019-12-17', 'pfsDesignId': 1099528409104, 'slitOffset': 0.0}


 Comments   
Comment by hassan [ 08/Feb/20 ]

The issue here is that fitContinuum.py needs to interpolate the wavelength data from the input detectormap, (ie detectormap.getWavelength() ). The wavelength information needs to be monotonically rising in order for the interpolation to function. The detectormap in this case is the output of bootstrapDetectorMap.py

Examining the wavelength information for this 'bootstrapped' detectormap, about 253 of the 600 fibers have wavelength information which is not monotonically rising. In each of those 253 cases, the non-monotonicity appears at the ends of the wavelength sequence, corresponding to the 0 < detY < 60 and 4160 < detY 4176 ranges in the wavelength direction, on the detector.

It seems that the Chebyshev2D modelling of the detectormap correction that is performed within BootstrapDetectorMapTask is correct. The problem lies in the spline modelling within DetectorMap. I suspect with no arc data close to the above detector ranges, the spline solution may not necessarily extrapolate to a monotonic solution.

Comment by hassan [ 08/Feb/20 ]

The wavelengths information from the original July 2019 detectormap used as input to the bootstrap is monotonic for all fibers.

Note that the same error takes place if bootstrapDetectorMap.py is run twice (with the output of the first run replacing the July 2019 dataset as the default detectormap, ie. ingested into the butler calibration repository), with the same arc and field visits.

Comment by hassan [ 19/Feb/20 ]

(Thanks to ncaplar for spotting this) the underlying cause of this problem is that the header information in the arc exposure in the example provided here (visit=436) is incorrect. It states that the arc is Neon, when in fact the lamp is a Krypton one.

The bootstrapDetectorMap.py loads only those reference lines for the lamp specified in the header and tries to match the observed lines against those reference lines. This lead to very few lines being matched (and being Ne lines, wrong matches) in the centre of the detector. The result is a very poor wavelength solution.

This was confirmed by making a local modification to bootstrapDetectorMap.py to force it to load only Krypton lines. The result was a good detectormap, with many matched lines and a monotonically rising wavelength solution, as expected.

reduceArc.py (with again a local modification forcing it to load only Kr lines) worked fine with a test with the same arc.

Additional tests will be performed with other arcs. It appears that there are other arcs incorrectly identified, but further checks need to be done to be sure.

Comment by price [ 20/Feb/20 ]

If you have a list of visits with the wrong headers, we can put them into our database and get them fixed on ingest (PIPE2D-405).

Comment by hassan [ 20/Feb/20 ]

That sounds like a good idea, and the correct procedure. Thanks, will do.

Comment by hassan [ 03/Mar/20 ]

Plot https://pfspipe.ipmu.jp/jira/secure/attachment/12515/quiver-visit-436.png shows the difference between the observed and expected (from July 2019 detectormap) detector positions for matched lines during a bootstrapDetectorMap run. While there is an approx 6 pixel shift in the spatial direction, the transformation between expected and observed does not appear to be affine.

As ncaplar and J Gunn notes, if the fibers are separated across the individual CCDs, then there is separate affine solutions for each separate group of fibers. For example, from the plot, the rightmost 4 fibers show a systematic shift in both spatial and wavelength directions, whereas the leftmost 6 fibers show a spatial shift and a shear in the wavelength direction. Least squared fits on the two separate groups of fibers verify that the changes can be modeled by two separate affine matrices (with the matrix for the left group describing a 6 pixel shift and shear, and for the matrix for the right group a 5.5 pixel shift spatially and 1.5 pixel in the wavelength direction.

The current bootstrap model does not assume 2 separate CCDs. This should be considered.

Comment by rhl [ 04/Mar/20 ]

Good point re pairs of CCDs (not true in the n arm). A full affine is probably overkill for the relative motion of the two CCDs, however Bernstein et al. PASP 129.7 2017 use a full affine for a similar problem and this might be appropriate here.

Note that we need an affine for the complete detector too, and the per-CCD term should generally be held fixed (except e.g. after warming the camera).

This needs to be added to the DetectorMap model not just the bootstrap (this is moot until we have a map that models all the fibres together).

Comment by hassan [ 07/Apr/20 ]

Problem found to be incorrect lamp keyword values in header. With PIPE2D-536, this has been fixed. reduceArc.py no longer raises the problematic error.

Generated at Sat Feb 10 15:54:17 JST 2024 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.