Exemple #1
0
def load_all_tracks(file_ext='.phat',loud=False):
    '''
    loads as lists of track objects.
    '''
    from params import PHAT_TRACKS_BASE,VW_BASE,TRACKS_BASE
    track_bulge = PHAT_TRACKS_BASE+'hbz07y389/'
    btrack = [get_tracks(phat,loud=loud) for phat in get_afile(track_bulge,'*HB'+file_ext)]
    
    track_bulge_more = PHAT_TRACKS_BASE+'hbz07y389/toomanytoplot/'
    btrackmore = [get_tracks(phat,loud=loud) for phat in get_afile(track_bulge_more,'*'+file_ext)]

    track_disk = PHAT_TRACKS_BASE+'S11_Z0.017_Y0.279/'
    dtrack = [get_tracks(phat,loud=loud) for phat in get_afile(track_disk,'*'+file_ext)]
    
    # The HB tracks don't have MS...
    track_msbulge = TRACKS_BASE+'ell00/C_Z0.07_Y_0.389/'
    bmstrack = [get_tracks(phat,loud=loud) for phat in get_afile(track_msbulge,'*ENV_0.7*'+file_ext)]
    
    return btrack, btrackmore, dtrack, bmstrack
def plot_tracks(tracks):
    # e.g.
    from GenUtils import get_afile
    tracks = [get_tracks(t) for t in get_afile('/Users/Phil/research/Italy//tracks/ell00/C_Z0.07_Y_0.389/','*phat')]
    T = [Tracks.get_stable_col(t,'LOG_TE') for t in tracks]
    L = [Tracks.get_stable_col(t,'LOG_L') for t in tracks]
    M = [info_from_track_filename(i.name)['M'] for i in tracks]
    x = [plt.plot(t,l,color='black') for t,l in zip(T,L)]
    x = [plt.annotate('%.2f'%m,xy=(max(t),l[argmax(t)]),color='blue',ha='right') for m,t,l in zip(M,T,L)]
    plt.axis([5,3.2,-2,4.5])
    
    '''
Exemple #3
0
def process_zctmp(extrastr='',zctmp=None,zc=None,processed=None):
    from GenUtils import get_afile
    if zctmp == None:
        zctmp = get_afile(os.getcwd()+'/','*'+extrastr+'*.zctmp')[0]
    if zc == None:
        zc =  get_afile(os.getcwd()+'/','*'+extrastr+'*.zc')[0]
    if processed == None:
        process = zc+'.dat'
    fed = 0
    p = open(process,'w')
    zct = open(zctmp,'r').readlines()
    metalbins = map(float,zct[1].strip().split())    
    halfbins = np.diff(metalbins)/2
    halfbin = halfbins[0] # this is just the equally spaced step in metallicity
    zc_data = read_zc(zc)
    sfr = zc_data['SFR']
    sfr_err = zc_data['SFRerr1']
    for j in range(2,len(zct)):
        #zct_line = time1 time2 sfr_z1 sfr_z2 ...
        zct_line = map(float,zct[j].strip().split())
        # sfr array is shifted two indices...
        if (sfr[j-2] != 0.): 
            fracerr = sfr_err[j-2]/sfr[j-2]
        else:
            fracerr = 0.
        l = 0
        for k in range(len(metalbins)):
            l+=1
            if zct_line[1] == 10.15: 
                zct_line[1]= 10.13
                fed = 1
            p.write('%.3f %.3f %.7f %.7f %.12f %.12f \n' % \
                            (metalbins[k]-halfbin, metalbins[k]+halfbin, \
                             zct_line[0], zct_line[1], \
                             zct_line[l+1], fracerr*zct_line[l+1]))
    
    p.close()
    print 'process_zctmp wrote',process
    if fed == 1: 'warning, found age of 10.15, changed to 10.13 to work with TRILEGAL 2.0'
    return process
Exemple #4
0
'''
wrapper to run Leo's bccode.
BCDIR must be set in .cshrc
This works better than call_bccode.py.
'''

import sys,os
sys.path.append(os.environ['PYTHON_CODES'])
from GenUtils import get_afile
BCDIR = os.environ['BCDIR']

if len(sys.argv) < 3: 
    print 'usage python color_tracks.py filter res track_location'
    print 'if res = 0 full resoltion res>0 set resolution'
    print 'ex phat 0.0 /Users/Phil/research/PHAT/tracks/S11_Z0.017_Y0.279/'
    sys.exit()

filter = sys.argv[1]
res = float(sys.argv[2])
track_loc(sys.argv[3])

tracks = get_afile(track_loc,'*PMS*')

Tracks = [track+'_'+str(res) for track in tracks if res !=0]
if len(Tracks) == 0: Tracks = tracks


[os.system(' '.join((os.path.join(BCDIR,'main'),filter,track,str(res)))) for track in Tracks]
Exemple #5
0
 agb_iso_track = isotrack_dir+agbmix.split('/')[-2]+'/'
 if not os.path.isdir(agb_iso_track): 
     os.mkdir(agb_iso_track)
     print 'made dir:',agb_iso_track
 
 
 make_readme(agb_iso_track,agbmix)
 mets = [l for l in os.listdir(agbmix) if os.path.isdir(l) and l.startswith('Z')]
 mfile = open(ifmr,'w')
 mfile.write('# M_i M_f Z\n')
 
 isofiles,Zs,Ys = [],[],[]
 for met in mets:
     isofile = agb_iso_track+(met+'_'+name+'.dat').lower()
     out = open(isofile,'w')
     filenames = get_afile(agbmix+met+'/','*.dat')
     print 'found',len(filenames),'with metallicity',met
     for filename in filenames:
         addpt = []
         track =  get_numeric_data(filename)
         ntp = AGBTracks.get_col(track,'NTP')
         age = AGBTracks.get_col(track,'age/yr')
         phi = AGBTracks.get_col(track,'PHI_TP')
         logt = AGBTracks.get_col(track,'T_*')
         logl = AGBTracks.get_col(track,'L_*')
         
         TPs = get_TP_inds(ntp)
         phi[0]= -1. # The first line in the agb track is 1. This isn't the quiessent...
         
         # The Quessent phase is the the max phase in each TP, i.e., closest to 1.
         qs = [list(phi).index(np.max(phi[TP])) for TP in TPs]
Exemple #6
0
wrapper to run Leo's bccode.
BCDIR must be set in .cshrc
This works better than call_bccode.py.
'''

