Ejemplo n.º 1
0
def load_qa_frame(filename, frame=None, flavor=None):
    """ Load an existing QA_Frame or generate one, as needed

    Args:
        filename: str
        frame: Frame object, optional
        flavor: str, optional
            Type of QA_Frame

    Returns:
        qa_frame: QA_Frame object
    """
    if os.path.isfile(filename): # Read from file, if it exists
        qaframe = read_qa_frame(filename)
        log.info("Loaded QA file {:s}".format(filename))
        # Check against frame, if provided
        if frame is not None:
            for key in ['camera','expid','night','flavor']:
                assert getattr(qaframe, key) == frame.meta[key.upper()]
    else:  # Init
        if frame is None:
            log.error("QA file {:s} does not exist.  Expecting frame input".format(filename))
        qaframe = QA_Frame(frame)
    # Set flavor?
    if flavor is not None:
        qaframe.flavor = flavor
    # Return
    return qaframe
Ejemplo n.º 2
0
    def test_init_qa_fiberflat(self):
        #- Init FiberFlat dict
        qafrm = QA_Frame(self._make_frame(flavor='flat'))
        qafrm.init_fiberflat()
        assert qafrm.qa_data['FIBERFLAT']['PARAM']['MAX_RMS'] > 0.

        #- ReInit FiberFlat dict
        qafrm.init_fiberflat(re_init=True)
        assert qafrm.qa_data['FIBERFLAT']['PARAM']['MAX_RMS'] > 0.
Ejemplo n.º 3
0
    def test_init_qa_skysub(self):
        #- Init SkySub dict
        qafrm = QA_Frame(self._make_frame(flavor='dark'))
        qafrm.init_skysub()
        assert qafrm.qa_data['SKYSUB']['PARAM']['PCHI_RESID'] > 0.

        #- ReInit SkySub dict
        qafrm.init_skysub(re_init=True)
        assert qafrm.qa_data['SKYSUB']['PARAM']['PCHI_RESID'] > 0.
Ejemplo n.º 4
0
    def test_init_qa_fluxcalib(self):
        #- Init FluxCalib dict
        qafrm = QA_Frame(self._make_frame(flavor='dark'))
        qafrm.init_fluxcalib()
        assert qafrm.qa_data['FLUXCALIB']['PARAM']['MAX_ZP_OFF'] > 0.

        #- ReInit FluxCalib dict
        qafrm.init_fluxcalib(re_init=True)
        assert qafrm.qa_data['FLUXCALIB']['PARAM']['MAX_ZP_OFF'] > 0.
Ejemplo n.º 5
0
 def test_qa_frame_write_load_data(self):
     # Write
     frm0 = self._make_frame()
     qafrm0 = QA_Frame(frm0)
     write_qa_frame(self.qafile_b0, qafrm0)
     # Load
     qafrm2 = load_qa_frame(self.qafile_b0, frm0)
     assert qafrm2.night == qafrm0.night
Ejemplo n.º 6
0
 def test_io_qa_frame(self):
     nspec = 3
     nwave = 10
     wave = np.arange(nwave)
     flux = np.random.uniform(size=(nspec, nwave))
     ivar = np.ones(flux.shape)
     frame = Frame(wave, flux, ivar, spectrograph=0)
     frame.meta = dict(CAMERA='b0', FLAVOR='dark', NIGHT='20160607', EXPID=1)
     #- Init
     qaframe = QA_Frame(frame)
     qaframe.init_skysub()
     # Write
     desio_qa.write_qa_frame(self.testyfile, qaframe)
     # Read
     xqaframe = desio_qa.read_qa_frame(self.testyfile)
     # Check
     self.assertTrue(qaframe.qa_data['SKYSUB']['PARAM']['PCHI_RESID'] == xqaframe.qa_data['SKYSUB']['PARAM']['PCHI_RESID'])
     self.assertTrue(qaframe.flavor == xqaframe.flavor)
Ejemplo n.º 7
0
    def test_init_qa_skysub(self):
        #- Init SkySub dict
        qafrm = QA_Frame(self._make_frame(flavor='dark'))
        qafrm.init_skysub()
        assert qafrm.qa_data['SKYSUB']['PARAMS']['PCHI_RESID'] > 0.

        #- ReInit SkySub dict
        qafrm.init_skysub(re_init=True)
        assert qafrm.qa_data['SKYSUB']['PARAMS']['PCHI_RESID'] > 0.
