Blame view

src/idl/dustem_set_data.pro 13.2 KB
262cff06   Ilyes Choubani   minor changes to ...
1
PRO dustem_set_data,m_fit,m_show,x_fit,x_show,rchi2_weight=rchi2_weight,f_HI=f_HI,help=help
abebbdf3   Ilyes Choubani   General update: A...
2

427f1205   Jean-Michel Glorian   version 4.2 merged
3
4
5
6
;+
; NAME:
;    dustem_set_data
; PURPOSE:
04efbaa5   Ilyes Choubani   Correcting set_da...
7
8
9
;    ## adapting the data structures to the format used by the fitting algorithm 
;    Initializes the dustem data structure (!dustem_data) used in the fitting
;    Initializes the !dustem_show structure which is either a copy or a more detailed version of !dustem_data 
427f1205   Jean-Michel Glorian   version 4.2 merged
10
11
12
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
04efbaa5   Ilyes Choubani   Correcting set_da...
13
;    dustem_set_data(m_fit,x_fit,m_show,x_show,[/help])
427f1205   Jean-Michel Glorian   version 4.2 merged
14
; INPUTS:
04efbaa5   Ilyes Choubani   Correcting set_da...
15
16
17
18
19
20
;    ## used in initializing !dustem_data
;    m_fit : dustemwrap structure contaning emission data to be fitted 
;    x_fit : dustemwrap structure containing extinction data to be fitted
;    ## used in initializing !dustem_show
;    m_show : dustemwrap structure containing emission data to be displayed
;    x_show : dustemwrap structure containing extinctiond data to be displayed
427f1205   Jean-Michel Glorian   version 4.2 merged
21
22
23
24
25
26
27
28
29
30
31
; OPTIONAL INPUT PARAMETERS:
;    None
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
;    None
; ACCEPTED KEY-WORDS:
;    help      = If set print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
04efbaa5   Ilyes Choubani   Correcting set_da...
32
;    initializes !dustem_data/!dustem_show
427f1205   Jean-Michel Glorian   version 4.2 merged
33
34
35
36
37
38
39
40
;    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
04efbaa5   Ilyes Choubani   Correcting set_da...
41
42
;    dir=!dustem_wrap_soft_dir+'/Data/EXAMPLE_OBSDATA/'
;    file=dir+'example_SED_1.xcat'
427f1205   Jean-Michel Glorian   version 4.2 merged
43
;    spec=read_xcat(file,/silent)
04efbaa5   Ilyes Choubani   Correcting set_da...
44
45
;    var = dustem_set_data(spec,x_fit,spec,x_show)
;    #in this example !dustem_data and !dustem_show are identical
427f1205   Jean-Michel Glorian   version 4.2 merged
46
47
48
49
50
51
52
; 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
04efbaa5   Ilyes Choubani   Correcting set_da...
53
54
;    I. Choubani (2022): dustem_check_data is introduced and the data structure format of the latest release is respected.
;-                       dustem_set_data is turned into a procedure.
427f1205   Jean-Michel Glorian   version 4.2 merged
55

4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
56

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

5a2643a4   Ilyes Choubani   cleaning/improvin...
62
;Cleaninig fitting/showing structure(s) 
3ff9cac3   Ilyes Choubani   general update
63
64
65
66
67
for i=0L,n_tags(!dustem_data)-1 do begin
    !dustem_data.(i) = ptr_new()
    !dustem_show.(i) = ptr_new()
endfor

5a2643a4   Ilyes Choubani   cleaning/improvin...
68
;#FITTING STRUCTURE
3c479f24   Ilyes Choubani   Allowing to fix p...
69

