Exemple #1
0
inputfile = './galacticus_stages_19.hdf5'

h5file = tables.openFile(inputfile, "r")

timeTable = getData.getTimestepTable(h5file)
print timeTable

# In order to plot the physical values we need h
h = 0.72

# Boxsize in Mpc, for easy centering
boxSize = 32000 / 1000

# Calculate the center of mass coordinates
# Get dataset at z=0
nodeData = getData.getOutput(h5file, timeTable[len(timeTable) - 1, 0])
#print 'Check time at center of mass calculation: ', timeTable[len(timeTable)-1,1]
nHalos = len(nodeData.positionX)
comCoord = np.zeros(3)
for i in range(nHalos):
    comCoord[0] += nodeData.positionX[i]
    comCoord[1] += nodeData.positionY[i]
    comCoord[2] += nodeData.positionZ[i]
comCoord = comCoord / nHalos / timeTable[len(timeTable) - 1, 2] * h
print 'Coordinates of the center of mass: ', comCoord[0], comCoord[
    1], comCoord[2]

tStart = 0
tEnd = len(timeTable)
for i in range(tStart, tEnd):
    #for i in range(tstep,tstep+1):
inputfile = 'inputtemp'

h5file = tables.openFile(inputfile,"r")

timeTable = getData.getTimestepTable(h5file)
print timeTable

# In order to plot the physical values we need h
h = 0.73

# Boxsize in Mpc, for easy centering
#boxSize = 32000/1000

# Calculate the center of mass coordinates
# Get dataset at z=0
nodeData = getData.getOutput(h5file,timeTable[len(timeTable)-1,0])
#print 'Check time at center of mass calculation: ', timeTable[len(timeTable)-1,1]
nHalos = len(nodeData.positionX)
comCoord = np.zeros(3)
for i in range(nHalos):
	comCoord[0] += nodeData.positionX[i]
	comCoord[1] += nodeData.positionY[i]
	comCoord[2] += nodeData.positionZ[i]
comCoord = comCoord/nHalos/timeTable[len(timeTable)-1,2]*h
maxCoord = np.zeros(3)

print 'Coordinates of the center of mass: ', comCoord[0], comCoord[1], comCoord[2]

maxCoord[0] = nodeData.positionX[0]
maxCoord[1] = nodeData.positionY[0]
maxCoord[2] = nodeData.positionZ[0]
Exemple #3
0
    if xlog == 'log':
        ax.set_xscale('log')
    ax.set_xlabel(xlabel)
    ax.set_ylabel('#')
    ax.set_title(title)
    fig.text(0.82, 0.95, r'z = %.2f' % timeTable[tstep, 3])
    title = (savepath + title + 'inputtemp' + ' ' + str(tstep).zfill(4) + '.' +
             fileformat).replace(" ", "_")
    plt.savefig(title, dpi=savedpi, format=fileformat)


