-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_tcool_mass_dist.py
61 lines (47 loc) · 2.1 KB
/
save_tcool_mass_dist.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
#############################################
# Compile distributions of mass below a given
# cooling time for each dataset into a table
#############################################
import yt
yt.enable_parallelism()
import yt.units as u
import numpy as np
datasets = yt.load("DD????/DD????")
storage = {}
cgm_only = True
for my_storage, ds in datasets.piter(dynamic=False, storage=storage):
sph = ds.sphere('c',(206,'kpc'))
if cgm_only:
dsk = ds.disk([0.5,0.5,0.5], [0,0,1], (20,'kpc'), (1.3, 'kpc'))
cgm = sph - dsk
cgm.set_field_parameter('center', ds.arr([0.5,0.5,0.5], 'code_length'))
dataset = cgm
else:
dataset = sph
# Cummulative profile
prof = yt.create_profile(dataset, ("gas","cooling_time"), ("gas","cell_mass"),
accumulation=False, fractional=False, weight_field=None,
units={'cooling_time':'Gyr','cell_mass':'Msun'},
extrema={"cooling_time":(1e-6, 1e6)})
# Std Dev of tcool as function of tcool
tc_binner = np.digitize(dataset['gas','cooling_time'].to('Gyr'), prof.x_bins)
tcool_stddev = np.zeros(prof.x.size)
for i in range(1, prof.x_bins.size):
this_bin = tc_binner==i
tcool_stddev[i-1] = np.std(dataset['gas','cooling_time'][this_bin].to('Gyr'))
my_storage.result_id = int(ds.basename[-4:])
my_storage.result = (prof['cell_mass'], tcool_stddev)
if yt.is_root():
data_arr = np.zeros((prof.x.size, len(datasets)+1))
stddev_arr = np.zeros_like(data_arr)
data_arr[:,0] = prof.x
stddev_arr[:,0] = prof.x
for i in range(len(datasets)):
data_arr[:,i+1] = storage[i][0]
stddev_arr[:,i+1] = storage[i][1]
np.savetxt("tcool_mass_dist_CGM{}.txt".format("" if cgm_only else "-disk"),
data_arr,
header="tcool [Gyr] DD0000 mass [Msun] DD0001 mass ... etc")
np.savetxt("tcool_stddev_CGM{}.txt".format("" if cgm_only else "-disk"),
stddev_arr,
header="tcool [Gyr] DD0000 stddev(tcool) [Gyr] DD0001 stddev(tcool) ... etc")