示例#1
0

	shellprofilear.append(bincount)
	shellprofilear.append(aGasMassHot)
	shellprofilear.append(aGasMassO6)
	shellprofilear.append(aGasMassLowIon)
	shellprofilear.append(aGasMassCold)
	shellprofilear.append(aGasFluxHot)
	shellprofilear.append(aGasFluxO6)
	shellprofilear.append(aGasFluxLowIon)
	shellprofilear.append(aGasFluxCold)

	bincount+=1

foutname = today+'PhaseShells.txt'
outline3 = SF.line_to_string(shellprofilear, newline='y')
i = open(foutname, 'a')
i.write(outline3)
i.close()	



MetalMassHot = np.array(MetalMassHot)
MetalMassO6 = np.array(MetalMassO6)
MetalMassLowIon = np.array(MetalMassLowIon)
MetalMassCold = np.array(MetalMassCold)

GasMassHot = np.array(GasMassHot)
GasMassO6 = np.array(GasMassO6)
GasMassLowIon = np.array(GasMassLowIon)
GasMassCold = np.array(GasMassCold)
		print 'but please stop at z=',Zs[count], ' N = ',SF.N_for_z(Zs[count])
	print 'updating good_halos.txt'
	if (os.path.isfile('good_halos.txt')):
		f = np.loadtxt('good_halos.txt', ndmin=2)
		haloIDs = f[:,3]
		if (ID[count] in haloIDs):
			print 'this already has an entry in good_halos.txt'
			print 'keep going? '
			override = raw_input('y/n ')
			if (override == 'n'):
				print 'ok not including this branch '
				good = False
	if (good):
		g = open('good_halos.txt', 'a')
		line = [haloN,  fhires[count], nDM[count], ID[count], Zs[0], Zs[count], SF.N_for_z(Zs[0]), SF.N_for_z(Zs[count]), type, nstar[count]]
		lala = SF.line_to_string(line)
		g.write(lala)
		g.close()
else:
	print 'do not do this halo!' 

print 'updating tried_halos.txt'
g = open('tried_halos.txt', 'a')
line = [haloN,  fhires[count], nDM[count], ID[count],  Zs[0], Zs[count], SF.N_for_z(Zs[0]), SF.N_for_z(Zs[count]), good, type, nstar[count]]
lala = SF.line_to_string(line)
g.write(lala)
g.close()

if (doplots != 'y'):
	print 'skipping plots '
	sys.exit()
	vesc_order = np.argsort(vesc_ar[count])
	
	mass_sorted_cumsum = np.cumsum(sig_ar[count][vesc_order])
	mass_sorted_cumsum /= mass_sorted_cumsum[-1]
	vesc_med = np.interp(0.5, mass_sorted_cumsum,vesc_ar[count][vesc_order] )
	vesc_25 = np.interp(0.25, mass_sorted_cumsum,vesc_ar[count][vesc_order] )
	vesc_75 = np.interp(0.75, mass_sorted_cumsum,vesc_ar[count][vesc_order] )
	print 'name of ep ',ep_name_ar[count]
	print 'num of snaps in ep', Neps_ar[count]
	print 'vesc ',len(vesc_ar[count])
	print 'sig ',len(sig_ar[count])
	weight_avg_vesc = np.average(vesc_ar[count], weights=sig_ar[count])
	print 'weighted average vesc ',weight_avg_vesc
	print '25th, 50th, 75th percentile vesc ',vesc_25, vesc_med, vesc_75
	weighted_avg_sig = np.average(sig_ar[count], weights=sig_ar[count])/area_of_cell
	print 'weighted average sig ',weighted_avg_sig
	unweighted_avg_sig = np.mean(sig_ar[count])/area_of_cell
	print 'unweighted average sig ',unweighted_avg_sig
	
	myline = [count, ep_name_ar[count], Neps_ar[count], weight_avg_vesc, vesc_25, vesc_med, vesc_75, weighted_avg_sig, unweighted_avg_sig, maxSF_ar[count], totMass_ar[count], duration_ar[count] ]
	mystring = SF.line_to_string(myline)
	f.write(mystring)
	print count, average_weighted_sig
	shell_histresults = np.histogram(vesc_ar[count], num_bins, range=(0, 1000), weights=np.array(mass_ar[count])/totalmass)
	[histx, histy] = ssp.create_plottable_hist(shell_histresults)
	plt.plot(histx,histy, color=color_ar[count], ls = ls_ar[count], lw=2)
	count+=1
