Blame view

LabTools/IRAP/JPB/make_phangs_ssps_isrf_prediction.pro 6.88 KB
ccbd30b1   Jean-Philippe Bernard   First commit
1
2
PRO make_phangs_ssps_isrf_prediction,source_name=source_name,save=save,help=help

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
3
4
;,resolution_filter=resolution_filter

ccbd30b1   Jean-Philippe Bernard   First commit
5
6
7
8
;+
; NAME:
;       make_phangs_ssps_isrf_prediction
; CALLING SEQUENCE:
14ae4f23   Jean-Philippe Bernard   improved
9
;       make_phangs_ssps_isrf_prediction[,source_name=][,/save][,/help]
ccbd30b1   Jean-Philippe Bernard   First commit
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; PURPOSE:
;       predicts the minimum ISRF in voronoi bins
; INPUTS:
;       None
; OPTIONAL KEYWORDS:
;       save        = if set, save the classes
;       help        = if set, print this help
; OUTPUTS:
;	    None
; OPTIONAL INPUT:
;       source_name = source name (default='ngc0628')
; OPTIONAL OUTPUT:
;       None
; PROCEDURE AND SUBROUTINE USED
14ae4f23   Jean-Philippe Bernard   improved
24
25
26
;       ISRF saved is the one predicted by dustem_plugin_phangs_stellar_isrf for each Muse Voronoi bin,
;       scaled in amplitude to match the Muse filter data for that Voronoi bin.
;       The G0 value computed is wrt the Mathis field at 1 mic.
ccbd30b1   Jean-Philippe Bernard   First commit
27
; SIDE EFFECTS:
14ae4f23   Jean-Philippe Bernard   improved
28
;       produces file _isrf_min_prediction.sav
ccbd30b1   Jean-Philippe Bernard   First commit
29
; EXAMPLE:
14ae4f23   Jean-Philippe Bernard   improved
30
;       make_phangs_ssps_isrf_prediction,source_name='ngc0628',/save
ccbd30b1   Jean-Philippe Bernard   First commit
31
32
33
34
35
36
37
38
39
40
; MODIFICATION HISTORY:
;       written by Jean-Philippe Bernard
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'make_phangs_ssps_isrf_prediction'
  goto,the_end
ENDIF

;===== predicts the minimum ISRF in voronoi bins
14ae4f23   Jean-Philippe Bernard   improved
41
;===== The prediction is scaled to the Muse filter data observations
ccbd30b1   Jean-Philippe Bernard   First commit
42
43
44
45
46

win=0L
;window,win,xsize=900,ysize=1000 & win=win+1

;=== This is where the data is read from and the ISRFs will be stored
ccbd30b1   Jean-Philippe Bernard   First commit
47
48
49
50
51
52
53
54
data_dir=!phangs_data_dir+'/ISRF/WORK/'

use_model='DBP90'    ;Example with default keywords uses the DBP90 model
use_polarization=0   ; initialize Dustemwrap in no polarization mode 

;== INITIALISE DUSTEM
dustem_init,model=use_model,polarization=use_polarization,show_plots=show_plots

ccbd30b1   Jean-Philippe Bernard   First commit
55
56
57
use_source_name='ngc0628'
IF keyword_set(source_name) THEN use_source_name=source_name

997cc66d   Jean-Philippe Bernard   improved
58
object_distance=(phangs_get_galaxy_distance(use_source_name)).dist
ccbd30b1   Jean-Philippe Bernard   First commit
59
60
CASE use_source_name OF
	'ngc0628':BEGIN
997cc66d   Jean-Philippe Bernard   improved
61
		;object_distance=9.84  ;MPc
ccbd30b1   Jean-Philippe Bernard   First commit
62
63
		object_thickness=0.1  ;kpc
	END
82beee16   Jean-Philippe Bernard   improved
64
	'ngc3351':BEGIN
997cc66d   Jean-Philippe Bernard   improved
65
		;object_distance=9.96  ;MPc
82beee16   Jean-Philippe Bernard   improved
66
67
		object_thickness=0.1  ;kpc
	END
ccbd30b1   Jean-Philippe Bernard   First commit
68
69
ENDCASE

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
70
71
72
73
74
75
reso_str=''
;stop
;IF keyword_set(resolution_filter) THEN BEGIN
;		reso_str='_'+resolution_filter
;ENDIF

ccbd30b1   Jean-Philippe Bernard   First commit
76
77
78
79
dustem_define_la_common
obp=[1.1,0,1.15,1]

