Blame view

src/idl/dustem_plugin_phangs_stellar_continuum.pro 9.47 KB
b58e9569   Jean-Philippe Bernard   First commit
1
FUNCTION dustem_plugin_phangs_stellar_continuum,key=key $
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
2
3
4
5
6
7
                                			   			 ,val=val $
                                			   			 ,scope=scope $
                                			   			 ,paramtag=paramtag $
                                			   			 ,age_values=age_values $
                                			   			 ,metalicity_values=metalicity_values $
                                			   			 ,paramdefault=paramdefault $
c0b28cb2   Jean-Philippe Bernard   Changed G0 into F...
8
;                                			   			 ,object_distance=object_distance $    ;not used
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
9
10
                                			   			 ,Voronoi_Npix=Voronoi_Npix $
                                			   			 ,help=help
b58e9569   Jean-Philippe Bernard   First commit
11
12
13
14
15
16
17
18
;+
; NAME:
;    dustem_plugin_phangs_stellar_continuum
; PURPOSE:
;    DustEMWrap plugin to add EMILES stellar template emission to Dustemwrap SEDs
; CATEGORY:
;    DustEM, Distributed, Mid-Level, Plugin
; CALLING SEQUENCE:
bca3c9b1   Jean-Philippe Bernard   corrected issue w...
19
;    stellar_continuum=dustem_plugin_phangs_stellar_continuum([,key=][,val=][,scope=][,paramtag=][paramdefault=][,/help])
b58e9569   Jean-Philippe Bernard   First commit
20
21
22
23
; INPUTS:
;    None
; OPTIONAL INPUT PARAMETERS:
;    key  = input parameter number
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
24
25
;					  First parameter: Amplitude factor for the emission
;           Second parameter: E(B-V) for extinction to stars applied to the template, as used in Phangs
b58e9569   Jean-Philippe Bernard   First commit
26
27
28
;           Following 13*6 parameters are weights by which to multiply the MILES templates [Msun/pc^2]
;    val  = corresponding input parameter value
; OUTPUTS:
bca3c9b1   Jean-Philippe Bernard   corrected issue w...
29
;    stellar_continuum = stellar continuum spectrum resampled on dustem wavelengths [MJy/sr]
b58e9569   Jean-Philippe Bernard   First commit
30
; OPTIONAL OUTPUT PARAMETERS:
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
31
;    scope = if set, return the scope of the plugin
b58e9569   Jean-Philippe Bernard   First commit
32
;    paramdefault = default values of parameters
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
33
;    paramtag = if set, return the return plugin parameter names as strings
b58e9569   Jean-Philippe Bernard   First commit
34
35
; ACCEPTED KEY-WORDS:
;    help                  = if set, print this help
88f84272   Jean-Philippe Bernard   changed
36
;    method                = SSP used. can be EMILES or CB19. default='EMILES'
b58e9569   Jean-Philippe Bernard   First commit
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
;    The DustEMWrap IDL code must be installed
; PROCEDURE:
;    This is a DustEMWrap plugin for phangs
;    It differs from dustem_plugin_emiles_stellar_continuum.pro only by the way the extinction is applied to the output spectrum
; EXAMPLES
;    dustem_init
;    vec=dustem_plugin_phangs_stellar_continuum(scope=scope)
; MODIFICATION HISTORY:
;    Written by JPB June 2023
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_plugin_phangs_stellar_continuum'
  output=0.
  goto,the_end
ENDIF

25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
61
62
IF keyword_set(scope) THEN BEGIN
    scope='ADD_SED' 
0ed06487   Jean-Philippe Bernard   new version now w...
63
64
65
66
    out=0
    goto, the_scope
ENDIF 

88f84272   Jean-Philippe Bernard   changed
67
68
;use_method='EMILES'
use_method='CB19'
b58e9569   Jean-Philippe Bernard   First commit
69
70
71
72

age_values=[0.03, 0.05, 0.08, 0.15, 0.25, 0.40, 0.60, 1.0, 1.75, 3.0, 5.0, 8.5, 13.5]
metalicity_values=[-1.48630, -0.961400, -0.351200, +0.0600000, +0.255900, +0.397100]

