def acid(self): """Association ID""" for _, constraint in self.constraints.items(): if constraint.get('is_acid', False): value = re.sub('\\\\', '', constraint['value']) try: acid = ACID(value) except ValueError: pass else: break else: id = 'a{:0>3}'.format(self.discovered_id.value) acid = ACID((id, 'DISCOVERED')) return acid
def get_candidate_list(value): """Parse the candidate list from a item value Parameters ---------- value : str The value from the item to parse. Usually item['ASN_CANDIDATE'] Returns ------- [ACID, ...] The list of parsed candidates. """ result = [] evaled = evaluate(value) if is_iterable(evaled): result = [ACID(v) for v in evaled] return result
def _add_items(self, items, meta=None, product_name_func=None, acid='o999', **kwargs): """Force adding items to the association Parameters ---------- items : [object[, ...]] A list of items to make members of the association. meta : dict A dict to be merged into the association meta information. The following are suggested to be assigned: - `asn_type` The type of association. - `asn_rule` The rule which created this association. - `asn_pool` The pool from which the exposures came from - `program` Originating observing program product_name_func : func Used if product name is 'undefined' using the class's procedures. acid : str The association candidate id to use. Since Level2 associations require it, one must be specified. Notes ----- This is a low-level shortcut into adding members, such as file names, to an association. All defined shortcuts and other initializations are by-passed, resulting in a potentially unusable association. `product_name_func` is used to define the product names instead of the default methods. The call signature is: product_name_func(item, idx) where `item` is each item being added and `idx` is the count of items. """ if meta is None: meta = {} # Setup association candidate. if acid.startswith('o'): ac_type = 'observation' elif acid.startswith('c'): ac_type = 'background' else: raise ValueError( 'Invalid association id specified: "{}"' '\n\tMust be of form "oXXX" or "c1XXX"'.format(acid) ) self._acid = ACID((acid, ac_type)) # set the default exptype exptype = 'science' for idx, item in enumerate(items, start=1): self.new_product() members = self.current_product['members'] if isinstance(item, tuple): expname = item[0] else: expname = item # check to see if kwargs are passed and if exptype is given if kwargs: if 'with_exptype' in kwargs: if item[1]: exptype = item[1] else: exptype = 'science' member = Member({ 'expname': expname, 'exptype': exptype }, item=item) members.append(member) self.update_validity(member) self.update_asn() # If a product name function is given, attempt # to use. if product_name_func is not None: try: self.current_product['name'] = product_name_func(item, idx) except Exception: logger.debug( 'Attempted use of product_name_func failed.' ' Default product name used.' ) self.data.update(meta) self.sequence = next(self._sequence)