Commit a22638d59d64fed75ee0ebc9e6d0fb6f6f802ff6
1 parent
2f9a477d
Exists in
master
first commit
Showing
1 changed file
with
154 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,154 @@ |
1 | +FUNCTION dustem_read_cb19_stellar_templates,age_values=age_values $ | |
2 | + ,metalicity_values=metalicity_values $ | |
3 | + ,template_wav=template_wav $ | |
4 | + ,Mstars=Mstars $ | |
5 | + ,info_only=info_only $ | |
6 | + ,info_st=info_st $ | |
7 | + ,help=help | |
8 | + | |
9 | +;+ | |
10 | +; NAME: | |
11 | +; dustem_read_cb19_stellar_templates | |
12 | +; PURPOSE: | |
13 | +; reads EMILES stellar population templates | |
14 | +; CATEGORY: | |
15 | +; DustEMWrap, Distributed, High-Level, User Example | |
16 | +; CALLING SEQUENCE: | |
17 | +; templates=dustem_read_cb19_stellar_templates([age_values=][,metalicity_values=][,template_waves=][,Mstars=][,/info_only][,info_st=][,/help]) | |
18 | +; INPUTS: | |
19 | +; age_values : array of age values | |
20 | +; metalicity_values : array of metalicity values | |
21 | +; OPTIONAL INPUT PARAMETERS: | |
22 | +; None | |
23 | +; OUTPUTS: | |
24 | +; templates : SSP templates (F_lambda) [Lsun Msun^-1 A^-1] | |
25 | +; OPTIONAL OUTPUT PARAMETERS: | |
26 | +; template_wav = common wavelength array for templates [Angstroem] | |
27 | +; Mstars = Mass of stars [Msun] | |
28 | +; info_st = info structure for the templates | |
29 | +; ACCEPTED KEY-WORDS: | |
30 | +; info_only : if set, read only the information structure | |
31 | +; help : if set, prints this help | |
32 | +; COMMON BLOCKS: | |
33 | +; None | |
34 | +; SIDE EFFECTS: | |
35 | +; None | |
36 | +; RESTRICTIONS: | |
37 | +; The DustEM fortran code must be installed | |
38 | +; The DustEMWrap IDL code must be installed | |
39 | +; PROCEDURES AND SUBROUTINES USED: | |
40 | +; | |
41 | +; EXAMPLES | |
42 | +; st=dustem_read_cb19_stellar_templates(age_values=age_values,metalicity_values=metalicity_values,template_wav=template_wav) | |
43 | +; MODIFICATION HISTORY: | |
44 | +; Written by JPB June-2023 | |
45 | +; Evolution details on the DustEMWrap gitlab. | |
46 | +; See http://dustemwrap.irap.omp.eu/ for FAQ and help. | |
47 | +;- | |
48 | + | |
49 | +IF keyword_set(help) THEN BEGIN | |
50 | + doc_library,'dustem_read_cb19_stellar_templates' | |
51 | + templates=-1 | |
52 | + goto,the_end | |
53 | +END | |
54 | + | |
55 | +;=== This is what we want | |
56 | +age_values_wanted=[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] | |
57 | +metalicity_values_wanted=[-1.48630, -0.961400, -0.351200, +0.0600000, +0.255900, +0.397100] | |
58 | +NagesWanted=n_elements(age_values_wanted) | |
59 | +NZWanted=n_elements(metalicity_values_wanted) | |
60 | + | |
61 | +;=== This is what we have | |
62 | +Z=[0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.004, 0.006, 0.008, 0.010, 0.014, 0.017, 0.020, 0.030, 0.040, 0.060] | |
63 | +;la métallicité solaire pour ce set étant: Z=0.01524, et donc ces modèles vont en gros de [Z/Zo]= -2.18 à +0.59 | |
64 | +Z0=0.01524 | |
65 | +Z=alog10(Z/Z0) | |
66 | +;print,Z | |
67 | +; -2.18299 -1.88196 -1.48401 -1.18298 -0.881955 -0.580925 -0.404834 -0.279895 -0.182985 -0.0368569 0.0474640 0.118045 0.294136 0.419075 0.595166 | |
68 | +NZ=n_elements(Z) | |
69 | + | |
70 | +dir_templates=!dustem_wrap_soft_dir+'/Data/SSPs/CB2019/CB19_Chabrier/Mu100/' | |
71 | +files=file_search(dir_templates+'*.fits') | |
72 | +Nfiles=n_elements(files) | |
73 | +;metalicities=fltarr(Nfiles) | |
74 | +;ffile=strarr(Nfiles) | |
75 | +;FOR i=0L,Nfiles-1 DO BEGIN | |
76 | +; file=files[i] | |
77 | +; pos=strposmulti(file,'/') | |
78 | +; ffile[i]=strmid(file[i],pos[n_elements(pos)-1]+1,1000) | |
79 | +; pos=strposmulti(ffile[i],'_') | |
80 | +; metalicities[i]=float(strmid(ffile[i],pos[0]+2,pos[1]-pos[0]-2)) | |
81 | +; stop | |
82 | +; ;metalicities[i]= | |
83 | +;ENDFOR | |
84 | + | |
85 | +;read one fits file for header infos | |
86 | +file=dir_templates+'cb2019_z001_chab_hr_xmilesi_ssp.fits' | |
87 | +d=mrdfits(file,1,h) | |
88 | +wavs=d.wavelength | |
89 | +tagnames=tag_names(d) | |
90 | +ages=tagnames[1:*] | |
91 | +Nages=n_elements(ages) | |
92 | +ages=strmid(ages,1,1000) | |
93 | +aages=fltarr(Nages) | |
94 | +FOR i=0L,Nages-1 DO BEGIN | |
95 | + pos=strposmulti(ages[i],'P',count) | |
96 | + IF count NE 0 THEN BEGIN | |
97 | + aages[i]=float(textoidl_str_replace(ages[i],'P','.'))/1.e9 ;Gyr | |
98 | + ENDIF | |
99 | +ENDFOR | |
100 | +ages=aages | |
101 | +Nages=n_elements(ages) | |
102 | + | |
103 | +all_ssps=ptrarr(NZ,Nages) | |
104 | +FOR i=0L,Nfiles-1 DO BEGIN | |
105 | + st=mrdfits(files[i],1,h) | |
106 | + FOR j=0L,Nages-1 DO BEGIN | |
107 | + all_ssps[i,j]=ptr_new(st.(j+1)) | |
108 | + ENDFOR | |
109 | +ENDFOR | |
110 | + | |
111 | +;interpolate on requested age an metalicities | |
112 | +Ntemplates=NagesWanted*NZWanted | |
113 | +templates=ptrarr(Ntemplates) | |
114 | +FOR i=0L,Ntemplates-1 DO BEGIN | |
115 | + ij=index2ij([i],[NagesWanted,NZWanted]) | |
116 | + iage=ij[0,0] | |
117 | + imet=ij[0,1] | |
118 | + age=age_values_wanted[iage] | |
119 | + met=metalicity_values_wanted[imet] | |
120 | + ;==== CAUTION, this is nearest neighbour interpolation | |
121 | + dist_age=abs(age-ages) | |
122 | + dist_Z=abs(met-Z) | |
123 | + ind_age=where(dist_age EQ min(dist_age)) | |
124 | + ind_Z=where(dist_Z EQ min(dist_Z)) | |
125 | + templates[i]=all_ssps[ind_Z[0],ind_age[0]] | |
126 | + ;print,ind_age[0],ind_Z[0] | |
127 | + ;==== This is nearest neighbour on age and interpolation on Z | |
128 | + ssps_used=all_ssps[*,ind_age[0]] | |
129 | + xx=indgen(Nz) | |
130 | + toto=interpol(xx,Z,met) | |
131 | + u1=abs(toto-round(toto)) | |
132 | + u2=abs(toto-fix(toto)) | |
133 | + ;print,round(toto),toto,fix(toto) | |
134 | + ;print,1.-u1,1.-u2 | |
135 | + templates[i]=ptr_new((*ssps_used[round(toto)])*(1.-u1) + (*ssps_used[fix(toto)])*(1.-u2)) | |
136 | + ;stop | |
137 | +ENDFOR | |
138 | + | |
139 | +age_values=age_values_wanted | |
140 | +metalicity_values=metalicity_values_wanted | |
141 | + | |
142 | +;print,age_values | |
143 | +;print,metalicity_values | |
144 | + | |
145 | +;stop | |
146 | + | |
147 | +angstroem2mic=1.e6/1.e10 | |
148 | +template_wav=wavs*angstroem2mic ;mic | |
149 | + | |
150 | +the_end: | |
151 | + | |
152 | +RETURN,templates | |
153 | + | |
154 | +END | |
0 | 155 | \ No newline at end of file | ... | ... |