# Path: emirdrp/core/recipe.py
# class EmirRecipe(recipes.BaseRecipe):
#     """Base clase for all EMIR Recipes
# 
# 
#     Attributes
#     ----------
#     logger :
#          recipe logger
# 
#     datamodel : EmirDataModel
# 
#     """
#     logger = logging.getLogger(__name__)
#     datamodel = emirdrp.datamodel.EmirDataModel()
# 
#     def types_getter(self):
#         imgtypes = [prods.MasterBadPixelMask,
#                     prods.MasterBias,
#                     prods.MasterDark,
#                     prods.MasterIntensityFlat,
#                     prods.MasterSpectralFlat,
#                     prods.MasterSky
#                     ]
#         getters = [cor.get_corrector_p, cor.get_corrector_b, cor.get_corrector_d,
#                    [cor.get_corrector_f, cor.get_checker], cor.get_corrector_sf, cor.get_corrector_s]
# 
#         return imgtypes, getters
# 
#     def get_filters(self):
#         import collections
#         imgtypes, getters = self.types_getter()
#         used_getters = []
#         for rtype, getter in zip(imgtypes, getters):
#             self.logger.debug('get_filters, %s  %s', rtype, getter)
#             if rtype is None:
#                 # Unconditional
#                 if isinstance(getter, collections.Iterable):
#                     used_getters.extend(getter)
#                 else:
#                     used_getters.append(getter)
#             else:
#                 # Search
#                 for key, val in self.RecipeInput.stored().items():
#                     if isinstance(val.type, rtype):
#                         if isinstance(getter, collections.Iterable):
#                             used_getters.extend(getter)
#                         else:
#                             used_getters.append(getter)
#                         break
#                 else:
#                     pass
#         return used_getters
# 
#     def init_filters_generic(self, rinput, getters, ins):
#         # with BPM, bias, dark, flat and sky
#         if numina.ext.gtc.check_gtc():
#             self.logger.debug('running in GTC environment')
#         else:
#             self.logger.debug('running outside of GTC environment')
# 
#         meta = emirdrp.processing.info.gather_info(rinput)
#         self.logger.debug('obresult info')
#         for entry in meta['obresult']:
#             self.logger.debug('frame info is %s', entry)
#         correctors = [getter(rinput, meta, ins, self.datamodel) for getter in getters]
#         flow = flowmod.SerialFlow(correctors)
#         return flow
# 
#     def init_filters(self, rinput, ins='EMIR'):
#         getters = self.get_filters()
#         return self.init_filters_generic(rinput, getters, ins)
# 
#     def aggregate_result(self, result, rinput):
#         return result


import logging
import emirdrp.core.extra as extra
import emirdrp.requirements as reqs
import emirdrp.products as prods
import emirdrp.processing.combine as comb
import emirdrp.decorators
from numina.array import combine
from numina.core import Result
from numina.core.query import Ignore
from numina.core.recipes import timeit
from numina.processing.combine import basic_processing_with_combination
from numina.util.context import manage_fits
from emirdrp.core.recipe import EmirRecipe
        processed_img = flow(c_img)

        hdr = processed_img[0].header
        self.set_base_headers(hdr)

        self.logger.debug('append BPM')
        if rinput.master_bpm is not None:
            self.logger.debug('using BPM from inputs')
            hdul_bpm = rinput.master_bpm.open()
            hdu_bpm = extra.generate_bpm_hdu(hdul_bpm[0])
        else:
            self.logger.debug('using empty BPM')
            hdu_bpm = extra.generate_empty_bpm_hdu(processed_img[0])

        # Append the BPM to the result
        processed_img.append(hdu_bpm)
        self.logger.info('end stare image (off) reduction')
        result = self.create_result(reduced_image=processed_img)

        return result


    def set_base_headers(self, hdr):
        """Set metadata in FITS headers."""
        hdr = super(StareImageRecipe2, self).set_base_headers(hdr)
        # Set EXP to 0
        hdr['EXP'] = 0
        return hdr



# Path: emirdrp/core/recipe.py
# class EmirRecipe(recipes.BaseRecipe):
#     """Base clase for all EMIR Recipes
# 
# 
#     Attributes
#     ----------
#     logger :
#          recipe logger
# 
#     datamodel : EmirDataModel
# 
#     """
#     logger = logging.getLogger(__name__)
#     datamodel = emirdrp.datamodel.EmirDataModel()
# 
#     def types_getter(self):
#         imgtypes = [prods.MasterBadPixelMask,
#                     prods.MasterBias,
#                     prods.MasterDark,
#                     prods.MasterIntensityFlat,
#                     prods.MasterSpectralFlat,
#                     prods.MasterSky
#                     ]
#         getters = [cor.get_corrector_p, cor.get_corrector_b, cor.get_corrector_d,
#                    [cor.get_corrector_f, cor.get_checker], cor.get_corrector_sf, cor.get_corrector_s]
# 
#         return imgtypes, getters
# 
#     def get_filters(self):
#         import collections
#         imgtypes, getters = self.types_getter()
#         used_getters = []
#         for rtype, getter in zip(imgtypes, getters):
#             self.logger.debug('get_filters, %s  %s', rtype, getter)
#             if rtype is None:
#                 # Unconditional
#                 if isinstance(getter, collections.Iterable):
#                     used_getters.extend(getter)
#                 else:
#                     used_getters.append(getter)
#             else:
#                 # Search
#                 for key, val in self.RecipeInput.stored().items():
#                     if isinstance(val.type, rtype):
#                         if isinstance(getter, collections.Iterable):
#                             used_getters.extend(getter)
#                         else:
#                             used_getters.append(getter)
#                         break
#                 else:
#                     pass
#         return used_getters
# 
#     def init_filters_generic(self, rinput, getters, ins):
#         # with BPM, bias, dark, flat and sky
#         if numina.ext.gtc.check_gtc():
#             self.logger.debug('running in GTC environment')
#         else:
#             self.logger.debug('running outside of GTC environment')
# 
#         meta = emirdrp.processing.info.gather_info(rinput)
#         self.logger.debug('obresult info')
#         for entry in meta['obresult']:
#             self.logger.debug('frame info is %s', entry)
#         correctors = [getter(rinput, meta, ins, self.datamodel) for getter in getters]
#         flow = flowmod.SerialFlow(correctors)
#         return flow
# 
#     def init_filters(self, rinput, ins='EMIR'):
#         getters = self.get_filters()
#         return self.init_filters_generic(rinput, getters, ins)
# 
#     def aggregate_result(self, result, rinput):
#         return result


# Path: emirdrp/recipes/image/stare.py
import logging
import emirdrp.core.extra as extra
import emirdrp.requirements as reqs
import emirdrp.products as prods
import emirdrp.processing.combine as comb
import emirdrp.decorators
from numina.array import combine
from numina.core import Result
from numina.core.query import Ignore
from numina.core.recipes import timeit
from numina.processing.combine import basic_processing_with_combination
from numina.util.context import manage_fits
from emirdrp.core.recipe import EmirRecipe

        processed_img = flow(c_img)

        hdr = processed_img[0].header
        self.set_base_headers(hdr)

        self.logger.debug('append BPM')
        if rinput.master_bpm is not None:
            self.logger.debug('using BPM from inputs')
            hdul_bpm = rinput.master_bpm.open()
            hdu_bpm = extra.generate_bpm_hdu(hdul_bpm[0])
        else:
            self.logger.debug('using empty BPM')
            hdu_bpm = extra.generate_empty_bpm_hdu(processed_img[0])

        # Append the BPM to the result
        processed_img.append(hdu_bpm)
        self.logger.info('end stare image (off) reduction')
        result = self.create_result(reduced_image=processed_img)

        return result


    def set_base_headers(self, hdr):
        """Set metadata in FITS headers."""
        hdr = super(StareImageRecipe2, self).set_base_headers(hdr)
        # Set EXP to 0
        hdr['EXP'] = 0
        return hdr



class StareImageBaseRecipe(EmirRecipe):