Blame view

src/idl/dustem_set_data.pro 11.5 KB
3ff9cac3   Ilyes Choubani   general update
1
2
3
4
5
FUNCTION dustem_set_data,st_sed_fit=st_sed_fit,st_sed_show=st_sed_show,st_ext_fit=st_ext_fit,st_ext_show=st_ext_show,rchi2_weight=rchi2_weight,f_HI=f_HI,help=help


;update the help

427f1205   Jean-Michel Glorian   version 4.2 merged
6
7
8
9
10
11
12
13
14

;+
; NAME:
;    dustem_set_data
; PURPOSE:
;    Initializes the dustem data structure (!dustem_data)
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
3ff9cac3   Ilyes Choubani   general update
15
;    dustem_set_data(data_sed=data_sed,data_ext=data_ext,[/help])
427f1205   Jean-Michel Glorian   version 4.2 merged
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
; INPUTS:
;    spec: array of structures containing a SED
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help      = If set print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    initializes !dustem_data
;    wavelengths are forced to be the central filter wavelength for
;    photometric data
; RESTRICTIONS:
;    The dustem idl wrapper must be installed
; PROCEDURE:
;    None
; EXAMPLES
;    dustem_init
;    dir=getenv('DUSTEM_SOFT_DIR')+'/src/dustem3.8_web/SEDs/'
;    file=dir+'Gal_composite_spectrum.xcat'
;    spec=read_xcat(file,/silent)
;    dustem_set_data,spec
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard
;    see evolution details on the dustem cvs maintained at CESR
;    Contact J.-Ph. Bernard (Jean-Philippe.Bernard@cesr.fr) in case of problems.
; 
;    V. Guillet (2012) : dustem_set_data is turned into a function which can be used 
;                        indifferently for sed, ext, polext
3ff9cac3   Ilyes Choubani   general update
49
50
;    I. Choubani (2022): Introducing the dustem_check_data procedure where the new format outlined by the latest release is taken into account.
;    This function uses two main input structures: DATA_SED and DATA_EXT. Polarization data is included within each. 
427f1205   Jean-Michel Glorian   version 4.2 merged
51
52
;-

4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
53

427f1205   Jean-Michel Glorian   version 4.2 merged
54
55
56
57
58
IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_set_data'
  goto,the_end
ENDIF

3ff9cac3   Ilyes Choubani   general update
59
60
61
62
63
64
65
;Cleaninig data/showing structure 
for i=0L,n_tags(!dustem_data)-1 do begin
    !dustem_data.(i) = ptr_new()
    !dustem_show.(i) = ptr_new()
endfor

xx=dustem_check_data(data_sed=st_sed_fit,data_ext=st_ext_fit,sed=sed,ext=ext,polext=polext,polsed=polsed,polfrac=polfrac,psi_em=psi_em,qsed=qsed,used=used,qext=qext,uext=uext,psi_ext=psi_ext)    
1355825c   Ilyes Choubani   General update
66
;stop
3ff9cac3   Ilyes Choubani   general update
67
;outputs whatever the input structure has, into organized seperate structures formatted for the fitting process.
09e61d64   Ilyes Choubani   cleaned set_data ...
68

3ff9cac3   Ilyes Choubani   general update
69
70
71
72
;If SED/EXT data is present in the structure it is fitted automatically. 
;If the user wished to not fit it they will have to null the corresponding fields in the input fitting structure. 
IF isa(sed) THEN !dustem_data.sed = ptr_new(sed)
IF isa(ext) THEN !dustem_data.ext = ptr_new(ext)
09e61d64   Ilyes Choubani   cleaned set_data ...
73

3ff9cac3   Ilyes Choubani   general update
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
;####################
;OLD VARIABLE. KEPT IT.
; If f_HI is specified, multiply the data by f_HI
If keyword_set(f_HI) and ptr_valid(!dustem_data.sed) then begin
    if f_HI gt 0 then (*!dustem_data.sed).values *= f_HI else f_HI = 1.
endif else f_HI = 1.
if keyword_set(f_HI) and ptr_valid(!dustem_data.ext) then begin
    if f_HI gt 0 then (*!dustem_data.ext).values *= f_HI else f_HI = 1.
endif else f_HI = 1.
defsysv,'!dustem_f_HI',f_HI
;####################