04efbaa5   Ilyes Choubani   Correcting set_da...
70
dustem_check_data,m_fit,x_fit,sed,ext,polext,polsed,polfrac,psi_em,qsed,used,qext,uext,psi_ext,fpolext  
eab2e158   Jean-Philippe Bernard   did some (sometim...
71
;stop
3ff9cac3   Ilyes Choubani   general update
72
;outputs whatever the input structure has, into organized seperate structures formatted for the fitting process.
09e61d64   Ilyes Choubani   cleaned set_data ...
73

abebbdf3   Ilyes Choubani   General update: A...
74
;FITTING STRUCTURE INITIALIZATION
3ff9cac3   Ilyes Choubani   general update
75
76
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 ...
77

3ff9cac3   Ilyes Choubani   general update
78
79
80
81
82
83
84
85
86
87
88
89
;####################
;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
;####################

3ff9cac3   Ilyes Choubani   general update
90
if !run_pol then begin
266ae799   Ilyes Choubani   General update
91
    
abebbdf3   Ilyes Choubani   General update: A...
92
    if keyword_set(m_fit) then begin
262cff06   Ilyes Choubani   minor changes to ...
93
    
3ff9cac3   Ilyes Choubani   general update
94
        teststks = isa(qsed) and isa(used)
9074d6cd   Jean-Philippe Bernard   fixed a bug of Na...
95
    ;stop
1355825c   Ilyes Choubani   General update
96
        IF ~teststks  then message, 'Stokes parameters are not set correctly. Please check the input structure. Aborting...'
3ff9cac3   Ilyes Choubani   general update
97
    
abebbdf3   Ilyes Choubani   General update: A...
98
        ;☆EMISSION 
1355825c   Ilyes Choubani   General update
99
        message, 'Polarization component(s) to fit: QSED and USED' ,/continue
abebbdf3   Ilyes Choubani   General update: A...
100
101
102
        
        
        ;☆Mandatory presence in polar mode 
3ff9cac3   Ilyes Choubani   general update
103
104
        IF isa(qsed) THEN BEGIN        
            !dustem_data.qsed = ptr_new(qsed)
b0cabd3c   Ilyes Choubani   general update
105
106
107
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.qsed).values *= f_HI
        ENDIF    
abebbdf3   Ilyes Choubani   General update: A...
108
        ;☆Mandatory presence in polar mode
3ff9cac3   Ilyes Choubani   general update
109
110
        if isa(used) then BEGIN
            !dustem_data.used = ptr_new(used)
b0cabd3c   Ilyes Choubani   general update
111
112
113
            if keyword_set(f_HI) then if f_HI gt 0 then $
          	(*!dustem_data.used).values *= f_HI
        ENDIF
1355825c   Ilyes Choubani   General update
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        
        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
        
abebbdf3   Ilyes Choubani   General update: A...
129
        ENDIF
1355825c   Ilyes Choubani   General update
130
131
132
133
134
135
136
137
138
139
        
        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
140
    endif
759a527d   Ilyes Choubani   general update
141
    
abebbdf3   Ilyes Choubani   General update: A...
142
    if keyword_set(x_fit) then begin
5a2643a4   Ilyes Choubani   cleaning/improvin...
143
    
3ff9cac3   Ilyes Choubani   general update
144
        ;Two tests that determine what the user will eventually fit
3ff9cac3   Ilyes Choubani   general update
145
        testexstks = isa(qext) and isa(uext)
3ff9cac3   Ilyes Choubani   general update
146
        
1355825c   Ilyes Choubani   General update
147
148
        IF ~testexstks then message, 'Extinction stokes parameters/Polarization data is not set correctly. Please check the input structure. Aborting...'
         
3ff9cac3   Ilyes Choubani   general update
149
        ;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
150
151
152
       
        message, 'Extinction polarization component(s) to fit: QEXT and UEXT',/continue
       
3ff9cac3   Ilyes Choubani   general update
153
154
        if isa(polext) then BEGIN        
            !dustem_data.polext = ptr_new(polext)
b0cabd3c   Ilyes Choubani   general update
155
156
157
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.polext).values *= f_HI
        ENDIF
3ff9cac3   Ilyes Choubani   general update
158
159
        IF isa(qext) THEN BEGIN        
            !dustem_data.qext = ptr_new(qext)
b0cabd3c   Ilyes Choubani   general update
160
161
162
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.qext).values *= f_HI
        ENDIF
3ff9cac3   Ilyes Choubani   general update
163
164
        if isa(uext) then BEGIN 
            !dustem_data.uext = ptr_new(uext)
