Add a shot dictionary to :attr:`shots`, applying our survey's :attr:`declination`, and
        optionally averaging and merging with duplicate previous shot.
769291
def add_shot(self, shot):
        
        if not self.shots or not shot.get('TO', None) or not self.shots[-1].get('TO', None):
            return super(MergingSurvey, self).add_shot(shot)

        from_, to = shot['FROM'], shot['TO']
        prev_shot = self.shots[-1]
        prev_from, prev_to = prev_shot['FROM'], prev_shot['TO']

        if from_ == prev_from and to == prev_to:
            # dupe shot! calculate iterative "running" mean and merge into the previous shot
            total_count = prev_shot.dupe_count + 1

            log.debug('Merging %d shots "%s" <- "%s"', total_count, prev_shot, shot)
            if abs(shot['AZM'] - prev_shot['AZM']) > 2.0:
                log.warning('Merged forward AZM disagreement of %0.1f for "%s" <- "%s"', abs(shot['AZM'] - prev_shot['AZM']), prev_shot, shot)
            if abs(shot['INC'] - prev_shot['INC']) > 2.0:
                log.warning('Merged forward INC disagreement of %0.1f for "%s" <- "%s"', abs(shot['INC'] - prev_shot['INC']), prev_shot, shot)
            if abs(shot['LENGTH'] - prev_shot['LENGTH']) > 1.0:
                log.warning('Merged forward LENGTH disagreement of %0.1f for "%s" <- "%s"', abs(shot['LENGTH'] - prev_shot['LENGTH']), prev_shot, shot)

            avg_length = (prev_shot['LENGTH'] * prev_shot.dupe_count + shot['LENGTH']) / total_count
            avg_azm = (prev_shot['AZM'] * prev_shot.dupe_count + shot['AZM']) / total_count
            avg_inc = (prev_shot['INC'] * prev_shot.dupe_count + shot['INC']) / total_count
            merged_comments = ('%s %s' % (prev_shot.get('COMMENT', '') or '', shot.get('COMMENT', '') or '')).strip() or None

            prev_shot['LENGTH'], prev_shot['AZM'], prev_shot['INC'], prev_shot['COMMENT'] = avg_length, avg_azm, avg_inc, merged_comments
            prev_shot.dupe_count += 1

        elif from_ == prev_to and to == prev_from:
            # backsight! we do the same iterative "running" mean rather than assuming a single forward and single back
            total_count = prev_shot.dupe_count + 1
            inv_azm, inv_inc = self._inverse_azm(shot['AZM']), self._inverse_inc(shot['INC'])

            log.debug('Merging %d backsights "%s" <- "%s"', total_count, prev_shot, shot)
            if abs(inv_azm - prev_shot['AZM']) > 2.0:
                log.warning('Backsight AZM disagreement of %0.1f for "%s" <- "%s"', abs(inv_azm - prev_shot['AZM']), prev_shot, shot)
            if abs(inv_inc - prev_shot['INC']) > 2.0:
                log.warning('Backsight INC disagreement of %0.1f for "%s" <- "%s"', abs(inv_inc - prev_shot['INC']), prev_shot, shot)
            if abs(shot['LENGTH'] - prev_shot['LENGTH']) > 1.0:
                log.warning('Backsight LENGTH disagreement of %0.1f for "%s" <- "%s"', abs(shot['LENGTH'] - prev_shot['LENGTH']), prev_shot, shot)

            avg_length = (prev_shot['LENGTH'] * prev_shot.dupe_count + shot['LENGTH']) / total_count
            avg_azm = (prev_shot['AZM'] * prev_shot.dupe_count + inv_azm) / total_count
            avg_inc = (prev_shot['INC'] * prev_shot.dupe_count + inv_inc) / total_count
            merged_comments = ('%s %s' % (prev_shot.get('COMMENT', '') or '', shot.get('COMMENT', '') or '')).strip() or None

            prev_shot['LENGTH'], prev_shot['AZM'], prev_shot['INC'], prev_shot['COMMENT'] = avg_length, avg_azm, avg_inc, merged_comments
            prev_shot.dupe_count += 1

        else:
            # a new, different shot; no merge
            return super(MergingSurvey, self).add_shot(shot)
1076605
def update(self, dct):
        """"""
        d = self.__dict__.copy()
        d.update(dct)
        self.set_attrs(**d)
744425
def add_photometry(self, compare_to_existing=True, **kwargs):
        """"""
        self._add_cat_dict(
            Photometry,
            self._KEYS.PHOTOMETRY,
            compare_to_existing=compare_to_existing,
            **kwargs)
        return
