-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_sn1987a_image_analysis.pro
executable file
·236 lines (201 loc) · 9.88 KB
/
new_sn1987a_image_analysis.pro
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
@conf_error2d
pro new_sn1987a_image_analysis, files, counts, lobes=lobes,ring=ring,ptsrc=ptsrc,bilat=bilat, lobsrc=lobsrc ,all=all,doplot=doplot
if n_elements(doplot) eq 0 then doplot=1
nf=n_elements(files)
for k=0,nf-1 do begin
file=files[k]
count=counts[k]
if keyword_set(all) then n=4 else n=0
for i=0,n do begin
if keyword_set(all) then begin
ring = 0 & lobes =0 & ptsrc=0 & bilat = 0 & lobsrc=0
case i of
0: ring=1
1: lobes=1
2: ptsrc=1
3: bilat=1
4: lobsrc=1
endcase
endif
if keyword_set(ring) then mo='ring'
if keyword_set(lobes) then mo='lobes'
if keyword_set(ptsrc) then mo='ptsrc'
if keyword_set(bilat) then mo='bilat'
if keyword_set(lobsrc) then mo='lobsrc'
add='_'+mo
sdir=mo+'/'
if not exist(sdir) then spawn,'mkdir '+sdir
nn=1
fpars=create_struct('a0',0d,'a0err',0d,'a1',0d,'a1err',0d,$
'x0',0d,'x0err',0d,'y0',0d,'y0err',0d,$
'sigr',0d,'sigrerr',dblarr(2),'r0',0d,'r0err',dblarr(2),$
's0',0d,'s0err',0d,'theta0',0d,'theta0err',0d,$
'sigt0',0d,'sigt0err',0d,'sigr0',0d,'sigr0err',0d,$
's1',0d,'s1err',0d,'theta1',0d,'theta1err',0d,$
'sigt1',0d,'sigt1err',0d,'sigr1',0d,'sigr1err',0d,$
's2',0d,'s2err',0d,'theta2',0d,'theta2err',0d,$
'sigt2',0d,'sigt2err',0d,'sigr2',0d,'sigr2err',0d,$
's3',0d,'s3err',0d,'theta3',0d,'theta3err',0d,$
'sigt3',0d,'sigt3err',0d,'sigr3',0d,'sigr3err',0d,$
'counts',0d,$
'xsrc', 0d, 'xsrcerr', 0d, 'ysrc',0d, 'ysrcerr', 0d,$
'wsrc', 0d, 'wsrcerr', 0d, 'fsrc', 0d,$
'fsrcerr', dblarr(2), 'iter',0,'chisq',0d,'dof',0d)
npars=n_tags(fpars)
!p.multi=[0,1,3]
im=mrdfits(file)
im=im-min(im)
im=im/max(im) ;;;LOSE FLUX INFO
im=im/total(im)*count
; PRINT, 'im = ',im
deproject_image,im,newim
print,total(im),total(newim)
new_sn1987a_fit,newim,a,sigma,chisq,dof,iter,fitim,perror,lobes=lobes,ring=ring,ptsrc=ptsrc,bilat=bilat,lobsrc=lobsrc,doplot=doplot
rdis,im
rdis,newim
rdis,fitim
for j=0,npars-3,2 do fpars.(j)=a[j/2]
for j=1,npars-2,2 do fpars.(j)=sigma[(j-1)/2]
r0=a[5]
r0err=perror[*,5]
fpars.r0err=r0err
fpars.sigrerr=perror[*,4]
fpars.fsrcerr=perror[*,26]
fpars.iter=iter
fpars.chisq=chisq
fpars.dof=dof
; ofile='new_sn1987a'+add+'_fitim.fits'
root=str_sep(file,'.fits')
ofile=root[0]+add+'_fitim.fits'
mwrfits,newim,sdir+ofile,/create
mwrfits,fitim,sdir+ofile
diff=newim-fitim
mwrfits,diff,sdir+ofile
fparfile=root[0]+add+'_fpars.fits'
mwrfits,fpars,sdir+fparfile,/create
print,r0,r0err
!p.multi=0
endfor
endfor
return
end
pro new_sn1987a_image_analysis_standard,lobes=lobes,ring=ring,ptsrc=ptsrc,bilat=bilat,all=all,hardsoft=hardsoft
if not keyword_set(lobes) and not keyword_set(ring) and not keyword_set(ptsrc) and not keyword_set(bilat) and not keyword_set(all) and not keyword_set(hardsoft) then begin
print,'Need to specify model (lobes, ring, ptsrc, bilat, all, hardsoft)'
return
endif
if keyword_set(all) then doall=3 else doall=0
for aa=0,doall do begin
if keyword_set(all) then begin
ring=0 & ptsrc=0 & bilat=0 & lobes=0
case aa of
0: ring=1
1: ptsrc=1
2: bilat=1
3: lobes=1
endcase
endif
if keyword_set(ring) then sdir='ring/'
if keyword_set(ptsrc) then sdir='ptsrc/'
if keyword_set(lobes) then sdir='lobes/'
if keyword_set(bilat) then sdir='bilat/'
; if keyword_set(hardsoft) then sdir='hardsoft/'+sdir
if not exist(sdir) then spawn,'mkdir '+sdir
if not keyword_set(hardsoft) then begin
n=ntostr([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21])
n=[n,'22a','22b','23a','23b','23c','24']
; dir='~jracusin/data/sn1987a/image_analysis/'
; dir='/bulk/shadow/racusin/sn1987a/image_analysis/'
; dir='/Volumes/Firewire1/racusin/sn1987a/image_analysis/'
; dir=!data+'/sn1987a/image_analysis/'
dir='../image_analysis/'
cd,dir
files=dir+['sn1987a1_300-8000_cr.fits','sn1987a2_300-8000_cr.fits','sn1987a3_300-8000_cr.fits','sn1987a4_300-8000_cr.fits','sn1987a5_300-8000_cr.fits','sn1987a6_300-8000_cr.fits','sn1987a7_300-8000_cr.fits','sn1987a8_300-8000_cr.fits','sn1987a9_300-8000_cr.fits','sn1987a10_300-8000_cr.fits','sn1987a11_300-8000_cr.fits','sn1987a12_300-8000_cr.fits','sn1987a13_300-8000_cr.fits','sn1987a14_300-8000_cr.fits','sn1987a15_300-8000_cr.fits','sn1987a16_300-8000_cr.fits','sn1987a17_300-8000_cr.fits','sn1987a19_300-8000_cr.fits','sn1987a20A_300-8000_cr.fits','sn1987a21A_300-8000_cr.fits','sn1987a22a_300-8000_cr.fits','sn1987a22b_300-8000_cr.fits','sn1987a23a_300-8000_cr.fits','sn1987a23b_300-8000_cr.fits','sn1987a23c_300-8000_cr.fits','sn1987a24_300-8000_cr.fits']
endif else begin
n=['16m','16h','16s','17m','17h','17s','19m','19h','19s','20m','20h','20s']
dir='/Volumes/Firewire1/racusin/sn1987a/hardsoft_images/'
cd,dir
files=dir+['sn1987a16_1500-8000.fits','sn1987a16_2000-8000.fits','sn1987a16_300-800.fits','sn1987a17_1500-8000.fits','sn1987a17_2000-8000.fits','sn1987a17_300-800.fits','sn1987a19_1500-8000.fits','sn1987a19_2000-8000.fits','sn1987a19_300-800.fits','sn1987a20A_1500-8000_psu.fits','sn1987a20A_2000-8000_psu.fits','sn1987a20A_300-800_psu.fits']
; bilat=1
endelse
; files=dir+['sn1987a1_300-8000_cr.fits','sn1987a2_300-8000_cr.fits','sn1987a3_300-8000_cr.fits','sn1987a4_300-8000_cr.fits','sn1987a5_300-8000_cr.fits','sn1987a6_300-8000_cr.fits','sn1987a7_300-8000_cr.fits','sn1987a8_300-8000_cr.fits','sn1987a9_300-8000_cr.fits','sn1987a10_300-8000_cr.fits','sn1987a11_300-8000_cr.fits','sn1987a12_300-8000_cr.fits','sn1987a13_300-8000_cr.fits','sn1987a14_300-8000_cr.fits','sn1987a15_300-8000_cr.fits','sn1987a16_300-8000_cr.fits','sn1987a17_300-8000_cr.fits','sn1987a19_300-8000_cr.fits','sn1987a20A_300-8000_cr.fits','sn1987a20A_300-8000_cr_psu.fits','sn1987a20H_300-8000_cr.fits','sn1987a20H_300-8000_cr_psu.fits','sn1987a21A_300-8000_cr.fits','sn1987a21A_300-8000_cr_psu.fits','sn1987a21H_300-8000_cr.fits','sn1987a21H_300-8000_cr_psu.fits']
nn=n_elements(files)
fpars=create_struct('a0',0d,'a0err',0d,'a1',0d,'a1err',0d,$
'x0',0d,'x0err',0d,'y0',0d,'y0err',0d,$
'sigr',0d,'sigrerr',dblarr(2),'r0',0d,'r0err',dblarr(2),$
's0',0d,'s0err',0d,'theta0',0d,'theta0err',0d,$
'sigt0',0d,'sigt0err',0d,'sigr0',0d,'sigr0err',0d,$
's1',0d,'s1err',0d,'theta1',0d,'theta1err',0d,$
'sigt1',0d,'sigt1err',0d,'sigr1',0d,'sigr1err',0d,$
's2',0d,'s2err',0d,'theta2',0d,'theta2err',0d,$
'sigt2',0d,'sigt2err',0d,'sigr2',0d,'sigr2err',0d,$
's3',0d,'s3err',0d,'theta3',0d,'theta3err',0d,$
'sigt3',0d,'sigt3err',0d,'sigr3',0d,'sigr3err',0d,$
'counts',0d,'iter',0,'chisq',0d,'dof',0d)
counts=[690,607,9030,1800,6226,6427,9277,9668,11856,17979,16557,24939,27048,30940,30870,32798,27945,12008,12119,9204,3537,4970,2663,3103,3566,8361]*1d
if keyword_set(hardsoft) then counts=[5841,2410,8148,5258,2170,6429,2110,828,2739,2247,916,2721]*1d
npars=n_tags(fpars)
fpars=replicate(fpars,nn)
r0=dblarr(nn) & r0err=dblarr(2,nn)
!p.multi=[0,4,3]
g=0
print,'set g'
colprint,indgen(nn),n,files
stop
if g ne 0 then begin
fpars0=mrdfits(sdir+'new_sn1987a_fpars.fits',1)
struct_assign,fpars0,fpars
endif
for i=g,nn-1 do begin
print,i
im=mrdfits(files[i])
im=im-min(im)
im=im/max(im) ;;;LOSE FLUX INFO
im=im/total(im)*counts[i]
deproject_image,im,newim
print,total(im),total(newim)
; sn1987a_fit,newim,a,fitim,chisq,iter,sigma,r0errs,i,stack=stack
new_sn1987a_fit,newim,a,sigma,chisq,dof,iter,fitim,perror,lobes=lobes,ring=ring,ptsrc=ptsrc,bilat=bilat
; !p.multi=0
rdis,im
rdis,newim
rdis,fitim
;; for j=0,n_elements(a)-1 do fpars[i].(j)=a[j]
; for j=0,npars-3,2 do fpars[i].(j)=a[j/2]
;; dof=200.^2-22.
;; csigma=sigma*sqrt(chisq/dof)
; for j=1,npars-2,2 do fpars[i].(j)=sigma[(j-1)/2]
fnames = tag_names(fpars) ;KAF added combined loop to account for COUNTS having no errors
j = 0
for i = 0,n_elements(a)-1 do begin
print, 'j = ',j
print, 'fname[j] = ',fnames[j]
fpars.(j) = a[i]
if fnames[j] ne 'COUNTS' then begin
fpars.(j+1) = sigma[i]
j = j+2
endif else begin
j = j+1
endelse
endfor
r0[i]=a[5]
r0err[*,i]=perror[*,5]
fpars[i].r0err=r0err[*,i]
fpars[i].sigrerr=perror[*,4]
fpars[i].iter=iter
fpars[i].chisq=chisq
fpars[i].dof=dof
stop
ofile='new_sn1987a'+ntostr(n[i])+'_fitim.fits'
mwrfits,newim,sdir+ofile,/create
mwrfits,fitim,sdir+ofile
diff=newim-fitim
mwrfits,diff,sdir+ofile
mwrfits,fpars,sdir+'new_sn1987a_fpars.fits',/create
;stop
endfor
print,r0,r0err
!p.multi=0
endfor
return
end