b0cabd3c   Ilyes Choubani   general update
165
166
167
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.uext).values *= f_HI
        ENDIF
1355825c   Ilyes Choubani   General update
168
        
07372e26   Ilyes Choubani   Corrected huge pl...
169
170
171
172
173
174
        if isa(psi_ext) then BEGIN 
            !dustem_data.psi_ext = ptr_new(psi_ext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.psi_ext).values *= f_HI
        ENDIF
        
67bd858a   Ilyes Choubani   Replication of th...
175
176
177
178
179
180
181
        ;added for completeness 
        if isa(fpolext) then BEGIN        
            !dustem_data.fpolext = ptr_new(fpolext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_data.fpolext).values *= f_HI
        ENDIF
        
b0cabd3c   Ilyes Choubani   general update
182
    endif
3ff9cac3   Ilyes Choubani   general update
183
184
endif

5a2643a4   Ilyes Choubani   cleaning/improvin...
185
;#SHOWING STRUCTURE
3ff9cac3   Ilyes Choubani   general update
186

04efbaa5   Ilyes Choubani   Correcting set_da...
187
188
189
if keyword_set(m_fit) and not keyword_set(m_show) then m_show=m_fit
if keyword_set(x_fit) and not keyword_set(x_show) then x_show = x_fit

427f1205   Jean-Michel Glorian   version 4.2 merged
190

3ff9cac3   Ilyes Choubani   general update
191
;Setting of the structure that will be displayed
07372e26   Ilyes Choubani   Corrected huge pl...
192
dustem_check_data,m_show,x_show,sed,ext,polext,polsed,polfrac,psi_em,qsed,used,qext,uext,psi_ext,fpolext
5a2643a4   Ilyes Choubani   cleaning/improvin...
193

3ff9cac3   Ilyes Choubani   general update
194
195
IF isa(sed) THEN !dustem_show.sed = ptr_new(sed)
IF isa(ext) THEN !dustem_show.ext = ptr_new(ext)
3ff9cac3   Ilyes Choubani   general update
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  
;####################
;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...
210
    
abebbdf3   Ilyes Choubani   General update: A...
211
    if isa(m_show) then begin ; because sometimes this keyword isn't set.
3ff9cac3   Ilyes Choubani   general update
212
213
214
        
        teststks = isa(qsed) and isa(used)
        
1355825c   Ilyes Choubani   General update
215
        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
216
        
1355825c   Ilyes Choubani   General update
217
218
219
220
221
222
        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
223
        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
224
        if teststks and ~(isa(polsed)) and ~(isa(polfrac)) and isa(psi_em) then nowshowing = 'QSED, USED and PSI_EM'
3ff9cac3   Ilyes Choubani   general update
225
        
4fd64cbb   Ilyes Choubani   dustem_fit_sed_po...
226

3ff9cac3   Ilyes Choubani   general update
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
        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
abebbdf3   Ilyes Choubani   General update: A...
256
    if isa(x_show) then begin
3ff9cac3   Ilyes Choubani   general update
257
258
        teststks = isa(qext) and isa(uext)
        
1355825c   Ilyes Choubani   General update
259
        IF (~teststks) then message, 'Extinction stokes parameters/Polarization data is not set correctly. Please check the input structure. Aborting...'
04efbaa5   Ilyes Choubani   Correcting set_da...
260
                
