Example #1
0
def test_step_by_step(master_dir):
    # Masters
    spectrograph = load_spectrograph('shane_kast_blue')
    msarc, tslits_dict, mstrace = load_kast_blue_masters(aimg=True, tslits=True)
    # Instantiate
    master_key = 'A_1_01'
    parset = spectrograph.default_pypeit_par()
    par = parset['calibrations']['tilts']
    wavepar = parset['calibrations']['wavelengths']
    waveTilts = wavetilts.WaveTilts(msarc, tslits_dict, spectrograph, par, wavepar,
                                    det=1, master_key=master_key,
                                    master_dir=master_dir,reuse_masters=True)
    # Extract arcs
    arccen, maskslits = waveTilts.extract_arcs(waveTilts.slitcen, waveTilts.slitmask, msarc, waveTilts.inmask)
    assert arccen.shape == (2048,1)
    # Tilts in the slit
    slit = 0
    waveTilts.slitmask = pixels.tslits2mask(waveTilts.tslits_dict)
    thismask = waveTilts.slitmask == slit
    waveTilts.lines_spec, waveTilts.lines_spat = waveTilts.find_lines(arccen[:, slit], waveTilts.slitcen[:, slit], slit)

    trcdict = waveTilts.trace_tilts(waveTilts.msarc, waveTilts.lines_spec, waveTilts.lines_spat, thismask, slit)
    assert isinstance(trcdict, dict)
    # 2D Fit
    spat_order = waveTilts._parse_param(waveTilts.par, 'spat_order', slit)
    spec_order = waveTilts._parse_param(waveTilts.par, 'spec_order', slit)
    coeffs = waveTilts.fit_tilts(trcdict, thismask, waveTilts.slitcen[:, slit], spat_order, spec_order,slit, doqa=False)
    tilts = tracewave.fit2tilts(waveTilts.slitmask_science.shape, coeffs, waveTilts.par['func2d'])
    assert np.max(tilts) < 1.01
Example #2
0
def test_run(master_dir):
    # Masters
    spectrograph = load_spectrograph('shane_kast_blue')
    msarc, tslits_dict, mstrace = load_kast_blue_masters(aimg=True, tslits=True)
    # Instantiate
    master_key = 'A_1_01'
    spectrograph.detector[0]['saturation'] = 60000.
    spectrograph.detector[0]['nonlinear'] = 0.9
    par = pypeitpar.WaveTiltsPar()
    wavepar = pypeitpar.WavelengthSolutionPar()
    waveTilts = wavetilts.WaveTilts(msarc, tslits_dict, spectrograph, par, wavepar,
                                    det=1, master_key=master_key,
                                    master_dir=master_dir, reuse_masters=True)
    # Run
    tilts_dict, mask = waveTilts.run(doqa=False)
    assert isinstance(tilts_dict['tilts'], np.ndarray)
Example #3
0
def test_wavetilts():
    #
    wvtilts = wavetilts.WaveTilts(**instant_dict)
    # I/O
    outfile = data_path('tst_wavetilts.fits')
    wvtilts.to_file(outfile, overwrite=True)
    _wvtilts = wavetilts.WaveTilts.from_file(outfile)

    # Test
    for key in instant_dict.keys():
        if isinstance(instant_dict[key], np.ndarray):
            assert np.array_equal(wvtilts[key],_wvtilts[key])
        else:
            assert wvtilts[key] == _wvtilts[key]
    # Write again
    wvtilts.to_file(outfile, overwrite=True)
    os.remove(outfile)
