-
Notifications
You must be signed in to change notification settings - Fork 2
/
new_makesyntheticspectra_composite.py
428 lines (359 loc) · 28.3 KB
/
new_makesyntheticspectra_composite.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
import numpy as np
from pyspeckit.spectrum.models import lte_molecule
from pyspeckit.spectrum.models.lte_molecule import get_molecular_parameters
from astroquery.linelists.cdms import CDMS
import astropy.units as u
import matplotlib.pyplot as plt
from astroquery.splatalogue import utils, Splatalogue
import scipy.constants as cnst
from astropy.io import fits
import glob
from astropy.modeling import models#Fittable1DModel, Parameter, fitting
from utilities import *#Q_rot_asym,mulu,vradio,t_rad,nupper_estimated,opticaldepth,qngrabber
import matplotlib as mpl
import pdb
import sys
Splatalogue.QUERY_URL= 'https://splatalogue.online/c_export.php'
mpl.interactive(True)
plt.close('all')
def lineprofile(sigma,nu_0,nu):
return (1/(np.sqrt(2*np.pi)*sigma))*np.exp(-(nu-nu_0)**2/(2*sigma**2))
def cdms_get_molecule_name(my_molecule_name, **kwargs):
basename = dict(CDMS.query_lines(min_frequency=1*u.GHz, max_frequency=500*u.GHz, molecule=my_molecule_name, parse_name_locally=True, get_query_payload=True, **kwargs))['Molecules']
return " ".join(basename.split(" ")[1:])
'''Collect constants for N_tot and N_upper calculations'''
source='DS10'
c=cnst.c*u.m/u.s
k=cnst.k*u.J/u.K
h=cnst.h*u.J*u.s
sigma_sb=cnst.sigma*u.W/((u.m)**(2)*(u.K)**(4))
b_0=24679.98*u.MHz
a_0=127484*u.MHz
c_0=23769.70*u.MHz
m=b_0**2/(a_0*c_0)
Tbg=2.7355*u.K
trotdict={'SgrB2S':300*u.K,'DSi':300*u.K,'DSii':150*u.K,'DSiii':150*u.K,'DSiv':150*u.K,'DSv':100*u.K,'DSVI':300*u.K,'DSVII':200*u.K,'DSVIII':215*u.K,'DSIX':150*u.K,'DS10':150*u.K}
testT=trotdict[source]
#qrot_partfunc=partfunc(testT)#Q_rot_asym(testT).to('')
R_i=1
kappa=((2*b_0)-a_0-c_0)/(a_0-c_0)
f=1
dopplershifts={'SgrB2S':0.000228,'DSi':0.0001865,'DSii':0.000163,'DSiii':0.00017500261911843952,'DSiv':0.00018225233186845314,'DSv':0.0001838576164010067,'DSVI':0.0001661613132158407,'DSVII':0.00016320118280935546,'DSVIII':0.0001662062062062062,'DSIX':0.00015453732389175085,'DS10':0.00015794099431186572}#:0.000190713}/old doppler S: 0.0002306756533745274/0.00015954965399894244/0.00016236367659115043
s_othermol_dshift_v={' CH3CHO ':67.45330305*u.km/u.s,' C2H5OH ':67.45330305*u.km/u.s,' CH3OCHO ':67.45330305*u.km/u.s,' C(18)O ':69.551850256*u.km/u.s,' 13CH3OH ':67.5*u.km/u.s,' SO ':70.5*u.km/u.s}#' CH3OH ':68352.680424
ds2_othermol_dshift_v={' CH3OCHO ':49*u.km/u.s,' CH3CHO ':49*u.km/u.s,' C2H5OH ':49.3*u.km/u.s}#47831.782945392486 m / s
ds5_othermol_dshift_v={}
othermol_dopplershift={' CH3CHO ':0.000225,' C2H5OH ':0.000225,' CH3OCHO ':0.000225,' C(18)O ':0.000232}
ds9_othermol_dshift_v={}
sourceothers={'SgrB2S':s_othermol_dshift_v,'DSi':{},'DSii':ds2_othermol_dshift_v,'DSiii':{},'DSiv':{},'DSv':ds5_othermol_dshift_v,'DSVI':{},'DSVII':{},'DSVIII':{},'DSIX':ds9_othermol_dshift_v,'DS10':{}}
othermol_dshift_v=sourceothers[source]
z=dopplershifts[source]
z_vel=z*c
sourcelocs=
homedict={'SgrB2S':'/blue/adamginsburg/d.jeff/XCLASS2021/files/SgrB2S/OctReimage_K/','DSi':'/blue/adamginsburg/d.jeff/XCLASS2021/files/DSi/field10originals_K/','DSii':'DSi':'/blue/adamginsburg/d.jeff/XCLASS2021/files/DSii/field10originals_K/','DSiii':'/aug2023qrotfix/','DSiv':'/aug2023qrotfix/','DSv':f'/aug2023qrotfix/','DSVI':'/aug2023qrotfix/','DSVII':f'/aug2023qrotfix/','DSVIII':f'/aug2023qrotfix/','DSIX':f'/aug2023qrotfix/'}
origsourcepath=f'/blue/adamginsburg/d.jeff/SgrB2DSreorg/field{fnum}/CH3OH/{source}/{sourcepath}'
texlocs=
texmappath=origsourcepath+texlocs[source]+'bootstrap_texmap_3sigma_allspw_withnans_weighted.fits'
fwhmpath=glob.glob(texlocs[source]+'*fwhm*')[0]
nch3ohpath=glob.glob(texlocs[source]+'ntotmap_allspw_withnans_weighted_useintercept_3sigma.fits')[0]
texmapdata=fits.getdata(texmappath)*u.K
fwhmmap=fits.getdata(fwhmpath)*u.km/u.s
nch3ohmap=fits.getdata(nch3ohpath)*u.cm**-2
pixdict={'SgrB2S':(70,59),'DSi':(36,42),'DSii':(22,24),'DSiii':(24,24),'DSiv':(32,31),'DSv':(19,19),'DSVI':(62,62),'DSVII':(75,75),'DSVIII':(50,50),'DSIX':(34,32),'DS10':(35,35)}#SgrB2S:61,64, DSIX:(34,35)
targetpix=pixdict[source]
testT=texmapdata[targetpix[0],targetpix[1]]#350*u.K
fwhm_at_pix=fwhmmap[targetpix[0],targetpix[1]]
nch3oh_at_pix=nch3ohmap[targetpix[0],targetpix[1]]
#print(fwhm_at_pix)
#pdb.set_trace()
sourcepath=sourcelocs[source]
print(f'Collecting spectra from {sourcepath}')
incubes=glob.glob(sourcepath)
inspecs=glob.glob(sourcepath+'/*.txt')
instds=glob.glob(texlocs[source]+'errorimgs/std/*.fits')
images=['spw0','spw1','spw2','spw3']
spectra=[]
stds=[]
for spew in images:
for f1 in inspecs:
if spew in f1:
if str(targetpix[0]) in f1 and str(targetpix[1]) in f1:
spectra.append(f1)
continue
else:
continue
for f2 in instds:
if spew in f2:
stds.append(f2)
continue
else:
continue
assert 'spw0' in spectra[0] and 'spw0' in stds[0], 'List out of order'
print('Spectra and stds are sequential order')
linewidth=fwhm_at_pix#2.5*u.km/u.s#2.5 km/s is ideal for DSVI
print(f'Absolute model line width: {linewidth}\n')
specieslist=[' CH3OH ',' CH3OCHO ',' HOONO ',' HNCO ',' DCN ',' H2CO ',' C2H5OH ',' CH3CHO ',' CH3COOH ',' CH3NH2 ', ' CH3OCH3 ', ' HC3N ',' NH2CHO ', ' NH2CN ',' NH2D ',' SO2 ',' SO ',' t-HCOOH ',' a-H2CCHOH ',' s-H2CCHOH ',' H2CCNH ',' CH3CH2CHO ',' HCCCHO ',' SiS ',' CH2DOH ',' C(18)O ',' HDO ',' CH2CHCN ',' CH3CH2CN ',' c-H2COCH2 ', ' c-HCCCH ',' CCS ',' CH2NH ',"Ethylene Glycol",' cis-CH2OHCHO ','Acetone', ' CH3CN ',' CH2CHCN ',' CH3O13CHO ', ' SiO ', ' OCS ', 'N2D+', ' CH3C(15)N ',' CH3CCH ',' CH3SH ',' 13CS ', ' H2S ', ' SO ',' CH3(18)OH ', ' 13CH3OH ']
linelistdict={' CH3OH ':'JPL',' CH3OCHO ':'JPL',' CH3CHO ':'JPL',' C2H5OH ':'CDMS',' CH3OCH3 ':'JPL',' DCN ':'JPL',' OCS ':'CDMS',' 13CH3OH ':'CDMS',' H2CO ':'CDMS',' HC3N ':'CDMS',' C(18)O ':'CDMS',' 13CS ':'CDMS',' SO2 ':'CDMS',' NH2CHO ':'JPL',' HNCO ':'CDMS',' SO ':'CDMS', ' SiO ':'CDMS',' H2S ':'CDMS',' c-HCCCH ':'CDMS', 'HC3N v7=1':'CDMS',' H213CO ':'CDMS',' 13CH3CN ':'CDMS',' CH3COOH ':'CDMS',' t-HCOOH ':'CDMS',' CH3O13CHO ':'TopModel',' HNO3 ':'JPL',' CH3O13CHO, vt = 0, 1 ':'CDMS',' NH2CN ':'JPL',' CH2CHCN ':'CDMS','CH3OCHO v=1':'JPL',' 18OCS ':'CDMS',' CH3NCO, vb = 0 ':'CDMS',' CH3CH2CN ':'CDMS',' NH2CO2CH3 v=1 ':'JPL',' HOCN ':'CDMS',' 13CH3CCH ':'JPL'}#' H15NO3 ':'JPL'}
jplnamelist={}
cdmsnamelist={' 13CH3OH ':'C-13-H3OH, vt=0,1',' C(18)O ':'CO-18',' 13CS ':'C-13-S, v=0,1',' NH2CHO ':'HC(O)NH2, v=0',' c-HCCCH ':'c-C3H2','HC3N v7=1':'HC3N, v7=1',' H213CO ':'H2C-13-O',' 13CH3CN ':'C-13-H3CN, v=0',' 18OCS ':'O-18-CS',' N17O ':'N-15-O-17',' CH3CH2CN ':'C2H5CN, v=0', ' 13CH3OCH3 ':'C-13-H3OCH3',}#' 13CH3CCH ':'C-13-H3CCH'}# CH3O13CHO, vt = 0, 1 ':'CH3OC-13-HO, vt=0,1'}# H15NO3':'HN-15-O3'}#' CH3NCO, vb=0 ':'CH3NCO, vb=0'}#' H2S ':'H2S'}#'CO-18'}#' HC3N ':'HC3N, v=0',' C2H5OH ':'C2H5OH,v=0',' CH3OCH3 ':'CH3OCH3, v=0',' OCS ':'060503 OCS, v=0',
sgrb2scolumns={' CH3OH ':1.7e18*u.cm**-2,' CH3OCHO ':3e16*u.cm**-2, ' CH3CHO ':1.5e16*u.cm**-2,' C2H5OH ':9e16*u.cm**-2,' CH3OCH3 ':9e15*u.cm**-2,' DCN ':3.5e16*u.cm**-2, ' OCS ':6e17*u.cm**-2,' 13CH3OH ':7e17*u.cm**-2,' H2CO ':7e17*u.cm**-2,' HC3N ':1e16*u.cm**-2, ' C(18)O ':1.3e19*u.cm**-2,' 13CS ':3e16*u.cm**-2,' SO2 ':2e17*u.cm**-2,' NH2CHO ':9e15*u.cm**-2,' HNCO ':3e17*u.cm**-2,' SO ':5e17*u.cm**-2,' SiO ':1e15*u.cm**-2,' H2S ':2e18*u.cm**-2,' c-HCCCH ':5e15*u.cm**-2, 'HC3N v7=1':5e15*u.cm**-2,' H213CO ':7e16*u.cm**-2,' 13CH3CN ':1e16*u.cm**-2,' CH2CHCN ':4e15*u.cm**-2,' 18OCS ':3e17*u.cm**-2,' CH3NCO, vb = 0 ':1e16*u.cm**-2,' CH3CH2CN ':1.5e16*u.cm**-2,}#' 13CH3CCH ':1e17*u.cm**-2}#' NH2CN ':1e15*u.cm**-2,}#' 13CH3OCH3 ':1e14*u.cm**-2}#'CH3OCHO v=1':1e17*u.cm**-2}#' CH3O13CHO ':1e14*u.cm**-2,' H2CCO ':1e16*u.cm**-2,}#' H2CS ':1e18*u.cm**-2,' CH3(18)OH ':2.5e16*u.cm**-2,' NH2CN ':1e14*u.cm**-2, ' NH2D ':1e15*u.cm**-2, ' t-HCOOH ':5e14*u.cm**-2,' SiS ':1e14*u.cm**-2, ' c-HCCCH ':2.5e15*u.cm**-2, 'Acetone':6e13*u.cm**-2,' CH3C(15)N ':3e13*u.cm**-2,' SiN ':2e15*u.cm**-2, ' CH3NH2 ':9e15*u.cm**-2,}#' HOONO ':5e15*u.cm**-2,' CH3COOH ':2e15*u.cm**-2,
#CDMS - ' CH3OH ':1.2e17*u.cm**-2,
dsicolumns={' CH3OH ':1.7e18*u.cm**-2,' CH3OCHO ':2.5e16*u.cm**-2, ' CH3CHO ':1.2e16*u.cm**-2,' C2H5OH ':9e16*u.cm**-2,' CH3OCH3 ':7e15*u.cm**-2,' DCN ':1.5e16*u.cm**-2, ' OCS ':8e17*u.cm**-2,' 13CH3OH ':7e17*u.cm**-2,' H2CO ':7e17*u.cm**-2,' HC3N ':1.7e16*u.cm**-2, ' C(18)O ':7e19*u.cm**-2,' 13CS ':4e16*u.cm**-2,' SO2 ':7e16*u.cm**-2,' NH2CHO ':9e15*u.cm**-2,' HNCO ':2e17*u.cm**-2,' SO ':9e16*u.cm**-2,' SiO ':1e16*u.cm**-2,' H2S ':3.5e18*u.cm**-2,' c-HCCCH ':5e15*u.cm**-2, 'HC3N v7=1':5e15*u.cm**-2,' H213CO ':7e16*u.cm**-2,' 13CH3CN ':1e16*u.cm**-2,' CH2CHCN ':1e15*u.cm**-2,' 18OCS ':1e17*u.cm**-2,' CH3NCO, vb = 0 ':2.5e15*u.cm**-2,' CH3CH2CN ':1e16*u.cm**-2,}#' HOCN ':1e16*u.cm**-2}#' NH2CO2CH3 v=1 ':1e16*u.cm**-2}#' CH3O13CHO, vt = 0, 1 ':5e16*u.cm**-2,}#' H15NO3 ':1e17*u.cm**-2}#{' CH3OH ':1e17*u.cm**-2,' CH3OCHO ':3e14*u.cm**-2,' HOONO ':1e15*u.cm**-2,' HNCO ':0.7e15*u.cm**-2,' DCN ':1e14*u.cm**-2,' H2CO ':1e16*u.cm**-2,' C2H5OH ':3e15*u.cm**-2, ' CH3CHO ':2e14*u.cm**-2,' CH3COOH ':0.7e14*u.cm**-2, ' CH3NH2 ':1e15*u.cm**-2, ' CH3OCH3 ':6e13*u.cm**-2,' HC3N ':1e14*u.cm**-2, ' NH2CHO ':1e12*u.cm**-2,' NH2CN ':0.8e14*u.cm**-2, ' NH2D ':1e15*u.cm**-2, ' SO2 ':8e14*u.cm**-2, ' SO ':7e11*u.cm**-2, ' t-HCOOH ':5e14*u.cm**-2,' SiS ':5e13*u.cm**-2,' C(18)O ':5e17*u.cm**-2,' CH2DOH ':5e15*u.cm**-2, ' CH2NH ':1e13*u.cm**-2,"Ethylene Glycol":1e13*u.cm**-2,'Acetone':0.25e13*u.cm**-2, ' SiO ':7e13*u.cm**-2, ' OCS ':5.25e15*u.cm**-2, ' 13CS ':5e14*u.cm**-2, ' 13CH3OH ':2e15*u.cm**-2}
ds2columns={' CH3OH ':1.2e18*u.cm**-2,' CH3OCHO ':3e15*u.cm**-2,' CH3CHO ':3e15*u.cm**-2,' C2H5OH ':3e16*u.cm**-2,' CH3OCH3 ':3e15*u.cm**-2,' DCN ':5e15*u.cm**-2,' OCS ':3e17*u.cm**-2,' 13CH3OH ':1.5e17*u.cm**-2,' H2CO ':4e17*u.cm**-2,' HC3N ':9e15*u.cm**-2,' C(18)O ':6e19*u.cm**-2,' 13CS ':1e16*u.cm**-2,' SO2 ':2.5e16*u.cm**-2,' NH2CHO ':3e15*u.cm**-2,' HNCO ':5e16*u.cm**-2,' SO ':1.2e17*u.cm**-2, ' SiO ':5e15*u.cm**-2,' H2S ':1.2e18*u.cm**-2,' c-HCCCH ':3e15*u.cm**-2, 'HC3N v7=1':6e16*u.cm**-2,' H213CO ':2e16*u.cm**-2,' 13CH3CN ':2e15*u.cm**-2,' CH2CHCN ':5e14*u.cm**-2,' 18OCS ':6e15*u.cm**-2,' CH3NCO, vb = 0 ':3e14*u.cm**-2,' CH3CH2CN ':3e15*u.cm**-2,}#' HOCN ':1e16*u.cm**-2}#'CH3O13CHO, vt = 0, 1':5e15*u.cm**-2' CH3(18)OH ':2.5e15*u.cm**-2, ' CH3NH2 ':1e15*u.cm**-2, ' (13)CN ':1.5e15*u.cm**-2 NH2CN ':1e13*u.cm**-2, ' NH2D ':1e15*u.cm**-2, ' t-HCOOH ':1e14*u.cm**-2, ' SiS ':4e15*u.cm**-2,}' HOONO ':1e16*u.cm**-2,'Carbon Dioxide':5e16*u.cm**-2,' NaCl ':1e16*u.cm**-2,' CH3COOH ':7e14*u.cm**-2,' HDCO ':1e18*u.cm**-2,
ds3columns={' CH3OH ':9e17*u.cm**-2,' CH3OCHO ':7e15*u.cm**-2,' CH3CHO ':3e15*u.cm**-2,' C2H5OH ':3e16*u.cm**-2,' CH3OCH3 ':3e15*u.cm**-2,' DCN ':5e15*u.cm**-2,' OCS ':3.5e17*u.cm**-2,' 13CH3OH ':1.5e17*u.cm**-2,' H2CO ':4e17*u.cm**-2,' HC3N ':9e15*u.cm**-2,' C(18)O ':6e19*u.cm**-2,' 13CS ':1e16*u.cm**-2,' SO2 ':2.5e16*u.cm**-2,' NH2CHO ':1e15*u.cm**-2,' HNCO ':2e16*u.cm**-2,' SO ':1e17*u.cm**-2, ' SiO ':5e15*u.cm**-2,' H2S ':1.5e18*u.cm**-2,' c-HCCCH ':5e15*u.cm**-2, 'HC3N v7=1':9e15*u.cm**-2,' H213CO ':1e16*u.cm**-2,' 13CH3CN ':3e15*u.cm**-2,' CH2CHCN ':4e14*u.cm**-2,' 18OCS ':4e16*u.cm**-2,' CH3NCO, vb = 0 ':3e14*u.cm**-2,' CH3CH2CN ':3.5e15*u.cm**-2,}
ds4columns={' CH3OH ':1.3e18*u.cm**-2,' CH3OCHO ':7.5e15*u.cm**-2,' CH3CHO ':4e15*u.cm**-2,' C2H5OH ':4e16*u.cm**-2,' CH3OCH3 ':3e15*u.cm**-2,' DCN ':7e15*u.cm**-2,' OCS ':5e17*u.cm**-2,' 13CH3OH ':1.5e17*u.cm**-2,' H2CO ':4e17*u.cm**-2,' HC3N ':1e16*u.cm**-2,' C(18)O ':6e19*u.cm**-2,' 13CS ':2e16*u.cm**-2,' SO2 ':2.5e16*u.cm**-2,' NH2CHO ':2e15*u.cm**-2,' HNCO ':2e16*u.cm**-2,' SO ':1e17*u.cm**-2, ' SiO ':5e15*u.cm**-2,' H2S ':1.8e18*u.cm**-2,' c-HCCCH ':5e15*u.cm**-2, 'HC3N v7=1':1.5e16*u.cm**-2,' H213CO ':2e16*u.cm**-2,' 13CH3CN ':5e15*u.cm**-2,' CH2CHCN ':4e14*u.cm**-2,' 18OCS ':7e16*u.cm**-2,' CH3NCO, vb = 0 ':3e14*u.cm**-2,' CH3CH2CN ':6e15*u.cm**-2,}
ds5columns={' CH3OH ':3e17*u.cm**-2,' CH3OCHO ':3e15*u.cm**-2,' CH3CHO ':1e15*u.cm**-2,' C2H5OH ':9e15*u.cm**-2,' CH3OCH3 ':1.3e15*u.cm**-2,' DCN ':5e15*u.cm**-2,' OCS ':6e16*u.cm**-2,' 13CH3OH ':9e16*u.cm**-2,' H2CO ':1e17*u.cm**-2,' HC3N ':2e15*u.cm**-2,' C(18)O ':1e19*u.cm**-2,' 13CS ':4.5e15*u.cm**-2,' SO2 ':9e15*u.cm**-2,' NH2CHO ':4e14*u.cm**-2,' HNCO ':1e16*u.cm**-2,' SO ':2e16*u.cm**-2, ' SiO ':5e15*u.cm**-2,' H2S ':4e17*u.cm**-2,' c-HCCCH ':5e14*u.cm**-2, 'HC3N v7=1':5e15*u.cm**-2,' H213CO ':5e15*u.cm**-2,' 13CH3CN ':8e14*u.cm**-2,' CH2CHCN ':1e13*u.cm**-2,' 18OCS ':6e15*u.cm**-2,' CH3NCO, vb = 0 ':1e14*u.cm**-2,' CH3CH2CN ':5e14*u.cm**-2,}
ds6columns={' CH3OH ':2e18*u.cm**-2,' CH3OCHO ':2.5e16*u.cm**-2, ' CH3CHO ':1.3e16*u.cm**-2,' C2H5OH ':9e16*u.cm**-2,' CH3OCH3 ':7e15*u.cm**-2,' DCN ':3.5e16*u.cm**-2, ' OCS ':6e17*u.cm**-2,' 13CH3OH ':7e17*u.cm**-2,' H2CO ':7e17*u.cm**-2,' HC3N ':1e16*u.cm**-2, ' C(18)O ':7e19*u.cm**-2,' 13CS ':4e16*u.cm**-2,' SO2 ':7e16*u.cm**-2,' NH2CHO ':9e15*u.cm**-2,' HNCO ':2e17*u.cm**-2,' SO ':2e17*u.cm**-2,' SiO ':1e16*u.cm**-2,' H2S ':2e18*u.cm**-2,' c-HCCCH ':5e15*u.cm**-2, 'HC3N v7=1':5e15*u.cm**-2,' H213CO ':7e16*u.cm**-2,' 13CH3CN ':9e15*u.cm**-2,' CH2CHCN ':2.5e15*u.cm**-2,' 18OCS ':1e17*u.cm**-2,' CH3NCO, vb = 0 ':2.5e15*u.cm**-2,' CH3CH2CN ':9e15*u.cm**-2,}
ds7columns={' CH3OH ':5e17*u.cm**-2,' CH3OCHO ':5e15*u.cm**-2,' CH3CHO ':1.5e15*u.cm**-2,' C2H5OH ':1e16*u.cm**-2,' CH3OCH3 ':3e15*u.cm**-2,' DCN ':2e15*u.cm**-2,' OCS ':2e17*u.cm**-2,' 13CH3OH ':8e16*u.cm**-2,' H2CO ':1e17*u.cm**-2,' HC3N ':6e15*u.cm**-2,' C(18)O ':1.5e19*u.cm**-2,' 13CS ':5e15*u.cm**-2,' SO2 ':4e15*u.cm**-2,' NH2CHO ':7e14*u.cm**-2,' HNCO ':1.5e16*u.cm**-2,' SO ':3e16*u.cm**-2, ' SiO ':3e15*u.cm**-2,' H2S ':6e17*u.cm**-2,' c-HCCCH ':2e15*u.cm**-2, 'HC3N v7=1':3e16*u.cm**-2,' H213CO ':6e15*u.cm**-2,' 13CH3CN ':2e15*u.cm**-2,' CH2CHCN ':4e14*u.cm**-2,' 18OCS ':4e16*u.cm**-2,' CH3NCO, vb = 0 ':1e15*u.cm**-2, ' CH3CH2CN ':5e15*u.cm**-2,}#{' CH3OH ':1e16*u.cm**-2,' CH3OCHO ':1e15*u.cm**-2,' HOONO ':1e15*u.cm**-2,' HNCO ':1e15*u.cm**-2,' DCN ':1e14*u.cm**-2,' H2CO ':1e16*u.cm**-2,' C2H5OH ':3e15*u.cm**-2, ' CH3CHO ':1e14*u.cm**-2,' CH3COOH ':1e14*u.cm**-2, ' CH3NH2 ':1e15*u.cm**-2, ' CH3OCH3 ':1e14*u.cm**-2,' HC3N ':1e14*u.cm**-2, ' NH2CHO ':1e12*u.cm**-2,' NH2CN ':1e14*u.cm**-2, ' NH2D ':1e15*u.cm**-2, ' SO2 ':1e15*u.cm**-2, ' SO ':6e11*u.cm**-2, ' t-HCOOH ':1e14*u.cm**-2,' SiS ':1e14*u.cm**-2, ' OCS ':3e15*u.cm**-2, ' SiO ':1e14*u.cm**-2}
ds8columns={' CH3OH ':7e17*u.cm**-2,' CH3OCHO ':5e15*u.cm**-2,' CH3CHO ':2.5e15*u.cm**-2,' C2H5OH ':3e16*u.cm**-2,' CH3OCH3 ':3e15*u.cm**-2,' DCN ':2e15*u.cm**-2,' OCS ':3.5e17*u.cm**-2,' 13CH3OH ':8e16*u.cm**-2,' H2CO ':1e17*u.cm**-2,' HC3N ':6e15*u.cm**-2,' C(18)O ':4e19*u.cm**-2,' 13CS ':5e15*u.cm**-2,' SO2 ':4e15*u.cm**-2,' NH2CHO ':7e14*u.cm**-2,' HNCO ':4e16*u.cm**-2,' SO ':3e16*u.cm**-2, ' SiO ':2e15*u.cm**-2,' H2S ':8e17*u.cm**-2,' c-HCCCH ':2e15*u.cm**-2, 'HC3N v7=1':1e16*u.cm**-2,' H213CO ':9e15*u.cm**-2,' 13CH3CN ':2e15*u.cm**-2,' CH2CHCN ':4e14*u.cm**-2,' 18OCS ':3e16*u.cm**-2,' CH3NCO, vb = 0 ':1e15*u.cm**-2, ' CH3CH2CN ':3e15*u.cm**-2,}
ds9columns={' CH3OH ':2.5e17*u.cm**-2,' CH3OCHO ':9e14*u.cm**-2,' CH3CHO ':1e14*u.cm**-2,' C2H5OH ':7e15*u.cm**-2,' CH3OCH3 ':9e14*u.cm**-2,' DCN ':3e15*u.cm**-2,' OCS ':1e17*u.cm**-2,' 13CH3OH ':1.5e16*u.cm**-2,' H2CO ':9e15*u.cm**-2,' HC3N ':9e14*u.cm**-2,' C(18)O ':9e18*u.cm**-2,' 13CS ':4e15*u.cm**-2,' SO2 ':2.5e15*u.cm**-2,' NH2CHO ':3e14*u.cm**-2,' HNCO ':5e15*u.cm**-2,' SO ':2e16*u.cm**-2, ' SiO ':6e14*u.cm**-2,' H2S ':3.5e17*u.cm**-2,' c-HCCCH ':8e14*u.cm**-2, 'HC3N v7=1':5e15*u.cm**-2,' H213CO ':5e15*u.cm**-2,' 13CH3CN ':5e14*u.cm**-2,' CH3CH2CN ':9e14*u.cm**-2,}#{' CH3OH ':1e15*u.cm**-2,' CH3OCHO ':1e15*u.cm**-2,' HOONO ':1e15*u.cm**-2,' HNCO ':1e15*u.cm**-2,' DCN ':1e14*u.cm**-2,' H2CO ':1e16*u.cm**-2,' C2H5OH ':3e15*u.cm**-2, ' CH3CHO ':1e14*u.cm**-2,' CH3COOH ':1e14*u.cm**-2, ' CH3NH2 ':1e15*u.cm**-2, ' CH3OCH3 ':1e14*u.cm**-2,' HC3N ':1e14*u.cm**-2, ' NH2CHO ':1e12*u.cm**-2,' NH2CN ':1e14*u.cm**-2, ' NH2D ':1e15*u.cm**-2, ' SO2 ':1e15*u.cm**-2, ' SO ':6e11*u.cm**-2, ' t-HCOOH ':1e14*u.cm**-2,' SiS ':1e14*u.cm**-2, ' OCS ':3e15*u.cm**-2, ' SiO ':1e14*u.cm**-2}
ds10columns={' CH3OH ':6e17*u.cm**-2,' CH3OCHO ':3e15*u.cm**-2,' CH3CHO ':9e14*u.cm**-2,' C2H5OH ':9e15*u.cm**-2,' CH3OCH3 ':2e15*u.cm**-2,' DCN ':3e15*u.cm**-2,' OCS ':1.5e17*u.cm**-2,' 13CH3OH ':1e17*u.cm**-2,' H2CO ':6e16*u.cm**-2,' HC3N ':5e15*u.cm**-2,' C(18)O ':3e19*u.cm**-2,' 13CS ':1e16*u.cm**-2,' SO2 ':6e15*u.cm**-2,' NH2CHO ':5e14*u.cm**-2,' HNCO ':5e15*u.cm**-2,' SO ':5e16*u.cm**-2, ' SiO ':4e15*u.cm**-2,' H2S ':4e17*u.cm**-2,' c-HCCCH ':9e14*u.cm**-2, 'HC3N v7=1':5e15*u.cm**-2,' H213CO ':1e16*u.cm**-2,' 13CH3CN ':1.5e15*u.cm**-2,}
weeds=[' CH3OCHO ', ' CH3CHO ']
cdmsproblemchildren=['OCS','13CS','C(18)O','HNCO','SO','HC3N','CH3NCO, vb=0','CH3CH2CN']
problemchildren2=['CH3NCO, vb=0']
sourcecolumns={'SgrB2S':sgrb2scolumns,'DSi':dsicolumns, 'DSii':ds2columns,'DSiii':ds3columns,'DSiv':ds4columns,
'DSv':ds5columns,'DSVI':ds6columns,'DSVII':ds7columns,'DSVIII':ds8columns,'DSIX':ds9columns,'DS10':ds10columns}
columndict=sourcecolumns[source]
#plt.rcParams['figure.dpi'] = 300
#plt.figure(1, figsize=(30,10))
molcolors=['red','cyan','orange','brown','deepskyblue','darkviolet','yellow','pink','darkviolet','darkkhaki','silver','blue','lime','magenta','grey','plum','fuchsia','darkcyan','magenta','deeppink','gold','palegreen','goldenrod','indigo','dodgerblue','mediumpurple','yellow','red']
spwmoldict={}
dummylist=[]
p1firstmolline={}#list(np.ones(len(columndict.keys())))
p2firstmolline={}
p3firstmolline={}
p4firstmolline={}
firstmolline=p1firstmolline
plotspecpad=0.005*u.GHz
n=1
for m in columndict.keys():
p1firstmolline.update({m:1})
p2firstmolline.update({m:1})
p3firstmolline.update({m:1})
p4firstmolline.update({m:1})
for spectrum, img, stdimage in zip(spectra,images,stds):
print('Getting ready - '+img)
plt.rcParams['figure.dpi'] = mode
plt.figure(n, figsize=(20,10))
n+=1
if img == 'spw1':
firstmolline=p2firstmolline
if img == 'spw2':
firstmolline=p3firstmolline
if img == 'spw3':
firstmolline=p4firstmolline
'''
plt.xlim(xmin=(p1minfreq-plotspecpad).value,xmax=(p1maxfreq+plotspecpad).value)
plt.xlabel(r'$\nu$ (Hz)',fontsize=16)
plt.ylabel('T$_b$ (K)',fontsize=16)
plt.ylim(ymax=100)
plt.tick_params(labelsize=13)
plt.legend()
plt.tight_layout()
plt.show()
'''
spec=np.genfromtxt(spectrum)
error=fits.getdata(stdimage)[targetpix[0],targetpix[1]]*u.K
freqs=(spec[:,0]*u.MHz).to('GHz')#cube.spectral_axis
data=spec[:,1]*u.K
freqflip=False
if freqs[0] > freqs[1]:
freqs=freqs[::-1]
data=data[::-1]
freqflip=True
print('Corrected decreasing frequency axis')
else:
pass
freq_min=freqs[0]*(1+z)#215*u.GHz
freq_max=freqs[(len(freqs)-1)]*(1+z)#235*u.GHz
assert freq_max > freq_min, 'Decreasing frequency axis'
print('Plotting model spectra')
plt.plot(freqs.value,data.value,drawstyle='steps-mid',color='black')
'''Generate methanol table for use during contaminant search'''
#pdb.set_trace()
Jfreqs, Jaij, Jdeg, JEU, qrot = get_molecular_parameters('CH3OH',
catalog='JPL',
fmin=freq_min,
fmax=freq_max)
#sys.exit()
qrot_partfunc=qrot(testT)
methanol_table=Splatalogue.query_lines(freq_min, freq_max, chemical_name=' CH3OH ', energy_max=1840, energy_type='eu_k', line_lists=[linelistdict[' CH3OH ']], show_upper_degeneracy=True)
minmethtable=utils.minimize_table(methanol_table)
mlines=((minmethtable['Freq']*10**9)/(1+z)*u.Hz).to('GHz')
mqns=minmethtable['QNs']
meuks=minmethtable['EU_K']*u.K
meujs=meuks*k
mdegs=methanol_table['Upper State Degeneracy']
mlog10aijs=minmethtable['log10_Aij']
maijs=10**mlog10aijs*u.s**-1
'''Create background model for the methanol lines and other species'''
baseline=models.Linear1D(slope=(0*(u.K/u.Hz)),intercept=0*u.K)
#mbaseline=models.Linear1D(slope=(0*(u.K/u.Hz)),intercept=0*u.K)
baseline.bounding_box=(freqs[0],freqs[(len(freqs)-1)])
#mbaseline.bounding_box=(freqs[0],freqs[(len(freqs)-1)])
#modelspec=baseline
methmodelspec=baseline
plot=np.linspace(freqs[0],freqs[(len(freqs)-1)],np.shape(spec)[0]).to('GHz')
modeldict={}
#sys.exit()
for molecule,hue,first in zip(list(columndict.keys())[1:], molcolors,list(firstmolline.keys())[1:]):
'''Generate species table for contaminant search'''
modelspec=baseline
species_table= Splatalogue.query_lines(freq_min, freq_max, chemical_name=molecule, energy_max=1840, energy_type='eu_k', line_lists=[linelistdict[molecule]], show_upper_degeneracy=True)
if len(species_table['Chemical Name']) == 0:
print(f'No transitions for {molecule} in {img}. Continue')
continue
else:
pass
#a=cdms_get_molecule_name('CH3NCO, vb=0')
ll=linelistdict[molecule]
param_molname=molecule.replace(' ','')
if ll == 'CDMS':
#if molecule in cdmsnamelist.keys():
if molecule in cdmsnamelist.keys():
molname=cdmsnamelist[molecule]
elif molecule == ' CH3NCO, vb = 0 ':
molname=cdms_get_molecule_name('CH3NCO, vb=0')
else:
molname=cdms_get_molecule_name(param_molname)#cdmsnamelist[molecule]
#else:
#molname=param_molname
if param_molname in cdmsproblemchildren:
cCfreqs, cCaij, cCdeg, cCEU, c_qrot = get_molecular_parameters(molname,catalog='CDMS',
fmin=freq_min, fmax=(freq_max+100*u.GHz),)
else:
cCfreqs, cCaij, cCdeg, cCEU, c_qrot = get_molecular_parameters(molname,
catalog='CDMS',fmin=freq_min,fmax=freq_max,)
if ll == 'JPL':
if molecule in jplnamelist.keys():
molname=cdmsnamelist[molecule]
else:
molname=param_molname
cJfreqs, cJaij, cJdeg, cJEU, c_qrot = get_molecular_parameters(molname,catalog='JPL',
fmin=freq_min,
fmax=freq_max,)
c_qrot_partfunc=c_qrot(testT)
minchemtable=utils.minimize_table(species_table)
if molecule in othermol_dshift_v.keys():
otherz=othermol_dshift_v[molecule]/c
clines=((minchemtable['Freq']*10**9)/(1+otherz)*u.Hz).to('GHz')
else:
clines=((minchemtable['Freq']*10**9)/(1+z)*u.Hz).to('GHz')
cqns=minchemtable['QNs']
ceuks=minchemtable['EU_K']*u.K
ceujs=ceuks*k
cdegs=species_table['Upper State Degeneracy']
clog10aijs=minchemtable['log10_Aij']
caijs=10**clog10aijs*u.s**-1
cntot=columndict[molecule]
print(f'Begin model loops for {molecule}')
linedetections=[]
for line,deg,euj,aij,qn in zip(clines,cdegs,ceujs,caijs,cqns):
#print(f'Transition: {qn} @ {line.to("GHz")}')
if molecule in othermol_dshift_v.keys():
restline=line*(1+otherz)
else:
restline=line*(1+z)
est_nupper=nupper_estimated(cntot,deg,c_qrot_partfunc,euj,testT).to('cm-2')
modlinewidth=velocitytofreq(linewidth,line)
lineprofilesigma=modlinewidth/2*np.sqrt(2*np.log(2))
phi_nu=lineprofile(sigma=lineprofilesigma,nu_0=restline,nu=restline)
intertau=lte_molecule.line_tau(testT, cntot, qrot_partfunc, deg, restline, euj, aij)
est_tau=(intertau/modlinewidth).to('')
#print(f'Estimated tau: {"{:.3f}".format(est_tau)}')
trad=t_rad(tau_nu=est_tau,ff=f,nu=restline,T_ex=testT).to('K')
if trad >= 3*error:
#print(f'Estimated brightness: {"{:.3f}".format(trad)}')
#modlinewidth=velocitytofreq(linewidth,line)
#print(f'Model linewidth (Hz): {modlinewidth}')
modelline=models.Gaussian1D(mean=line, stddev=modlinewidth, amplitude=trad)
#modelgaus+=modelline
modelspec+=modelline
linedetections.append(True)
else:
#print(f'{qn} line brightness ({trad}) below 3sigma threshold ({3*error})')
linedetections.append(False)
continue
if molecule == ' CH3CHO ':
dummylist.append((freqs,modelspec(freqs)))#spwmoldict.update({img:(freqs,modelspec(freqs))})
if firstmolline[first] and True in linedetections:
plt.plot(freqs,modelspec(freqs),drawstyle='steps-mid',color=hue,label=molecule)
firstmolline[first]=0
elif True in linedetections:
plt.plot(freqs,modelspec(freqs),drawstyle='steps-mid',color=hue)
if ' CH3OH ' in columndict:
print('Begin CH3OH modeling\n')
mdetections=[]
for line,deg,euj,aij,qn in zip(mlines,mdegs,meujs,maijs,mqns):
#print(f'Transition: {qn} @ {line.to("GHz")}')
restline=line*(1+z)
modlinewidth=velocitytofreq(linewidth,line)
lineprofilesigma=modlinewidth/2*np.sqrt(2*np.log(2))
phi_nu=lineprofile(sigma=lineprofilesigma,nu_0=restline,nu=restline)
methntot=columndict[' CH3OH ']
est_nupper=nupper_estimated(methntot,deg,qrot_partfunc,euj,testT).to('cm-2')
intertau=lte_molecule.line_tau(testT, methntot, qrot_partfunc, deg, restline, euj, aij)
est_tau=(intertau*phi_nu).to('')
#print(f'Estimated tau: {"{:.3f}".format(est_tau)}')
trad=t_rad(tau_nu=est_tau,ff=f,nu=restline,T_ex=testT).to('K')
if trad >= 3*error:
#print(f'Estimated brightness: {"{:.3f}".format(trad)}')
#print(f'Model linewidth (Hz): {modlinewidth}')
modelline=models.Gaussian1D(mean=line, stddev=modlinewidth, amplitude=trad)
#modelgaus+=modelline
methmodelspec+=modelline
mdetections.append(True)
#elif qn == '16(6)-16(7)E1vt=1':
#pdb.set_trace()
else:
#print(f'{qn} line brightness ({"{:.3f}".format(trad)}) below 3sigma threshold ({3*error})')
mdetections.append(False)
continue
#compositespec=modelspec+methmodelspec
if firstmolline[' CH3OH ']:
plt.plot(freqs,methmodelspec(freqs),drawstyle='steps-mid',linestyle='--',color='green',label=' CH3OH ')
firstmolline[' CH3OH ']=0
print('yay')
else:
plt.plot(freqs,methmodelspec(freqs),drawstyle='steps-mid',linestyle='--',color='green')
print('yayy')
'''
print('Overplotting axvlines and transition annotations')
for line,qn,detected in zip(clines,cqns,linedetections):
if detected:
plt.axvline(x=line.value,linestyle='--',color='yellow',ymin=0.25)
plt.annotate(qn, (line.value, 0), (line.value-0.002,40),rotation=90)
else:
continue
for mline,mqn,detected in zip(mlines,mqns,mdetections):
if detected:
plt.axvline(x=mline.value,linestyle='--',color='pink',ymin=0.25)
plt.annotate(mqn, (mline.value, 0), (line.value-0.002,40),rotation=90)
else:
continue
'''
'''
if img == 'spw3':
p2maxfreq=max(freqs)
plt.xlim(xmin=(p2minfreq-plotspecpad).value,xmax=(p2maxfreq+plotspecpad).value)
'''
if img == '':
plt.xlabel(r'$\nu$ (GHz)',fontsize=16)
plt.ylabel('T$_b$ (K)',fontsize=16)
plt.xlim(xmin=231.7,xmax=232)
plt.ylim(ymax=100,ymin=-20)
plt.tick_params(labelsize=13)
plt.tight_layout()
plt.legend()
#plt.savefig(fr'C:/Users/desmond/Desktop/submission_bootstrap_{source}_{img}_qrotfix_compositespectra.pdf')
plt.show()
sys.exit()
else:
plt.xlabel(r'$\nu$ (GHz)',fontsize=16)
plt.ylabel('T$_b$ (K)',fontsize=16)
plt.xlim(xmin=(min(freqs)-plotspecpad).value,xmax=(max(freqs)+plotspecpad).value)
plt.ylim(ymax=100)
plt.tick_params(labelsize=13)
plt.tight_layout()
plt.legend()
#plt.savefig(fr'C:/Users/desmond/Desktop/CH3OHTemps/CompositeSpectra/submission_bootstrap_{source}_{img}_qrotfix_compositespectra.pdf')
plt.show()