def dictOfBigramIcTimes(listOfBigrams, df, ict_XY_l=None, label='call', ict_label='ict'): '''searches sequences (listOfBigrams) of type <label> in the dataframe and returns a dictionary with the ict_label values of the sequences Parameters ---------- listOfBigrams : list of bigrams df : pandas data frame ict_XY_l : dictionary of lists bigrams as keys and the ict of the bigrams as values label : type of sequence, or name of the column in df where to look for the sequences ict_label : str name of the column Return ------ ict_XY : dictionary with lists ICIs by bigram ''' if ict_XY_l is None: ict_XY_l = defaultdict(list) for seq in listOfBigrams: try: seqdf = daT.returnSequenceDf(df, seq, label='call') except ValueError: # sequence not found, continue with the next seq continue ky = ''.join(seq) # seqdf.head(20) ict_XY_l[ky].extend(seqdf[ict_label].values) return ict_XY_l
def pl_ic_bigram_times( df0, my_bigrams, ignoreKeys="default", label="call", oFig=None, violinInner="box", yrange="default", ylabel="time (s)", minNumBigrams=5, ): """violin plot of the ict of a my_bigrams Parameters: ----------- df0 : pandas dataframe wirth ict column mu_bigrams : sequence to search for ignoteKeys : 'default' removes ['_ini', '_end'] label : type of sequence oFig : output figure violinInner : viloin lor parameter yrange : 'default' (0, mu*2) """ if ignoreKeys == "default": ignoreKeys = ["_ini", "_end"] topBigrams = daT.removeFromList(daT.returnSortingKeys(Counter(my_bigrams)), ignoreKeys) bigrTimes = [] bigrNames = [] for seq in topBigrams: df = daT.returnSequenceDf(df0, seq, label=label) # print(len(df)) ict = df.ict.values if len(ict) > minNumBigrams: # bigrTimes[tuple(seq)] = ict[ ~ np.isnan(ict)] bigrTimes.append(ict[~np.isnan(ict)]) bigrNames.append(seq) kys = ["{}{}".format(a, b) for a, b in bigrNames] # sns.violinplot( bigrTimes, names=kys, inner=violinInner) sns.boxplot(bigrTimes, names=kys) if yrange == "default": meanVls = [np.mean(item) for item in bigrTimes if len(item) > 1] yrange = (0, np.mean(meanVls)) plt.ylim(yrange) plt.ylabel(ylabel) plt.savefig(oFig, bbox_inches="tight")