0ed06487   Jean-Philippe Bernard   new version now w...
73
74
75
;==== This does not work because the info files has many more entries than there are available ssps.
;age_values=age_values_emiles
;metalicity_values=met_values_emiles
9a3272b1   Jean-Philippe Bernard   improved
76
77
78
79
80
81
82
83
;This does not work either
;st_templates=read_muse_templates_info(age_values=age_values,metalicity_values=metalicity_values,Nbins=Nbins,Nage=Nage,NZ=Nmetalicity,bins=bins)
;print,age_values
;     0.030000000     0.050000000     0.080000000      0.15000000      0.25000000      0.40000000      0.60000000       1.0000000       1.7500000       3.0000000       5.0000000       8.5000000       13.500000
;print,metalicity_values
;     -1.49000    -0.960000    -0.350000    0.0600000     0.260000     0.400000

;stop
0ed06487   Jean-Philippe Bernard   new version now w...
84

b58e9569   Jean-Philippe Bernard   First commit
85
86
Nage=n_elements(age_values)
Nmetalicity=n_elements(metalicity_values)
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
87
Nparam=Nage*Nmetalicity+2    ;+2 is for Amplitude and E(B-V)
0ed06487   Jean-Philippe Bernard   new version now w...
88
89

;==== define parameter tags
4a2d1650   Jean-Philippe Bernard   improved
90
91
92
93
94
95
96
97
98
99
100
101
102
IF keyword_set(paramtag) THEN BEGIN
	paramtag=strarr(Nparam)
	paramtag[0]='Amplitude'
	paramtag[1]='E(B-V)'
	FOR i=2L,Nparam-1 DO BEGIN
		ij=index2ij([i-2],[Nage,Nmetalicity])
		paramtag[i]='Age'+strtrim(ij[0,0],2)+'Met'+strtrim(ij[0,1],2)
	ENDFOR
	GOTO,the_paramtag
ENDIF

paramdefault=dblarr(Nparam)
paramdefault[*]=0.D0         ;default parameter values is 0.
0ed06487   Jean-Philippe Bernard   new version now w...
103
104
105

;==== decode key keyword. 
;stop
b58e9569   Jean-Philippe Bernard   First commit
106
107
108
109
110
111
112
113
114
115
paramvalues=paramdefault
IF keyword_set(key) THEN BEGIN
  ind=where(key EQ 1,count)
  IF count NE 0 THEN paramvalues[0]=val[ind[0]]
  FOR i=1L,Nparam-1 DO BEGIN
  	ind=where(key EQ i+1,count)
  	IF count NE 0 THEN paramvalues[i]=val[ind[0]]
  ENDFOR
ENDIF

0ed06487   Jean-Philippe Bernard   new version now w...
116
;==== initialize templates if not already present
b58e9569   Jean-Philippe Bernard   First commit
117
118
defsysv,'!dustem_plugin_phangs_stellar_continuum',exist=exist
IF exist EQ 0 THEN BEGIN
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
119
	st={ssps:ptr_new(),wavs:ptr_new(),Mstars:ptr_new(),mstars_o_Lv:ptr_new(),Mstarprems:ptr_new()}
b58e9569   Jean-Philippe Bernard   First commit
120
121
122
	defsysv,'!dustem_plugin_phangs_stellar_continuum',st
ENDIF
IF not ptr_valid(!dustem_plugin_phangs_stellar_continuum.ssps) THEN BEGIN
88f84272   Jean-Philippe Bernard   changed
123
124
125
	message,'Initializing SSP templates',/info
	CASE use_method of
		'EMILES': BEGIN
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
126
			template_flux=dustem_read_emiles_stellar_templates(age_values,metalicity_values,template_wav=template_wav,Mstars=Mstars,Ms_o_Lv=Ms_o_Lv,Mstarprems=Mstarprems)
88f84272   Jean-Philippe Bernard   changed
127
128
129
		END
		'CB19': BEGIN
			;== this is just to get the Mstars
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
130
			bidon=dustem_read_emiles_stellar_templates(age_values,metalicity_values,template_wav=template_wav,Mstars=Mstars,Ms_o_Lv=Ms_o_Lv,Mstarprems=Mstarprems)
88f84272   Jean-Philippe Bernard   changed
131
			;== This is to read in the CB19 templates
4a2d1650   Jean-Philippe Bernard   improved
132
			;== Note, templates are already interpolated on dustem wavelenghts (!)
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
133
			template_flux=dustem_read_cb19_stellar_templates(age_values=age_values,metalicity_values=metalicity_values,template_wav=template_wav);,Mstars=Mstars)
88f84272   Jean-Philippe Bernard   changed
134
135
		END
	ENDCASE
e1a8a693   Jean-Philippe Bernard   improved
136
	!dustem_plugin_phangs_stellar_continuum.ssps=ptr_new(template_flux)   ; in Lsun Msun^-1 A^-1
