def calc_branch_count(self):
<EOL>self.tree_events = np.array(sorted([(n.time_before_present, len(n.clades)-<NUM_LIT:1>)<EOL>for n in self.tree.find_clades() if not n.bad_branch],<EOL>key=lambda x:-x[<NUM_LIT:0>]))<EOL>from collections import defaultdict<EOL>dn_branch = defaultdict(int)<EOL>for (t, dn) in self.tree_events:<EOL><INDENT>dn_branch[t]+=dn<EOL><DEDENT>unique_mergers = np.array(sorted(dn_branch.items(), key = lambda x:-x[<NUM_LIT:0>]))<EOL>nbranches = [[ttconf.BIG_NUMBER, <NUM_LIT:1>], [unique_mergers[<NUM_LIT:0>,<NUM_LIT:0>]+ttconf.TINY_NUMBER, <NUM_LIT:1>]]<EOL>for ti, (t, dn) in enumerate(unique_mergers[:-<NUM_LIT:1>]):<EOL><INDENT>new_n = nbranches[-<NUM_LIT:1>][<NUM_LIT:1>]+dn<EOL>next_t = unique_mergers[ti+<NUM_LIT:1>,<NUM_LIT:0>]+ttconf.TINY_NUMBER<EOL>nbranches.append([t, new_n])<EOL>nbranches.append([next_t, new_n])<EOL><DEDENT>new_n += unique_mergers[-<NUM_LIT:1>,<NUM_LIT:1>]<EOL>nbranches.append([next_t, new_n])<EOL>nbranches.append([-ttconf.BIG_NUMBER, new_n])<EOL>nbranches=np.array(nbranches)<EOL>self.nbranches = interp1d(nbranches[:,<NUM_LIT:0>], nbranches[:,<NUM_LIT:1>], kind='<STR_LIT>')<EOL>
calculates an interpolation object that maps time to the number of
concurrent branches in the tree. The result is stored in self.nbranches