Blame view

src/idl/dustem_compute_sed.pro 6.35 KB
283845da   Ilyes Choubani   Small corrections...
1
FUNCTION dustem_compute_sed,p_dim,$
cee5beec   Jean-Philippe Bernard   just changed form...
2
                            st=st,$
0fc2c233   Annie Hughes   added input spec ...
3
                            input_spec=input_spec, $
14188148   Jean-Philippe Bernard   improved
4
                            input_wav=input_wav, $
0b156835   Annie Hughes   improved inline d...
5
                            sed_spec=sed_spec, $
88f84272   Jean-Philippe Bernard   changed
6
                            use_previous_fortran=use_previous_fortran, $
80386bb1   Jean-Philippe Bernard   removed need for ...
7
                            filters=filters, $
14188148   Jean-Philippe Bernard   improved
8
9
10
                            sed_index=sed_index, $
                            spec_index=spec_index, $
                            no_sort=no_sort, $
cee5beec   Jean-Philippe Bernard   just changed form...
11
                            help=help
427f1205   Jean-Michel Glorian   version 4.2 merged
12

427f1205   Jean-Michel Glorian   version 4.2 merged
13
14
15
;+
; NAME:
;    dustem_compute_sed
f09e876c   Annie Hughes   updated doc help
16
;
427f1205   Jean-Michel Glorian   version 4.2 merged
17
; PURPOSE:
07a51917   Ilyes Choubani   updating help sec...
18
;    Computes a SED for a given Dustem model
f09e876c   Annie Hughes   updated doc help
19
;
427f1205   Jean-Michel Glorian   version 4.2 merged
20
21
; CATEGORY:
;    Dustem
f09e876c   Annie Hughes   updated doc help
22
;
427f1205   Jean-Michel Glorian   version 4.2 merged
23
; CALLING SEQUENCE:
14188148   Jean-Philippe Bernard   improved
24
;    sed=dustem_compute_sed(p_dim[,st][,input_spec=][,input_wav=][,sed_spec=][,/use_previous_fortran][,filters=][,sed_index=][,spec_index=][,/help])
f09e876c   Annie Hughes   updated doc help
25
;
427f1205   Jean-Michel Glorian   version 4.2 merged
26
; INPUTS:
0fc2c233   Annie Hughes   added input spec ...
27
28
29
;    p_dim      = parameter values. This is actually optional, and
;    will not be used if st or input_spec are provided, but
;    leaving like this for backwards compatbility.
f09e876c   Annie Hughes   updated doc help
30
;
427f1205   Jean-Michel Glorian   version 4.2 merged
31
; OPTIONAL INPUT PARAMETERS:
0fc2c233   Annie Hughes   added input spec ...
32
33
34
35
36
;    st         = Dustem Fortran output structure. Takes precedence
;                 over p_dim. NB THIS IS ALSO THE OUTPUT VARIABLE.
;    input_spec = input spectrum that will be used to calculate
;                 SED. Expected units are MJy/sr. Takes precedence
;                 over p_dim and st
14188148   Jean-Philippe Bernard   improved
37
;    input_wav  = input wavelengths corresponding to input_spec
80386bb1   Jean-Philippe Bernard   removed need for ...
38
;    filters    = if set, use these filters to compute the SED (if not use filters in !dustem_data or all known filters if !dustem_data does not exist)
14188148   Jean-Philippe Bernard   improved
39
40
;    sed_index  = index of filters which are large filters (color correction needed) 
;    spec_index  = index of filters which are narow filters (no color correction needed) 
427f1205   Jean-Michel Glorian   version 4.2 merged
41
42
; OUTPUTS:
;    sed       = computed SED for filters in !dustem_data
f09e876c   Annie Hughes   updated doc help
43
;
427f1205   Jean-Michel Glorian   version 4.2 merged
44
; OPTIONAL OUTPUT PARAMETERS:
0fc2c233   Annie Hughes   added input spec ...
45
46
;    st      = Dustem fortran output structure NB THIS IS ALSO AN INPUT VARIABLE.
;    sed_spec    = final emission spectrum
f09e876c   Annie Hughes   updated doc help
47
;
427f1205   Jean-Michel Glorian   version 4.2 merged
48
; ACCEPTED KEY-WORDS:
88f84272   Jean-Philippe Bernard   changed
49
;    use_previous_fortran = if set, uses the output of the previous fortran run, and does not run the fortran.
14188148   Jean-Philippe Bernard   improved
50
;    no_sort   = if set, input arrays are assumed to already be orderd by increasing wavelengths (passed to dustem_cc)
427f1205   Jean-Michel Glorian   version 4.2 merged
51
;    help      = If set, print this help
f09e876c   Annie Hughes   updated doc help
52
;
427f1205   Jean-Michel Glorian   version 4.2 merged
53
54
; COMMON BLOCKS:
;    None
f09e876c   Annie Hughes   updated doc help
55
;
427f1205   Jean-Michel Glorian   version 4.2 merged
56
57
; SIDE EFFECTS:
;    None
f09e876c   Annie Hughes   updated doc help
58
;
427f1205   Jean-Michel Glorian   version 4.2 merged
59
; RESTRICTIONS:
f09e876c   Annie Hughes   updated doc help
60
61
;    The DustEMWrap IDL code must be installed
;
427f1205   Jean-Michel Glorian   version 4.2 merged
62
63
; PROCEDURE:
;    None
f09e876c   Annie Hughes   updated doc help
64
;
427f1205   Jean-Michel Glorian   version 4.2 merged
65
66
67
; EXAMPLES
;    
; MODIFICATION HISTORY:
f09e876c   Annie Hughes   updated doc help
68
;    Written by J.-Ph. Bernard 2008
84fd3e7e   Annie Hughes   comments
69
70
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
427f1205   Jean-Michel Glorian   version 4.2 merged
71
72
73
74
75
76
77
78
;-

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