f.close()
plt.legend(my_special_legend, loc='best')
plt.savefig(str(today) +'normedeps'+'.pdf')
示例#4
0
Gdists = SF.calcdist2(haloX, haloY, haloZ, G['p'][:, 0][Gclose],
                      G['p'][:, 1][Gclose], G['p'][:, 2][Gclose], boxsize)
Ghalo = Gdists < Rvir

TempCutISM = PhysTemp[Gclose][Ghalo] < TempBound1
TempCutCGMCool = PhysTemp[Gclose][Ghalo] < TempBound2
TempCutCGMWarm = (PhysTemp[Gclose][Ghalo] >=
                  TempBound2) * (PhysTemp[Gclose][Ghalo] < TempBound3)
TempCutCGMHot = PhysTemp[Gclose][Ghalo] >= TempBound3

ISMDensCut = PhysRho[Gclose][Ghalo] > 0.1

MISM1 = np.sum(G['m'][Gclose][Ghalo][ISMDensCut]) * 1e10 / h
MISM2 = np.sum(G['m'][Gclose][Ghalo][ISMDensCut * TempCutISM]) * 1e10 / h

MCGM1 = np.sum(
    G['m'][Gclose][Ghalo][TempCutCGMCool * np.invert(ISMDensCut)]) * 1e10 / h
MCGM2 = np.sum(G['m'][Gclose][Ghalo][TempCutCGMCool * np.invert(
    TempCutISM * ISMDensCut)]) * 1e10 / h
MCGM3 = np.sum(G['m'][Gclose][Ghalo][TempCutCGMWarm]) * 1e10 / h
MCGM4 = np.sum(G['m'][Gclose][Ghalo][TempCutCGMHot]) * 1e10 / h

Line = [M / h, Mstar / h, MISM1, MISM2, MCGM1, MCGM2, MCGM3, MCGM4, a, Nsnap]

foutname = today + 'TheramlProfile.txt'
print SF.line_to_string(Line, newline='n')
outline2 = SF.line_to_string(Line, newline='y')
g = open(foutname, 'a')
g.write(outline2)
g.close()
    weight_avg_vesc = np.average(vesc_ar[count], weights=sig_ar[count])
    print 'weighted average vesc ', weight_avg_vesc
    print '25th, 50th, 75th percentile vesc ', vesc_25, vesc_med, vesc_75
    weighted_avg_sig = np.average(sig_ar[count],
                                  weights=sig_ar[count]) / area_of_cell
    print 'weighted average sig ', weighted_avg_sig
    unweighted_avg_sig = np.mean(sig_ar[count]) / area_of_cell
    print 'unweighted average sig ', unweighted_avg_sig

    myline = [
        count, lasta_ar[count], Neps_ar[count], weight_avg_vesc, vesc_25,
        vesc_med, vesc_75, weighted_avg_sig, unweighted_avg_sig,
        maxSF_ar[count], totMass_ar[count], duration_ar[count]
    ]
    thar.append('z=' + str(lasta_ar[count]))
    mystring = SF.line_to_string(myline)
    f.write(mystring)
    shell_histresults = np.histogram(vesc_ar[count],
                                     num_bins,
                                     range=(0, 1000),
                                     weights=np.array(mass_ar[count]) /
                                     totalmass)
    [histx, histy] = ssp.create_plottable_hist(shell_histresults)
    plt.plot(histx,
             histy,
             color=color_ar[count],
             ls=ls_ar[count],
             lw=2,
             alpha=0.5)
    count += 1
plt.legend(thar, loc='best')
strang1 = f.readline()
strang2 = f.readline()	

dars = f.readlines()
f.close()
gork = open(foutname, 'w')
gork.write(strang1)
gork.write(strang2)
count = 0
for line in dars:
	xsd = line.split()
	xsd[6] = finalx[count]
	xsd[7] = finaly[count]
	xsd[8] = finalz[count]
	myline = SF.line_to_string(xsd, newline='y', tabs='y')
	#print myline
	gork.write(myline)
	count +=1
	if (count >= len(finalx)):
		break
gork.close()

OSinddsum = np.fabs(OSinddx) + np.fabs(OSinddy) + np.fabs(OSinddz)
finalddsum = np.fabs(finalddx) + np.fabs(finalddy) + np.fabs(finalddz)
initddsum = np.fabs(ddx) + np.fabs(ddy) + np.fabs(ddz)