67bd858a   Ilyes Choubani   Replication of th...
261
262
263
264
265
266
267
268
        if teststks and isa(polext) and ~(isa(polextfrac)) and ~(isa(psi_ext)) then nowshowing = 'QEXT, UEXT and POLEXT'
        if teststks and isa(polext) and ~(isa(polextfrac)) and isa(psi_ext) then nowshowing = 'QEXT, UEXT, POLEXT and PSI_EXT'
        if teststks and ~(isa(polext)) and isa(polextfrac) and ~(isa(psi_ext)) then nowshowing = 'QEXT, UEXT and POLEXTFRAC'
        if teststks and ~(isa(polext)) and isa(polextfrac) and isa(psi_ext) then nowshowing = 'QEXT, UEXT, POLEXTFRAC and PSI_EXT'
        if teststks and ~(isa(polext)) and ~(isa(polextfrac)) and ~(isa(psi_ext)) then nowshowing = 'QEXT and UEXT'
        if teststks and isa(polext) and isa(polextfrac) and ~(isa(psi_ext)) then nowshowing = 'QEXT, UEXT, POLEXT and POLEXTFRAC'
        if teststks and isa(polext) and isa(polextfrac) and isa(psi_ext) then nowshowing = 'QEXT, UEXT, POLEXTFRAC, POLEXT and PSI_EXT'
        if teststks and ~(isa(polext)) and ~(isa(polextfrac)) and isa(psi_ext) then nowshowing = 'QEXT, UEXT and PSI_EXT'
3ff9cac3   Ilyes Choubani   general update
269
        
3ff9cac3   Ilyes Choubani   general update
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
        
        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
67bd858a   Ilyes Choubani   Replication of th...
294
295
296
297
298
299
300
301
302
        
        ;Added for completeness
        
        if isa(fpolext) then BEGIN        
            !dustem_show.fpolext = ptr_new(fpolext)
            if keyword_set(f_HI) then if f_HI gt 0 then $
           	(*!dustem_show.fpolext).values *= f_HI
        ENDIF
        
3ff9cac3   Ilyes Choubani   general update
303
304
    endif
endif
427f1205   Jean-Michel Glorian   version 4.2 merged
305

09e61d64   Ilyes Choubani   cleaned set_data ...
306
IF keyword_set(rchi2_weight) THEN BEGIN
427f1205   Jean-Michel Glorian   version 4.2 merged
307
308
	!fit_rchi2_weight.sed     = rchi2_weight.sed
	!fit_rchi2_weight.ext     = rchi2_weight.ext
09e61d64   Ilyes Choubani   cleaned set_data ...
309
	
6a714abf   Ilyes Choubani   small fix to dust...
310
	IF !run_pol THEN BEGIN
1355825c   Ilyes Choubani   General update
311
    	
3ff9cac3   Ilyes Choubani   general update
312
313
    	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...
314
    	
3ff9cac3   Ilyes Choubani   general update
315
316
    	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...
317
318
    ENDIF
    
3ff9cac3   Ilyes Choubani   general update
319
320
321
322
323
324
ENDIF ELSE BEGIN

    !fit_rchi2_weight.sed=1.
    !fit_rchi2_weight.ext=1.
    
    If !run_pol THEN BEGIN
1355825c   Ilyes Choubani   General update
325
        
3ff9cac3   Ilyes Choubani   general update
326
327
        IF isa(qsed) THEN !fit_rchi2_weight.qsed=1.
        IF isa(used) THEN !fit_rchi2_weight.used=1.
1355825c   Ilyes Choubani   General update
328
        
3ff9cac3   Ilyes Choubani   general update
329
330
        IF isa(qext) THEN !fit_rchi2_weight.qext=1.
        IF isa(uext) THEN !fit_rchi2_weight.uext=1.
1355825c   Ilyes Choubani   General update
331
    
3ff9cac3   Ilyes Choubani   general update
332
    ENDIF
427f1205   Jean-Michel Glorian   version 4.2 merged
333

3ff9cac3   Ilyes Choubani   general update
334
ENDELSE
427f1205   Jean-Michel Glorian   version 4.2 merged
335

04efbaa5   Ilyes Choubani   Correcting set_da...
336
337
338
; ;Setting the data and wavelength tags in '!dustem_fit'
; ;ask about it because !dustem_fit's tag was initially empty...s
; ((*!dustem_fit).data)=ptr_new(!dustem_data)
5a2643a4   Ilyes Choubani   cleaning/improvin...
339
340


427f1205   Jean-Michel Glorian   version 4.2 merged
341
342
the_end:

04efbaa5   Ilyes Choubani   Correcting set_da...
343
344
; 
; return,0.
3ff9cac3   Ilyes Choubani   general update
345
346
347
348




427f1205   Jean-Michel Glorian   version 4.2 merged
349
END