Blame view

LabTools/IRAP/JPB/phangs_compare_seds_isrf.pro 6.78 KB
694026f6   Jean-Philippe Bernard   commented
1
PRO phangs_compare_seds_isrf,isrf_class $
026c2ba5   Jean-Philippe Bernard   improved
2
							,isrf_class_analysis=isrf_class_analysis $
694026f6   Jean-Philippe Bernard   commented
3
4
5
6
							,N_seds=N_seds $
							,normalize=normalize $
							,weighted=weighted $
							,include_herschel_filters=include_herschel_filters
42b6dd57   Jean-Philippe Bernard   first commit
7

694026f6   Jean-Philippe Bernard   commented
8
9
;phangs_compare_seds_isrf,0,N_seds=100L    ;test works
;phangs_compare_seds_isrf,0,N_seds=100L,/weighted   ;not working because weights are infinite
026c2ba5   Jean-Philippe Bernard   improved
10
;phangs_compare_seds_isrf,0,N_seds=100L,/normalize   ;not working some mismatch
38087e96   Jean-Philippe Bernard   first commit
11

694026f6   Jean-Philippe Bernard   commented
12
13
;phangs_compare_seds_isrf,15,N_seds=100L
;phangs_compare_seds_isrf,15,N_seds=1000L,/normalize
026c2ba5   Jean-Philippe Bernard   improved
14
15
16
17
;phangs_compare_seds_isrf,15,N_seds=1000L,/normalize,/weighted
;phangs_compare_seds_isrf,15,N_seds=1000L,/normalize,/weighted,/include_herschel_filters

;phangs_compare_seds_isrf,15,N_seds=1000L,/normalize,/weighted,/include_herschel_filters,isrf_class_analysis=14
694026f6   Jean-Philippe Bernard   commented
18

c2457c07   Jean-Philippe Bernard   improved
19
20
21
22
;phangs_compare_seds_isrf,8,N_seds=100L,/normalize,/weighted,isrf_class_analysis=18

;phangs_compare_seds_isrf,8,N_seds=100L,/normalize,/weighted,isrf_class_analysis=18

e6540543   Jean-Philippe Bernard   improved
23
24
25
26
27
28
;phangs_compare_seds_isrf,18,N_seds=100L,isrf_class_analysis=18
;phangs_compare_seds_isrf,18,N_seds=100L,isrf_class_analysis=17
;phangs_compare_seds_isrf,18,N_seds=100L,isrf_class_analysis=17,/weighted
;phangs_compare_seds_isrf,18,N_seds=100L,isrf_class_analysis=16,/weighted
;phangs_compare_seds_isrf,18,N_seds=100L,isrf_class_analysis=14,/weighted

c2457c07   Jean-Philippe Bernard   improved
29
30
;=== weird, these look similar
;phangs_compare_seds_isrf,8,N_seds=100L,/normalize,/weighted,isrf_class_analysis=14
54583f40   Jean-Philippe Bernard   improved
31
32
33
34
;=== weird, these are ok
;phangs_compare_seds_isrf,8,N_seds=100L,/weighted,isrf_class_analysis=14
;=== weird this also
;phangs_compare_seds_isrf,8,N_seds=100L,/weighted,isrf_class_analysis=14,/include_herschel_filters
c2457c07   Jean-Philippe Bernard   improved
35

82beee16   Jean-Philippe Bernard   improved
36
37
38
;phangs_compare_seds_isrf,26,N_seds=100L,/weighted,isrf_class_analysis=22,/include_herschel_filters
;phangs_compare_seds_isrf,26,N_seds=100L,/weighted,isrf_class_analysis=22

694026f6   Jean-Philippe Bernard   commented
39
define_la_common
42b6dd57   Jean-Philippe Bernard   first commit
40
41

dir=!phangs_data_dir+'/ISRF/GRIDS/'
38087e96   Jean-Philippe Bernard   first commit
42
isrf_class_str='_isrfclass'+strtrim(isrf_class,2)
42b6dd57   Jean-Philippe Bernard   first commit
43
model='DBP90'
82beee16   Jean-Philippe Bernard   improved
44
45
46
47
;table_name=dir+model+'_MuseISRF_JWST_G0_YPAH_YVSG_4Phangs'+isrf_class_str+'.fits'
table_name=dir+model+'_MuseISRF_JWST_G0_YPAH_YVSG_4Phangs_noionis'+isrf_class_str+'.fits'
stp=mrdfits(table_name,1,hp)
st=mrdfits(table_name,2,h)
8cd73405   Jean-Philippe Bernard   first commit
48
Nst=n_elements(st)
42b6dd57   Jean-Philippe Bernard   first commit
49

694026f6   Jean-Philippe Bernard   commented
50
51
52
53
54

use_filters_names=['F360M','F0770W','F1000W','F1130W','F2100W']
IF keyword_set(include_herschel_filters) THEN BEGIN
	use_filters_names=['F360M','F0770W','F1000W','F1130W','F2100W','PACS_BLUE','PACS_GREEN','PACS_RED','PSW','PMW','PLW']
ENDIF
51c39c71   Jean-Philippe Bernard   first commit
55
filters=dustem_filter_names2filters(use_filters_names)
758aaa55   Jean-Philippe Bernard   first commit
56
Nfilters=n_elements(filters)
42b6dd57   Jean-Philippe Bernard   first commit
57
58

ii=100L
c750f66d   Jean-Philippe Bernard   first commit
59

38087e96   Jean-Philippe Bernard   first commit
60
Nseds=100L
0f653ae3   Jean-Philippe Bernard   first commit
61
62
IF keyword_set(N_seds) THEN Nseds=N_seds

42b6dd57   Jean-Philippe Bernard   first commit
63
Nparams=3
8cd73405   Jean-Philippe Bernard   first commit
64
true_params=fltarr(Nseds,Nparams)
2d3601c1   Jean-Philippe Bernard   first commit
65
fitted_params=fltarr(Nseds,Nparams)
694026f6   Jean-Philippe Bernard   commented
66
facts=fltarr(Nseds)
026c2ba5   Jean-Philippe Bernard   improved
67
chi2s=fltarr(Nseds)
8cd73405   Jean-Philippe Bernard   first commit
68
69
seed=1

026c2ba5   Jean-Philippe Bernard   improved
70
71
72
73
74
use_isrf_class_analysis=0L
IF keyword_set(isrf_class_analysis) THEN BEGIN
	use_isrf_class_analysis=isrf_class_analysis
ENDIF

8cd73405   Jean-Philippe Bernard   first commit
75
FOR j=0L,Nseds-1 DO BEGIN
1045844e   Jean-Philippe Bernard   first commit
76
	;seed=1
b171b249   Jean-Philippe Bernard   first commit
77
	inn=abs(randomu(seed))
026c2ba5   Jean-Philippe Bernard   improved
78
    ii=long(inn*Nst)
38087e96   Jean-Philippe Bernard   first commit
79
    ;print,inn,ii
8cd73405   Jean-Philippe Bernard   first commit
80
81
82
83
84
85
86
87
	sed=dustem_initialize_sed(Nfilters)
	;sed=fltarr(Nfilters)
	tags=tag_names(st)
	FOR i=0L,Nfilters-1 DO BEGIN
		ind=where(tags EQ 'I'+filters[i],count)
		sed[i].filter=filters[i]
		sed[i].stokesI=st[ii].(ind[0])
	ENDFOR
e6540543   Jean-Philippe Bernard   improved
88
	sed.sigmaii=(sed.stokesI*0.1)^2
8cd73405   Jean-Philippe Bernard   first commit
89
90
91
92
93
94
	FOR i=0L,Nparams-1 DO BEGIN
	  true_params[j,i]=st[ii].(i)
	ENDFOR

	;stop

026c2ba5   Jean-Philippe Bernard   improved
95
96
	;fit_isrf_class_str='_isrfclass0'
	fit_isrf_class_str='_isrfclass'+strtrim(use_isrf_class_analysis,2)
