Ejemplo n.º 1
0
def getLumFun(sim,simname,bins=50,loglmin=43,loglmax=46,vol=25**3,minm=1e6,filename='LumFun.pkl'):
	munits = sim.s['mass'].units
        tunits = sim.s['x'].units/sim.s['vel'].units
        mdotunits = munits/tunits

        tbinsh =np.array([bhanalysis.getTime(zz,sim) for zz in zbinsl])
        tbinsl = np.array([bhanalysis.getTime(zz,sim) for zz in zbinsh])
        dtbins = tbinsh - tbinsl
        dlogl = np.float(loglmax-loglmin)/bins
	if not os.path.exists(simname+'.BHorbit.abridged'):  mkAbridgeOrbit(simname,sim,lmin=10**loglmin,mmin=minm)	
	mass, mdot, dm, dt, scale = readcol.readcol(simname+'.BHorbit.abridged',twod=False)
	ok, = np.where((mass - dm > minm/munits.in_units("Msol"))&(mdot > 10**loglmin/(0.1*3e10*3e10*mdotunits.in_units('g s**-1'))))
	del(dm)
	del(mass)
	gc.collect()
	mdot = pynbody.array.SimArray(mdot[ok],mdotunits)
	dt = pynbody.array.SimArray(dt[ok],tunits)
	scale = scale[ok]
	del(ok)
	gc.collect()
	lum = mdot.in_units('g s**-1')*0.1*3e10*3e10
	del(mdot)
	gc.collect()
	data = np.zeros((len(z),bins))
	for i in range(len(z)):
		print 'redshift ', z[i]
		oo, = np.where((scale**-1 -1 > zbinsl[i])&(scale**-1 -1 < zbinsh[i]))
		weights = dt[oo].in_units('Gyr')/(dtbins[i]*dlogl*vol)
		lumhist, lumbins = np.histogram(np.log10(lum[oo]),range=[loglmin,loglmax],weights=weights,bins=bins)
		data[i,:] = lumhist
		del(oo)
		gc.collect()
	del(lum)
	gc.collect()
	if filename:
		print "saving data..."
		f = open(filename,'wb')
		pickle.dump([data,lumbins],f)
		f.close()
	return data, lumbins
Ejemplo n.º 2
0
def colortime(halos=[1,2],average=False,shade=False,simdirs=['romulus8.256gst3.bwBH'],dodust=True,dustfile = 'dust.pkl',magfile = 'mags.pkl',hcol=['red','blue'],simstyle=['solid','solid'],plotData=True,simlabels=['Romulus'],hlabels=['halo 1','halo 2'],overplot=False):
	simcnt = 0
	print "number of halos", len(halos)
        for dir in simdirs:
                print "getting data for ", dir
                magf = open(dir+'/'+magfile,'rb')
                mags = pickle.load(magf)
                magf.close()
                zmax = mags['z'].max()
                zmin = mags['z'].min()
                red = mags['z']
		if dodust:
                        dustf = open(dir+'/'+dustfile,'rb')
                        dust = pickle.load(dustf)
                        dustf.close()
                hcnt = 0
		f = open(dir+'/files.list')
		files = f.readlines()
		f.close()
		s = pynbody.load(dir+'/'+files[0].strip('\n'))
		time = [bhanalysis.getTime(z,s) for z in red]
		color = np.zeros((len(halos),len(mags['v'][0])))
                for h in halos:
                        u, = np.where(np.array(mags['halos'])==h)
                        if len(u) > 1:
                                print "WARNING more than one entry in magnitudes file for halo", h, "using first entry..."
                        if len(u) == 0:
                                print "Halo", h, " not found in magnitudes file... skipping..."
                                continue
			if average==True:
				color[hcnt,:] = mags['u'][u[0]] - mags['v'][u[0]]
			else:
				color[hcnt,:] = mags['u'][u[0]] - mags['v'][u[0]]
			if dodust==True:
                                ud, = np.where(np.array(dust['halos'])==h)
                                if len(u) > 1: print "WARNING more than one entry in dust file for halo", h, "using first entry..."
                                if len(u) == 0:
                                        print "Halo", h, " not found in dust file... skipping..."
                                        continue
                                reddening =  dust['u'][ud[0]] - dust['v'][ud[0]]
                                color[hcnt,:] += reddening
			if average==False and shade==False:
				labelstr = None
                                if hlabels[hcnt] or simlabels[simcnt]: labelstr = simlabels[simcnt]+" "+hlabels[hcnt]
				plt.plot(time,color[hcnt,:],color=hcol[hcnt],linewidth=2,linestyle=simstyle[simcnt],label=labelstr)
			hcnt += 1
		if average==True and shade==False:
			labelstr = None
			if hlabels[0] or simlabels[0]: labelstr = simlabels[0]+" "+hlabels[0]
			plt.errorbar(time,color.mean(axis=0),color=hcol[0],yerr=color.std(axis=0),linewidth=2,linestyle=simstyle[simcnt],label=labelstr)
		if shade==True and average==False:
			labelstr = None
                        if hlabels[0] or simlabels[0]: labelstr = simlabels[0]+" "+hlabels[0]
			plt.fill_between(time,color.min(axis=0),color.max(axis=0),facecolor=hcol[0],alpha=0.5)	
		if shade==True and average==True:
			labelstr = None
                        if hlabels[0] or simlabels[0]: labelstr = simlabels[0]+" "+hlabels[0]
			print labelstr
			plt.plot(time,color.mean(axis=0),color=hcol[0],label=labelstr,linestyle=simstyle[simcnt],linewidth=2)
                        plt.fill_between(time,color.mean(axis=0)-color.std(axis=0),color.mean(axis=0)+color.std(axis=0),facecolor=hcol[0],alpha=0.5,label=labelstr)
		simcnt += 1
	
	if plotData == True:
		volumeAnalysis.CANDELS_M31['Time'] = [bhanalysis.getTime(z,s) for z in volumeAnalysis.CANDELS_M31['redshift']]
	        volumeAnalysis.CANDELS_MW['Time'] = [bhanalysis.getTime(z,s) for z in volumeAnalysis.CANDELS_MW['redshift']]
		plt.errorbar(volumeAnalysis.CANDELS_M31['Time'],volumeAnalysis.CANDELS_M31['UV'],yerr=[volumeAnalysis.CANDELS_M31['UV-'],volumeAnalysis.CANDELS_M31['UV+']],fmt='^',color='k',markersize=10,label='CANDELS M31')
	        plt.errorbar(volumeAnalysis.CANDELS_MW['Time'],volumeAnalysis.CANDELS_MW['UV'],yerr=[volumeAnalysis.CANDELS_MW['UV-'],volumeAnalysis.CANDELS_MW['UV+']],fmt='D',color='grey',markersize=10,label='CANDELS MW')
	if overplot==False:
		plt.xticks(fontsize=20)
	        plt.ylabel('U-V color',fontsize=40)
	        plt.xlabel('Time (Gyr)',fontsize=40)
	        plt.plot([0,9],[1.3,1.3],'k--')

	plt.legend(loc='upper left',fontsize=22)
	return