;NOTA BENE: The user is bound to fit Q and U together.
if !run_pol then begin
266ae799   Ilyes Choubani   General update
89
    
3ff9cac3   Ilyes Choubani   general update
90
    if keyword_set(st_sed_fit) then begin
266ae799   Ilyes Choubani   General update
91
    
3ff9cac3   Ilyes Choubani   general update
92
93
        teststks = isa(qsed) and isa(used)
    
1355825c   Ilyes Choubani   General update
94
        IF ~teststks  then message, 'Stokes parameters are not set correctly. Please check the input structure. Aborting...'
3ff9cac3   Ilyes Choubani   general update
95
96
    
        ;EMISSION 
3ff9cac3   Ilyes Choubani   general update
97
        
1355825c   Ilyes Choubani   General update
98
        message, 'Polarization component(s) to fit: QSED and USED' ,/continue
3ff9cac3   Ilyes Choubani   general update
99
100
101

        IF isa(qsed) THEN BEGIN        
            !dustem_data.qsed = ptr_new(qsed)
b0cabd3c   Ilyes Choubani   general update
102
103
104
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.qsed).values *= f_HI
        ENDIF    
1355825c   Ilyes Choubani   General update
105
        
3ff9cac3   Ilyes Choubani   general update
106
107
        if isa(used) then BEGIN
            !dustem_data.used = ptr_new(used)
b0cabd3c   Ilyes Choubani   general update
108
109
110
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.used).values *= f_HI
        ENDIF
1355825c   Ilyes Choubani   General update
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
        
        if isa(polsed) then BEGIN
            
            !dustem_data.polsed = ptr_new(polsed)
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.polsed).values *= f_HI
            
        ENDIF 
        
        if isa(polfrac) then BEGIN
            
            !dustem_data.polfrac = ptr_new(polfrac)
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.polfrac).values *= f_HI
        
        ENDIF 
        
        
        if isa(psi_em) then BEGIN
            
            !dustem_data.psi_em = ptr_new(psi_em)
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.psi_em).values *= f_HI
        
        ENDIF 
        
        
b0cabd3c   Ilyes Choubani   general update
138
    endif
759a527d   Ilyes Choubani   general update
139
    
3ff9cac3   Ilyes Choubani   general update
140
141
142
143
    if keyword_set(st_ext_fit) then begin
        ;Two tests that determine what the user will eventually fit
        
        testexstks = isa(qext) and isa(uext)
3ff9cac3   Ilyes Choubani   general update
144
        
1355825c   Ilyes Choubani   General update
145
146
        IF ~testexstks then message, 'Extinction stokes parameters/Polarization data is not set correctly. Please check the input structure. Aborting...'
         
3ff9cac3   Ilyes Choubani   general update
147
        ;EXTINCTION - allowed for the default fitting of both because I do not know if the same formalism should be applied to the extinction data because it also implies deviding extinction data into two components. 
1355825c   Ilyes Choubani   General update
148
149
150
       
        message, 'Extinction polarization component(s) to fit: QEXT and UEXT',/continue
       
3ff9cac3   Ilyes Choubani   general update
151
152
        if isa(polext) then BEGIN        
            !dustem_data.polext = ptr_new(polext)
b0cabd3c   Ilyes Choubani   general update
153
154
155
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.polext).values *= f_HI
        ENDIF
3ff9cac3   Ilyes Choubani   general update
156
157
        IF isa(qext) THEN BEGIN        
            !dustem_data.qext = ptr_new(qext)
b0cabd3c   Ilyes Choubani   general update
158
159
160
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.qext).values *= f_HI
        ENDIF
3ff9cac3   Ilyes Choubani   general update
161
162
        if isa(uext) then BEGIN 
            !dustem_data.uext = ptr_new(uext)
b0cabd3c   Ilyes Choubani   general update
163
164
165
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.uext).values *= f_HI
        ENDIF
1355825c   Ilyes Choubani   General update
166
        
b0cabd3c   Ilyes Choubani   general update
167
    endif
3ff9cac3   Ilyes Choubani   general update
168
169
170
171
endif


if not keyword_set(st_sed_show) then st_sed_show=st_sed_fit
427f1205   Jean-Michel Glorian   version 4.2 merged
172

