def plotsummary(ax, lc, trace, **kwargs): summary = pm.summary(trace) summary['mode'] = list(utils.modes(trace).values()) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) tbl = table(ax, summary.round(3), **kwargs) tbl.set_fontsize(30) return tbl
def acfplot_withsummary(axs, lc, trace, summary_kwargs={}, acf_kwargs={}): summary = pm.summary(trace) summary['mode'] = list(utils.modes(trace).values()) plotacf(axs[0], lc, **acf_kwargs) axs[1].xaxis.set_visible(False) axs[1].yaxis.set_visible(False) table(axs[1], summary.round(3)) pl.tight_layout() return axs
def lcplot(ax, lc, trace=None, detrend_order=2, plot_outliers=False, plot_trend=False, uncertainties=False, highlight_color='r', vline_color='b', sigmaclip_kernel_size=5, sigmaclip_sigma=5, **kwargs): ax.plot(lc.t, lc.flux, '.', color='k') trend = utils.trend(lc.t, lc.flux, detrend_order) mask = utils.clipmask(lc.t, lc.flux, kernel_size=sigmaclip_kernel_size, sigma=sigmaclip_sigma) if plot_outliers: ax.plot(lc.t[mask], lc.flux[mask], '.', color=highlight_color, label='masked outliers') if plot_trend: ax.plot(lc.t, trend, color=highlight_color, label='order {0} polynomial fit'.format(detrend_order)) if trace is not None: period = utils.modes(trace)['P'] low, high = pm.stats.hpd(trace['P'], credible_interval=0.67) for i in np.arange(np.int((lc.t[-1] - lc.t[0]) / period) + 2): if not uncertainties: ax.axvline(min(lc.t) + i * period, alpha=0.3, linewidth=2, color=vline_color) if uncertainties: vlines_min = min(lc.t) + i * low vlines_max = min(lc.t) + i * high ax.axvspan(vlines_min, vlines_max, alpha=0.3, color=vline_color) ax.set_xlim((min(lc.t), max(lc.t))) return ax
def writesummary(lc, trace, file): summary = pm.summary(trace) summary['mode'] = list(utils.modes(trace).values()) columns = [ c + "_" + n for c, n in itertools.product(list(summary.index), list(summary.columns)) ] columnstring = '\t'.join(columns) columnstring += '\tepic\n' if not os.path.isfile(file): with open(file, "w") as f: f.write("Generated with round.py version 0.1 on " + "{0}\n".format( datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))) f.write("Campaign: {0}\n".format(campaign)) f.write(columnstring) summarystring = summary.to_numpy().flatten() summarystring = np.append(summarystring, lc.id) summarystring = summarystring[None, :] fmtstring = ["%0.3f"] * (summarystring.size - 1) + ["%d"] with open(file, "a+") as f: np.savetxt(f, summarystring, fmt=fmtstring, delimiter='\t') return summarystring
def detect_mode(cf): '''Given a cantus firmus as a list of ints, attempts to detect the mode and returns a tuple containing a string for the name of the mode and ints representing the notes present in the mode, assuming that the first note provided is the tonic.''' modes = u.modes() tonic = cf[0] transposed = [(note - tonic) % 12 for note in cf] sums = [(sum(1 for note in transposed if note in modes[mode]), mode) for mode in modes] max_freq = max(sums, key=lambda i: i[0])[0] filtered = [i[1] for i in sums if i[0] == max_freq] if len(filtered) == 1: notes = [(note + tonic) % 12 for note in modes[filtered[0]]] return (filtered[0], notes) else: while True: stout = "Which mode is this in: " + ", ".join(filtered) + "?\n" resp = raw_input(stout).lower() if resp in modes: notes = [(note + tonic) % 12 for note in modes[resp]] return (resp, notes) print "I didn't recognize that. Type the name of a mode.\n"