Example #1
0
    def tfit(self,save=False,fitres=False):
        """
        A quick look at the fits to the temperature
        save - saves the plot
        fitres - plots the residuals
        """
        line = [6300,6587]
        nel = len(line)
        f = plt.figure( figsize=(6,6) )
        f.subplots_adjust(hspace=0.0001)

        ax = []
        for i in range(nel):
            p = getelnum.Getelnum(line[i])           
            elstr = p.elstr.upper()

            if i is 0:
                ax.append(plt.subplot(nel,1,i+1))
            else:
                ax.append(plt.subplot(nel,1,i+1,sharex=ax[0]))
                
            fitabund, fitpar, t,abund = postfit.tfit(line[i])    
            if fitres:
                abund = fitabund

            tarr = np.linspace(t.min(),t.max(),100)        
            ax[i].set_ylabel('[%s/H]' % elstr)
            ax[i].scatter(t,abund,color='black',s=10)
            ax[i].scatter(p.teff_sol,0.,color='red',s=30)
            ax[i].plot(tarr,np.polyval(fitpar,tarr),lw=2,color='red')        

            yerr = np.array([s.std_dev() for s in self.stats[elstr]])
            yerr = yerr.reshape((2,1))

            ax[i] = self.errpt(ax[i],(0.9,0.9),xerr=p.tefferr,yerr=yerr)
            ax[i].set_ylabel('['+elstr+'/H]')

            if i is nel-1:
                ax[i].set_xlabel('$\mathbf{ T_{eff} }$')
            else:
                ax[i].set_xticklabels('',visible=False)
                #remove overlapping zeroes
                yticks = ax[i].get_yticks()[1:]
                ax[i].set_yticks(yticks)

        if save:
            plt.savefig('Thesis/pyplots/teff.ps')
Example #2
0
def dump(file='Thesis/texcmd.tex'):
    """
    Dumps the short hands used in the latex paper.
    """

    conn = sqlite3.connect(os.environ['STARSDB'])
    cur = conn.cursor()
    lines = [6300,6587]
    el    = ['O','C']
    f = open(file,'w')
    line = []

    plotter = plotgen.Plotgen()
    ncomp,stdcomp = plotter.comp(texcmd=True)
    nstars= plotter.abundhist(texcmd=True)

    #number of different disk populations

    popnames = ['Thin','Thick','Halo','Bdr']
    popsym   = ['dn','dk','h','dn/dk']
    npoptot  = []

    for i in range(len(popnames)):
        cmd = """
SELECT count(pop_flag) FROM mystars WHERE pop_flag = "%s" 
AND
((%s) OR (%s))
""" % (popsym[i],postfit.globcut('O'),postfit.globcut('C') )

        print cmd
        cur.execute(cmd)
        npop = (cur.fetchall())[0][0]
        npoptot.append(npop)
        line.append(r'\nc{\n%s}{%i} %% # of stars in %s pop.' % (popnames[i],npop,popnames[i]))

    npoptot = np.array(npoptot).sum()
    line.append(r'\nc{\nPop}{%i} %% # of stars with pop prob' % npoptot)
    
    #Cuts specific to each line.
    
    for i in range(len(lines)):
        p = getelnum.Getelnum(el[i])
        line.append(r'\nc{\vsiniCut%s}{%i} %% vsinicut for %s' % (el[i],p.vsinicut,el[i]))

        line.append(r'\nc{\teffCut%slo}{%i} %% teff for %s' % (el[i],p.teffrng[0],el[i]))
        line.append(r'\nc{\teffCut%shi}{%i} %% teff for %s' % (el[i],p.teffrng[1],el[i]))


        fitabund,x,x,abund = postfit.tfit(lines[i])
        maxTcorr = max(np.abs(fitabund-abund))

        line.append(r'\nc{\maxT%s}{%.2f} %% max temp correction %s' % (el[i],maxTcorr,el[i]))
        line.append(r'\nc{\nComp%s}{%i} %% # of comparison stars %s' % (el[i],ncomp[i],el[i]))
        line.append(r'\nc{\StdComp%s}{%.2f} %% std of comparison stars %s' % (el[i],stdcomp[i],el[i]))
        line.append(r'\nc{\nStars%s}{%i} %% Number of stars with %s analysis' % (el[i],nstars[i],el[i]))
        

    #Values sepecific to both lines
    line.append(r'\nc{\coThresh}{%.2f} %% Theshhold for high co' % (p.coThresh))
    line.append(r'\nc{\scatterCut}{%.2f} %% Cut on the scatter' % (p.scattercut))
    line.append(r'\nc{\teffSol}{%i} %% Solar Effective Temp' % (p.teff_sol))


    statdict = plotter.exo(texcmd=True)
    for pop in statdict.keys():
        for elstr in statdict[pop].keys():
            for moment in statdict[pop][elstr].keys():
                value = statdict[pop][elstr][moment]
                if moment[0] is 'n':
                    line.append(r'\nc{\%s%s%s}{%i} %% %s - %s - %s'% 
                                (pop,elstr,moment,value,pop,elstr,moment))
                else:
                    line.append(r'\nc{\%s%s%s}{%.2f} %% %s - %s - %s'% 
                                (pop,elstr,moment,value,pop,elstr,moment))


    statdict = table.dump_stars(texcmd=True)
    for key in statdict.keys():
        value = statdict[key]
        if key[0] is 'n': #treat integers a certain way
            line.append(r'\nc{\%s}{%d} %% '% (key,value))
        else:
            line.append(r'\nc{\%s}{%.2f} %% '% (key,value))

    for l in line:        
        l = l.replace('\nc','\newcommand')
        f.write(l+'\n')

    return line