242187
def addImg(self, img):
        '''
        
        '''
        # self.opts['imgs'].append(img)

        self.img = imread(img, 'gray', 'uint8')

        didFindCorners, corners = self.method()
        self.opts['foundPattern'].append(didFindCorners)

        if didFindCorners:
            self.findCount += 1
            self.objpoints.append(self.objp)
            self.opts['imgPoints'].append(corners)
        return didFindCorners
1333664
def merge(d, *dicts):
    

    for d_update in dicts:
        if not isinstance(d, dict):
            raise TypeError("{0} is not a dict".format(d))

        dict_merge_pair(d, d_update)

    return d
708777
def shot_create_asset(self, *args, **kwargs):
        
        if not self.cur_shot:
            return
        asset = self.create_asset(project=self.cur_shot.project, shot=self.cur_shot)
        if not asset:
            return
        atypes = {}
        for c in self.shot_asset_model.root.childItems:
            atypes[c.internal_data()] = c
        atypeitem = atypes.get(asset.atype)
        if not atypeitem:
            atypedata = djitemdata.AtypeItemData(asset.atype)
            atypeitem = treemodel.TreeItem(atypedata, self.shot_asset_model.root)
            atypes[asset.atype] = atypeitem
        assetdata = djitemdata.AssetItemData(asset)
        treemodel.TreeItem(assetdata, atypeitem)
751853
private void addDict(String word, String... poses){
		if(word.length() > MAX_LEN)
			MAX_LEN = word.length();
		if(word.length() < MIN_LEN)
			MIN_LEN = word.length();
		if(poses==null||poses.length==0){
			if(!dp.containsKey(word))
				dp.put(word, null);
			return;
		}

		for(int j = 0; j < poses.length; j++) {
			dp.put(word, poses[j]);
			
		}
	}
86063
def _add_to_to_ordered_dict(self, d, dataset_index, recommended_only=False):
        
        if self.doses_dropped_sessions:
            for key in sorted(list(self.doses_dropped_sessions.keys())):
                session = self.doses_dropped_sessions[key]
                session._add_single_session_to_to_ordered_dict(d, dataset_index, recommended_only)
        self._add_single_session_to_to_ordered_dict(d, dataset_index, recommended_only)
1018815
def add_substitution(self, substitution):
        
        if isinstance(substitution, dict):
            self._substitutions.append(substitution)
        else:
            self._substitutions.append(substitution.get())
429487
def shot2shot(insurvey, inshot, calculate_lrud=True):
    """"""
    # FIXME: requires angles in degrees only, no grads

    splays = insurvey.splays[inshot['FROM']]
    if calculate_lrud and not inshot.is_splay and splays:
        # Try our best to convert PocketTopo splay shots into LRUDs
        print '\n\n' 'sta %s has %d splays' % (inshot['FROM'], len(splays))

        left_azm, right_azm = (inshot['AZM'] - 90) % 360, (inshot['AZM'] + 90) % 360
        left_shot, right_shot = None, None
        left_candidates = find_candidate_splays(splays, left_azm, 0)
        if left_candidates:
            left_shot = max(left_candidates, key=lambda shot: hd(shot['INC'], shot['LENGTH']))
            left = hd(left_shot['INC'], left_shot['LENGTH'])
        else:
            left = 0
        right_candidates = find_candidate_splays(splays, right_azm, 0)
        if right_candidates:
            right_shot = max(right_candidates, key=lambda shot: hd(shot['INC'], shot['LENGTH']))
            right = hd(right_shot['INC'], right_shot['LENGTH'])
        else:
            right = 0

        print '\t' 'left=%.1f  azm=%.1f  right=%.1f' % (left_azm, inshot['AZM'], right_azm)
        print '\t' '%d candidate LEFT shots' % len(left_candidates)
        for splay in left_candidates:
            print '\t\t\t' + str(splay)
        print '\t\t' '%.1f - Chose: %s' % (left, str(left_shot))
        print '\t' '%d candidate RIGHT shots' % len(right_candidates)
        for splay in right_candidates:
            print '\t\t\t' + str(splay)
        print '\t\t' '%.1f - Chose: %s' % (right, str(right_shot))

        up_candidates = find_candidate_vert_splays(splays, 90)
        if up_candidates:
            up_shot = max(up_candidates, key=lambda splay: vd(splay['INC'], splay['LENGTH']))
            up = vd(up_shot['INC'], up_shot['LENGTH'])
        else:
            up = 0
        down_candidates = find_candidate_vert_splays(splays, -90)
        if down_candidates:
            down_shot = max(down_candidates, key=lambda splay: vd(splay['INC'], splay['LENGTH']))  # TODO: should vd() give negative and we find min()?
            down = vd(down_shot['INC'], down_shot['LENGTH'])
        else:
            down = 0

        print '\t', inshot, 'LRUD=', ', '.join(('%0.1f' % v) for v in (left, right, up, down))
        assert(all(v >=0 for v in (left, right, up, down)))
    else:
        up, down, left, right = None, None, None, None

    return compass.Shot([
        ('FROM', inshot['FROM']),
        # Compass requires a named TO station, so we must invent one for splays
        ('TO', inshot['TO'] or '%s.s%03d' % (inshot['FROM'], random.randint(0,1000))),
        ('LENGTH', m2ft(inshot.length)),
        # BEARING/AZM named inconsistently in Davies to reflect each program's arbitrary name. We
        # can't use `inshot.azm` here because we need the "raw" compass value without declination
        ('BEARING', inshot['AZM']),
        ('INC', inshot.inc),
        ('LEFT', m2ft(left) if left is not None else -9.90),
        ('UP', m2ft(up) if left is not None else -9.90),
        ('DOWN', m2ft(down) if left is not None else -9.90),
        ('RIGHT', m2ft(right) if left is not None else -9.90),  # Compass requires this order!
        # Compass 'L' flag excludes splays from cave length calculation
        ('FLAGS', (compass.Exclude.LENGTH, compass.Exclude.PLOT) if inshot.is_splay else ()),
        # COMMENTS/COMMENT named inconsistently in Davies to reflect each program's arbitrary name
        ('COMMENTS', inshot['COMMENT'])
    ])