b58e9569   Jean-Philippe Bernard   First commit
137
138
	!dustem_plugin_phangs_stellar_continuum.wavs=ptr_new(template_wav)
	!dustem_plugin_phangs_stellar_continuum.mstars=ptr_new(Mstars)
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
139
140
	!dustem_plugin_phangs_stellar_continuum.mstars_o_Lv=ptr_new(Ms_o_Lv)
	!dustem_plugin_phangs_stellar_continuum.mstarprems=ptr_new(Mstarprems)
b58e9569   Jean-Philippe Bernard   First commit
141
142
143
ENDIF

;stop
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
144
145
146
147
148
149
150
151
use_Voronoi_Npix=1.   ;deg^2
IF keyword_set(Voronoi_Npix) THEN use_Voronoi_Npix=Voronoi_Npix
;use_object_distance=1.   ;MPc
;IF keyword_set(object_distance) THEN use_object_distance=object_distance

;bin_surface_pc2=use_bin_surface*!pi^2/180.^2*(use_object_distance*1.e6)^2   ;surface in pc^2
;Npixfact=(1./(0.2/60./60.))^2        ;how much Muse pixels of 0.2 arcsec in 1 deg^2
;bin_surface_Npixmuse=use_bin_surface*Npixfact
b58e9569   Jean-Philippe Bernard   First commit
152
153
154

lambir=dustem_get_wavelengths()
Nwavs=n_elements(lambir)
9a3272b1   Jean-Philippe Bernard   improved
155
output=dblarr(Nwavs,3)
b58e9569   Jean-Philippe Bernard   First commit
156
157
wavs=*!dustem_plugin_phangs_stellar_continuum.wavs
Mstars=*!dustem_plugin_phangs_stellar_continuum.mstars
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
158
159
Ms_o_Lv=*!dustem_plugin_phangs_stellar_continuum.mstars_o_Lv
Mstarprems=*!dustem_plugin_phangs_stellar_continuum.Mstarprems
b58e9569   Jean-Philippe Bernard   First commit
160
161
;==== sum up the stellar spectrum
;stop
9a3272b1   Jean-Philippe Bernard   improved
162
FOR i=2L,Nparam-1 DO BEGIN
b58e9569   Jean-Philippe Bernard   First commit
163
164
165
	IF paramvalues[i] NE 0. THEN BEGIN
		;stop
		;only interpolate within the template wavelengths
4a2d1650   Jean-Philippe Bernard   improved
166
		;ind=where(lambir LE max(wavs) AND lambir GE min(wavs),count)
9a3272b1   Jean-Philippe Bernard   improved
167
		Mstar=Mstars[i-2]
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
168
169
		Mstarprem=Mstarprems[i-2]
		M_o_Lv=Ms_o_Lv[i-2]
4a2d1650   Jean-Philippe Bernard   improved
170
		ssp=*(*!dustem_plugin_phangs_stellar_continuum.ssps)[i-2]
bca3c9b1   Jean-Philippe Bernard   corrected issue w...
171
172
		;output[*,0]=output[*,0]+paramvalues[i]*Mstar*ssp
		;==== below is trying to remove Mstar
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
173
174
175
176
177
178
179
180
		;output[*,0]=output[*,0]+paramvalues[i]*ssp
		;==== below is trying to multiply weights by L/M
		;output[*,0]=output[*,0]+paramvalues[i]/M_o_Lv*ssp*use_bin_surface
		;output[*,0]=output[*,0]+paramvalues[i]/M_o_Lv*ssp/use_bin_surface
		;output[*,0]=output[*,0]+paramvalues[i]*ssp*Mstar/(bin_surface_pc2)
		;output[*,0]=output[*,0]+paramvalues[i]*ssp*Mstar/(bin_surface_Npixmuse)
;		output[*,0]=output[*,0]+paramvalues[i]*ssp*Mstar/(use_Voronoi_Npix)
		output[*,0]=output[*,0]+paramvalues[i]*ssp*Mstarprem/(use_Voronoi_Npix)
4a2d1650   Jean-Philippe Bernard   improved
181
		message,'Mstar='+strtrim(Mstar,2)+' paramvalue='+strtrim(paramvalues[i],2),/info
b58e9569   Jean-Philippe Bernard   First commit
182
183
	ENDIF