3ff9cac3   Ilyes Choubani   general update
173
;Setting of the structure that will be displayed
1355825c   Ilyes Choubani   General update
174
175
yy=dustem_check_data(data_sed=st_sed_show,data_ext=st_ext_show,sed=sed,ext=ext,polext=polext,polsed=polsed,polfrac=polfrac,qsed=qsed,used=used,qext=qext,uext=uext,psi_em=psi_em,psi_ext=psi_ext)
;stop
3ff9cac3   Ilyes Choubani   general update
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
IF isa(sed) THEN !dustem_show.sed = ptr_new(sed)
IF isa(ext) THEN !dustem_show.ext = ptr_new(ext)

  
;####################
;OLD VARIABLE. KEPT IT.
; If f_HI is specified, multiply the data by f_HI
If keyword_set(f_HI) and ptr_valid(!dustem_show.sed) then begin
    if f_HI gt 0 then (*!dustem_show.sed).values *= f_HI else f_HI = 1.
endif else f_HI = 1.
if keyword_set(f_HI) and ptr_valid(!dustem_show.ext) then begin
    if f_HI gt 0 then (*!dustem_show.ext).values *= f_HI else f_HI = 1.
endif else f_HI = 1.
defsysv,'!dustem_f_HI',f_HI
;####################

if !run_pol then begin
6a714abf   Ilyes Choubani   small fix to dust...
193
    
3ff9cac3   Ilyes Choubani   general update
194
195
196
197
    if isa(st_sed_show) then begin ; because sometimes this keyword isn't set.
        
        teststks = isa(qsed) and isa(used)
        
1355825c   Ilyes Choubani   General update
198
        IF (~teststks and ~isa(polsed)) or (~teststks and ~isa(polfrac)) then message, 'Stokes parameters/Polarization showing data is not set correctly. Please check the input structure. Aborting...'
3ff9cac3   Ilyes Choubani   general update
199
        
1355825c   Ilyes Choubani   General update
200
201
202
203
204
205
        if teststks and isa(polsed) and ~(isa(polfrac)) and ~(isa(psi_em)) then nowshowing = 'QSED, USED and POLSED'
        if teststks and isa(polsed) and ~(isa(polfrac)) and isa(psi_em) then nowshowing = 'QSED, USED, POLSED and PSI_EM'
        if teststks and ~(isa(polsed)) and isa(polfrac) and ~(isa(psi_em)) then nowshowing = 'QSED, USED and POLFRAC'
        if teststks and ~(isa(polsed)) and isa(polfrac) and isa(psi_em) then nowshowing = 'QSED, USED, POLFRAC and PSI_EM'
        if teststks and ~(isa(polsed)) and ~(isa(polfrac)) and ~(isa(psi_em)) then nowshowing = 'QSED and USED'
        if teststks and isa(polsed) and isa(polfrac) and ~(isa(psi_em)) then nowshowing = 'QSED, USED, POLSED and POLFRAC'
3ff9cac3   Ilyes Choubani   general update
206
        if teststks and isa(polsed) and isa(polfrac) and isa(psi_em) then nowshowing = 'QSED, USED, POLFRAC, POLSED and PSI_EM'
1355825c   Ilyes Choubani   General update
207
        if teststks and ~(isa(polsed)) and ~(isa(polfrac)) and isa(psi_em) then nowshowing = 'QSED, USED and PSI_EM'
3ff9cac3   Ilyes Choubani   general update
208
        
4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
209

3ff9cac3   Ilyes Choubani   general update
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
        message, 'Polarization component(s) to show: '+nowshowing ,/continue
        
        
        If isa(polsed) then BEGIN    ;Apply changes to !dustem_data here.      
            !dustem_show.polsed = ptr_new(polsed)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.polsed).values *= f_HI
        ENDIF
        If isa(polfrac) then BEGIN        
            !dustem_show.polfrac = ptr_new(polfrac)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.polfrac).values *= f_HI
        ENDIF
        IF isa(qsed) THEN BEGIN        
            !dustem_show.qsed = ptr_new(qsed)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.qsed).values *= f_HI
        ENDIF    
        if isa(used) then BEGIN
            !dustem_show.used = ptr_new(used)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.used).values *= f_HI
        ENDIF
        if isa(psi_em) then BEGIN
            !dustem_show.psi_em = ptr_new(psi_em)
            if keyword_set(f_HI) then if f_HI gt 0 then $
            (*!dustem_show.psi_em).values *= f_HI
        ENDIF        
    endif
    if isa(st_ext_show) then begin
        teststks = isa(qext) and isa(uext)
        
