Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
    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")
Ejemplo n.º 3
0
	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))
    for file_ in allfiles:
        a = np.loadtxt(file_, skiprows = 1)                                  #takes normalized and phased files from Matt's matlab script output
        t = a[:,0]
        y = a[:,1]
        temp = temps[temp_counter]
        temp_counter += 1
        popt, pcov = scipy.optimize.curve_fit(monoexp, t, y, params, bounds = input_file.mono_bnds)         #least squares refinement of parameters against data
        a1, T1, b = popt          
        params = np.array([a1, T1, b])                                       #sets next temperature guess based on prev. temp refinement
        perr = np.sqrt(np.diag(pcov))                                        #converts covariance to esd
        a1_err, T1_err, b_err = perr
        
        if input_file.err_append == True:
            try:
                a1_str = sigfig.round_sig_error(a1, a1_err, 1, paren = True)       
            except:
                a1_str = '{0} +- {1}'.format(a1, a1_err)
            try:
                T1_str = sigfig.round_sig_error(T1, T1_err, 1, paren = True)
            except:
                T1_str = '{0} +- {1}'.format(T1, T1_err)
            try:
                b_str = sigfig.round_sig_error(b, b_err, 1, paren = True)
            except:    
                b_str = '{0} +- {1}'.format(b, b_err)
                
            data.append((a1_str, T1_str, b_str))                          #appends the esd to the end of the value to which it refers
        else:
            data.append((a1, T1, b))
        
Ejemplo n.º 5
0
plt.close(fig5)

# Now, let's do some triangle plots and output the parameters of interest.
# Cepheid parameters:
if corner is not None:
    tp1 = c.triangle_plot(['M', 'betaP', 'betaVI', 'betaOH'])
    tp1.savefig('Ceph_triangle.pdf')
else:
    print "Warning:  corner is not installed, so no triangle plots. To install:"
    print "pip install corner"

# Now we output some tables.
fout = open('results_table.txt', 'w')
fout.write("Cepheids\n")
fout.write("--------\n")
fout.write('M:      %s +/- %s\n' % sigfig.round_sig_error(M, e_M, 2))
fout.write('betaP:  %s +/- %s\n' % sigfig.round_sig_error(betaP, e_betaP, 2))
fout.write('betaOH:  %s +/- %s\n' %
           sigfig.round_sig_error(betaOH, e_betaOH, 2))

hosts = []
headers = ['Host', 'DM', 'betaVI']
headers += ['eps%d' % i for i in range(cfg.model.NGauss)]
cols = [[], []]
ecols = [[], []]
for i in range(cfg.model.NGauss):
    cols.append([])
    ecols.append([])

if cfg.model.use_MW:
    hosts.append('MW')
Ejemplo n.º 6
0
    arr = array(arr).T

    labs = ['$a_%d$' % j for j in range(a_s.shape[1])]
    labs = labs + ['$\epsilon_{sn}$', '$H_0$']
    #tp1 = c.triangle_plot(['M_sn:%d' % i, 'beta_st:%d' % i, 'gamma_st:%d' % i,
    #                       'eps_sn:%d' % i, 'H0'])
    tp1 = corner.corner(arr, labels=labs, truths=median(arr, axis=0))
    tp1.savefig('SN_triangle_%s.pdf' % cfg.data.sn_filt[i])
    plt.close(tp1)

# Now we output some tables.
fout = open('results_table.txt', 'w')
fout.write("SNe\n")
fout.write("---\n")
fout.write('v_pec:  %s +/- %s\n' %
           sigfig.round_sig_error(pec_vel, e_pec_vel, 2))
headers = ['filter']
headers = headers + ["a[%d]" % i for i in range(Nbasis)]
headers = headers + ["eps"]
if len(cfg.data.sn_filt) == 1:
    cols = [[a[i]] for i in range(Nbasis)] + [[eps_sn]]
    errors = [[e_a[i]] for i in range(Nbasis)] + [[e_eps_sn]]
else:
    cols = [a[i, :] for i in range(Nbasis)] + [eps_sn]
    errors = [e_a[i, :] for i in range(Nbasis)] + [e_eps_sn]
labels = cfg.data.sn_filt
print cols
lines = sigfig.format_table(cols=cols,
                            errors=errors,
                            n=2,
                            labels=labels,
Ejemplo n.º 7
0
    the_R = Rlambs[:, i]
    the_sig = evar[:, i]
    covmat = cov([the_a, the_b, the_c, the_R])

    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)
Ejemplo n.º 8
0
      the_a = a[:,f2,:]
   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)