コード例 #1
0
ファイル: voidFinder.py プロジェクト: epaillasv/VoidFinder
thresh = 0.2

outfile = 'voidCatalogue.dat'

sim = '/cosma5/data/Eagle/ScienceRuns/Planck1/'\
'L0025N0376/PE/REFERENCE/data/'

tag = '028_z000p000'

start = time.time()

print('Starting void search.')
print('Reading: ' + sim + tag)
print('')

boxsize = eagle.readAttribute("SNAPSHOT", sim, tag, "/Header/BoxSize")
numpart_pertype = eagle.readAttribute("SNAPSHOT", sim, tag, "/Header/NumPart_Total")
np = numpy.sum(numpart_pertype)
ngas, ndm, nstar, nbh = numpart_pertype[0], numpart_pertype[1], numpart_pertype[4], numpart_pertype[5]

maxvoid_radius = boxsize / 2.

print('BoxSize = ' + repr(boxsize))
print('Total number of particles: ' + repr(np))
print('ngas: ' + repr(ngas))
print('ndm: ' + repr(ndm))
print('nstar: ' + repr(nstar))
print('nbh: ' + repr(nbh))
print('')
print('Proceeding to read data...')
コード例 #2
0
ファイル: eagletools.py プロジェクト: Samwalton9/eaglestuff
def savesubhalo(halo,subgroup,parttype,path="/data5/astjmack/halos/"):
	halo = halo
	subgroup = subgroup
	parttype = parttype
	good_types = [0,4,5]
	boxsize = E.readAttribute("SUBFIND", sim, tag, "/Header/BoxSize")
	h = E.readAttribute("SUBFIND", sim, tag, "/Header/HubbleParam")
	masstable = E.readAttribute("SUBFIND", sim, tag, "/Header/MassTable") / h
	boxsize = boxsize/h
	groupnum = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/GroupNumber")
	subgroupnum = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SubGroupNumber")
	subgroupnum = subgroupnum[groupnum == halo]
	r_200 = E.readArray("SUBFIND_GROUP", sim, tag, "/FOF/Group_R_Crit200")[halo-1]
	fsid = E.readArray("SUBFIND_GROUP", sim, tag, "FOF/FirstSubhaloID")
	pos = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/Coordinates")[groupnum == halo, :]
	pos = pos[subgroupnum == subgroup, :]
	if parttype in good_types:
		mass = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/Mass")[groupnum == halo]
		mass = mass[subgroupnum == subgroup]
	elif parttype == 1:
		mass = np.ones(len(pos))*masstable[1]
		
	vel = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/Velocity")[groupnum == halo, :]
	vel = vel[subgroupnum == subgroup, :]
	if parttype == 4:
		stars_h = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Hydrogen")[groupnum == halo]
		stars_fe = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Iron")[groupnum == halo]
		stars_o = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Oxygen")[groupnum == halo]
		stars_mg = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Magnesium")[groupnum == halo]
		starformtime = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/StellarFormationTime")[groupnum == halo]
		stars_h = stars_h[subgroupnum == subgroup]
		stars_fe = stars_fe[subgroupnum == subgroup]
		stars_o = stars_o[subgroupnum == subgroup]
		stars_mg = stars_mg[subgroupnum == subgroup]
		starformtime = starformtime[subgroupnum == subgroup]
		solar_h = 0.706498
		solar_fe = 0.00110322
		solar_mg = 0.000590706
		solar_o = 0.00549262
		solar_fe_h = np.log10(solar_fe/solar_h)
		solar_mg_fe = np.log10(solar_mg/solar_h)-(solar_fe_h)
		solar_o_fe = np.log10(solar_o/solar_h)-(solar_fe_h)
		stars_fe_h = np.log10(stars_fe/stars_h)
		stars_mg_fe = np.log10(stars_mg/stars_h)-(stars_fe_h)
		stars_o_fe = np.log10(stars_o/stars_h)-(stars_fe_h)
		fe_h = np.array([str_fe_h - solar_fe_h for str_fe_h in stars_fe_h])
		mg_fe = np.array([str_a_fe - solar_mg_fe for str_a_fe in stars_mg_fe])
		o_fe = np.array([str_o_fe - solar_o_fe for str_o_fe in stars_o_fe])

	subhaloindex = fsid[halo-1]+subgroup
	CoP = E.readArray("SUBFIND", sim, tag, "/Subhalo/CentreOfPotential")[subhaloindex, :]
	subhalovel = E.readArray("SUBFIND", sim, tag, "/Subhalo/Velocity")[subhaloindex, :]

	#Calculate the abundance ratios (relative to solar abundances from EAGLE)
	

	rel_pos = [[pos[0]-CoP[0],pos[1]-CoP[1],pos[2]-CoP[2]] for pos in pos] #Relative positions

	#re-position overlapped particles
	for i in range(0,len(rel_pos)):
		if abs(rel_pos[i][0]) > (boxsize/2):
			if np.sign(rel_pos[i][0]) == -1:
				rel_pos[i][0] = rel_pos[i][0] + boxsize
			else:
				rel_pos[i][0] = rel_pos[i][0] - boxsize
		if abs(rel_pos[i][1]) > (boxsize/2):
			if np.sign(rel_pos[i][1]) == -1:
				rel_pos[i][1] = rel_pos[i][1] + boxsize
			else:
				rel_pos[i][1] = rel_pos[i][1] - boxsize
		if abs(rel_pos[i][2]) > (boxsize/2):
			if np.sign(rel_pos[i][2]) == -1:
				rel_pos[i][2] = rel_pos[i][2] + boxsize
			else:
				rel_pos[i][2] = rel_pos[i][2] - boxsize
	rel_pos = np.array(rel_pos)

	#Make a mask for R_Crit200 and reduce arrays to contain only these values.
	r_crit_mask =[]
	for i in range(0,len(rel_pos)):
		if np.sqrt(rel_pos[i][0]**2+rel_pos[i][1]**2+rel_pos[i][2]**2) <= 0.15*r_200:
			r_crit_mask.append(True)
		else:
			r_crit_mask.append(False)
	r_crit_mask = np.array(r_crit_mask, dtype='bool')
	rel_pos_1 = rel_pos[r_crit_mask]
	mass = mass[r_crit_mask]
	vel = vel[r_crit_mask]
	if parttype == 4:
		fe_h = fe_h[r_crit_mask]
		mg_fe = mg_fe[r_crit_mask]
		o_fe = o_fe[r_crit_mask]
		fe_h = np.array(fe_h)
		mg_fe = np.array(mg_fe)
		o_fe = np.array(o_fe)
	
	"""
	nanmask = np.zeros(len(fe_h))
	for i in range(0, len(fe_h)):
		if (np.isnan(fe_h[i]) == True) | (np.isinf(fe_h[i]) == True) | (np.isnan(mg_fe[i]) == True) | (np.isinf(mg_fe[i]) == True) | (np.isnan(o_fe[i]) == True) | (np.isinf(o_fe[i]) == True):
			nanmask[i] = False
		else:
			nanmask[i] = True

	nanmask = np.array(nanmask, dtype='bool')

	rel_pos_1 = rel_pos_1[nanmask]
	mass = mass[nanmask]
	vel = vel[nanmask]
	fe_h = fe_h[nanmask]
	mg_fe = mg_fe[nanmask]
	o_fe = o_fe[nanmask]
	starformtime = starformtime[nanmask]
	"""
	#Remove galaxy bulk motion from velocities
	vel = [bulkvel-subhalovel for bulkvel in vel]

	#Perform angular momentum calculation
	mv = [m*v for m,v in zip(mass,vel)]	
	ang_mom = [np.cross(rpos,mv) for rpos,mv in zip(rel_pos_1,mv)]
	tot_ang_mom = map(sum, zip(*ang_mom))
	tot_ang_mom = E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Spin")[subhaloindex, :]
	print str(tot_ang_mom)
	yaw = np.arccos(tot_ang_mom[1]/(np.sqrt(tot_ang_mom[0]**2+tot_ang_mom[1]**2)))
	pitch = np.arccos(tot_ang_mom[1]/(np.sqrt(tot_ang_mom[1]**2+tot_ang_mom[2]**2)))
	roll = np.arccos(tot_ang_mom[0]/(np.sqrt(tot_ang_mom[0]**2+tot_ang_mom[2]**2)))
	cos = np.cos
	sin = np.sin
	yaw_tran = np.matrix([[cos(yaw), -sin(yaw), 0],[sin(yaw), cos(yaw), 0],[0,0,1]])
	pitch_tran = np.matrix([[cos(pitch), 0, sin(pitch)],[0,1,0],[-sin(pitch), 0, cos(pitch)]])
	roll_tran = np.matrix([[1,0,0],[0,cos(roll),-sin(roll)],[0,sin(roll),cos(roll)]])
	trans = np.array(roll_tran*pitch_tran*yaw_tran)

	#Transform positions and velocities
	r_tran = np.array([np.array([np.dot(i, trans[0]), np.dot(i, trans[1]), np.dot(i,trans[2])]) for i in rel_pos_1])
	vel_tran = np.array([np.array([np.dot(j, trans[0]), np.dot(j, trans[1]), np.dot(j, trans[2])]) for j in vel])

	#Calculate radial position
	R_pos = np.array([np.sqrt(rpos[0]**2 + rpos[2]**2) for rpos in r_tran])
	z_pos = abs(np.array(zip(*r_tran)[1]))
	
	#vertical and Circular angular momentum
	#mv = [m*v for m,v in zip(mass,vel)]
	ang_mom = [np.cross(rpos,v) for rpos,v in zip(r_tran,vel)]

	#Calculate star formation ages
	Mpc = 3.08567758e22
	t_0 = 13.8
	H_0 = h  * 100
	#t_a = [(2*a**(3/2))/(3*H_0)/(1e9*365*24*60*60) for a in starformtime]
	if parttype == 4:
		ages = starformtime #[t_0 - t for t in t_a]
	
	if parttype == 4:
		partarray = np.array([zip(*r_tran)[0], zip(*r_tran)[2], zip(*r_tran)[1], zip(*vel_tran)[0], zip(*vel_tran)[2], zip(*vel_tran)[1], mass, R_pos, z_pos, fe_h, mg_fe, r_200, zip(*ang_mom)[1], ages, o_fe] )
	else:
		partarray = np.array([zip(*r_tran)[0], zip(*r_tran)[2], zip(*r_tran)[1], zip(*vel_tran)[0], zip(*vel_tran)[2], zip(*vel_tran)[1], mass, R_pos, z_pos, r_200, zip(*ang_mom)[1]])
	ensure_dir(path+run+"_FOF"+str(halo)+"_SUB"+str(subgroup)+"/")
	np.save(path+run+"_FOF"+str(halo)+"_SUB"+str(subgroup)+"/part"+str(parttype)+"dat", partarray)
コード例 #3
0
ファイル: newetools.py プロジェクト: Samwalton9/eaglestuff
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import colors
from matplotlib import gridspec
from scipy.stats import gaussian_kde
import numpy as np
import eagle as E
import os
import math
import csv

default_run = "L0050N0752"
default_sim = "/data5/simulations/EAGLE/"+default_run+"/REFERENCE/data"
default_tag = "028_z000p000"

boxsize = E.readAttribute("SUBFIND", default_sim, default_tag, "/Header/BoxSize")
h = E.readAttribute("SUBFIND", default_sim, default_tag, "/Header/HubbleParam")
boxsize = boxsize/h
masstable = E.readAttribute("SUBFIND", default_sim, default_tag, "/Header/MassTable") / h

def ensure_dir(f):
	""" Ensure a a file exists and if not make the relevant path """
	d = os.path.dirname(f)
	if not os.path.exists(d):
			os.makedirs(d)

def correctwrap(rel_pos):
	""" Correct the periodic wrap in EAGLE """
	for i in range(0,len(rel_pos)):
		if abs(rel_pos[i][0]) > (boxsize/2):
			if np.sign(rel_pos[i][0]) == -1: