-
Notifications
You must be signed in to change notification settings - Fork 0
/
createMtreeStat.py
79 lines (62 loc) · 2.26 KB
/
createMtreeStat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import vtk
from vtk import *
from vtk.util.numpy_support import vtk_to_numpy
import matplotlib.patches as mpatches
from matplotlib.legend_handler import HandlerLine2D
import matplotlib.cm as cm
file_name = "/home/subhashis/VisData/merger_trees/firsttreewithUmass.vtp"
# Read the source file.
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(file_name)
reader.Update() # Needed because of GetScalarRange
#output = reader.GetOutput()
#scalar_range = output.GetScalarRange()
#pt_array = vtk_to_numpy(reader.GetOutput.GetPoint())
haloid = vtk_to_numpy(reader.GetOutput().GetPointData().GetArray('haloid'))
mvir = vtk_to_numpy(reader.GetOutput().GetPointData().GetArray('mvir'))
particleCount = vtk_to_numpy(reader.GetOutput().GetPointData().GetArray('particleCount'))
snap_num = vtk_to_numpy(reader.GetOutput().GetPointData().GetArray('Snap_num'))
totalParMass = vtk_to_numpy(reader.GetOutput().GetPointData().GetArray('totalParMass'))
uMass = vtk_to_numpy(reader.GetOutput().GetPointData().GetArray('uMass'))
noh = len(haloid)
xaxis = range(0,noh)
#area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
#plt.plot(xaxis, np.sort(mvir))
#plt.plot(xaxis, np.sort(uMass))
#plt.show()
virial_mass = np.zeros(89)
for i in range(0,89):
count = 0
for j in range(0,noh):
if snap_num[j] == i:
count += 1
virial_mass[i] += mvir[j]
#virial_mass[i] /= count
#print count
#print virial_mass
totalParticle_mass = np.zeros(89)
for i in range(0,89):
count = 0
for j in range(0,noh):
if snap_num[j] == i:
count += 1
totalParticle_mass[i] += totalParMass[j]
#totalParticle_mass[i] /= count
u_mass = np.zeros(89)
for i in range(0,89):
count = 0
for j in range(0,noh):
if snap_num[j] == i:
count += 1
u_mass[i] += uMass[j]
#u_mass[i] /= count
plt.plot(range(0,89),virial_mass,label='Virial Mass')
plt.plot(range(0,89),totalParticle_mass,label='DM Particle Mass')
#plt.plot(range(0,89),u_mass)
plt.xlabel('Timestep')
plt.ylabel('Mass 1e14 Msun/h')
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,ncol=2, mode="expand", borderaxespad=0.)
plt.show()