82beee16   Jean-Philippe Bernard   improved
97
98
	;table_name_2=dir+model+'_MuseISRF_JWST_G0_YPAH_YVSG_4Phangs'+fit_isrf_class_str+'.fits'
	table_name_2=dir+model+'_MuseISRF_JWST_G0_YPAH_YVSG_4Phangs_noionis'+fit_isrf_class_str+'.fits'
026c2ba5   Jean-Philippe Bernard   improved
99
    ;print,ii
f11c9166   Jean-Philippe Bernard   improved
100
	params=dustem_brute_force_fit(sed,table_name_2,filters,fact=fact,chi2=chi2,normalize=normalize,rchi2=rchi2,show_sed=show_sed $
8cd73405   Jean-Philippe Bernard   first commit
101
			   					 ,params_hit=params_hit,params_uncertainties=params_uncertainties,params_min=params_min,params_max=params_max $
441c3551   Jean-Philippe Bernard   improved
102
			   					 ,fixed_parameters_description=fixed_parameters_description,fixed_parameters_values=fixed_parameters_values $
026c2ba5   Jean-Philippe Bernard   improved
103
104
105
106
107
108
			   					 ,weighted_params=weighted_params,best_sed=best_sed,best_grid_sed=best_grid_sed,all_chi2s=all_chi2s)
	;print,params,fact
    ;IF fact GT 2 THEN BEGIN
    ;	print,ii,fact,chi2
    ;	stop
    ;ENDIF
694026f6   Jean-Philippe Bernard   commented
109
    facts[j]=fact
026c2ba5   Jean-Philippe Bernard   improved
110
    chi2s[j]=chi2
58e1b6ca   Jean-Philippe Bernard   improved
111
112
113
114
    params[1]=params[1]/fact
    params[2]=params[2]/fact
    weighted_params[1]=weighted_params[1]/fact
    weighted_params[2]=weighted_params[2]/fact
441c3551   Jean-Philippe Bernard   improved
115
    ;fitted_params[j,*]=params
4bab2444   Jean-Philippe Bernard   improved
116
117
118
119
120
    IF keyword_set(weighted) THEN BEGIN
    	fitted_params[j,*]=weighted_params
	ENDIF ELSE BEGIN
		fitted_params[j,*]=params
	ENDELSE
8cd73405   Jean-Philippe Bernard   first commit
121
ENDFOR
42b6dd57   Jean-Philippe Bernard   first commit
122

694026f6   Jean-Philippe Bernard   commented
123
124
;stop

38087e96   Jean-Philippe Bernard   first commit
125
xtit='True parameter ('+isrf_class_str+')'
c2457c07   Jean-Philippe Bernard   improved
126
ytit='recovered parameter ('+fit_isrf_class_str+')'
3a667b1d   Jean-Philippe Bernard   first commit
127

694026f6   Jean-Philippe Bernard   commented
128
129
130
131
132
tit='G0'

tit_str=':'
IF keyword_set(weighted) THEN tit_str=tit_str+' weighted'
IF keyword_set(normalize) THEN tit_str=tit_str+' normalized'
82beee16   Jean-Philippe Bernard   improved
133
IF keyword_set(include_herschel_filters) THEN tit_str=tit_str+' JWST+Herschel' ELSE tit_str=tit_str+' JWST'
694026f6   Jean-Philippe Bernard   commented
134
135

;window,win & win=win+1
026c2ba5   Jean-Philippe Bernard   improved
136
137
win=0L
!p.multi=[0,1,3]
c2457c07   Jean-Philippe Bernard   improved
138
psym='Filled Circle'
026c2ba5   Jean-Philippe Bernard   improved
139

c2457c07   Jean-Philippe Bernard   improved
140
window,win,xsize=500,ysize=900,title='Fitted' & win=win+1
694026f6   Jean-Philippe Bernard   commented
141
xrange=minmax(true_params[*,0])
c2457c07   Jean-Philippe Bernard   improved
142
cgplot,true_params[*,0],fitted_params[*,0],tit='G0'+tit_str,psym=psym,/xlog,/ylog,xtit=xtit,ytit=ytit,xrange=xrange,yrange=xrange
32cccb36   Jean-Philippe Bernard   first commit
143
144
cgoplot,10^!x.crange,10^!y.crange,linestyle=2,color='red',thickness=3