d339db1c   Jean-Philippe Bernard   improved
79
80
;stop

80386bb1   Jean-Philippe Bernard   removed need for ...
81
82
83
84
85
86
87
IF ptr_valid((*!dustem_fit).param_init_values) THEN BEGIN
   use_param_init_values=(*(*!dustem_fit).param_init_values)
ENDIF ELSE BEGIN
   use_param_init_values=p_dim
ENDELSE

;stop
0fc2c233   Annie Hughes   added input spec ...
88
IF not keyword_set(st) and not keyword_set(input_spec) THEN BEGIN
d339db1c   Jean-Philippe Bernard   improved
89
   ;==== JPB: This division leads to NaN for initial values at 0 !!
80386bb1   Jean-Philippe Bernard   removed need for ...
90
   dustem_activate_plugins,p_dim/use_param_init_values,st=st,use_previous_fortran=use_previous_fortran
427f1205   Jean-Michel Glorian   version 4.2 merged
91
92
ENDIF

d339db1c   Jean-Philippe Bernard   improved
93
94
;stop

0fc2c233   Annie Hughes   added input spec ...
95
IF not keyword_set(input_spec) THEN BEGIN
e983bf0b   Jean-Philippe Bernard   tried to optimize...
96
   ; Convert into MJy/sr/1d20
a39f6d2a   Jean-Philippe Bernard   improved
97
   fact=dustem_get_emission_conversion_factor()
0fc2c233   Annie Hughes   added input spec ...
98
99
   SED_spec = st.sed.em_tot * fact
   use_wavs = st.sed.wav
e983bf0b   Jean-Philippe Bernard   tried to optimize...
100
   ;===== Adding plugin output to spectrum ----------------
0fc2c233   Annie Hughes   added input spec ...
101
102
103
104
105
106
107
108
109
   plugin_tags=(*!dustem_plugin).name
   ind=where(plugin_tags NE 'NONE',Nplugins)
   IF Nplugins NE 0 THEN BEGIN
      FOR i=0L,Nplugins-1 DO BEGIN
         IF total(strsplit((*!dustem_plugin)[i].scope,'+',/extract) eq 'ADD_SED') THEN BEGIN
            SED_spec+=(*(*!dustem_plugin)[i].spec)[*,0]
         ENDIF
      ENDFOR
   ENDIF
e983bf0b   Jean-Philippe Bernard   tried to optimize...
110
ENDIF ELSE BEGIN
0fc2c233   Annie Hughes   added input spec ...
111
   SED_spec=input_spec
14188148   Jean-Philippe Bernard   improved
112
113
114
115
116
   IF keyword_set(input_wav) THEN BEGIN
      use_wavs=input_wav
   ENDIF ELSE BEGIN
      use_wavs=dustem_get_wavelengths()
   ENDELSE
e983bf0b   Jean-Philippe Bernard   tried to optimize...
117
ENDELSE
0fc2c233   Annie Hughes   added input spec ...
118

452c334e   Ilyes Choubani   Implementation Of...
119
;------------------------------------------
e983bf0b   Jean-Philippe Bernard   tried to optimize...
120
121
;This should not happen anyway
;IF not isarray(SED_spec) THEN stop
80386bb1   Jean-Philippe Bernard   removed need for ...
122

