Beispiel #1
0
    def get_arc(self):
        """
        Load or generate the Arc image

        Requirements:
          master_key, det, par

        Args:

        Returns:
            ndarray: :attr:`msarc` image

        """
        # Check internals
        self._chk_set(['det', 'calib_ID', 'par'])

        # Prep
        arc_rows = self.fitstbl.find_frames('arc',
                                            calib_ID=self.calib_ID,
                                            index=True)
        self.arc_files = self.fitstbl.frame_paths(arc_rows)
        self.master_key_dict['arc'] \
                = self.fitstbl.master_key(arc_rows[0] if len(arc_rows) > 0 else self.frame,
                                          det=self.det)

        if self._cached('arc', self.master_key_dict['arc']):
            # Previously calculated
            self.msarc = self.calib_dict[self.master_key_dict['arc']]['arc']
            return self.msarc

        # Instantiate with everything needed to generate the image (in case we do)
        self.arcImage = arcimage.ArcImage(
            self.spectrograph,
            files=self.arc_files,
            det=self.det,
            msbias=self.msbias,
            par=self.par['arcframe'],
            master_key=self.master_key_dict['arc'],
            master_dir=self.master_dir,
            reuse_masters=self.reuse_masters)

        # Load the MasterFrame (if it exists and is desired)?
        self.msarc = self.arcImage.load()
        if self.msarc is None:  # Otherwise build it
            msgs.info("Preparing a master {0:s} frame".format(
                self.arcImage.frametype))
            self.msarc = self.arcImage.build_image(bias=self.msbias,
                                                   bpm=self.msbpm)
            # Save to Masters
            if self.save_masters:
                self.arcImage.save()

        # Save & return
        self._update_cache('arc', 'arc', self.msarc)
        return self.msarc
Beispiel #2
0
def load_kast_blue_masters(aimg=False,
                           edges=False,
                           tilts=False,
                           wvcalib=False,
                           pixflat=False):
    """
    Load up the set of shane_kast_blue master frames

    Order is Arc, edges, tilts_dict, wv_calib, pixflat

    Args:
        get_spectrograph:
        aimg:
        edges (bool, optional):
            Load the slit edges
        tilts:
        datasec:
        wvcalib:

    Returns:
        list: List of calibration items

    """

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

    master_dir = os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked',
                              'Shane_Kast_blue')

    reuse_masters = True

    # Load up the Masters
    ret = []

    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()
        ret.append(msarc)

    if edges:
        trace_file = '{0}.gz'.format(
            os.path.join(master_dir,
                         MasterFrame.construct_file_name('Edges', master_key)))
        ret.append(edgetrace.EdgeTraceSet.from_file(trace_file))

    if tilts:
        tilts_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Tilts', master_key))
        tilts_dict = wavetilts.WaveTilts.from_master_file(
            tilts_file).tilts_dict
        ret.append(tilts_dict)

    if wvcalib:
        calib_file = os.path.join(
            master_dir,
            MasterFrame.construct_file_name('WaveCalib',
                                            master_key,
                                            file_format='json'))
        wv_calib = waveio.load_wavelength_calibration(calib_file)
        ret.append(wv_calib)

    # Pixelflat
    if pixflat:
        calib_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Flat', master_key))
        flatField = flatfield.FlatField.from_master_file(calib_file)
        ret.append(flatField.mspixelflat)

    # Return
    return ret
Beispiel #3
0
def load_kast_blue_masters(aimg=False,
                           tslits=False,
                           tilts=False,
                           wvcalib=False,
                           pixflat=False):
    """
    Load up the set of shane_kast_blue master frames

    Order is Arc, tslits_dict, tilts_dict, wv_calib, pixflat

    Args:
        get_spectrograph:
        aimg:
        tslits (bool, optional):
            Load the tslits_dict
        tilts:
        datasec:
        wvcalib:

    Returns:
        list: List of calibration items

    """

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

    master_dir = os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked',
                              'Shane_Kast_blue')
    #    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()
        ret.append(msarc)

    if tslits:
        trace_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Trace', master_key))
        tslits_dict, mstrace = traceslits.TraceSlits.load_from_file(trace_file)
        ret.append(tslits_dict)
        ret.append(mstrace)

    if tilts:
        tilts_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Tilts', master_key))
        tilts_dict = wavetilts.WaveTilts.load_from_file(tilts_file)
        ret.append(tilts_dict)

    if wvcalib:
        calib_file = os.path.join(
            master_dir,
            MasterFrame.construct_file_name('WaveCalib',
                                            master_key,
                                            file_format='json'))
        wv_calib = waveio.load_wavelength_calibration(calib_file)
        ret.append(wv_calib)

    # Pixelflat
    if pixflat:
        flatField = flatfield.FlatField(
            spectrograph,
            spectrograph.default_pypeit_par()['calibrations']
            ['pixelflatframe'])
        calib_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Flat', master_key))
        pixelflat = flatField.load_from_file(calib_file, 2)
        ret.append(pixelflat)

    # Return
    return ret
    # ToDo -- fix ifs
    if args.show:
        gingashow = True
    ## Get tslits_dict either from flatfiles or load from a json file
    if args.flatfiles is None:
        jdict = ltu.loadjson('tilt_nires.json')
        tslits_dict = jdict.copy()
        for tkey in tslits_dict.keys():
            tslits_dict[tkey] = np.array(tslits_dict[tkey])
    else:
        tslits_dict = get_tslits_nires(args.flatfiles, user_settings=par, gingashow=gingashow)

    # 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]
Beispiel #5
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
Beispiel #6
0
def load_kast_blue_masters(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

    master_dir = os.path.join(os.getenv('PYPEIT_DEV'), 'Cooked',
                              'Shane_Kast_blue')
    #    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()
        ret.append(msarc)

    if tslits:
        trace_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Trace', master_key))
        tslits_dict, mstrace = traceslits.TraceSlits.load_from_file(trace_file)
        ret.append(tslits_dict)
        ret.append(mstrace)

    if tilts:
        tilts_file = os.path.join(
            master_dir, MasterFrame.construct_file_name('Tilts', master_key))
        tilts_dict = wavetilts.WaveTilts.load_from_file(tilts_file)
        ret.append(tilts_dict)

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

    if wvcalib:
        calib_file = os.path.join(
            master_dir,
            MasterFrame.construct_file_name('WaveCalib',
                                            master_key,
                                            file_format='json'))
        wv_calib = waveio.load_wavelength_calibration(calib_file)
        ret.append(wv_calib)

    # Return
    return ret