def UpdateSummary(self, values): try: self.numOfPanelCtrl.SetValue(values[0]) except: pass try: self.widthCtrl.SetValue(str(round(float(values[1]), 3))) except: pass try: self.areaCtrl.SetValue(sigfig.round_sig(float(values[2]), 3)) except: pass try: self.avgDepthCtrl.SetValue(str(round(float(values[3]), 3))) except: pass try: self.avgVelCtrl.SetValue(sigfig.round_sig(float(values[4]), 3)) except: pass try: self.totalDisCtrl.SetValue(sigfig.round_sig(float(values[5]), 3)) except: pass self.startTimeCtrl.SetValue(values[6]) self.endTimeCtrl.SetValue(values[7])
def posteriors_plot(self, traces, database, stats_dic): #Number of traces to plot n_traces = len(traces) #Declare figure format size_dict = {'figure.figsize':(14,20), 'axes.labelsize':20, 'legend.fontsize':10} self.FigConf(plotSize = size_dict, Figtype = 'Grid', n_columns = 1, n_rows = n_traces) #Generate the color map self.gen_colorList(0, n_traces) #Plot individual traces for i in range(len(traces)): #Current trace trace_code = traces[i] mean_value = stats_dic[trace_code]['mean'] trace_array = stats_dic[trace_code]['trace'] #Plot HDP limits HDP_coords = stats_dic[trace_code]['95% HPD interval'] for HDP in HDP_coords: if mean_value > 0.001: label_limits = 'HPD interval: {} - {}'.format(round_sig(HDP_coords[0], 4), round_sig(HDP_coords[1], 4)) label_mean = 'Mean value: {}'.format(round_sig(mean_value, 4)) else: label_limits = 'HPD interval: {:.3e} - {:.3e}'.format(HDP_coords[0], HDP_coords[1]) label_mean = 'Mean value: {:.3e}'.format(mean_value) self.Axis[i].axvline(x = HDP, label = label_limits, color='grey', linestyle = 'dashed') self.Axis[i].axvline(x = mean_value, label = label_mean, color='grey', linestyle = 'solid') self.Axis[i].hist(trace_array, histtype='stepfilled', bins=35, alpha=.7, color=self.get_color(i), normed=False) self.Axis[i].set_ylabel(self.labels_latex_dic[trace_code]) #Add legend self.legend_conf(self.Axis[i], loc=2)
def print_data(self, fp): fp.write("\\startdata\n") for i, data in enumerate(self.data): if self.data_labels[i] != '': if self.data_label_types == "cutin": fp.write("\\cutinhead{%s}\n" % self.data_labels[i]) else: fp.write("\\sidehead{%s}\n" % self.data_labels[i]) rows = [] print 'data=', data for j in range(numpy.shape(data[0])[0]): rows.append([]) for k in range(len(data)): sf = self.sigfigs[i][k] if len(numpy.shape(data[k])) == 1: if type(data[k][j]) in float_types: if numpy.isnan(data[k][j]): rows[-1].append('\\ldots') else: rows[-1].append( sigfig.round_sig(data[k][j], sf)) else: rows[-1].append(str(data[k][j])) else: print data[k] if numpy.isnan(data[k][j, 0]): val = "\\ldots" else: val = sigfig.round_sig_error(data[k][j, 0], data[k][j, 1], sf, paren=True) rows[-1].append(val) for row in rows: fp.write(" & ".join(row)) fp.write("\\\\\n") fp.write("\\enddata\n")
def print_data(self,fp): fp.write("\\startdata\n") for i,data in enumerate(self.data): if self.data_labels[i] != '': if self.data_label_types == "cutin": fp.write("\\cutinhead{%s}\n" % self.data_labels[i]) else: fp.write("\\sidehead{%s}\n" % self.data_labels[i]) rows = [] for j in range(numpy.shape(data[0])[0]): rows.append([]) for k in range(len(data)): sf = self.sigfigs[i][k] if len(numpy.shape(data[k])) == 1: if type(data[k][j]) in float_types: if numpy.isnan(data[k][j]): rows[-1].append('\\ldots') else: rows[-1].append(sigfig.round_sig(data[k][j], sf)) else: rows[-1].append(str(data[k][j])) else: print data[k] print 'El cosos de error', [j,0] # if numpy.isnan(data[k][j,0]): if numpy.isnan(data[k][j][0]): val = "\\ldots" else: val = sigfig.round_sig_error(data[k][j][0],data[k][j][1],sf, paren=True) rows[-1].append(val) for row in rows: fp.write(" & ".join(row)) fp.write("\\\\\n") fp.write("\\enddata\n")
def add_row(self, row, sigfig, errorup=None, errordown=None, percent=False): if sigfig is None: temp = np.array(column).reshape((1, len(temp))) else: temp = [] for i, v in enumerate(row): if (errordown is not None) and (errorup is not None): rounded = sf.round_sig_error2(v, errorup[i], errordown[i], sigfig) string = "$%s ^{+%s}_{-%s}" % rounded elif (errordown is None) and (errorup is not None): rounded = sf.round_sig_error(v, errorup[i], sigfig) string = "$%s \\pm %s" % rounded elif (errorup is None): rounded = sf.round_sig(v, sigfig) string = "$%s" % rounded if percent: string += "\\%$" else: string += "$" temp.append(string) temp = np.array(temp).reshape((1, len(temp))) if self.array is None: self.array = deepcopy(temp) else: self.array = np.vstack((self.array, temp))
lamost_id = dat['LAMOST_ID'][choose] lamost_id = np.array([fmt_id(val) for val in lamost_id]) ra = dat['RA'][choose] dec = dat['Dec'][choose] teff = dat['Teff'][choose] logg = dat['logg'][choose] mh = dat['MH'][choose] cm = dat['CM'][choose] nm = dat['NM'][choose] am = dat['AM'][choose] ak = dat['Ak'][choose] mass = dat['Mass'][choose] logAge = dat['logAge'][choose] teff = np.array([int(val) for val in teff]) logg = np.array([round_sig(val, 3) for val in logg]) mh = np.array([round_sig(val, 3) for val in mh]) cm = np.array([round_sig(val, 3) for val in cm]) nm = np.array([round_sig(val, 3) for val in nm]) am = np.array([round_sig(val, 3) for val in am]) ak = np.array([round_sig(val, 3) for val in ak]) mass = np.array([round_sig(val, 2) for val in mass]) logAge = np.array([round_sig(val, 2) for val in logAge]) teff_err = dat['Teff_err'][choose] logg_err = dat['logg_err'][choose] mh_err = dat['MH_err'][choose] cm_err = dat['CM_err'][choose] nm_err = dat['NM_err'][choose] am_err = dat['AM_err'][choose] ak_err = dat['Ak_err'][choose]
def traces_plot(self, traces, database, stats_dic): #Number of traces to plot n_traces = len(traces) #Declare figure format size_dict = {'figure.figsize':(14,20), 'axes.labelsize':12, 'legend.fontsize':14} self.FigConf(plotSize = size_dict, Figtype = 'Grid', n_columns = 1, n_rows = n_traces) #Generate the color map self.gen_colorList(0, n_traces) #Plot individual traces for i in range(n_traces): #Current trace trace_code = traces[i] trace_array = stats_dic[trace_code]['trace'] #Label for the plot mean_value = stats_dic[trace_code]['mean'] std_dev = stats_dic[trace_code]['standard deviation'] if mean_value > 0.001: label = r'{} = ${}$ $\pm${}'.format(self.labels_latex_dic[trace_code], round_sig(mean_value, 4), round_sig(std_dev, 4)) else: label = r'{} = ${:.3e}$ $\pm$ {:.3e}'.format(self.labels_latex_dic[trace_code], mean_value, std_dev) #Plot the data self.Axis[i].plot(trace_array, label=label, color = self.get_color(i)) self.Axis[i].axhline(y = mean_value, color=self.get_color(i), linestyle = '--' ) self.Axis[i].set_ylabel(self.labels_latex_dic[trace_code]) if i < n_traces - 1: self.Axis[i].set_xticklabels([]) #Add legend self.legend_conf(self.Axis[i], loc=2) return
lamost_id = dat['LAMOST_ID'][choose] lamost_id = np.array([fmt_id(val) for val in lamost_id]) ra = dat['RA'][choose] dec = dat['Dec'][choose] teff = dat['Teff'][choose] logg = dat['logg'][choose] mh = dat['MH'][choose] cm = dat['CM'][choose] nm = dat['NM'][choose] am = dat['AM'][choose] ak = dat['Ak'][choose] mass = dat['Mass'][choose] logAge = dat['logAge'][choose] teff = np.array([int(val) for val in teff]) logg = np.array([round_sig(val,3) for val in logg]) mh = np.array([round_sig(val, 3) for val in mh]) cm = np.array([round_sig(val, 3) for val in cm]) nm = np.array([round_sig(val, 3) for val in nm]) am = np.array([round_sig(val, 3) for val in am]) ak = np.array([round_sig(val, 3) for val in ak]) mass = np.array([round_sig(val, 2) for val in mass]) logAge = np.array([round_sig(val, 2) for val in logAge]) teff_err = dat['Teff_err'][choose] logg_err = dat['logg_err'][choose] mh_err = dat['MH_err'][choose] cm_err = dat['CM_err'][choose] nm_err = dat['NM_err'][choose] am_err = dat['AM_err'][choose] ak_err = dat['Ak_err'][choose]
med_a = median(the_a) med_b = median(the_b) med_c = median(the_c) med_R = median(the_R) e_a = sqrt(covmat[0, 0]) e_b = sqrt(covmat[1, 1]) e_c = sqrt(covmat[2, 2]) e_R = sqrt(covmat[3, 3]) sig = sqrt(median(the_sig)) l = ['%s(%s)' % (data.filters[i], "-".join(cf.Data.color))] l += list(sigfig.round_sig_error(med_a, e_a, 2)) l += list(sigfig.round_sig_error(med_b, e_b, 2)) l += list(sigfig.round_sig_error(med_c, e_c, 2)) l += list(sigfig.round_sig_error(med_R, e_R, 2)) l += [sigfig.round_sig(sig, 2)] outcols.append(l) outcols2 = [[sigfig.round_sig(covmat[i,j],2) for i in range(3)] \ for j in range(3)] format = "" for j in range(len(outcols[0])): maxlen = max([len(outcols[i][j]) for i in range(len(outcols))]) format += " %%%ds" % maxlen print >> f, "H0 = %.3f +\- %.3f" % (H0, eH0) print >> f, format % ('#f', 'a', '+/-', 'b', '+/-', 'c', '+/-', 'R', '+/-', 'sig') for outcol in outcols: print >> f, format % tuple(outcol)
elif f2 == -1: # something - B the_a = -a[:,f1,:] else: the_a = a[:,f2,:] - a[:,f1,:] med_a = median(the_a, axis=0) covmat = cov(the_a.T) e_a = sqrt(diag(covmat)) varc = (evar[f1] + evar[f2])/2 this_col = ['%s-%s' % (cols[0],cols[1])] for i in range(med_a.shape[0]): this_col += list(sigfig.round_sig_error(med_a[i], e_a[i], 2)) this_col += [sigfig.round_sig(sqrt(varc),2)] outcols.append(this_col) format = "" for j in range(len(outcols[0])): maxlen = max([len(outcols[i][j]) for i in range(len(outcols))]) format += " %%%ds" % maxlen labs = ['#clr'] for i in range(med_a.shape[0]): labs += ['a[%d]' % i,'+/-'] labs += ['sig'] labs = tuple(labs) print >>f, format % labs