-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_m31_obs.py
352 lines (310 loc) · 11.2 KB
/
plot_m31_obs.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
"""
Script to plot observed virial diagram for M31 GMCs. This script
generates figures 5, 6, and 7 of Krumholz, Lada, & Forbrich (2025).
"""
import astropy.units as u
from astropy.constants import G
from astropy.io import ascii as asc
import numpy as np
import matplotlib.pyplot as plt
# Read data
rawdata = asc.read('m31gmcs.csv')
# Break up data by source
ks = rawdata.keys()[0]
sources = rawdata[ks]
source_list = np.unique(sources)
data = { }
for s in source_list:
idx = rawdata[ks] == s
data[str(s)] = {
'AV' : np.array(rawdata['Av_i (mag)'][idx]),
'M' : rawdata['Mass_i (Msun)'][idx] * u.Msun,
'R' : rawdata['R_i (pc)'][idx] * u.pc,
'sigma12' : rawdata['sigma12_i (km/s)'][idx] * u.km/u.s,
'sigma13' : (rawdata['sigma13_i'][idx] *
(rawdata['13CO_S/N'][idx] > 15)) * u.km/u.s,
'Sigma' : rawdata['SD (Mo/pc^2)'][idx] * u.Msun/u.pc**2
}
# Discard sources with < 5 contour levels available
data = { k : data[k] for k in data.keys()
if len(data[k]['Sigma']) >= 5 }
# Compute derived quantities
for k in data.keys():
data[k]['logSigma'] = np.log10(data[k]['Sigma'] /
(u.Msun/u.pc**2))
data[k]['avir'] = (5 * data[k]['sigma12']**2 /
(np.pi * data[k]['R'] * G * data[k]['Sigma']))\
.to('')
data[k]['logs2r'] = np.log10((
data[k]['sigma12']**2 / data[k]['R']) /
(u.km**2 / u.s**2 / u.pc))
data[k]['avir13'] = (5 * data[k]['sigma13']**2 /
(np.pi * data[k]['R'] * G * data[k]['Sigma']))\
.to('')
data[k]['logs2r13'] = np.log10((
data[k]['sigma13']**2 / data[k]['R']) /
(u.km**2 / u.s**2 / u.pc))
sources = list(data.keys())
# Mark sources by whether they have rising high-Sigma tails
for s in sources:
if data[s]['avir'][-1] > data[s]['avir'][-2] and \
data[s]['avir'][-2] > data[s]['avir'][-3] and \
data[s]['avir'][-3] > data[s]['avir'][-4] and \
data[s]['avir'][-4] > data[s]['avir'][-5] and \
data[s]['avir'][-1] > np.mean(data[s]['avir']):
data[s]['rising'] = True
else:
data[s]['rising'] = False
data[s]['avir_mean'] = np.mean(data[s]['avir'])
avir13 = data[s]['avir13'][data[s]['avir13'] > 0]
data[s]['avir13_mean'] = np.mean(avir13)
if len(avir13) < 5:
data[s]['rising13'] = None
elif avir13[-1] > avir13[-2] and \
avir13[-2] > avir13[-3] and \
avir13[-3] > avir13[-4] and \
avir13[-4] > avir13[-5] and \
avir13[-1] > np.mean(avir13):
data[s]['rising13'] = True
else:
data[s]['rising13'] = False
if data[s]['rising13'] is None:
data[s]['rising_match'] = None
else:
data[s]['rising_match'] = data[s]['rising'] == data[s]['rising13']
# Compute statistics
ntot = len(sources)
mtot = np.sum([data[s]['M'][0].to(u.Msun).value
for s in sources]) * u.Msun
nrise = np.sum([data[s]['rising'] for s in sources])
mrise = np.sum([data[s]['rising'] * data[s]['M'][0].to(u.Msun).value
for s in sources]) * u.Msun
nrise13 = np.sum([data[s]['rising13'] == True for s in sources])
ntot13 = np.sum([data[s]['rising13'] != None for s in sources])
mtot13 = np.sum([(data[s]['rising13'] != None) * \
data[s]['M'][0].to(u.Msun).value
for s in sources]) * u.Msun
mrising13 = np.sum([(data[s]['rising13'] == True) * \
data[s]['M'][0].to(u.Msun).value
for s in sources]) * u.Msun
# Set fonts for plots
plt.rc('text', usetex=True)
plt.rc('font', family='serif', size=12)
# Plot setup
avir_lim = [-0.5, 1.7]
avirrel_lim = [-0.3, 0.4]
avir13_lim = [-0.45, 0.5]
cden_lim = [1.3, 2.8]
s2r_lim = [-1.2, 1.5]
s2r13_lim = [-1.4, 0.4]
ms = 2
# Create plot window
fig = plt.figure(1, figsize=(4,5))
fig.clf()
# Observers virial diagram
# Rising
ax = fig.add_subplot(3,2,1)
for s in sources:
if data[s]['rising']:
ax.plot(data[s]['logSigma'], data[s]['logs2r'],
marker='o', markersize=ms)
avir1 = np.log10(
(np.pi/5) * G * 10.**np.array(cden_lim) * u.Msun / u.pc**2 /
(u.km**2 / u.s**2 / u.pc))
ax.plot(cden_lim, avir1, 'k--', alpha=0.3)
ax.plot(cden_lim, avir1 + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(s2r_lim)
ax.set_xticklabels('')
ax.set_ylabel(r'$\log\sigma^2/R$ [km$^2$ s$^{-2}$ pc$^{-1}$]')
ax.set_title('Rising (N={:d})'.format(nrise),
size=12)
# Flat/falling
ax = fig.add_subplot(3,2,2)
for s in sources:
if not data[s]['rising']:
ax.plot(data[s]['logSigma'], data[s]['logs2r'],
marker='o', markersize=ms)
ax.plot(cden_lim, avir1, 'k--', alpha=0.3)
ax.plot(cden_lim, avir1 + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(s2r_lim)
ax.set_yticklabels('')
ax.set_xticklabels('')
ax.set_title('Flat/falling (N={:d})'.format(ntot-nrise), size=12)
# alpha_vir,obs versus sigma
# Rising sources
ax = fig.add_subplot(3,2,3)
for s in sources:
if data[s]['rising']:
ax.plot(data[s]['logSigma'], np.log10(data[s]['avir']),
marker='o', markersize=ms)
ax.plot(cden_lim, np.zeros(2), 'k--', alpha=0.3)
ax.plot(cden_lim, np.zeros(2) + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(avir_lim)
ax.set_xticklabels('')
ax.set_ylabel(r'$\log\alpha_\mathrm{vir}$')
# Non-rising sources
ax = fig.add_subplot(3,2,4)
for s in sources:
if not data[s]['rising']:
ax.plot(data[s]['logSigma'], np.log10(data[s]['avir']),
marker='o', markersize=ms)
ax.plot(cden_lim, np.zeros(2), 'k--', alpha=0.3)
ax.plot(cden_lim, np.zeros(2) + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(avir_lim)
ax.set_xticklabels('')
ax.set_yticklabels('')
# alpha_vir normalized to mean
# Rising sources
ax = fig.add_subplot(3,2,5)
for s in sources:
if data[s]['rising']:
ax.plot(data[s]['logSigma'],
np.log10(data[s]['avir']/data[s]['avir_mean']),
marker='o', markersize=ms)
ax.set_xlim(cden_lim)
ax.set_ylim(avirrel_lim)
ax.set_ylabel(r'$\log\alpha_\mathrm{vir}/\overline{\alpha}_\mathrm{vir}$')
ax.set_xlabel(r'$\log\Sigma$ [M$_\odot$ pc$^{-2}$]')
# Non-rising sources
ax = fig.add_subplot(3,2,6)
for s in sources:
if not data[s]['rising']:
ax.plot(data[s]['logSigma'],
np.log10(data[s]['avir']/data[s]['avir_mean']),
marker='o', markersize=ms)
ax.set_xlim(cden_lim)
ax.set_ylim(avirrel_lim)
ax.set_yticklabels('')
ax.set_xlabel(r'$\log\Sigma$ [M$_\odot$ pc$^{-2}$]')
# Adjust spacing
plt.subplots_adjust(right=0.95, top=0.95, wspace=0, hspace=0, left=0.2)
# Save
plt.savefig('m31_12co.pdf')
# Repeat previous steps for 13CO data
fig = plt.figure(2, figsize=(4,5))
fig.clf()
# Observers virial diagram
# Rising
ax = fig.add_subplot(3,2,1)
for s in sources:
if data[s]['rising13'] == True:
ax.plot(data[s]['logSigma'], data[s]['logs2r13'],
marker='o', markersize=ms)
avir1 = np.log10(
(np.pi/5) * G * 10.**np.array(cden_lim) * u.Msun / u.pc**2 /
(u.km**2 / u.s**2 / u.pc))
ax.plot(cden_lim, avir1, 'k--', alpha=0.3)
ax.plot(cden_lim, avir1 + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(s2r13_lim)
ax.set_xticklabels('')
ax.set_ylabel(r'$\log\sigma^2/R$ [km$^2$ s$^{-2}$ pc$^{-1}$]')
ax.set_title('Rising (N={:d})'.format(nrise13),
size=12)
# Flat/falling
ax = fig.add_subplot(3,2,2)
for s in sources:
if data[s]['rising13'] == False:
ax.plot(data[s]['logSigma'], data[s]['logs2r13'],
marker='o', markersize=ms)
ax.plot(cden_lim, avir1, 'k--', alpha=0.3)
ax.plot(cden_lim, avir1 + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(s2r13_lim)
ax.set_yticklabels('')
ax.set_xticklabels('')
ax.set_title('Flat/falling (N={:d})'.format(ntot13-nrise13), size=12)
# alpha_vir,obs versus sigma
# Rising sources
ax = fig.add_subplot(3,2,3)
for s in sources:
if data[s]['rising13'] == True:
ax.plot(data[s]['logSigma'], np.log10(data[s]['avir13']),
marker='o', markersize=ms)
ax.plot(cden_lim, np.zeros(2), 'k--', alpha=0.3)
ax.plot(cden_lim, np.zeros(2) + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(avir13_lim)
ax.set_xticklabels('')
ax.set_ylabel(r'$\log\alpha_\mathrm{vir}$')
# Non-rising sources
ax = fig.add_subplot(3,2,4)
for s in sources:
if data[s]['rising13'] == False:
ax.plot(data[s]['logSigma'], np.log10(data[s]['avir13']),
marker='o', markersize=ms)
ax.plot(cden_lim, np.zeros(2), 'k--', alpha=0.3)
ax.plot(cden_lim, np.zeros(2) + np.log10(2), 'k--', alpha=0.3)
ax.set_xlim(cden_lim)
ax.set_ylim(avir13_lim)
ax.set_xticklabels('')
ax.set_yticklabels('')
# alpha_vir normalized to mean
# Rising sources
ax = fig.add_subplot(3,2,5)
for s in sources:
if data[s]['rising13'] == True:
ax.plot(data[s]['logSigma'],
np.log10(data[s]['avir13']/data[s]['avir13_mean']),
marker='o', markersize=ms)
ax.set_xlim(cden_lim)
ax.set_ylim(avirrel_lim)
ax.set_ylabel(r'$\log\alpha_\mathrm{vir}/\overline{\alpha}_\mathrm{vir}$')
ax.set_xlabel(r'$\log\Sigma$ [M$_\odot$ pc$^{-2}$]')
# Non-rising sources
ax = fig.add_subplot(3,2,6)
for s in sources:
if data[s]['rising13'] == False:
ax.plot(data[s]['logSigma'],
np.log10(data[s]['avir13']/data[s]['avir13_mean']),
marker='o', markersize=ms)
ax.set_xlim(cden_lim)
ax.set_ylim(avirrel_lim)
ax.set_yticklabels('')
ax.set_xlabel(r'$\log\Sigma$ [M$_\odot$ pc$^{-2}$]')
# Adjust spacing
plt.subplots_adjust(right=0.95, top=0.95, wspace=0, hspace=0, left=0.2)
# Save
plt.savefig('m31_13co.pdf')
# Comparison of 12 and 13CO data for random subset of clouds
nsamp = 8
sources_both = [s for s in sources if data[s]['rising_match'] != None]
#idx = np.random.choice(len(sources_both), nsamp, replace=False)
idx = np.array([ 1, 2, 8, 12, 13, 19, 20, 23]) # Random set from random.choice
sources_sample = [sources_both[i] for i in idx]
fig = plt.figure(3, figsize=(4,6))
fig.clf()
avir_comp_lim = [-0.1, 0.2]
# Iterate over examples
for i, s in enumerate(sources_sample):
ax = fig.add_subplot(nsamp//2,2,i+1)
ax.plot((data[s]['logSigma']-data[s]['logSigma'][0]) /
(data[s]['logSigma'][-1]-data[s]['logSigma'][0]),
np.log10(data[s]['avir']/data[s]['avir_mean']),
'C0', marker='o', markersize=ms, label=r'$^{12}$CO')
ax.plot((data[s]['logSigma']-data[s]['logSigma'][0]) /
(data[s]['logSigma'][-1]-data[s]['logSigma'][0]),
np.log10(data[s]['avir13']/data[s]['avir13_mean']),
'C1', marker='o', markersize=ms, label=r'$^{13}$CO')
if i == 1:
ax.legend(loc='upper right', prop={'size' : 10})
ax.text(-0.01, 0.15, s, ha='left')
# Fix limits and axis labels
ax.set_xlim([-0.1,1.1])
ax.set_ylim(avir_comp_lim)
if i % 2 == 1:
ax.set_yticklabels('')
else:
ax.set_ylabel(r'$\log\alpha_\mathrm{vir}/\overline{\alpha}_\mathrm{vir}$')
if i < nsamp-2:
ax.set_xticklabels('')
else:
ax.set_xlabel(r'$\log\Sigma_\mathrm{rel}$')
# Adjust spacing
plt.subplots_adjust(left=0.18, right=0.95, top=0.95, hspace=0, wspace=0)
# Save
plt.savefig('12_13_comp.pdf')