Ejemplo n.º 8
0
    def test_init_qa_fluxcalib(self):
        #- Init FluxCalib dict
        qafrm = QA_Frame(self._make_frame(flavor='dark'))
        qafrm.init_fluxcalib()
        assert qafrm.qa_data['FLUXCALIB']['PARAMS']['MAX_ZP_OFF'] > 0.

        #- ReInit FluxCalib dict
        qafrm.init_fluxcalib(re_init=True)
        assert qafrm.qa_data['FLUXCALIB']['PARAMS']['MAX_ZP_OFF'] > 0.
Ejemplo n.º 9
0
    def test_init_qa_fiberflat(self):
        #- Init FiberFlat dict
        qafrm = QA_Frame(self._make_frame(flavor='flat'))
        qafrm.init_fiberflat()
        assert qafrm.qa_data['FIBERFLAT']['PARAMS']['MAX_RMS'] > 0.

        #- ReInit FiberFlat dict
        qafrm.init_fiberflat(re_init=True)
        assert qafrm.qa_data['FIBERFLAT']['PARAMS']['MAX_RMS'] > 0.
Ejemplo n.º 10
0
def read_qa_frame(filename):
    """Generate a QA_Frame object from a data file
    """
    #- check if filename is (night, expid, camera) tuple instead
    if not isinstance(filename, basestring):
        night, expid, camera = filename
        filename = findfile('qa', night, expid, camera)

    # Read
    qa_data = read_qa_data(filename)

    # Instantiate
    qaframe = QA_Frame(qa_data)

    return qaframe
Ejemplo n.º 11
0
 def test_init_qa_frame(self):
     #- Simple Init call
     qafrm1 = QA_Frame(self._make_frame(flavor='dark'))
     assert qafrm1.flavor == 'dark'
Ejemplo n.º 12
0
 def _write_qaframes(self):
     """Write QA data frame files"""
     frm0 = self._make_frame()
     frm1 = self._make_frame(camera='b1')
     qafrm0 = QA_Frame(frm0)
     qafrm1 = QA_Frame(frm1)
     # SKY
     qafrm0.init_skysub()
     qafrm1.init_skysub()
     qafrm0.qa_data['SKYSUB']['METRICS'] = {}
     qafrm1.qa_data['SKYSUB']['METRICS'] = {}
     qafrm0.qa_data['SKYSUB']['METRICS']['NSKY_FIB'] = 10
     qafrm1.qa_data['SKYSUB']['METRICS']['NSKY_FIB'] = 30
     # FLUX
     qafrm0.init_fluxcalib()
     qafrm1.init_fluxcalib()
     qafrm0.qa_data['FLUXCALIB']['METRICS'] = {}
     qafrm0.qa_data['FLUXCALIB']['METRICS']['ZP'] = 24.
     qafrm0.qa_data['FLUXCALIB']['METRICS']['RMS_ZP'] = 0.05
     qafrm1.qa_data['FLUXCALIB']['METRICS'] = {}
     qafrm1.qa_data['FLUXCALIB']['METRICS']['ZP'] = 24.5
     qafrm1.qa_data['FLUXCALIB']['METRICS']['RMS_ZP'] = 0.05
     # WRITE
     write_qa_frame(self.qafile_b0, qafrm0)
     write_qa_frame(self.qafile_b1, qafrm1)
Ejemplo n.º 13
0
 def _write_qaframes(self):
     """Write QA data frame files"""
     frm0 = self._make_frame()
     frm1 = self._make_frame(camera='b1')
     qafrm0 = QA_Frame(frm0)
     qafrm1 = QA_Frame(frm1)
     # SKY
     qafrm0.init_skysub()
     qafrm1.init_skysub()
     qafrm0.qa_data['SKYSUB']['QA'] = {}
     qafrm1.qa_data['SKYSUB']['QA'] = {}
     qafrm0.qa_data['SKYSUB']['QA']['NSKY_FIB'] = 10
     qafrm1.qa_data['SKYSUB']['QA']['NSKY_FIB'] = 30
     # FLUX
     qafrm0.init_fluxcalib()
     qafrm1.init_fluxcalib()
     qafrm0.qa_data['FLUXCALIB']['QA'] = {}
     qafrm0.qa_data['FLUXCALIB']['QA']['ZP'] = 24.
     qafrm0.qa_data['FLUXCALIB']['QA']['RMS_ZP'] = 0.05
     qafrm1.qa_data['FLUXCALIB']['QA'] = {}
     qafrm1.qa_data['FLUXCALIB']['QA']['ZP'] = 24.5
     qafrm1.qa_data['FLUXCALIB']['QA']['RMS_ZP'] = 0.05
     # WRITE
     write_qa_frame(self.qafile_b0, qafrm0)
     write_qa_frame(self.qafile_b1, qafrm1)