Example #4
0
    def get_tilts(self):
        """
        Load or generate the tilts image

        Requirements:
           msarc, tslits_dict, wv_calib
           det, par, spectrograph

        Returns:
            dict, ndarray: :attr:`tilts_dict` dictionary with tilts information (2D)
            and the updated slit mask array

        """
        # Check for existing data
        if not self._chk_objs(['msarc', 'msbpm', 'tslits_dict', 'wv_calib']):
            msgs.error('dont have all the objects')
            self.tilts_dict = None
            self.wt_maskslits = np.zeros_like(self.maskslits, dtype=bool)
            self.tslits_dict['maskslits'] += self.wt_maskslits
            return self.tilts_dict

        # Check internals
        self._chk_set(['det', 'calib_ID', 'par'])
        if 'arc' not in self.master_key_dict.keys():
            msgs.error('Arc master key not set.  First run get_arc.')

        # Return existing data
        if self._cached('tilts_dict', self.master_key_dict['arc']) \
                and self._cached('wtmask', self.master_key_dict['arc']):
            self.tilts_dict = self.calib_dict[
                self.master_key_dict['arc']]['tilts_dict']
            self.wt_maskslits = self.calib_dict[
                self.master_key_dict['arc']]['wtmask']
            self.tslits_dict['maskslits'] += self.wt_maskslits
            return self.tilts_dict

        # Instantiate
        self.waveTilts = wavetilts.WaveTilts(
            self.msarc,
            self.tslits_dict,
            self.spectrograph,
            self.par['tilts'],
            self.par['wavelengths'],
            det=self.det,
            master_key=self.master_key_dict['arc'],
            master_dir=self.master_dir,
            reuse_masters=self.reuse_masters,
            qa_path=self.qa_path,
            msbpm=self.msbpm)
        # Master
        self.tilts_dict = self.waveTilts.load()
        if self.tilts_dict is None:
            # TODO still need to deal with syntax for LRIS ghosts. Maybe we don't need it
            self.tilts_dict, self.wt_maskslits \
                    = self.waveTilts.run(maskslits=self.tslits_dict['maskslits'], doqa=self.write_qa,
                                         show=self.show)
            if self.save_masters:
                self.waveTilts.save()
        else:
            self.wt_maskslits = np.zeros_like(self.tslits_dict['maskslits'],
                                              dtype=bool)

        # Save & return
        self._update_cache('arc', ('tilts_dict', 'wtmask'),
                           (self.tilts_dict, self.wt_maskslits))
        self.tslits_dict['maskslits'] += self.wt_maskslits
        return self.tilts_dict
    # Get Tilts from scienceB image
    aImage = arcimage.ArcImage(spectrograph,
                               file_list=args.sciBfiles,
                               par=par['calibrations']['arcframe'])
    msarc = aImage.process(bias_subtract='overscan',
                           trim=False)
    pixlocn = pixels.gen_pixloc(aImage.stack.shape)
    bpm = spectrograph.bpm(shape=msarc.shape, det=1)
    # Extract spectrum at the center
    arccen, mask, _ = arc.get_censpec(tslits_dict['lcen'],
                                      tslits_dict['rcen'],
                                      pixlocn,
                                      msarc,
                                      1)
    waveTilts = wavetilts.WaveTilts(msarc, spectrograph=spectrograph,
                                    par=par['calibrations']['tilts'], det=1,
                                    tslits_dict=tslits_dict, pixlocn=pixlocn)
    nslits = tslits_dict['lcen'].shape[1]
    maskslits = np.zeros(nslits, dtype=bool)
    # QA is not working here
    mstilts, wt_maskslits = waveTilts.run(maskslits=maskslits,
                                          wv_calib=None,
                                          doqa=False)

    # Wavelength calibration from scienceB image
    arcparam = {}
    spectrograph.setup_arcparam(arcparam)
    setup = 'NIRES'
    waveCalib = wavecalib.WaveCalib(msarc,
                                    spectrograph=spectrograph,
                                    #par=par['calibrations']['wavelengths'],
Example #6
0
def load_kast_blue_masters(get_spectrograph=False, aimg=False, tslits=False, tilts=False,
                           datasec=False, wvcalib=False):
    """
    Load up the set of shane_kast_blue master frames

    Args:
        get_spectrograph:
        aimg:
        tslits:
        tilts:
        datasec:
        wvcalib:

    Returns:

    """

    spectrograph = load_spectrograph('shane_kast_blue')
    spectrograph.naxis = (2112,350)     # Image shape with overscan

    root_path = data_path('MF') if os.getenv('PYPEIT_DEV') is None \
                    else os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked', 'MF')
    master_dir = root_path+'_'+spectrograph.spectrograph

    reuse_masters = True

    # Load up the Masters
    ret = []

    if get_spectrograph:
        ret.append(spectrograph)

    master_key = 'A_1_01'
    if aimg:
        AImg = arcimage.ArcImage(spectrograph, master_key=master_key, master_dir=master_dir, reuse_masters=reuse_masters)
        msarc, _ = AImg.load_master(AImg.ms_name)
        ret.append(msarc)

    if tslits:
        traceSlits = traceslits.TraceSlits(None,spectrograph,None)
        # TODO: Should this be json now?
        tslits_dict, mstrace = traceSlits.load_master(os.path.join(master_dir,'MasterTrace_A_1_01.fits'))
        # This is a bit of a hack, but I'm adding the mstrace to the dict since we need it in the flat field test
        tslits_dict['mstrace'] = mstrace
        ret.append(tslits_dict)

    if tilts:
        wvTilts = wavetilts.WaveTilts(None, None, spectrograph, None, None, master_key=master_key,
                                      master_dir=master_dir, reuse_masters=reuse_masters)
        tilts_dict, _ = wvTilts.master()
        ret.append(tilts_dict)

    if datasec:
        datasec_img = spectrograph.get_datasec_img(data_path('b1.fits.gz'), 1)
        ret.append(datasec_img)

    if wvcalib:
        Wavecalib = wavecalib.WaveCalib(None, None, spectrograph,
                                        spectrograph.default_pypeit_par()['calibrations']['wavelengths'],
                                        master_key=master_key,
                                        master_dir=master_dir, reuse_masters=reuse_masters)
        wv_calib, _ = Wavecalib.master()
        ret.append(wv_calib)


    # Return
    return ret