ENDFOR
9a3272b1   Jean-Philippe Bernard   improved
184
output[*,0]=output[*,0]*paramvalues[0]
bca3c9b1   Jean-Philippe Bernard   corrected issue w...
185
186
;cgplot,wavs*1.e4,output[*,0],xrange=[4750,7000]
;stop
4a2d1650   Jean-Philippe Bernard   improved
187
;flux=output[*,0]
9a3272b1   Jean-Philippe Bernard   improved
188
;no polarization for now
4a2d1650   Jean-Philippe Bernard   improved
189
190
;output[*,1]=0.
;output[*,2]=0. 
9a3272b1   Jean-Philippe Bernard   improved
191

9a3272b1   Jean-Philippe Bernard   improved
192
;==== Caution:
e1a8a693   Jean-Philippe Bernard   improved
193
;output is Flambda in Lsun/pc2/AA
9a3272b1   Jean-Philippe Bernard   improved
194
195
;at this point, output is unredenned 
;==== must be transformed into MJy/sr
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
196
197
198
Lsun2ergs=3.828e33
pc2_to_cm2=(3.0857e18)^2
fact1=Lsun2ergs/pc2_to_cm2
9a3272b1   Jean-Philippe Bernard   improved
199
200
201
202
NHref=*!DUSTEM_HCD   ;NH dustemwrap reference [H/cm^2]
fact2=lambir*1.e4      ;[AA] to go from F_lambda in ergs/s/cm2/AA to Fnu ergs/s/cm2
fact3=1./NHref         ;[cm2/H] to go from ergs/s/cm2 to ergs/s/H
fact4=1.e4*(*!dustem_HCD)/(4.*!pi)/(3.e8/1.e-6/lambir)*1.e20/1.e7   ;This goes from ergs/s/H to MJy/sr (see dustem_plot_dataset)
7c0c94e9   Jean-Philippe Bernard   fixeds very nasty...
203
204
;fact=fact2*fact3*fact4
fact=fact1*fact2*fact3*fact4
9a3272b1   Jean-Philippe Bernard   improved
205

88f84272   Jean-Philippe Bernard   changed
206
207
208
209
210
211
;print,'flux(1mic)=',interpol(flux,lambir,1.),' ergs/s/cm2/AA'
;print,'fact2=',interpol(fact2,lambir,1.)
;print,'fact3=',fact3
;print,'fact4=',interpol(fact4,lambir,1.)
;print,'fact=',interpol(fact,lambir,1.)
;print,'flux(1mic)=',interpol(flux,lambir,1.)*interpol(fact,lambir,1.),' MJy/sr'
9a3272b1   Jean-Philippe Bernard   improved
212
213

;goto,no_unred
b58e9569   Jean-Philippe Bernard   First commit
214

b58e9569   Jean-Philippe Bernard   First commit
215
;==== reden spectrum using Calzetti's extinction law (which is what Phangs does)
9a3272b1   Jean-Philippe Bernard   improved
216
;cgplot,lambir,flux,/xlog,/ylog
b58e9569   Jean-Philippe Bernard   First commit
217
;factor -1 is to reden, instead of unreden. factor 1e4 is to go from microns to Angstroem
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
218
219
220
;This uses the prescription of Calzetti et al 2000. It is applied from 912AA to 2.2 mic, no correction applied before and beyound that.
;Note that the supplied color excess should be that derived for the stellar  continuum, EBV(stars), which (in Calzetti 2000) is related to the 
;reddening derived from the gas, EBV(gas), via the Balmer decrement by EBV(stars) = 0.44*EBV(gas)
4a2d1650   Jean-Philippe Bernard   improved
221
calz_unred, lambir*1.e4, output[*,0], -1.*paramvalues[1], flux_red, R_V = R_V
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
222
;Note: we could actually use our own dustemwrap extinction curve to do that.
b58e9569   Jean-Philippe Bernard   First commit
223
224
output[*,0]=flux_red

9a3272b1   Jean-Philippe Bernard   improved
225
226
no_unred:

9a3272b1   Jean-Philippe Bernard   improved
227
output[*,0]=output[*,0]*fact
4a2d1650   Jean-Philippe Bernard   improved
228
229
;output[*,1]=output[*,1]*fact
;output[*,2]=output[*,2]*fact
9a3272b1   Jean-Philippe Bernard   improved
230

88f84272   Jean-Philippe Bernard   changed
231
;print,'output=',interpol(output[*,0],lambir,1.),' MJy/sr'
9a3272b1   Jean-Philippe Bernard   improved
232
;stop
0ed06487   Jean-Philippe Bernard   new version now w...
233
234

the_scope:
0ed06487   Jean-Philippe Bernard   new version now w...
235
236

the_paramtag:
b58e9569   Jean-Philippe Bernard   First commit
237
238
239
240
241

the_end:
RETURN,output
  
END