778244
def clip(attrs, inputs, proto_obj):
    """"""
    new_attrs = translation_utils._fix_attribute_names(attrs, {'min' : 'a_min',
                                                               'max' : 'a_max'})
    if 'a_max' not in new_attrs:
        new_attrs = translation_utils._add_extra_attributes(new_attrs, {'a_max' : np.inf})
    if 'a_min' not in new_attrs:
        new_attrs = translation_utils._add_extra_attributes(new_attrs, {'a_min' : -np.inf})
    return 'clip', new_attrs, inputs
301768
def seq_create_shot(self, *args, **kwargs):
        
        if not self.cur_seq:
            return
        shot = self.create_shot(sequence=self.cur_seq)
        if shot:
            shotdata = djitemdata.ShotItemData(shot)
            treemodel.TreeItem(shotdata, self.seq_shot_model.root)
1314741
def shot(self, **kwargs):
        # type: (Any) -> str
        

        kwargs["mon"] = kwargs.get("mon", 1)
        return next(self.save(**kwargs))
567800
def update(self, dictionary):
        """"""
        allowed_attrs = list(self.__attributes__.keys())
        allowed_attrs += [a.alias for a in self.__attributes__.values()]
        for k in dictionary:
            # We only update existing attributes
            if k in allowed_attrs:
                setattr(self, k, dictionary[k])
        return self
596030
def augment(self, dct: NonAugmentedDict,
                document: Optional[YamlDocument] = None) -> AugmentedDict:
        
        Validator.instance_of(dict, raise_ex=True, dct=dct)

        # Apply any configured loader
        for instance in self._extensions:
            nodes = list(dict_find_pattern(dct, **instance.config()))
            for parent, k, val in nodes:
                parent.pop(k)
                fragment = instance.apply(
                    ExtensionContext(
                        mentor=self,
                        document=document or dct,
                        dct=dct,
                        parent_node=parent,
                        node=(k, val)
                    )
                )
                if fragment is not None:
                    parent.update(fragment)

        return dct
195248
def _flatten_obs(self, obs_dict, verbose=False):
        
        ob_lst = []
        for key in obs_dict:
            if key in self.keys:
                if verbose:
                    print("adding key: {}".format(key))
                ob_lst.append(obs_dict[key])
        return np.concatenate(ob_lst)
1321721
def add_dup(self, pkt):
        """"""
        log.debug("Recording a dup of %s", pkt)
        s = str(pkt)
        if s in self.dups:
            self.dups[s] += 1
        else:
            self.dups[s] = 1
        tftpassert(self.dups[s] < MAX_DUPS, "Max duplicates reached")