;dustem_init,show_plots=show_plots
9b37a060   Jean-Philippe Bernard   improved for smoo...
80
81
;needed only for NHCO (ie, not used)
;restore,data_dir+use_source_name+'_jwst_images'+reso_str+'.sav',/verb
14ae4f23   Jean-Philippe Bernard   improved
82
83
84
85
;% RESTORE: Restored variable: JWST_IMAGES.
;% RESTORE: Restored variable: FILTERS.
;% RESTORE: Restored variable: HREF.
;% RESTORE: Restored variable: NHCO.
ccbd30b1   Jean-Philippe Bernard   First commit
86
;needed for stellar parameters and voronoi bin info
4233645a   Jean-Philippe Bernard   improved
87
88
89
90
91
92
93
94
;restore,data_dir+use_source_name+'_muse_images'+reso_str+'.sav',/verb
file=data_dir+use_source_name+'_muse_data'+reso_str+'.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
restore,file,/verb
14ae4f23   Jean-Philippe Bernard   improved
95
96
97
98
99
100
101
;% RESTORE: Restored variable: ST_TEMPLATES.
;% RESTORE: Restored variable: ST_MUSE_WEIGHTS.
;% RESTORE: Restored variable: VORONOI_ID.
;% RESTORE: Restored variable: AGE_VALUES.
;% RESTORE: Restored variable: METALICITY_VALUES.
;% RESTORE: Restored variable: BINS.
;% RESTORE: Restored variable: HREF.
9b37a060   Jean-Philippe Bernard   improved for smoo...
102
;=== needed for muse_filters only (for absolute scaling of ISRF)
4233645a   Jean-Philippe Bernard   improved
103
104
105
106
107
108
109
110
;restore,data_dir+use_source_name+'_muse_filters_data'+reso_str+'.sav',/verb
file=data_dir+use_source_name+'_muse_filters_images'+reso_str+'.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
restore,file,/verb
14ae4f23   Jean-Philippe Bernard   improved
111
112
113
;% RESTORE: Restored variable: MUSE_IMAGES.
;% RESTORE: Restored variable: MUSE_FILTERS.
;% RESTORE: Restored variable: HREF.
9b37a060   Jean-Philippe Bernard   improved for smoo...
114
;=== needed for all_seds only (for normalisation to Muse)
4233645a   Jean-Philippe Bernard   improved
115
116
117
118
119
120
121
file=data_dir+use_source_name+'_muse_seds_muse_pixels'+reso_str+'.sav'
st_info=file_info(file)
IF st_info.exists NE 1 THEN BEGIN
	message,'Could not find '+file,/continue
	stop
ENDIF
restore,file,/verb
14ae4f23   Jean-Philippe Bernard   improved
122
123
;% RESTORE: Restored variable: ALL_SEDS.
;% RESTORE: Restored variable: ALL_SEDS_INDICES.
ccbd30b1   Jean-Philippe Bernard   First commit
124

9b0b6d7e   Jean-Philippe Bernard   finished implemen...
125
126
;stop

de766928   Jean-Philippe Bernard   improved
127
Nvor=max(voronoi_id)+1
ccbd30b1   Jean-Philippe Bernard   First commit
128

9b37a060   Jean-Philippe Bernard   improved for smoo...
129
;use_NHmap=NHCO       ;used NH map in 1.e21 (from CO)
ccbd30b1   Jean-Philippe Bernard   First commit
130
131
132
133
134
135
136
137

;stop
!quiet=1

t1=systime(0,/sec)
first_vid=0L
lambir=dustem_get_wavelengths(isrf_wavelengths=isrf_wavelengths)
;show_each=10
de766928   Jean-Philippe Bernard   improved
138
show_each=100.
ccbd30b1   Jean-Philippe Bernard   First commit
139
140
Nlamb=n_elements(isrf_wavelengths)

14ae4f23   Jean-Philippe Bernard   improved
141
142
143
144
145
146
147
148
149
ISRFS=dblarr(Nlamb,Nvor)
G0s=dblarr(Nvor)

;==== get Mathis field for G0 calculations
file=!dustem_soft_dir+'/data/ISRF_MATHIS.DAT'
readcol,file,Mathis_wavs,Mathis_ISRF
Mathis_ISRF=interpol(Mathis_ISRF,Mathis_wavs,isrf_wavelengths)
Mathis_1mic=interpol(Mathis_ISRF,isrf_wavelengths,1.0)

de766928   Jean-Philippe Bernard   improved
150
151
wavs=dustem_filter2wav(muse_filters[0:2])

ccbd30b1   Jean-Philippe Bernard   First commit
152
153
154
155
FOR vid=first_vid,Nvor-1 DO BEGIN
	IF vid mod show_each EQ 0 THEN BEGIN
		t2=systime(0,/sec)
		delta_t_hr=(t2-t1)/60.^2 ;elapsed time [hr]
