From 18b40a914a1b99e8dc91456fe08fe424dcc93702 Mon Sep 17 00:00:00 2001 From: deborape Date: Thu, 3 Aug 2023 13:38:37 -1000 Subject: [PATCH 1/2] fix it --- pypeit/core/wavecal/autoid.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pypeit/core/wavecal/autoid.py b/pypeit/core/wavecal/autoid.py index 887315cc30..b429708b36 100644 --- a/pypeit/core/wavecal/autoid.py +++ b/pypeit/core/wavecal/autoid.py @@ -1736,10 +1736,12 @@ def run_brute(self, min_nlines=10): self._det_weak = {} self._det_stro = {} for slit in range(self._nslit): - msgs.info("Working on slit: {}".format(slit)) if slit not in self._ok_mask: self._all_final_fit[str(slit)] = None + msgs.info('Ignoring masked slit {}'.format(slit)) continue + else: + msgs.info("Working on slit: {}".format(slit)) # TODO Pass in all the possible params for detect_lines to arc_lines_from_spec, and update the parset # Detect lines, and decide which tcent to use sigdetect = wvutils.parse_param(self._par, 'sigdetect', slit) @@ -1772,11 +1774,10 @@ def run_brute(self, min_nlines=10): # Now that all slits have been inspected, cross match to generate a # list of all lines in every slit, and refit all spectra - if self._nslit > 1: + obad_slits = self.cross_match(good_fit, self._det_weak) if self._ok_mask.size > 1 else np.array([]) + if obad_slits.size > 1: msgs.info('Checking wavelength solution by cross-correlating with all slits') - msgs.info('Cross-correlation iteration #1') - obad_slits = self.cross_match(good_fit, self._det_weak) cntr = 2 while obad_slits.size > 0: msgs.info('Cross-correlation iteration #{:d}'.format(cntr)) @@ -2034,7 +2035,7 @@ def cross_match(self, good_fit, detections): # to be classified as a bad slit here. Is this the behavior we want?? Maybe we should be more # conservative and call a bad any slit which results in an outlier here? good_slits = np.sort(sort_idx[np.unique(slit_ids[gdmsk, :].flatten())]) - bad_slits = np.setdiff1d(np.arange(self._nslit), good_slits, assume_unique=True) + bad_slits = np.setdiff1d(np.arange(self._nslit)[self._ok_mask], good_slits, assume_unique=True) nbad = bad_slits.size if nbad > 0: msgs.info('Working on {:d}'.format(nbad) + ' bad slits: {:}'.format(bad_slits + 1)) From 826a5040ed504b9924dd8ea2df817f72338040de Mon Sep 17 00:00:00 2001 From: Debora Pelliccia Date: Tue, 8 Aug 2023 15:24:17 -1000 Subject: [PATCH 2/2] more fixes --- pypeit/core/arc.py | 4 ++-- pypeit/core/wavecal/autoid.py | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pypeit/core/arc.py b/pypeit/core/arc.py index aceec8e935..2404fa5d07 100644 --- a/pypeit/core/arc.py +++ b/pypeit/core/arc.py @@ -485,12 +485,12 @@ def get_censpec(slit_cen, slitmask, arcimg, gpm=None, box_rad=3.0, continue # Check if this slit is masked if slit_bpm is not None and slit_bpm[islit]: - msgs.info('Ignoring masked slit {}'.format(islit)) + msgs.info('Ignoring masked slit {}'.format(islit+1)) # TODO -- Avoid using NaNs arc_spec[:,islit] = np.nan continue if verbose: - msgs.info('Extracting approximate arc spectrum along the center of slit {0}'.format(islit)) + msgs.info('Extracting approximate arc spectrum along the center of slit {0}'.format(islit+1)) # Create a mask for the pixels that will contribue to the arc arcmask = _gpm & (np.absolute(spat[None,:] - slit_cen[:,islit,None]) < box_rad) # Trimming the image makes this much faster diff --git a/pypeit/core/wavecal/autoid.py b/pypeit/core/wavecal/autoid.py index b429708b36..2ac2f41995 100644 --- a/pypeit/core/wavecal/autoid.py +++ b/pypeit/core/wavecal/autoid.py @@ -1738,10 +1738,10 @@ def run_brute(self, min_nlines=10): for slit in range(self._nslit): if slit not in self._ok_mask: self._all_final_fit[str(slit)] = None - msgs.info('Ignoring masked slit {}'.format(slit)) + msgs.info('Ignoring masked slit {}'.format(slit+1)) continue else: - msgs.info("Working on slit: {}".format(slit)) + msgs.info("Working on slit: {}".format(slit+1)) # TODO Pass in all the possible params for detect_lines to arc_lines_from_spec, and update the parset # Detect lines, and decide which tcent to use sigdetect = wvutils.parse_param(self._par, 'sigdetect', slit) @@ -1753,7 +1753,7 @@ def run_brute(self, min_nlines=10): # Were there enough lines? This mainly deals with junk slits if self._all_tcent.size < min_nlines: - msgs.warn("Not enough lines to identify in slit {0:d}!".format(slit)) + msgs.warn("Not enough lines to identify in slit {0:d}!".format(slit+1)) self._det_weak[str(slit)] = [None,None] self._det_stro[str(slit)] = [None,None] # Remove from ok mask @@ -1772,12 +1772,14 @@ def run_brute(self, min_nlines=10): # Print preliminary report good_fit[slit] = self.report_prelim(slit, best_patt_dict, best_final_fit) - # Now that all slits have been inspected, cross match to generate a + # Now that all slits have been inspected, cross match (if there are bad fit) to generate a # list of all lines in every slit, and refit all spectra - obad_slits = self.cross_match(good_fit, self._det_weak) if self._ok_mask.size > 1 else np.array([]) - if obad_slits.size > 1: + # in self.cross_match() good fits are cross correlate with each other, so we need to have at least 2 good fits + if np.where(good_fit[self._ok_mask])[0].size > 1 and np.any(np.logical_not(good_fit[self._ok_mask])): msgs.info('Checking wavelength solution by cross-correlating with all slits') + msgs.info('Cross-correlation iteration #1') + obad_slits = self.cross_match(good_fit, self._det_weak) cntr = 2 while obad_slits.size > 0: msgs.info('Cross-correlation iteration #{:d}'.format(cntr)) @@ -2859,13 +2861,12 @@ def report_final(self): for slit in range(self._nslit): # Prepare a message for bad wavelength solutions badmsg = '---------------------------------------------------' + msgs.newline() +\ - 'Final report for slit {0:d}/{1:d}:'.format(slit+1, self._nslit) + msgs.newline() +\ - ' Wavelength calibration not performed!' + 'Final report for slit {0:d}/{1:d}:'.format(slit+1, self._nslit) + msgs.newline() if slit not in self._ok_mask: - msgs.warn(badmsg) + msgs.warn(badmsg + 'Masked slit ignored') continue if self._all_patt_dict[str(slit)] is None: - msgs.warn(badmsg) + msgs.warn(badmsg + ' Wavelength calibration not performed!') continue st = str(slit) if self._all_patt_dict[st]['sign'] == +1: