Exemplo n.º 1
0
def show_recipes(args):

    drpsys = DrpSystem()

    # Query instruments
    if args.instrument:
        name = args.instrument
        res = [(name, drpsys.query_by_name(name))]
    else:
        res = drpsys.query_all().items()

    # Function to print
    if args.template:
        this_recipe_print = print_recipe_template
    else:
        this_recipe_print = print_recipe

    for name, theins in res:
        # Per instrument
        if theins:
            for pipe in theins.pipelines.values():
                for mode, recipe_fqn in pipe.recipes.items():
                    if not args.name or (recipe_fqn in args.name):
                        Cls = import_object(recipe_fqn)
                        this_recipe_print(Cls, name=recipe_fqn, insname=theins.name, pipename=pipe.name, modename=mode)
        else:
            print_no_instrument(name)
Exemplo n.º 2
0
def show_instruments(args):
    mm = DrpSystem()

    if args.name:
        for name in args.name:
            drp = mm.query_by_name(name)
            if drp:
                print_instrument(drp, modes=args.om)
            else:
                print_no_instrument(name)
    else:
        drps = mm.query_all()
        for drp in drps.values():
            print_instrument(drp, modes=args.om)
Exemplo n.º 3
0
    def __init__(self, ob_table, prod_table, req_table):
        super(BaseDictDAL, self).__init__()

        # Check that the structure de base is correct
        self.ob_table = ob_table
        self.prod_table = prod_table
        self.req_table= req_table
        self.drps = DrpSystem()
Exemplo n.º 4
0
def show_observingmodes(args):

    drpsys = DrpSystem()

    if args.instrument:
        name = args.instrument
        res = [(name, drpsys.query_by_name(name))]
    else:
        res = drpsys.query_all().items()

    for name, theins in res:
        if theins:
            for mode in theins.modes:
                if not args.name or (mode.key in args.name):
                    print_obsmode(mode, theins)
        else:
            print_no_instrument(name)
Exemplo n.º 5
0
def test_fake_pipeline(monkeypatch):
    def mockreturn(group=None):
        def fake_loader():
            confs = None
            modes = None
            pipelines = {"default": Pipeline("default", {}, 1)}
            fake = InstrumentDRP("FAKE", confs, modes, pipelines)
            return fake

        ep = pkg_resources.EntryPoint("fake", "fake.loader")
        monkeypatch.setattr(ep, "load", lambda: fake_loader)
        return [ep]

    monkeypatch.setattr(pkg_resources, "iter_entry_points", mockreturn)

    alldrps = DrpSystem().query_all()
    for k, v in alldrps.items():
        assert_valid_instrument(v)
Exemplo n.º 6
0
class BaseDictDAL(AbsDAL):
    def __init__(self, ob_table, prod_table, req_table):
        super(BaseDictDAL, self).__init__()

        # Check that the structure de base is correct
        self.ob_table = ob_table
        self.prod_table = prod_table
        self.req_table= req_table
        self.drps = DrpSystem()

    def search_oblock_from_id(self, obsid):
        try:
            ob = self.ob_table[obsid]
            return ObservingBlock(**ob)
        except KeyError:
            raise NoResultFound("oblock with id %d not found" % obsid)

    def search_recipe(self, ins, mode, pipeline):
        recipe_fqn = self.search_recipe_fqn(ins, mode, pipeline)
        klass = import_object(recipe_fqn)
        return klass

    def search_recipe_fqn(self, ins, mode, pipename):

        drp = self.drps.query_by_name(ins)

        this_pipeline = drp.pipelines[pipename]
        recipes = this_pipeline.recipes
        recipe_fqn = recipes[mode]
        return recipe_fqn

    def search_recipe_from_ob(self, ob, pipeline):
        ins = ob.instrument
        mode = ob.mode
        return self.search_recipe(ins, mode, pipeline)

    def search_prod_obsid(self, ins, obsid, pipeline):
        '''Returns the first coincidence...'''
        ins_prod = self.prod_table[ins]

        # search results of these OBs
        for prod in ins_prod.values():
            if prod['ob'] == obsid:
                # We have found the result, no more checks
                return StoredProduct(**prod)
        else:
            raise NoResultFound('result for ob %i not found' % obsid)

    def search_prod_req_tags(self, req, ins, tags, pipeline):
        return self.search_prod_type_tags(req.type, ins, tags, pipeline)

    def search_prod_type_tags(self, tipo, ins, tags, pipeline):
        """Returns the first coincidence..."""

        klass = tipo.__class__
        drp = self.drps.query_by_name(ins)
        label = product_label(drp, klass)

        # search results of these OBs
        for prod in self.prod_table[ins]:
            pk = prod['type'] 
            pt = prod['tags']
            if pk == label and tags_are_valid(pt, tags):
                # this is a valid product
                # We have found the result, no more checks
                # Make a copy
                rprod = dict(prod)
                rprod['content'] = load(tipo, prod['content'])
                return StoredProduct(**rprod)
        else:
            msg = 'type %s compatible with tags %r not found' % (klass, tags)
            raise NoResultFound(msg)
    
    def search_param_req(self, req, instrument, mode, pipeline):

        req_table_ins = self.req_table.get(instrument, {})
        req_table_insi_pipe = req_table_ins.get(pipeline, {})
        mode_keys = req_table_insi_pipe.get(mode, {})
        if req.dest in mode_keys:
            value = mode_keys[req.dest]
            content = StoredParameter(value)
            return content
        else:
            raise NoResultFound("No parameters for %s mode, pipeline %s", mode, pipeline)            

    def obsres_from_oblock_id(self, obsid):
        este = self.ob_table[obsid]
        obsres = obsres_from_dict(este)

        this_drp = self.drps.query_by_name(obsres.instrument)
        tagger = None
        for mode in this_drp.modes:
            if mode.key == obsres.mode:
                tagger = mode.tagger
                break
        else:
            raise ValueError('no mode for %s in instrument %s' % (obsres.mode, obsres.instrument))

        if tagger is None:
            master_tags = {}
        else:
            master_tags = tagger(obsres)

        obsres.tags = master_tags
        return obsres
Exemplo n.º 7
0
 def __init__(self, ob_table, reqs):
     self.ob_table = ob_table
     self._reqs = reqs
     self.drps = DrpSystem()
Exemplo n.º 8
0
class ComandLineDAL(AbsDAL):
    '''A DAL to use with the command line interface'''

    def __init__(self, ob_table, reqs):
        self.ob_table = ob_table
        self._reqs = reqs
        self.drps = DrpSystem()

    def search_rib_from_ob(self, obsres, pipeline):
        return None

    def obsres_from_oblock_id(self, obsid):
        este = self.ob_table[obsid]
        obsres = obsres_from_dict(este)

        this_drp = self.drps.query_by_name(obsres.instrument)
        tagger = None
        for mode in this_drp.modes:
            if mode.key == obsres.mode:
                tagger = mode.tagger
                break
        else:
            raise ValueError(
                'no mode for {0}.mode in instrument {0}.instrument'.format(
                    obsres))

        if tagger is None:
            master_tags = {}
        else:
            master_tags = tagger(obsres)

        obsres.tags = master_tags
        return obsres

    def search_oblock_from_id(self, obsid):
        try:
            ob = self.ob_table[obsid]
            return ObservingBlock(**ob)
        except KeyError:
            raise NoResultFound("oblock with id %d not found" % obsid)

    def search_recipe_from_ob(self, obsres, pipeline):

        _logger.info("Identifier of the observation result: %d", obsres.id)

        _logger.info("instrument name: %s", obsres.instrument)
        my_ins = self.drps.query_by_name(obsres.instrument)
        if my_ins is None:
            raise ValueError('no instrument named %r' % obsres.instrument)

        my_pipe = my_ins.pipelines.get(pipeline)

        if my_pipe is None:
            raise ValueError('no pipeline named %r' % pipeline)

        _logger.info("observing mode: %r", obsres.mode)

        recipe_fqn = my_pipe.recipes.get(obsres.mode)
        recipeclass = import_object(recipe_fqn)

        return recipeclass

    def search_prod_type_tags(self, typo, ins, tags, pipeline):
        '''Returns the first coincidence...'''
        _logger.debug('search for instrument %s, type %s with tags %s',
                      ins, typo, tags)
        return StoredProduct(id=100, content='null.fits', tags={})

    def search_prod_req_tags(self, req, ins, tags, pipeline):
        """Returns the first coincidence..."""
        _logger.debug('search for instrument %s, req %s with tags %s',
                      ins, req, tags)
        key = req.dest
        try:
            product = self._reqs['requirements'][key]
            content = storage.load(req.type, product)
        except KeyError:
            raise NoResultFound("key %s not found" % key)

        return StoredProduct(id=-1, content=content, tags={})

    def search_prod_obsid(self, ins, obsid, pipeline):
        return StoredProduct(id=-1, content='null.fits', tags={})

    def search_param_req(self, req, instrument, mode, pipeline):
        key = req.dest
        _logger.debug('search for instrument %s, req %s',
                      instrument, req)
        try:
            param = self._reqs['requirements'][key]
            content = storage.load(req.type, param)

        except KeyError:
            raise NoResultFound("key %s not found" % key)
        return StoredParameter(content)