427f1205   Jean-Michel Glorian   version 4.2 merged
123
;COMPUTE THE MODEL SED
88f84272   Jean-Philippe Bernard   changed
124
;JPB: problem there: we should be able to compute an SED even when there is no data in !dustem_data
80386bb1   Jean-Philippe Bernard   removed need for ...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
IF ptr_valid((*!dustem_data).sed) THEN BEGIN
   dustem_sed = (*(*!dustem_data).sed).values * 0.
   use_filters=(*(*!dustem_data).sed).filt_names
   use_filter_wavs=(*(*!dustem_data).sed).wav
ENDIF ELSE BEGIN
   IF keyword_set(filters) THEN BEGIN
      use_filters=filters
   ENDIF ELSE BEGIN
      use_filters=dustem_get_all_filter_names()
   ENDELSE
   Nfilters=n_elements(use_filters)
   dustem_sed=(dustem_initialize_sed(Nfilters)).stokesI
   use_filter_wavs=dustem_filter2wav(use_filters)
ENDELSE
427f1205   Jean-Michel Glorian   version 4.2 merged
139
140
141
142
143
144
145

IF !dustem_do_cc NE 0 AND !dustem_never_do_cc EQ 0 THEN BEGIN
  message,'DOING color correction calculations',/info
ENDIF ELSE BEGIN
  message,'SKIPPING color correction calculations: we take previous values of cc',/info
ENDELSE

14188148   Jean-Philippe Bernard   improved
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;defines which filters need color correction, which don't
count_sed=0
count_spec=0
IF keyword_set(sed_index) OR keyword_set(spec_index) THEN BEGIN
   IF keyword_set(sed_index) THEN BEGIN
      ind_sed=sed_index
      count_sed=n_elements(ind_sed)
   ENDIF
   IF keyword_set(spec_index) THEN BEGIN
      ind_spec=spec_index
      count_spec=n_elements(ind_spec)
   ENDIF
ENDIF ELSE BEGIN
   ind_sed=where(use_filters NE 'SPECTRUM' and use_wavs gt 0.,count_sed)
   ;ind_spec=where((*(*!dustem_data).sed).filt_names EQ 'SPECTRUM',count_spec)
   ind_spec=where(use_filters EQ 'SPECTRUM',count_spec)
ENDELSE

427f1205   Jean-Michel Glorian   version 4.2 merged
164
IF count_sed NE 0 THEN BEGIN
80386bb1   Jean-Philippe Bernard   removed need for ...
165
  filter_names=(use_filters)[ind_sed]
14188148   Jean-Philippe Bernard   improved
166
  ssed=dustem_cc(use_wavs,SED_spec,filter_names,cc=cc,no_sort=no_sort)  
9ccf7615   Jean-Philippe Bernard   modified to fit u...
167
  dustem_sed[ind_sed]=ssed
427f1205   Jean-Michel Glorian   version 4.2 merged
168
ENDIF ELSE BEGIN
e983bf0b   Jean-Philippe Bernard   tried to optimize...
169
  message,"**** WARNING **** NO FILTER defined in DATA for COLOUR CORRECTION",/continue
427f1205   Jean-Michel Glorian   version 4.2 merged
170
171
172
173
174
ENDELSE

;For spectrum data points, interpolate in log-log
;Linear interpolation leads to wrong values, in particular where few
;wavelengths points exist in the model (long wavelengths).
427f1205   Jean-Michel Glorian   version 4.2 merged
175
IF count_spec NE 0 THEN BEGIN
0fc2c233   Annie Hughes   added input spec ...
176
;    dustem_sed[ind_spec]=interpol(SED_spec,st.sed.wav,(((*(*!dustem_data).sed).wav)[ind_spec]))
80386bb1   Jean-Philippe Bernard   removed need for ...
177
178
    ;dustem_sed[ind_spec]=interpol(SED_spec,use_wavs,(((*(*!dustem_data).sed).wav)[ind_spec]))
    dustem_sed[ind_spec]=interpol(SED_spec,use_wavs,use_filter_wavs[ind_spec])
5f04fa07   Ilyes Choubani   general update
179
    ;dustem_sed(ind_spec)=10^interpol(alog10(spec),alog10(st.sed.wav),alog10((((*!dustem_data.sed).wav)(ind_spec))))
427f1205   Jean-Michel Glorian   version 4.2 merged
180
ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
181
182

;clean pointers
14188148   Jean-Philippe Bernard   improved
183
184
;JPB: not sure why doing this here. May be too often when intensively using this code.
;heap_gc
427f1205   Jean-Michel Glorian   version 4.2 merged
185
186
187

the_end:

427f1205   Jean-Michel Glorian   version 4.2 merged
188
189
190
RETURN,dustem_sed

END