# loop over timesteps
for i in range(tStart, tEnd):

    tstep = i
    nodeData = getData.getOutput(h5file, timeTable[tstep, 0])
    makeHistogram('Histogram of Disk Gas Masses', nodeData.diskGasMass[:],
                  10**np.linspace(6, 15,
                                  25), (0.8, 4000), 'log', 'log', r'M$_\odot$')
    makeHistogram('Histogram of Disk Gas Metallicity',
                  nodeData.diskGasMetals[:] / nodeData.diskGasMass[:] / 0.02,
                  np.linspace(0, 20, 40), (0.8, 4000), 'nonlog', 'log',
                  r'solar abundances')
    makeHistogram('Histogram of Outflowed Metals', nodeData.outflowedMetals[:],
                  10**np.linspace(0, 11,
                                  40), (0.8, 4000), 'log', 'log', r'M$_\odot$')
    makeHistogram('Histogram of Disk Stellar Mass',
                  nodeData.diskStellarMass[:], 10**np.linspace(6, 15, 20),
                  (0.8, 4000), 'log', 'log', r'M$_\odot$')
    makeHistogram('Histogram of Disk Gas Fraction',
                  nodeData.diskGasMass[:] / nodeData.nodeMass[:],
	ax.set_ylim(ylimits)
	if xlog == 'log':
		ax.set_xscale('log')
	ax.set_xlabel(xlabel)
	ax.set_ylabel('#')
	ax.set_title(title)
	fig.text(0.82,0.95,r'z = %.2f'%timeTable[tstep,3])
	title = (savepath+title+'inputtemp'+' '+str(tstep).zfill(4)+'.'+fileformat).replace(" ","_")
	plt.savefig(title,dpi=savedpi,format=fileformat)


# loop over timesteps
for i in range(tStart,tEnd):

	tstep=i
	nodeData = getData.getOutput(h5file,timeTable[tstep,0])
	makeHistogram('Histogram of Disk Gas Masses',nodeData.diskGasMass[:],
		      10**np.linspace(6,15,25),(0.8,4000),'log','log',r'M$_\odot$')
	makeHistogram('Histogram of Disk Gas Metallicity',nodeData.diskGasMetals[:]
		      /nodeData.diskGasMass[:]/0.02,np.linspace(0,20,40),(0.8,4000)
		      ,'nonlog','log',r'solar abundances')
	makeHistogram('Histogram of Outflowed Metals',nodeData.outflowedMetals[:],
		      10**np.linspace(0,11,40),(0.8,4000),'log','log',r'M$_\odot$')
	makeHistogram('Histogram of Disk Stellar Mass'   ,nodeData.diskStellarMass[:],
		      10**np.linspace(6,15,20),(0.8,4000),'log','log',r'M$_\odot$')
        makeHistogram('Histogram of Disk Gas Fraction'   ,nodeData.diskGasMass[:]/nodeData.nodeMass[:],
		      10**np.linspace(-8,1,20),(0.8,4000),'log','log',r'M$_\odot$')
	makeHistogram('Histogram of SFR (combined)'   ,nodeData.spheroidStarFormationRate[:]+nodeData.diskStarFormationRate[:],
		      10**np.linspace(-5,12,20),(0.8,4000),'log','log',r'M$_\odot$')
	makeHistogram('Histogram of Virial Radii',nodeData.nodeVirialRadius[:],
		      np.linspace(0,2,40),(0.8,4000),'nonlog','log',r'Mpc')
	if(timeTable[i,1] == nodeHistory[0].time):
		tIndexNodeDataStart = i
		#print 'First halo data at tIndex ', i
		break
if tIndexNodeDataStart == len(timeTable)-1:
	print 'Attention, halo is only present at z=0?'
	sys.exit(1)
if tIndexNodeDataStart > tIndexEnd:
	print 'Attention, no halo data in selected time range'


# loop over the timesteps from tIndexStart to tIndexEnd
for tIndex in range(tIndexStart,tIndexEnd+1):
	print 'tstep ', tIndex, 'time: ', timeTable[tIndex,1]
	# get the nodeData for tIndex
	nodeData = getData.getOutput(h5file,timeTable[tIndex,0])
	nHalos = len(nodeData.positionX) # number of halos in that timestep
	# ATTENTION: Positions seem to be in Mpc/h
	# ATTENTION: Also check for the masses
	positionX = nodeData.positionX[0:nHalos]/timeTable[tIndex,2]*h
	positionY = nodeData.positionY[0:nHalos]/timeTable[tIndex,2]*h
	positionZ = nodeData.positionZ[0:nHalos]/timeTable[tIndex,2]*h
	
	# Put nodeHistory[tIndex] into plotData values for easier plotting
	if tIndex>=tIndexNodeDataStart:
		# put the data to be plotted into the plotData array
		# the data vector should have length of tIndex-tIndexStart+1
		plotData1 = np.zeros(tIndex-tIndexNodeDataStart+1)
		plotData2 = np.zeros(tIndex-tIndexNodeDataStart+1)
		plotData3 = np.zeros(tIndex-tIndexNodeDataStart+1)
		plotData4 = np.zeros(tIndex-tIndexNodeDataStart+1)
# The time table starts at highest redshift
# and goes to redshift = 0. Its length corresponds
# to the number of timesteps in our galacticus file
# Format: nodeDataIndex, time since big bang, scale factor, z

# output the timeTable for debugging purposes
print timeTable
galacticusTimesteps = h5file.root.Outputs._v_nchildren

# Make a list of nodes
nodeHistory = [ NodeClass() ]

# Index of z=0 in our timeTable (end of our simulation)
tIndexEnd = len(timeTable)-1
# Get z=0 Output
nodeData = getData.getOutput(h5file,timeTable[tIndexEnd,0])
# Select the node to trace (at z=0)
# by giving the table index in the nodeData field (starting with 0)
#aIndex = 150
nodeHistory[0].arrayIndex = aIndex
# Get the properties for the selected node at z=0
nodeHistory[0].time = timeTable[tIndexEnd,1] # time in Gyr
nodeHistory[0].nodeIndex = nodeData.nodeIndex[aIndex] # nodeIndex
nodeHistory[0].diskStarFormationRate =  nodeData.diskStarFormationRate[aIndex]
nodeHistory[0].diskGasMass = nodeData.diskGasMass[aIndex]
nodeHistory[0].positionX = nodeData.positionX[aIndex]
nodeHistory[0].positionY = nodeData.positionY[aIndex]
nodeHistory[0].positionZ = nodeData.positionZ[aIndex]
nodeHistory[0].virialRadius = nodeData.nodeVirialRadius[aIndex]
nodeHistory[0].diskScaleLength = nodeData.diskScaleLength[aIndex]
nodeHistory[0].outflowedMass = nodeData.outflowedMass[aIndex]
Exemple #7
0
		tIndexNodeDataStart = i
		#print 'First halo data at tIndex ', i
		break
#if tIndexNodeDataStart == len(timeTable)-1:
	#print 'Attention, halo is only present at z=0?'
	#sys.exit(1)
#if tIndexNodeDataStart > tIndexEnd:
	#print 'Attention, no halo data in selected time range'


# loop over the timesteps from tIndexStart to tIndexEnd
for tIndex in range(tIndexStart,tIndexEnd+1):
	print 'indstart:', tIndexStart, 'tindexend:', tIndexEnd 
	print 'tstep ', tIndex, 'time: ', timeTable[tIndex,1]
	# get the nodeData for tIndex
	nodeData = getData.getOutput(h5file,timeTable[tIndex,0])
	nHalos = len(nodeData.positionX) # number of halos in that timestep
	# ATTENTION: Positions seem to be in Mpc/h
	# ATTENTION: Also check for the masses
	positionX = nodeData.positionX[0:nHalos]/timeTable[tIndex,2]*h
	positionY = nodeData.positionY[0:nHalos]/timeTable[tIndex,2]*h
	positionZ = nodeData.positionZ[0:nHalos]/timeTable[tIndex,2]*h
	
	# Put nodeHistory[tIndex] into plotData values for easier plotting
	if tIndex>=tIndexNodeDataStart:
		# put the data to be plotted into the plotData array
		# the data vector should have length of tIndex-tIndexStart+1
		plotData1 = np.zeros(tIndex-tIndexNodeDataStart+1)
		plotData2 = np.zeros(tIndex-tIndexNodeDataStart+1)
		plotData3 = np.zeros(tIndex-tIndexNodeDataStart+1)
		plotData4 = np.zeros(tIndex-tIndexNodeDataStart+1)