fig3 = plt.figure(figsize=(10, 6))
plt.xlabel('z')
plt.ylabel('ddx, ddy, ddz (kpc/h)')
plt.plot(Zs, initddsum, color='r', ls ='-', lw=1)
示例#7
0
strang1 = f.readline()
strang2 = f.readline()

dars = f.readlines()
f.close()
gork = open(foutname, 'w')
gork.write(strang1)
gork.write(strang2)
count = 0
for line in dars:
    xsd = line.split()
    xsd[6] = finalx[count]
    xsd[7] = finaly[count]
    xsd[8] = finalz[count]
    myline = SF.line_to_string(xsd, newline='y', tabs='y')
    #print myline
    gork.write(myline)
    count += 1
    if (count >= len(finalx)):
        break
gork.close()

OSinddsum = np.fabs(OSinddx) + np.fabs(OSinddy) + np.fabs(OSinddz)
finalddsum = np.fabs(finalddx) + np.fabs(finalddy) + np.fabs(finalddz)
initddsum = np.fabs(ddx) + np.fabs(ddy) + np.fabs(ddz)

fig3 = plt.figure(figsize=(10, 6))
plt.xlabel('z')
plt.ylabel('ddx, ddy, ddz (kpc/h)')
plt.plot(Zs, initddsum, color='r', ls='-', lw=1)
        haloIDs = f[:, 3]
        if (ID[count] in haloIDs):
            print 'this already has an entry in good_halos.txt'
            print 'keep going? '
            override = raw_input('y/n ')
            if (override == 'n'):
                print 'ok not including this branch '
                good = False
    if (good):
        g = open('good_halos.txt', 'a')
        line = [
            haloN, fhires[count], nDM[count], ID[count], Zs[0], Zs[count],
            SF.N_for_z(Zs[0]),
            SF.N_for_z(Zs[count]), type, nstar[count]
        ]
        lala = SF.line_to_string(line)
        g.write(lala)
        g.close()
else:
    print 'do not do this halo!'

print 'updating tried_halos.txt'
g = open('tried_halos.txt', 'a')
line = [
    haloN, fhires[count], nDM[count], ID[count], Zs[0], Zs[count],
    SF.N_for_z(Zs[0]),
    SF.N_for_z(Zs[count]), good, type, nstar[count]
]
lala = SF.line_to_string(line)
g.write(lala)
g.close()
	sys.exit()

finname1 = str(sys.argv[1])
f = open(finname1)
dars = np.loadtxt(f)
f.close()

SF_start = dars[:,13]
SF_end = dars[:,15]
Mstar = dars[:,8]
eta = dars[:,17]
epN = dars[:,0]

cut1 = Mstar > Mstarlowlim
cut2 = Mstar < Mstarupperlim
cut = cut1*cut2


foutname = today+'relevant_snaps.txt'
f = open(foutname, 'w')
count = 0 
while (count < len(SF_start[cut])):
	Nstart = N_for_T(SF_start[cut][count])
	Nend = N_for_T(SF_end[cut][count])
	print epN[cut][count], Mstar[cut][count]/1e10, Nstart, Nend, eta[cut][count]
	line = [epN[cut][count], Mstar[cut][count]/1e10, Nstart, Nend, eta[cut][count]]
	thestring = SF.line_to_string(line)
	f.write(thestring)
	count+=1
