def echelle_2dfit(self, wv_calib, debug=False, skip_QA=False): """ Evaluate 2-d wavelength solution for echelle data. Unpacks wv_calib for slits to be input into arc.fit2darc Args: wv_calib (dict): Wavelength calibration debug (bool, optional): Show debugging info skip_QA (bool, optional): Skip QA Returns: dict: dictionary containing information from 2-d fit """ msgs.info('Fitting 2-d wavelength solution for echelle....') all_wave = np.array([], dtype=float) all_pixel = np.array([], dtype=float) all_order = np.array([], dtype=float) # Obtain a list of good slits ok_mask = np.where(~self.maskslits)[0] nspec = self.msarc.shape[0] for islit in wv_calib.keys(): if int(islit) not in ok_mask: continue iorder = self.spectrograph.slit2order(islit) mask_now = wv_calib[islit]['mask'] all_wave = np.append(all_wave, wv_calib[islit]['wave_fit'][mask_now]) all_pixel = np.append(all_pixel, wv_calib[islit]['pixel_fit'][mask_now]) all_order = np.append( all_order, np.full_like(wv_calib[islit]['pixel_fit'][mask_now], float(iorder))) fit2d_dict = arc.fit2darc(all_wave, all_pixel, all_order, nspec, nspec_coeff=self.par['ech_nspec_coeff'], norder_coeff=self.par['ech_norder_coeff'], sigrej=self.par['ech_sigrej'], debug=debug) self.steps.append(inspect.stack()[0][3]) # QA if not skip_QA: outfile_global = qa.set_qa_filename(self.master_key, 'arc_fit2d_global_qa', out_dir=self.qa_path) arc.fit2darc_global_qa(fit2d_dict, outfile=outfile_global) outfile_orders = qa.set_qa_filename(self.master_key, 'arc_fit2d_orders_qa', out_dir=self.qa_path) arc.fit2darc_orders_qa(fit2d_dict, outfile=outfile_orders) return fit2d_dict
def echelle_2dfit(self, wv_calib, debug=False, skip_QA=False): """ Fit a two-dimensional wavelength solution for echelle data. Primarily a wrapper for :func:`pypeit.core.arc.fit2darc`, using data unpacked from the ``wv_calib`` dictionary. Args: wv_calib (:obj:`dict`): Wavelength calibration dictionary. See ?? debug (:obj:`bool`, optional): Show debugging info skip_QA (:obj:`bool`, optional): Flag to skip construction of the nominal QA plots. Returns: :obj:`dict`: Dictionary containing information from 2-d fit. """ if self.spectrograph.pypeline != 'Echelle': msgs.error( 'Cannot execute echelle_2dfit for a non-echelle spectrograph.') msgs.info('Fitting 2-d wavelength solution for echelle....') all_wave = np.array([], dtype=float) all_pixel = np.array([], dtype=float) all_order = np.array([], dtype=float) # Obtain a list of good slits ok_mask_idx = np.where(np.invert(self.wvc_bpm))[0] ok_mask_order = self.slits.slitord_id[ok_mask_idx] nspec = self.msarc.image.shape[0] for iorder in wv_calib.keys(): # Spatial based if int(iorder) not in ok_mask_order: continue #try: # iorder, iindx = self.spectrograph.slit2order(self.spat_coo[self.slits.spatid_to_zero(int(islit))]) #except: # embed() mask_now = wv_calib[iorder]['mask'] all_wave = np.append(all_wave, wv_calib[iorder]['wave_fit'][mask_now]) all_pixel = np.append(all_pixel, wv_calib[iorder]['pixel_fit'][mask_now]) all_order = np.append( all_order, np.full_like(wv_calib[iorder]['pixel_fit'][mask_now], float(iorder))) # Fit fit2d_dict = arc.fit2darc(all_wave, all_pixel, all_order, nspec, nspec_coeff=self.par['ech_nspec_coeff'], norder_coeff=self.par['ech_norder_coeff'], sigrej=self.par['ech_sigrej'], debug=debug) self.steps.append(inspect.stack()[0][3]) # QA if not skip_QA: outfile_global = qa.set_qa_filename(self.master_key, 'arc_fit2d_global_qa', out_dir=self.qa_path) arc.fit2darc_global_qa(fit2d_dict, outfile=outfile_global) outfile_orders = qa.set_qa_filename(self.master_key, 'arc_fit2d_orders_qa', out_dir=self.qa_path) arc.fit2darc_orders_qa(fit2d_dict, outfile=outfile_orders) return fit2d_dict
def echelle_2dfit(self, wv_calib, debug=False, skip_QA=False): """ Fit a two-dimensional wavelength solution for echelle data. Primarily a wrapper for :func:`pypeit.core.arc.fit2darc`, using data unpacked from the ``wv_calib`` dictionary. Args: wv_calib (:class:`pypeit.wavecalib.WaveCalib`): Wavelength calibration object debug (:obj:`bool`, optional): Show debugging info skip_QA (:obj:`bool`, optional): Flag to skip construction of the nominal QA plots. Returns: :class:`pypeit.fitting.PypeItFit`: object containing information from 2-d fit. """ if self.spectrograph.pypeline != 'Echelle': msgs.error( 'Cannot execute echelle_2dfit for a non-echelle spectrograph.') msgs.info('Fitting 2-d wavelength solution for echelle....') all_wave = np.array([], dtype=float) all_pixel = np.array([], dtype=float) all_order = np.array([], dtype=float) # Obtain a list of good slits ok_mask_idx = np.where(np.invert(self.wvc_bpm))[0] ok_mask_order = self.slits.slitord_id[ok_mask_idx] nspec = self.msarc.image.shape[0] # Loop for ii in range(wv_calib.nslits): iorder = self.slits.ech_order[ii] if iorder not in ok_mask_order: continue # Slurp mask_now = wv_calib.wv_fits[ii].pypeitfit.bool_gpm all_wave = np.append(all_wave, wv_calib.wv_fits[ii]['wave_fit'][mask_now]) all_pixel = np.append(all_pixel, wv_calib.wv_fits[ii]['pixel_fit'][mask_now]) all_order = np.append( all_order, np.full_like(wv_calib.wv_fits[ii]['pixel_fit'][mask_now], float(iorder))) # Fit # THIS NEEDS TO BE DEVELOPED fit2d = arc.fit2darc(all_wave, all_pixel, all_order, nspec, nspec_coeff=self.par['ech_nspec_coeff'], norder_coeff=self.par['ech_norder_coeff'], sigrej=self.par['ech_sigrej'], debug=debug) self.steps.append(inspect.stack()[0][3]) # QA # TODO -- TURN QA BACK ON! #skip_QA = True if not skip_QA: outfile_global = qa.set_qa_filename(self.master_key, 'arc_fit2d_global_qa', out_dir=self.qa_path) arc.fit2darc_global_qa(fit2d, nspec, outfile=outfile_global) outfile_orders = qa.set_qa_filename(self.master_key, 'arc_fit2d_orders_qa', out_dir=self.qa_path) arc.fit2darc_orders_qa(fit2d, nspec, outfile=outfile_orders) return fit2d
nspec =int(nires_data[str(0)]['xnorm']) for ii in nires_data.keys(): if ii != 'arcparam' and ii != 'steps': all_pix_pypeit = np.concatenate((all_pix_pypeit, np.array(nires_data[ii]['xfit'])*(np.array(nires_data[ii]['xnorm'])-1.))) t_tmp = np.full_like(np.array(nires_data[ii]['xfit']), np.float(nires_data[ii]['norder'])) # t_tmp = np.full_like(np.array(nires_data[ii]['xfit']), np.float(ii)+1.) t_pypeit = np.concatenate((t_pypeit, t_tmp)) all_wv_pypeit = np.concatenate((all_wv_pypeit, np.array(nires_data[ii]['yfit']))) ########################################################################### ########################################################################### ########################################################################### # Run the actual fit: fit_dict = arc.fit2darc(all_wv_pypeit, all_pix_pypeit, t_pypeit, nspec, debug=debug) # Plots arc.fit2darc_global_qa(fit_dict) arc.fit2darc_orders_qa(fit_dict)