de766928   Jean-Philippe Bernard   improved
156
		frac_perc=(1.*vid)/(1.*Nvor)*100.
ccbd30b1   Jean-Philippe Bernard   First commit
157
		delta_t_remain=delta_t_hr/frac_perc*100.-delta_t_hr  ;remaining time [hr]
de766928   Jean-Philippe Bernard   improved
158
159
		message,'done '+strtrim(frac_perc,2)+' % in '+strtrim(delta_t_hr,2)+' hr remaining '+strtrim(delta_t_remain,2)+' hr',/continue
		;stop
ccbd30b1   Jean-Philippe Bernard   First commit
160
161
162
	ENDIF
	;===== get the SSP weights for the given voronoi bins
	weights=phangs_binid2weights(st_muse_weights,vid,st_templates,age_values,metalicity_values,reddening=reddening)
14ae4f23   Jean-Philippe Bernard   improved
163
164
165
	amplitude=1.         ;amplitude is set to 1, and will be corrected by G0 below
	use_reddening=0.     ;This sets Muse reddening to 0. Will be contsrained later
	fpd=phangs_stellar_continuum_plugin_weight2params(weights,parameter_values=val,redenning=use_reddening,/force_include_reddening,amplitude=amplitude,/force_include_amplitude)
8bc14240   Jean-Philippe Bernard   improved
166
167
168
  Nparams=n_elements(val)
  key=intarr(Nparams)
  FOR i=0L,Nparams-1 DO BEGIN
ccbd30b1   Jean-Philippe Bernard   First commit
169
170
171
	    toto=dustem_parameter_description2type(fpd[i],string_name=string_name,key=one_key)
	    key[i]=one_key
 	ENDFOR
14ae4f23   Jean-Philippe Bernard   improved
172
173
174
175
176
 	;==== compute the prediction stellar continuum for comparison to the Muse filter data.
 	;==== Here we use the reddening from MUSE
 	val_sed=val
 	val_sed[1]=reddening   ;for the SED, we use E(B-V)
 	spectrum=dustem_plugin_phangs_stellar_continuum(key=key,val=val_sed)
de766928   Jean-Philippe Bernard   improved
177
178
179
180
181
182
183
 	sed=interpol(spectrum[*,0],lambir,wavs)
 	IF ptr_valid(all_seds[vid]) THEN BEGIN
 		muse_sed=(*all_seds[vid]).stokesI
 	ENDIF ELSE BEGIN
 		muse_sed=sed
 		muse_sed[*]=la_undef()
 	ENDELSE
14ae4f23   Jean-Philippe Bernard   improved
184
185
186
187
188
189
190
191
192
193
 	facts=muse_sed/sed
 	muse_factor=la_mean(facts)     ;This takes the average value over the MUSE bands
 	;print,G0,reddening
 	;stop
 	val_isrf=val ;for the ISRF, we use E(B-V)=0
 	ISRFS[*,vid]=dustem_plugin_phangs_stellar_isrf(key=key,val=val_isrf,object_distance=object_distance,object_thickness=object_thickness)
 	ISRFS[*,vid]=ISRFS[*,vid]*muse_factor ;=== scale the amplitude of ISRFs to the muse data
 	;=== compute corresponding G0
 	G0=interpol(ISRFS[*,vid],isrf_wavelengths,1.)/Mathis_1mic
 	G0s[vid]=G0
ccbd30b1   Jean-Philippe Bernard   First commit
194
195
196
ENDFOR

IF keyword_set(save) THEN BEGIN
14ae4f23   Jean-Philippe Bernard   improved
197
198
	file_save=data_dir+use_source_name+'_isrf_min_prediction.sav'
	save,ISRFS,G0s,object_distance,object_thickness,use_source_name,file=file_save,/verb
de766928   Jean-Philippe Bernard   improved
199
	message,'Saved '+file_save,/continue
14ae4f23   Jean-Philippe Bernard   improved
200
	phangs_make_isrf_product,use_source_name,voronoi_id,ISRFS,G0s,object_distance,object_thickness
ccbd30b1   Jean-Philippe Bernard   First commit
201
202
ENDIF

14ae4f23   Jean-Philippe Bernard   improved
203
204
;cgplot,lindgen(Nvor),G0s,/ylog,yrange=[1.e-5,1],xtit='Voronoi ID',ytit='G0'

de766928   Jean-Philippe Bernard   improved
205
;stop
14ae4f23   Jean-Philippe Bernard   improved
206

ccbd30b1   Jean-Philippe Bernard   First commit
207
208
209
the_end:

END