-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootstrap_makecompositeradialabunprofile.py
190 lines (177 loc) · 6.28 KB
/
bootstrap_makecompositeradialabunprofile.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
import numpy as np
import matplotlib.pyplot as plt
from astropy.table import Table
import glob
import math
import pdb
import matplotlib as mpl
from collections import OrderedDict
import sys
mpl.interactive(True)
plt.close('all')
def rolling_median(data,kernel):
newlen=math.floor(len(data)/kernel)
median=[]
index=np.arange(newlen)
temp=[]
priorindex=0
nantally=0
for j in data:
nantest=np.isnan(j)
if nantest == True:
if (priorindex+1) % kernel == 0 and priorindex != 0:
med=np.nanmedian(temp)
median.append(med)
temp=[]
nantally=0
else:
nantally+=1
pass
elif nantally == 3:
del radmed[priorindex+1]
print(f'Deletion at index {priorindex+1}')
nantally=0
temp=[]
temperr=[]
else:
dataindex=np.where(data==j)[0][0]
if (dataindex+1) % kernel == 0 and dataindex != 0:
temp.append(j)
med=np.nanmedian(temp)
median.append(med)
temp=[]
nantally=0
#continueflag=True
else:
temp.append(j)
#if continueflag:
# continue
priorindex+=1#pdb.set_trace()
if len(median) != newlen:
pdb.set_trace()
return median
def rolling_median2(data,kernel,error):
newlen=math.floor(len(data)/kernel)
median=[]
mederr=[]
index=np.arange(newlen)
temp=[]
temperr=[]
priorindex=0
nantally=0
for j,e in zip(data,error):
nantest=np.isnan(j)
if nantest == True:
if (priorindex+1) % kernel == 0 and priorindex != 0:
med=np.nanmedian(temp)
if np.any(temperr):
mee=np.nanmedian(temperr)
print('yay')
else:
mee=np.nan
print('boo')
median.append(med)
mederr.append(mee)
temp=[]
temperr=[]
nantally=0
else:
nantally+=1
pass
elif nantally == 3:
del radmed[priorindex+1]
print(f'Deletion at index {priorindex+1}')
nantally=0
temp=[]
temperr=[]
else:
dataindex=np.where(data==j)[0][0]
if (dataindex+1) % kernel == 0 and dataindex != 0:
temp.append(j)
temperr.append(e)
med=np.nanmedian(temp)
mee=np.nanmedian(temperr)
median.append(med)
mederr.append(mee)
temp=[]
temperr=[]
nantally=0
#continueflag=True
else:
temp.append(j)
temperr.append(e)
#if continueflag:
# continue
priorindex+=1#pdb.set_trace()
if len(median) != newlen:
pdb.set_trace()
return median,mederr
pacmanfix=True
linestyles = {'solid':(0, ()),'densely dashdotdotted':(0, (3, 1, 1, 1, 1, 1)),'dotted':(0, (1, 5)),'densely dotted':(0, (1, 1)),'dashed':(0, (5, 5)),'densely dashed':(0, (5, 1)),'solid2':(0, ()),'dashdotted':(0, (3, 5, 1, 5)),'densely dashdotted': (0, (3, 1, 1, 1)),'densely dashdotdotdot':(0, (3, 1, 1, 1, 1, 1))}
pacman='pacman_sep2023revolution'
dataversion='sep2023revolution'#homedict[source].replace('/','')
datadir=f'/blue/adamginsburg/d.jeff/imaging_results/SgrB2DS-CH3OH/{dataversion}/'
pac_datadir='/blue/adamginsburg/d.jeff/imaging_results/SgrB2DS-CH3OH/pacman_sep2023revolution/'
paths=glob.glob(datadir+'*radialavgabun*.txt')
errpaths=glob.glob(datadir+'*err_avgabun.txt')
if pacmanfix:
print('Pacman Fix online')
pacpath=glob.glob(pac_datadir+'*radialavgabun*.txt')
errpacpath=glob.glob(pac_datadir+'*err_avgabun.txt')
oldpath=paths[9]
assert 'SgrB2S' in oldpath, 'SgrB2S not in old path'
paths[9]=pacpath[0]
comptable=Table.read(pac_datadir+'nov92023_allpropertytable.fits')
else:
comptable=Table.read(datadir+'nov92023_allpropertytable.fits')
figpath='/blue/adamginsburg/d.jeff/repos/CH3OHTemps/figures/'
sources=comptable['Source']
radii=comptable['Radius']
names={'DSi':'DS1','DSii':'DS2','DSiii':'DS3','DSiv':'DS4','DSv':'DS5','DSVI':'DS6','DSVII':'DS7','DSVIII':'DS8','DSIX':'DS9','SgrB2S':'SgrB2S'}
names2={'DSi':'DS1','DSii':'DS2','DSiii':'DS3','DSiv':'DS4','DSv':'DS5','DSVI':'DS6','DSVII':'DS7','DSVIII':'DS8','DSIX':'DS9','SgrB2S':'Sgr B2(S)'}
sortedpaths=[]
sortederrs=[]
for s in names.keys():
tes=s+'_'
for p in paths:
if tes in p:
sortedpaths.append(p)
for ss in names.keys():
tess=ss+'_'
for q in errpaths:
if tess in q:
sortederrs.append(q)
paths=sortedpaths
errpaths=sortederrs
plt.rcParams['figure.dpi']=300
plt.figure(figsize=(7,5))
for src,ls in zip(names.keys(),linestyles.keys()):
test=src+'_'
for i,e in zip(paths,errpaths):
if test in i:
sourceintable=np.where(sources==names[src])[0][0]
profile=np.genfromtxt(i)
proferr=np.genfromtxt(e)
tempx=profile[0]
listordered_centrtopix=tempx#[tempx<=radii[sourceintable]]
radialabun=profile[1]
radmed=rolling_median(listordered_centrtopix,3)
abunmed,errorabunmed=rolling_median2(radialabun,3,proferr)
upperabun=np.array(abunmed)+np.array(errorabunmed)
lowerabun=np.array(abunmed)-np.array(errorabunmed)
'''
if len(np.where(lowerabun < 1e-9)[0]) != 0:
pdb.set_trace()
'''
#print(f'{names2[src]}: {medtest[:5]}')
plt.plot(radmed,abunmed[:len(radmed)],label=f'{names2[src]}',linestyle=linestyles[ls],)#yerr=errorabunmed[:len(radmed)])
plt.fill_between(radmed,upperabun,lowerabun,alpha=0.2,)#color='blue')
plt.yscale('log')
plt.xlabel('$r$ (AU)',fontsize=14)
plt.ylabel('X(CH$_3$OH)',fontsize=14)
plt.ylim(ymin=5e-8)
plt.legend(bbox_to_anchor=(1.25, 1), loc="upper right")
#plt.colorbar(pad=0,label='N(H$_2$) (cm$^{-2}$)')#'T$_K$ (K)')
figsavepath=figpath+f'radialavgabundiag_{pacman}_allsource_noradcut_fillbetween.pdf'
plt.savefig(figsavepath,bbox_inches='tight')
plt.show()