694026f6   Jean-Philippe Bernard   commented
145
146
;window,win & win=win+1
xrange=minmax(true_params[*,1])
c2457c07   Jean-Philippe Bernard   improved
147
cgplot,true_params[*,1],fitted_params[*,1],tit='Ypah'+tit_str,psym=psym,/xlog,/ylog,xtit=xtit,ytit=ytit,xrange=xrange,yrange=xrange
32cccb36   Jean-Philippe Bernard   first commit
148
149
cgoplot,10^!x.crange,10^!y.crange,linestyle=2,color='red',thickness=3

694026f6   Jean-Philippe Bernard   commented
150
151
;window,win & win=win+1
xrange=minmax(true_params[*,2])
c2457c07   Jean-Philippe Bernard   improved
152
cgplot,true_params[*,2],fitted_params[*,2],tit='Yvsg'+tit_str,psym=psym,/xlog,/ylog,xtit=xtit,ytit=ytit,xrange=xrange,yrange=xrange
38087e96   Jean-Philippe Bernard   first commit
153
cgoplot,10^!x.crange,10^!y.crange,linestyle=2,color='red',thickness=3
3a667b1d   Jean-Philippe Bernard   first commit
154

e6540543   Jean-Philippe Bernard   improved
155
156
157
158
;window,win,xsize=500,ysize=900,title='Fitted Normalized' & win=win+1
;xrange=minmax(true_params[*,0])
;cgplot,true_params[*,0],fitted_params[*,0],tit='G0'+tit_str,psym=psym,/xlog,/ylog,xtit=xtit,ytit=ytit,xrange=xrange,yrange=xrange
;cgoplot,10^!x.crange,10^!y.crange,linestyle=2,color='red',thickness=3
026c2ba5   Jean-Philippe Bernard   improved
159

e6540543   Jean-Philippe Bernard   improved
160
161
162
;xrange=minmax(true_params[*,1])
;cgplot,true_params[*,1]*facts,fitted_params[*,1]*facts,tit='Ypah'+tit_str,psym=psym,/xlog,/ylog,xtit=xtit,ytit=ytit,xrange=xrange,yrange=xrange
;cgoplot,10^!x.crange,10^!y.crange,linestyle=2,color='red',thickness=3
026c2ba5   Jean-Philippe Bernard   improved
163

e6540543   Jean-Philippe Bernard   improved
164
165
166
;xrange=minmax(true_params[*,2])
;cgplot,true_params[*,2]*facts,fitted_params[*,2]*facts,tit='Yvsg'+tit_str,psym=psym,/xlog,/ylog,xtit=xtit,ytit=ytit,xrange=xrange,yrange=xrange
;cgoplot,10^!x.crange,10^!y.crange,linestyle=2,color='red',thickness=3
026c2ba5   Jean-Philippe Bernard   improved
167
168
169
170

cleanplot
window,win & win=win+1
diff_pah_perc=abs(true_params[*,1]-fitted_params[*,1])/true_params[*,1]*100.
82beee16   Jean-Philippe Bernard   improved
171
cgplot,facts,diff_pah_perc,psym=psym,xtit='fact',ytit='true-fitted Ypah [%]',/xlog,/ylog,tit='Ypah'+tit_str
32cccb36   Jean-Philippe Bernard   first commit
172

694026f6   Jean-Philippe Bernard   commented
173
174
cleanplot
window,win & win=win+1
82beee16   Jean-Philippe Bernard   improved
175
cgplot,chi2s,diff_pah_perc,psym=psym,xtit='chi2',ytit='true-fitted Ypah [%]',/xlog,/ylog,tit='Ypah'+tit_str
026c2ba5   Jean-Philippe Bernard   improved
176
177

stop
694026f6   Jean-Philippe Bernard   commented
178

42b6dd57   Jean-Philippe Bernard   first commit
179
END