1355825c   Ilyes Choubani   General update
242
        IF (~teststks) then message, 'Extinction stokes parameters/Polarization data is not set correctly. Please check the input structure. Aborting...'
3ff9cac3   Ilyes Choubani   general update
243
        
1355825c   Ilyes Choubani   General update
244
        if teststks and isa(polext) and ~(isa(psi_ext)) then nowshowing = 'QEXT, UEXT and POLEXT'
3ff9cac3   Ilyes Choubani   general update
245
        if teststks and isa(polext) and isa(psi_ext) then nowshowing = 'QEXT, UEXT, POLEXT and PSI_EXT'
1355825c   Ilyes Choubani   General update
246
247
        if teststks and ~(isa(polext)) and isa(psi_ext) then nowshowing = 'QEXT,UEXT and PSI_EXT' 
        if teststks and ~(isa(polext)) and ~(isa(psi_ext)) then nowshowing = 'QEXT and UEXT'
3ff9cac3   Ilyes Choubani   general update
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
        
        message, 'Polarization component(s) to show: '+nowshowing ,/continue
        
        ;EXTINCTION
        if isa(polext) then BEGIN        
            !dustem_show.polext = ptr_new(polext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.polext).values *= f_HI
        ENDIF
        IF isa(qext) THEN BEGIN        
            !dustem_show.qext = ptr_new(qext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.qext).values *= f_HI
        ENDIF
        if isa(uext) then BEGIN 
            !dustem_show.uext = ptr_new(uext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.uext).values *= f_HI
        ENDIF
        if isa(psi_ext) then BEGIN 
            !dustem_show.psi_ext = ptr_new(psi_ext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.psi_ext).values *= f_HI
        ENDIF
    endif
endif
427f1205   Jean-Michel Glorian   version 4.2 merged
274

09e61d64   Ilyes Choubani   cleaned set_data ...
275
IF keyword_set(rchi2_weight) THEN BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
276
277
	!fit_rchi2_weight.sed     = rchi2_weight.sed
	!fit_rchi2_weight.ext     = rchi2_weight.ext
09e61d64   Ilyes Choubani   cleaned set_data ...
278
	
6a714abf   Ilyes Choubani   small fix to dust...
279
	IF !run_pol THEN BEGIN
1355825c   Ilyes Choubani   General update
280
    	
3ff9cac3   Ilyes Choubani   general update
281
282
    	IF isa(qsed) THEN !fit_rchi2_weight.qsed  = rchi2_weight.qsed
    	IF isa(used) THEN !fit_rchi2_weight.used  = rchi2_weight.used
6a714abf   Ilyes Choubani   small fix to dust...
283
    	
3ff9cac3   Ilyes Choubani   general update
284
285
    	IF isa(qext) THEN !fit_rchi2_weight.qext  = rchi2_weight.qext
    	IF isa(uext) THEN !fit_rchi2_weight.uext  = rchi2_weight.uext
6a714abf   Ilyes Choubani   small fix to dust...
286
287
    ENDIF
    
3ff9cac3   Ilyes Choubani   general update
288
289
290
291
292
293
ENDIF ELSE BEGIN

    !fit_rchi2_weight.sed=1.
    !fit_rchi2_weight.ext=1.
    
    If !run_pol THEN BEGIN
1355825c   Ilyes Choubani   General update
294
        
3ff9cac3   Ilyes Choubani   general update
295
296
        IF isa(qsed) THEN !fit_rchi2_weight.qsed=1.
        IF isa(used) THEN !fit_rchi2_weight.used=1.
1355825c   Ilyes Choubani   General update
297
        
3ff9cac3   Ilyes Choubani   general update
298
299
        IF isa(qext) THEN !fit_rchi2_weight.qext=1.
        IF isa(uext) THEN !fit_rchi2_weight.uext=1.
1355825c   Ilyes Choubani   General update
300
    
3ff9cac3   Ilyes Choubani   general update
301
    ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
302

3ff9cac3   Ilyes Choubani   general update
303
ENDELSE
427f1205   Jean-Michel Glorian   version 4.2 merged
304
305
306
307


the_end:

3ff9cac3   Ilyes Choubani   general update
308
309
310
311
312
313
314
;stop
return,0.





427f1205   Jean-Michel Glorian   version 4.2 merged
315
END