-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_thermo_slabs_subset.py
145 lines (115 loc) · 5.11 KB
/
plot_thermo_slabs_subset.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
####################################################
# Plot a large 12 panel plot with thin slab
# projection, phase plots, SFR, and disk mass growth
####################################################
import yt
yt.enable_parallelism()
import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib.colors import LogNorm, SymLogNorm
from matplotlib.ticker import MultipleLocator
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np
rcParams.update({'font.size': 14})
datasets = yt.load('DD00??/DD00??')
for ds in datasets.piter(dynamic=False, ):
center = ds.quan(0.5,'code_length')
rs = ds.quan(3.5,'kpc')
widths = [
ds.quan(100,'kpc'),
# ds.quan(100,'kpc'),
ds.quan(200,'kpc'),
ds.quan(400,'kpc'),
ds.quan(800,'kpc')
]
thicknesses = [
rs,
# rs,
rs,
rs,
rs*2
]
labels = [
'100kpc',
# '100kpc_face',
'200kpc',
'400kpc',
'800kpc'
]
for width, thickness, label in zip(widths, thicknesses, labels):
fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(23,15))
if 'face' in label:
view = 'z'
# Thin slab is used for projections so I can avoid weighting by e.g. mass
rect = ds.region([center, center, center],
[center-width/2, center-width/2, center-thickness/2],
[center+width/2, center+width/2, center+thickness/2])
else:
view = 'x'
# Thin slab is used for projections so I can avoid weighting by e.g. mass
rect = ds.region([center, center, center],
[center-thickness/2, center-width/2, center-width/2],
[center+thickness/2, center+width/2, center+width/2])
assert (rect.get_field_parameter("center") == center).all()
#
# Projection Plots
#
fields = ['density','temperature','pressure','entropy',
'radial_velocity','cooling_time']
p = yt.ProjectionPlot(ds, view, fields, width=width,
data_source=rect, weight_field ='ones')
# Extract fixed resolution buffers
p_frb = p.data_source.to_frb(width, 512)
d_arr = np.array(p_frb['density'])
t_arr = np.array(p_frb['temperature'])
p_arr = np.array(p_frb['pressure'])
k_arr = np.array(p_frb['entropy'])
v_arr = np.array(p_frb['radial_velocity']) / 1e5 # km/s
c_arr = np.array(p_frb['cooling_time']) / 3.16887e8 / 1e9 # Gyr
# Plot FRBs
extent = (-width/2, width/2, -width/2, width/2)
d_im = ax[0,0].imshow(d_arr, origin='lower', norm=LogNorm(1e-31,1e-23),
extent=extent)
t_im = ax[1,0].imshow(t_arr, origin='lower', norm=LogNorm(1e3,1e7),
extent=extent, cmap='magma')
p_im = ax[0,1].imshow(p_arr, origin='lower', norm=LogNorm(1e-20,1e-12),
extent=extent, cmap='inferno')
k_im = ax[1,1].imshow(k_arr, origin='lower', norm=LogNorm(1e-2,1e3),
extent=extent, cmap='cividis')
v_im = ax[0,2].imshow(v_arr, origin='lower',
norm=SymLogNorm(1, linscale=0.3, base=10,
vmin=-2e2, vmax=2e2),
extent=extent, cmap='coolwarm')
c_im = ax[1,2].imshow(c_arr, origin='lower', norm=LogNorm(1e-3,1e2),
extent=extent, cmap='plasma')
# Add colorbars
d_cb = fig.colorbar(d_im, ax=ax[0,0], pad=0.01, shrink=0.9)
t_cb = fig.colorbar(t_im, ax=ax[1,0], pad=0.01, shrink=0.9)
p_cb = fig.colorbar(p_im, ax=ax[0,1], pad=0.01, shrink=0.9)
k_cb = fig.colorbar(k_im, ax=ax[1,1], pad=0.01, shrink=0.9)
v_cb = fig.colorbar(v_im, ax=ax[0,2], pad=0.01, shrink=0.9)
c_cb = fig.colorbar(c_im, ax=ax[1,2], pad=0.01, shrink=0.9)
# Add colorbar labels
d_cb.set_label(r'< Density > [g cm$^{-3}$]')
t_cb.set_label(r'< Temperature > [K]')
p_cb.set_label(r'< Pressure > [dyn cm$^{-2}$]')
k_cb.set_label(r'< Entropy > [keV cm$^2$]')
v_cb.set_label(r'< Radial Velocity > [km/s]')
c_cb.set_label(r'< Cooling Time > [Gyr]')
#
# Final details & save
#
if 'face' in label:
ax[0,0].set_xlabel('x (kpc)')
ax[0,0].set_ylabel('y (kpc)')
else:
ax[0,0].set_xlabel('y (kpc)')
ax[0,0].set_ylabel('z (kpc)')
time = '{:.0f} Myr'.format(np.round(ds.current_time.to('Myr'),0))
ax[0,0].text(0.03, 0.03, time, transform=ax[0,0].transAxes,
color='white', size='x-large', weight='bold')
fig.suptitle("{} width, {} thickness".format(width, thickness), fontsize=28)
fig.tight_layout(rect=[0, 0, 1, 0.97])
fig.subplots_adjust(hspace=0.1, wspace=0.3)
fig.savefig('{}_thermo_slab_proj_{}.png'.format(ds.basename, label))
plt.close(fig)