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 """ from lvmspec.qa.qa_frame import QA_Frame log=get_logger() 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
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
def test_init_qa_skysub(self): #- Init SkySub dict qafrm = QA_Frame(self._make_frame(flavor='science')) 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.
def test_init_qa_fluxcalib(self): #- Init FluxCalib dict qafrm = QA_Frame(self._make_frame(flavor='science')) 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.
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.
def read_qa_frame(filename): """Generate a QA_Frame object from a data file """ from lvmspec.qa.qa_frame import QA_Frame #- check if filename is (night, expid, camera) tuple instead if not isinstance(filename, str): 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
def _write_qaframes(self): """Write QA data frame files""" frm0 = self._make_frame(camera='b0') 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)
def test_init_qa_frame(self): #- Simple Init call qafrm1 = QA_Frame(self._make_frame(flavor='science')) assert qafrm1.flavor == 'science'