f.close()
示例#10
0
	count_ar = []
	frac_ar = []
	cellmass*=1e10/h
	totalfrac = 0 

	vesc_cge_ar = potter.calculate_escape_velocity([haloX, haloY, haloZ], [x_cells, y_cells, z_cells], G, S, D, where_do_we_go*h/a)  * np.sqrt(2.0)
	print 'halo is here ',haloX, haloY, haloZ
	while (count < len(x_cells)):
		totalfrac+=cellmass[count]/Mnewstars
		#vesc_cge_beta = potter2.calculate_escape_velocity([haloX, haloY, haloZ], [x_cells[count], y_cells[count], z_cells[count]], G, S, D,   where_do_we_go*h/a)*np.sqrt(2.0)
		print count, x_cells[count], y_cells[count], z_cells[count], vesc_cge_ar[count], cellmass[count],  cellmass[count]/Mnewstars, totalfrac
		frac_ar.append(cellmass[count]/Mnewstars)
		count_ar.append(count)
		count +=1

	vesc_cge_ar = np.array(vesc_cge_ar)
	count_ar = np.array(count_ar)
	frac_ar = np.array(frac_ar)
	vhist_header = [Nsnap, redshift, where_do_we_go ,  Rstars*a/h, Mnewstars, SFR_time_range, Nnewstars, the_surface_frac, haloX, haloY, haloZ]
	vhist_header_string = SF.line_to_string(vhist_header, newline='n')

	outtable = np.column_stack([count_ar, cellmass, vesc_cge_ar, x_cells, y_cells, z_cells, frac_ar ])
	foutname = str(today)+'Xsurface_list'+Nsnapstring+'N'+str(halo_to_do[workcount])+'.txt'
	np.savetxt(foutname, outtable,  fmt='%1.6e', header=vhist_header_string)
	if (do_graphs):
		foutname1a = str(today)+'image_stars'+Nsnapstring+'N'+str(halo_to_do[workcount])+'.pdf'
		foutnameDM = str(today)+'image_DM'+Nsnapstring+'N'+str(halo_to_do[workcount])+'.pdf'
		GL.pluscuts_2d_desnity_hist(S, Rstars, haloX, haloY, haloZ,  foutname1a, dolabel=True, extrapoints = [[x_cells[0], y_cells[0], z_cells[0]]], extrars=[-1])
		GL.pluscuts_2d_desnity_hist(D, Rstars, haloX, haloY, haloZ, foutnameDM, dolabel=True)
	workcount+=1
    OutflowingParticlesID_G2_095Rvir[here])

len95in25 = len(OutflowingParticlesID_G2_095Rvir[here])

Particles_G_095_len = len(Particles_G2_095)

here_still = np.in1d(Particles_G2_095, OutflowingParticlesID_025Rvir)

#fraction of particles at shell #2 at later epoch still from first burst of shell#1
len95stillin25 = len(Particles_G2_095[here_still])

#1. halo, 2. Nsnap1, 3. Nsnap2, 4. redshift1, 5. redshift2, 6. len25-number of outflowing particles from epoch1, shell1. 7. len95 - number of outflowing particles at epoch2, shell2. 8. len95in25 number of outflowing particles at epoch2, shell2, that were also outflowing at shell1 at epoch1. 9. len95in25/len95.  Fraction of outflowing particles at shell2 epoch2 that were also outflowing in shell1 at epoch1 over the number of outflowing particles in shell2 epoch2. 10. len95in25/len25. Fraction of outflowing particles at shell2 epoch2 that were also outflowing in shell1 at epoch1, over the number of outflowing particles from shell1 epoch1. 11. len95stillin25)/float(len25)- total number of particles in epoch2 shell2 that originated from outflowing particles from epoch1 shell 1. 12. index1. 13. index2. 14. use_v0 (True if vcut =0, False if vcut=vsig) #15 outflowrate1 #16 outflowrate2
print halo_to_do, Nsnap, Nsnap2, redshift1, redshift2, len25, len95, len95in25, len95stillin25, (
    float(len95in25) /
    float(len95)), (float(len95in25) /
                    float(len25)), (float(len95stillin25) /
                                    float(len25)), index1, index2, use_v0
BigString = [
    halo_to_do, Nsnap, Nsnap2, redshift1,
    redshift2, len25, len95, len95in25, len95stillin25,
    (float(len95in25) / float(len95)), (float(len95in25) / float(len25)),
    (float(len95stillin25) / float(len25)), index1, index2,
    int(use_v0), original_outflow_rate, second_outflow_rate
]
thestring = SF.line_to_string(BigString)

foutname = 'entrain_outflow_' + str(Nsnap) + 'halo' + str(halo_to_do) + '.txt'
g = open(foutname, 'a')
g.write(thestring)
g.close()
示例#12
0
f = open(finname1)
dars = np.loadtxt(f)
f.close()

SF_start = dars[:, 13]
SF_end = dars[:, 15]
Mstar = dars[:, 8]
eta = dars[:, 17]
epN = dars[:, 0]

cut1 = Mstar > Mstarlowlim
cut2 = Mstar < Mstarupperlim
cut = cut1 * cut2

foutname = today + 'relevant_snaps.txt'
f = open(foutname, 'w')
count = 0
while (count < len(SF_start[cut])):
    Nstart = N_for_T(SF_start[cut][count])
    Nend = N_for_T(SF_end[cut][count])
    print epN[cut][count], Mstar[cut][count] / 1e10, Nstart, Nend, eta[cut][
        count]
    line = [
        epN[cut][count], Mstar[cut][count] / 1e10, Nstart, Nend,
        eta[cut][count]
    ]
    thestring = SF.line_to_string(line)
    f.write(thestring)
    count += 1
f.close()