import sys, os

sys.path.append(os.environ['PYTHON_CODES'])
from GenUtils import get_afile

BCDIR = os.environ['BCDIR']

if len(sys.argv) < 3:
    print 'usage python color_tracks.py filter res track_location'
    print 'if res = 0 full resoltion res>0 set resolution'
    print 'ex phat 0.0 /Users/Phil/research/PHAT/tracks/S11_Z0.017_Y0.279/'
    sys.exit()

filter = sys.argv[1]
res = float(sys.argv[2])
track_loc(sys.argv[3])

tracks = get_afile(track_loc, '*PMS*')

Tracks = [track + '_' + str(res) for track in tracks if res != 0]
if len(Tracks) == 0: Tracks = tracks

[
    os.system(' '.join((os.path.join(BCDIR, 'main'), filter, track, str(res))))
    for track in Tracks
]
Exemple #7
0
    if not os.path.isdir(agb_iso_track):
        os.mkdir(agb_iso_track)
        print 'made dir:', agb_iso_track

    make_readme(agb_iso_track, agbmix)
    mets = [
        l for l in os.listdir(agbmix) if os.path.isdir(l) and l.startswith('Z')
    ]
    mfile = open(ifmr, 'w')
    mfile.write('# M_i M_f Z\n')

    isofiles, Zs, Ys = [], [], []
    for met in mets:
        isofile = agb_iso_track + (met + '_' + name + '.dat').lower()
        out = open(isofile, 'w')
        filenames = get_afile(agbmix + met + '/', '*.dat')
        print 'found', len(filenames), 'with metallicity', met
        for filename in filenames:
            addpt = []
            track = get_numeric_data(filename)
            ntp = AGBTracks.get_col(track, 'NTP')
            age = AGBTracks.get_col(track, 'age/yr')
            phi = AGBTracks.get_col(track, 'PHI_TP')
            logt = AGBTracks.get_col(track, 'T_*')
            logl = AGBTracks.get_col(track, 'L_*')

            TPs = get_TP_inds(ntp)
            phi[0] = -1.  # The first line in the agb track is 1. This isn't the quiessent...

            # The Quessent phase is the the max phase in each TP, i.e., closest to 1.
            qs = [list(phi).index(np.max(phi[TP])) for TP in TPs]
Exemple #8
0
def get_TP_inds(NTP):

def add_points_to_q_track(track,qs):

def find_dldt(track,TPs,addpt):

def diag_plots(track,logl,log    t,slopes,Qs,addpt,rising,fits,plotpath='DIAGPLOTS'):
    x = np.linspace(min(logt),max(logt))
    dd=plt.figure()
    dd=plt.title('%s %s M=%.2f'%(filename.split('/')[-3],filename.split('/')[-2],mass))
    dd=[plt.plot(x,fits[i][0]*x+fits[i][1],'--',color='blue',lw=0.5) for i in range(len(fits))]
    dd=plt.plot(logt,logl,color='black')
    dd=[plt.plot(logt[r],log    
    plt.figure()
    plt.plot(age,logt)
    plt.plot(age[Qs],logt[Qs],'o')
    plt.xlabel('age')
    plt.ylabel('Log T')
    plt.savefig(plotpath+'/diag_'+track.name.split('/')[-1].replace('.dat','age_T.png'))
    plt.close()
    
    plt.figure()
    plt.plot(age,logl)
    plt.plot(age[Qs],logl[Qs],'o')
    plt.xlabel('age')
    plt.ylabel('Log L')
    plt.savefig(plotpath+'/diag_'+track.name.split('/')[-1].replace('.dat','age_L.png'))
    plt.close()
    
    return


if __name__ == "__main__":
    
    #sources:
    agbmix = '/Users/Phil/research/Italy/WFC3SNAP/Sp2011/fromPaola/agb_full_wv/'
    name = 'agb_wv'
    
    # where to put stuff!
    trilegal_dir = '/Users/Phil/research/Italy/trilegal_1.3/'
    isotrack_dir = trilegal_dir+'isotrack/'
    agb_iso_track = isotrack_dir+agbmix.split('/')[-2]+'/'
    if not os.path.isdir(agb_iso_track): 
        os.mkdir(agb_iso_track)
        print 'made dir:',agb_iso_track
    
    readmef = agb_iso_track+'readme.txt'
    if os.path.isfile(readmef): 
        readme = open(agb_iso_track+'readme.txt','a')
        readme.write('\n --- %s --- \n'%time.strftime("%Y-%m-%d %H:%M:%S"))
    else:
        readme = open(agb_iso_track+'readme.txt','w')
    readme.write('This directory has agb tracks parsed from AGBTracksUtils. Sources are \n %s \n and within\n'%agbmix)
    readme.close()
    
    mets = [l for l in os.listdir(agbmix) if os.path.isdir(l) and l.startswith('Z')]
    
    isofiles,Zs,Ys = [],[],[]
    for met in mets:
        if met != 'Z0.019': continue
        isofile = agb_iso_track+(met+'_'+name+'.dat').lower()
        out = open(isofile,'w')
        filenames = get_afile(agbmix+met+'/','*.dat')
        print 'found',len(filenames),'with metallicity',met
        for filename in filenames:
            print filename
            skip=0
            addpt = []
            track =  get_numeric_data(filename)
            try: 
                ntp = AGBTracks.get_col(track,'NTP')
            except IndexError:
                print 'skipping',filename
                skip=1
                break
            
            TPs = get_TP_inds(ntp)
            
            age = AGBTracks.get_col(track,'age/yr')
            phi = AGBTracks.get_col(track,'PHI_TP')
            phi[0]= -1. # The first line in the agb track is 1. This isn't the quiessent...
            
            # The Quessent phase is the the max phase in each TP, i.e., closest to 1.
            qs = [list(phi).index(np.max(phi[TP])) for TP in TPs]
            Qs = qs
            logt = AGBTracks.get_col(track,'T_*')
            logl = AGBTracks.get_col(track,'L_*')
            
            mass = float(filename.split('/')[-1].split('_')[1])
            if len(Qs) <= 9 and mass < 3.: Qs,addpt = add_points_to_q_track(track,qs)
            Qs = map(int,Qs)
            rising,slopes,fits = find_dldt(track,TPs,addpt)
            
            make_iso_file(track,Qs,slopes,out)
            diag_plots(track,logl,logt,slopes,Qs,addpt,rising,fits,plotpath=met+'/DIAGPLOTS')
            plt.figure(100)
            dd=plt.plot(logt[map(int,Qs)],logl[map(int,Qs)],color='black',lw=2,label='%.2f'%(mass))
        
        out.close()    
        print 'wrote',isofile
        dd=plt.title('%s %s'%(filename.split('/')[-3],filename.split('/')[-2]))
        dd=plt.axis([3.74,3.35,2.8,4.5])
        plt.savefig('_'.join((filename.split('/')[-3],filename.split('/')[-2]))+'.png')
        if skip==0:
            isofiles.append(isofile)
            Ys.append(AGBTracks.get_col(track,'Y')[0])
            Zs.append(float(met.replace('Z','')))
        
    tracce = 'tracce_'+name+'.dat'
    metfile = make_met_file(tracce,Zs,Ys,isofiles)
    print 'wrote',tracce
    cmd_input_name = 'cmd_input_'+name+'.dat'
    cmd_input = make_cmd_input(cmd_input_name,tracce)
    print 'wrote',cmd_input_name





'''
Exemple #9
0
def read_all_asts(verts):
    '''
    Reads dolphot ast output. 20 columns of photometry data + 170 columns of dolphot out.
    verts is the vertices of some region where to kick out the rest of the ASTs.
    '''
    ra = dec = mag1in = mag2in = objtype = np.array([])
    mag1out = mag1err = snr1 = round1 = crowd1 = sharp1 = qflag1 = np.array([])
    mag2out = mag2err = snr2 = round2 = crowd2 = sharp2 = qflag2 = np.array([])

    names = [
        'X', 'Y', 'mag1in', 'mag2in', 'objtype', 'mag1out', 'mag1err', 'snr1',
        'sharp1', 'round1', 'crowd1', 'qflag1', 'mag2out', 'mag2err', 'snr2',
        'sharp2', 'round2', 'crowd2', 'qflag2'
    ]

    allfakes = get_afile('/astro/net/angst2/philrose/PHAT/simulated_data/',
                         '*fake')
    for fake in allfakes:
        #print '# '+fake
        drz = fake.replace('all.fake', 'F336W_drz.chip1.fits')
        proj = wcs.Projection(pyfits.open(drz)[0].header)

        t = np.genfromtxt(fake,
                          unpack=True,
                          usecols=(2, 3, 5, 15, 30, 33, 35, 37, 38, 39, 40, 46,
                                   49, 51, 53, 54, 55, 56, 62),
                          names=names)

        tra, tdec = proj.toworld((t['X'], t['Y']))
        points = np.column_stack((tra, tdec))
        inds = np.nonzero(nxutils.points_inside_poly(points, verts))[0]
        ra = np.append(ra, tra[inds])
        dec = np.append(dec, tdec[inds])
        mag1in = np.append(mag1in, t['mag1in'][inds])
        mag2in = np.append(mag2in, t['mag2in'][inds])
        objtype = np.append(objtype, t['objtype'][inds])
        mag1out = np.append(mag1out, t['mag1out'][inds])
        mag1err = np.append(mag1err, t['mag1err'][inds])
        snr1 = np.append(snr1, t['snr1'][inds])
        sharp1 = np.append(sharp1, t['sharp1'][inds])
        round1 = np.append(round1, t['round1'][inds])
        crowd1 = np.append(crowd1, t['crowd1'][inds])
        qflag1 = np.append(qflag1, t['qflag1'][inds])
        mag2out = np.append(mag2out, t['mag2out'][inds])
        mag2err = np.append(mag2err, t['mag2err'][inds])
        snr2 = np.append(snr2, t['snr2'][inds])
        sharp2 = np.append(sharp2, t['sharp2'][inds])
        round2 = np.append(round2, t['round2'][inds])
        crowd2 = np.append(crowd2, t['crowd2'][inds])
        qflag2 = np.append(qflag2, t['qflag2'][inds])

    ast = {
        'ra': ra,
        'dec': dec,
        'mag1in': mag1in,
        'mag2in': mag2in,
        'objtype': objtype,
        'mag1out': mag1out,
        'mag1err': mag1err,
        'snr1': snr1,
        'sharp1': sharp1,
        'round1': round1,
        'crowd1': crowd1,
        'qflag1': qflag1,
        'mag2out': mag2out,
        'mag2err': mag2err,
        'snr2': snr2,
        'sharp2': sharp2,
        'round2': round2,
        'crowd2': crowd2,
        'qflag2': qflag2
    }
    return ast