dustem_read_emiles_stellar_templates.pro
5.48 KB
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
FUNCTION dustem_read_emiles_stellar_templates,age_values, $
metalicity_values, $
template_wav=template_wav, $
Mstars=Mstars, $
info_only=info_only, $
info_st=info_st, $
help=help
;+
; NAME:
; dustem_read_emiles_stellar_templates
; PURPOSE:
; reads EMILES stellar population templates
; CATEGORY:
; DustEMWrap, Distributed, High-Level, User Example
; CALLING SEQUENCE:
; templates=dustem_read_emiles_stellar_templates(age_values,metalicity_values[,template_waves=][,Mstars=][,/info_only][,info_st=][,/help])
; INPUTS:
; age_values : array of age values
; metalicity_values : array of metalicity values
; OPTIONAL INPUT PARAMETERS:
; None
; OUTPUTS:
; templates : SSP templates (F_lambda) [Lsun Msun^-1 A^-1]
; OPTIONAL OUTPUT PARAMETERS:
; template_wav = common wavelength array for templates [Angstroem]
; Mstars = Mass of stars [Msun]
; info_st = info structure for the templates
; ACCEPTED KEY-WORDS:
; info_only : if set, read only the information structure
; help : if set, prints this help
; COMMON BLOCKS:
; None
; SIDE EFFECTS:
; None
; RESTRICTIONS:
; The DustEM fortran code must be installed
; The DustEMWrap IDL code must be installed
; PROCEDURES AND SUBROUTINES USED:
;
; EXAMPLES
; st=dustem_read_emiles_stellar_templates(age_values,Z_values)
; 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_read_emiles_stellar_templates'
templates=-1
goto,the_end
END
;dir_templates=!dustem_wrap_soft_dir+'/Data/SSPs/ssp_emiles-ch/'
dir_templates=!phangs_data_dir+'/ISRF/SSPs/ssp_emiles-ch_extended/'
;dir_templates=!dustem_wrap_soft_dir+'/Data/SSPs/ssp_emiles-ch_extended/'
;read templates info file
;IMF slope Z Age Mtotal M(*+remn) M* Mremn Mgas M(*+remn)/Lv M*/Lv Mv unknown
file=dir_templates+'templates_info.txt'
format='A,F,F,F,F,F,F,F,F,F,F,F,F'
readcol,file,imf,slope,z,age,Mtot,Mstar_rem,Mstar,Mremn,Mgas,Mstar_rem_o_Lv,Mstar_o_Lv,Mv,unknown,format=format
one_st={imf:'',slope:0.,z:0.,age:0.,Mtot:0.,Mstar_rem:0.,Mstar:0.,Mremn:0.,Mgas:0.,Mstar_rem_o_Lv:0.,Mstar_o_Lv:0.,Mv:0.,unknown:0.}
info_st=replicate(one_st,n_elements(imf))
info_st.imf=imf
info_st.slope=slope
info_st.z=z
info_st.age=age
info_st.mtot=Mtot
info_st.Mstar_rem=Mstar_rem
info_st.Mstar=Mstar
info_st.Mremn=Mremn
info_st.Mgas=Mgas
info_st.Mstar_rem_o_Lv=Mstar_rem_o_Lv
info_st.Mstar_o_Lv=Mstar_o_Lv
info_st.Mv=Mv
info_st.unknown=unknown
IF keyword_set(info_only) THEN BEGIN
templates=info_st
goto,the_end
ENDIF
;stop
;file name format is ssp_emiles-ch/Ech1.30Zp0.40T13.5000_iTp0.00_baseFe_linear_FWHM_variable.fits
;=== producing age and metalicity strings for file names
age_values_4str=string(age_values,format='(F7.4)')
FOR i=0L,n_elements(age_values_4str)-1 DO age_values_4str[i]=textoidl_str_replace(age_values_4str[i],' ','0')
metalicity_values_4str=round(metalicity_values*100.)/100. ;This is the array for metalicity values in fits files names
metalicity_values_4str=string(metalicity_values_4str,format='(F5.2)')
FOR i=0L,n_elements(metalicity_values_4str)-1 DO metalicity_values_4str[i]=textoidl_str_replace(metalicity_values_4str[i],' ','p')
FOR i=0L,n_elements(metalicity_values_4str)-1 DO metalicity_values_4str[i]=textoidl_str_replace(metalicity_values_4str[i],'-','m')
;print,age_values
;print,metalicity_values
;stop
;Ntemplates=n_elements(paramvalues)-1
Ntemplates=n_elements(age_values)*n_elements(metalicity_values)
Nage=n_elements(age_values)
Nmetalicity=n_elements(metalicity_values)
templates=ptrarr(Ntemplates)
;file names are like: Ech1.30Zm0.35T00.2500_iTp0.00_baseFe_linear_FWHM_variable.fits
file_start='Ech1.30'
file_end='_iTp0.00_baseFe_linear_FWHM_variable.fits'
ii=0L
Nage_str=6
Nmet_str=4
Mstars=fltarr(Ntemplates)
files_not_found=['']
FOR i=1L,Ntemplates DO BEGIN
zsign_str='p'
ij=index2ij([i-1],[Nage,Nmetalicity])
iage=ij[0,0]
imet=ij[0,1]
age=age_values[iage]
met=metalicity_values[imet]
met_str=metalicity_values_4str[imet]
age_str=age_values_4str[iage]
message,'reading template for Age '+age_str+' Met '+met_str,/info
file=dir_templates+file_start+'Z'+met_str+'T'+age_str+file_end
fi=file_info(file)
IF fi.exists THEN BEGIN
message,'Reading SSP '+file,/info
spec=readfits(file,h,2)
templates[ii]=ptr_new(spec)
make_axis,h,wavs
ind=where(info_st.z EQ met AND info_st.age EQ age,count)
IF count EQ 0 THEN BEGIN
message,'age,met not found in template info',/continue
stop
ENDIF ELSE BEGIN
Mstars[i-1]=info_st[ind[0]].Mstar
ENDELSE
ENDIF ELSE BEGIN
message,'file not found '+file,/continue
files_not_found=[files_not_found,file]
ENDELSE
ii=ii+1
ENDFOR
IF n_elements(files_not_found) NE 1 THEN BEGIN
files_not_found=files_not_found[1:*]
message,strmid(n_elements(files_not_found),2)+' SSP files were not found :',/continue
hprint,files_not_found
stop
ENDIF
;Nspec=n_elements(spec)
;print,min(wavs),max(wavs)
; 3500.2000 12000.250
angstroem2mic=1.e6/1.e10
template_wav=wavs*angstroem2mic ;mic
;do_interpol=1L
;IF do_interpol THEN BEGIN
lambir=dustem_get_wavelengths()
FOR i=0L,Ntemplates-1 DO BEGIN
;ind=where(lambir LE max(template_wav) AND lambir GE min(template_wav),count)
templates[i]=ptr_new(interpol(*templates[i],template_wav,lambir))
ENDFOR
template_wav=lambir
;ENDIF
the_end:
RETURN,templates
END