def __init__(self, fn, p0, x, y, yerr=None, plabels=None, caption=""): self.fn = fn self.x = x self.y = y self.yerr = yerr self.p0 = p0 self.p1, self.pcov = curve_fit(self.fn, self.x, self.y, p0=self.p0, sigma=yerr, absolute_sigma=(yerr is not None)) self.chisquare, self.pvalue = stats.chisquare(self.y, f_exp=self.y1, ddof=self.DF, axis=0) # Prep the table rows = [] for i, x in enumerate(self.p1): _row = [] if plabels is None: _row.append("p{}".format(i)) else: _row.append(plabels[i]) _row.append(x) _row.append(np.sqrt(self.pcov[i][i])) rows.append(_row) rows.append(["$\chi^2$", self.chisquare]) rows.append(['p', self.pvalue]) Table.__init__(self, ['Param', 'Value', 'Error'], rows, caption)
def bjobs_table(local_config=None, timeout=30, bg_run=False): bj = bjobs(local_config, timeout, bg_run) struct = [i.split() for i in bj.split("\r\n") if len(i) > 0] output = Table(struct[0], []) for line in struct[1:]: row = [line[0], line[1], line[2], line[3], line[4]] if len(line) > 10: row.append(line[5]) row.append(line[6] + " " + line[7]) row.append(line[8] + " " + line[9] + " " + line[10]) elif len(line) > 9: row.append("") row.append(line[5] + " " + line[6]) row.append(line[7] + " " + line[8] + " " + line[9]) elif len(line) > 8: row.append("") row.append(line[5] + " " + line[6]) row.append(line[7] + " " + line[8]) else: row.append("List is incorrectly formatted") row.append("List is incorrectly formatted") row.append("List is incorrectly formatted") output.insertRow(row) return output