Commit 303de20df1de39336f7395ba2f23e8f105c087b0
1 parent
e8f2930c
Exists in
master
updating check_data
Showing
1 changed file
with
58 additions
and
85 deletions
Show diff stats
src/idl/dustem_check_data.pro
1 | 1 | FUNCTION dustem_check_data,data_sed=data_sed,data_ext=data_ext,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 |
2 | 2 | |
3 | - | |
4 | -;NOTA BENE: No testing is done on the covariances. These will be used when debiasing the large P. | |
5 | - | |
3 | +;WRITE HELP SECTION . URGENT | |
4 | +;NOTA BENE: LargeP has not been debiasied yet. | |
6 | 5 | |
7 | 6 | ;CHECKING THE FORMAT OF THE SED STRUCTURE |
8 | 7 | IF KEYWORD_SET(data_sed) THEN BEGIN |
... | ... | @@ -15,7 +14,6 @@ IF KEYWORD_SET(data_sed) THEN BEGIN |
15 | 14 | wavs(ind)=dustem_filter2wav(data_sed(ind).filter) |
16 | 15 | ENDIF |
17 | 16 | ;=== Initializing observation structure |
18 | - ;it doesn't matter that data.StokesI is used, further test will take care of what is necessary. | |
19 | 17 | obs_EM={instru_names:data_sed.instru,filt_names:data_sed.filter,wav:wavs, values:data_sed.StokesI,sigma:sqrt(abs(data_sed.sigmaII))} |
20 | 18 | ;INITIALIZING OUTPUT STRUCTURES |
21 | 19 | sed = obs_EM |
... | ... | @@ -122,17 +120,17 @@ IF KEYWORD_SET(data_sed) THEN BEGIN |
122 | 120 | ENDELSE |
123 | 121 | psiemzone: |
124 | 122 | |
123 | + if nu eq 0 and nq eq 0 then goto, end_sed | |
125 | 124 | degtorad = !pi/180 |
126 | 125 | |
127 | - ;INSTEAD OF USING THE DATA THAT IS IN THE XCAT FILE WE WILL CODE IT ANEW. | |
128 | - | |
126 | + ;Generation of POLFRAC,POLSED and PSI data by default | |
129 | 127 | ;Testing on the presence of covariances otherwise an error is returned |
130 | - ;The testing happens here because covariances are needed for P,p and PSI. | |
128 | + ;The testing happens here because covariances are needed for the error estimation of P,p and PSI. | |
131 | 129 | |
132 | 130 | tstcovu = where((data_sed(testu).sigmaIU) EQ la_undef() or (data_sed(testu).sigmaQU) EQ la_undef(), ctcovu) |
133 | - if ctcovu NE 0 and ctestu EQ 0 then message, 'Covariance data is missing in StokesU data. Data, errors and covariances do not match. Aborting...' | |
131 | + if ctcovu NE 0 then message, 'Covariance data is missing in StokesU data. Data, errors and covariances do not match. Aborting...' | |
134 | 132 | tstcovq = where((data_sed(testq).sigmaIQ) EQ la_undef() or (data_sed(testq).sigmaQU) EQ la_undef(), ctcovq) |
135 | - if ctcovq NE 0 and ctestq EQ 0 then message, 'Covariance data is missing in StokesQ data. Data, errors and covariances do not match. Aborting...' | |
133 | + if ctcovq NE 0 then message, 'Covariance data is missing in StokesQ data. Data, errors and covariances do not match. Aborting...' | |
136 | 134 | |
137 | 135 | ;Matching both filter and spectrum points |
138 | 136 | |
... | ... | @@ -156,7 +154,7 @@ IF KEYWORD_SET(data_sed) THEN BEGIN |
156 | 154 | sigma = sqrt(variance_psi) |
157 | 155 | psi_em={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} |
158 | 156 | |
159 | - goto, pzone ; Not forgetting that the variances for polfrac and polsed were already computed. | |
157 | + goto, pzone ; the variances for polfrac and polsed were already computed. | |
160 | 158 | |
161 | 159 | pzone: |
162 | 160 | |
... | ... | @@ -173,10 +171,10 @@ IF KEYWORD_SET(data_sed) THEN BEGIN |
173 | 171 | |
174 | 172 | goto, end_sed |
175 | 173 | end_sed: |
174 | + | |
176 | 175 | ENDIF |
177 | 176 | |
178 | 177 | |
179 | - | |
180 | 178 | ;EXTINCTION HASN'T BEEN TREATED YET |
181 | 179 | |
182 | 180 | |
... | ... | @@ -193,15 +191,13 @@ IF KEYWORD_SET(data_ext) THEN begin |
193 | 191 | obs_EXT={instru_names:data_ext.instru,filt_names:data_ext.filter,wav:wavs, values:data_ext.EXT_I,sigma:sqrt(abs(data_ext.sigextII))} |
194 | 192 | ;INITIALIZING OUTPUT STRUCTURES |
195 | 193 | ext = obs_EXT |
196 | - polext = ext | |
197 | 194 | qext = ext |
198 | 195 | uext = ext |
199 | - psi_ext = ext | |
200 | 196 | |
201 | 197 | ind = where(data_ext.EXT_I NE la_undef() and finite(data_ext.EXT_I) EQ 1 and data_ext.sigextII NE la_undef() and finite(data_ext.sigextII) EQ 1,N_ext) ;Testing if the data and errors are set |
202 | 198 | IF N_ext EQ 0 THEN BEGIN |
203 | 199 | ext = ptr_new() |
204 | - goto, pexzone | |
200 | + goto, qexzone | |
205 | 201 | ENDIF ELSE BEGIN |
206 | 202 | ind = where(finite(data_ext.EXT_I) EQ 0 or finite(data_ext.sigextII) EQ 0, countnokex) ;Format is not okay if there are nan values but the wrapper recognizes the la_undef() value |
207 | 203 | IF countnokex NE 0 THEN BEGIN |
... | ... | @@ -228,76 +224,7 @@ IF KEYWORD_SET(data_ext) THEN begin |
228 | 224 | ext={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} |
229 | 225 | ENDIF |
230 | 226 | ENDELSE |
231 | - pexzone: | |
232 | - ans='' | |
233 | - polext.values=data_ext.EXT_P | |
234 | - polext.sigma=sqrt(abs(data_ext.sigextP)) | |
235 | - ;Testig if there is EXT_P data. If not move to EXT_Q testing | |
236 | - ind = where(data_ext.EXT_P NE la_undef() and finite(data_ext.EXT_P) EQ 1 and data_ext.sigextP NE la_undef() and finite(data_ext.sigextP) EQ 1,NP_ext) ;Testing if the data and errors are set | |
237 | - IF NP_ext EQ 0 THEN BEGIN | |
238 | - polext = ptr_new() | |
239 | - goto, qexzone | |
240 | - ENDIF ELSE BEGIN | |
241 | - ind = where(finite(data_ext.EXT_P) EQ 0 or finite(data_ext.sigextP) EQ 0, countnokpex) ;Format is not okay if there are nan values but the wrapper recognizes the la_undef() value | |
242 | - IF countnokpex NE 0 THEN BEGIN | |
243 | - message, "SED format isn't met. NaN value(s) detected in EXT_P data.",/continue | |
244 | - message, 'Without automatic format fitering you cannot proceed.',/continue | |
245 | - ans='' | |
246 | - read, ans, prompt='Would you like automatic format filtering? (Y/N):' | |
247 | - IF strupcase(ans) EQ 'N' THEN BEGIN | |
248 | - message,'You have chosen not to use automatic filtering. Please adjust the SED format.',/continue | |
249 | - message, 'Aborting ...' | |
250 | - ENDIF | |
251 | - ENDIF | |
252 | - IF strupcase(ans) EQ 'Y' THEN message, 'You have chosen automatic format filtering. Removal of undefined data points...',/continue $ | |
253 | - ELSE message, 'Data format is met. Removal of undefined data points...',/continue | |
254 | - tdaerrpex=where((data_ext.sigextP EQ la_undef() and data_ext.EXT_P NE la_undef()) or (data_ext.sigextP NE la_undef() and data_ext.EXT_P EQ la_undef()),ctdaerrpex) | |
255 | - IF ctdaerrpex NE 0 THEN message, 'Data and errors do not match. Undefinded data detected. Aborting...' | |
256 | - testpex=where(data_ext.sigextP NE 0. and finite(data_ext.sigextP) EQ 1 and data_ext.sigextP NE la_undef() and data_ext.EXT_P NE la_undef() and finite(data_ext.EXT_P) EQ 1,ctestpex) | |
257 | - IF ctestpex NE 0 THEN BEGIN | |
258 | - instru_names = polext.instru_names(testpex) | |
259 | - filt_names = polext.filt_names(testpex) | |
260 | - wav = polext.wav(testpex) | |
261 | - values = polext.values(testpex) | |
262 | - sigma = polext.sigma(testpex) | |
263 | - polext={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} | |
264 | - ENDIF | |
265 | - ENDELSE | |
266 | - psiexzone: | |
267 | - ans='' | |
268 | - psi_ext.values=data_ext.psi | |
269 | - psi_ext.sigma=sqrt(abs(data_ext.sigextpsi)) | |
270 | - ;Testig if there is EXT_P data. If not move to EXT_Q testing | |
271 | - ind = where(data_ext.psi NE la_undef() and finite(data_ext.psi) EQ 1 and data_ext.sigextpsi NE la_undef() and finite(data_ext.sigextpsi) EQ 1,NPSIEXT) ;Testing if the data and errors are set | |
272 | - IF NPSIEXT EQ 0 THEN BEGIN | |
273 | - psi_ext = ptr_new() | |
274 | - goto, qexzone | |
275 | - ENDIF ELSE BEGIN | |
276 | - ind = where(finite(data_ext.psi) EQ 0 or finite(data_ext.sigextpsi) EQ 0, countnokpsiex) ;Format is not okay if there are nan values but the wrapper recognizes the la_undef() value | |
277 | - IF countnokpsiex NE 0 THEN BEGIN | |
278 | - message, "SED format isn't met. NaN value(s) detected in PSI_EXT data.",/continue | |
279 | - message, 'Without automatic format fitering you cannot proceed.',/continue | |
280 | - ans='' | |
281 | - read, ans, prompt='Would you like automatic format filtering? (Y/N):' | |
282 | - IF strupcase(ans) EQ 'N' THEN BEGIN | |
283 | - message,'You have chosen not to use automatic filtering. Please adjust the SED format.',/continue | |
284 | - message, 'Aborting ...' | |
285 | - ENDIF | |
286 | - ENDIF | |
287 | - IF strupcase(ans) EQ 'Y' THEN message, 'You have chosen automatic format filtering. Removal of undefined data points...',/continue $ | |
288 | - ELSE message, 'Data format is met. Removal of undefined data points...',/continue | |
289 | - tdaerrpsiex=where((data_ext.sigextpsi EQ la_undef() and data_ext.psi NE la_undef()) or (data_ext.sigextpsi NE la_undef() and data_ext.psi EQ la_undef()),ctdaerrpsiex) | |
290 | - IF ctdaerrpsiex NE 0 THEN message, 'Data and errors do not match. Undefinded data detected. Aborting...' | |
291 | - testpsiex=where(data_ext.sigextpsi NE 0. and finite(data_ext.sigextpsi) EQ 1 and data_ext.sigextpsi NE la_undef() and data_ext.psi NE la_undef() and finite(data_ext.psi) EQ 1,ctestpsiex) | |
292 | - IF ctestpsiex NE 0 THEN BEGIN | |
293 | - instru_names = psi_ext.instru_names(testpsiex) | |
294 | - filt_names = psi_ext.filt_names(testpsiex) | |
295 | - wav = psi_ext.wav(testpsiex) | |
296 | - values = psi_ext.values(testpsiex) | |
297 | - sigma = psi_ext.sigma(testpsiex) | |
298 | - psi_ext={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} | |
299 | - ENDIF | |
300 | - ENDELSE | |
227 | + | |
301 | 228 | qexzone: |
302 | 229 | ans='' |
303 | 230 | qext.values=data_ext.EXT_Q |
... | ... | @@ -334,6 +261,7 @@ IF KEYWORD_SET(data_ext) THEN begin |
334 | 261 | qext={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} |
335 | 262 | ENDIF |
336 | 263 | ENDELSE |
264 | + | |
337 | 265 | uexzone: |
338 | 266 | ans='' |
339 | 267 | uext.values=data_ext.EXT_U |
... | ... | @@ -342,7 +270,7 @@ IF KEYWORD_SET(data_ext) THEN begin |
342 | 270 | ind = where(data_ext.EXT_U NE la_undef() and finite(data_ext.EXT_U) EQ 1 and data_ext.sigextUU NE la_undef() and finite(data_ext.sigextUU) EQ 1,NU_ext) ;Testing if the data and errors are set |
343 | 271 | IF NU_ext EQ 0 THEN BEGIN |
344 | 272 | uext = ptr_new() |
345 | - goto, end_ext | |
273 | + goto, psiexzone | |
346 | 274 | ENDIF ELSE BEGIN |
347 | 275 | ind = where(finite(data_ext.EXT_U) EQ 0 or finite(data_ext.sigextUU) EQ 0, countnokuex) ;Format is not okay if there are nan values but the wrapper recognizes the la_undef() value |
348 | 276 | IF countnokuex NE 0 THEN BEGIN |
... | ... | @@ -369,6 +297,51 @@ IF KEYWORD_SET(data_ext) THEN begin |
369 | 297 | uext={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} |
370 | 298 | ENDIF |
371 | 299 | ENDELSE |
300 | + | |
301 | + psiexzone: ;Starting the analogy here. | |
302 | + | |
303 | + if NU_EXT eq 0 and NQ_EXT eq 0 then goto, pexzone | |
304 | + degtorad = !pi/180 | |
305 | + | |
306 | + ;Generation of POLEXT and PSI_EXT data by default | |
307 | + ;Testing on the presence of covariances otherwise an error is returned | |
308 | + ;The testing happens here because covariances are needed for the error estimation of EXT_P,PSI_EXT. | |
309 | + | |
310 | + tstcovuex = where((data_ext(testuex).sigextIU) EQ la_undef() or (data_ext(testuex).sigmaQU) EQ la_undef(), ctcovuex) | |
311 | + if ctcovuex NE 0 then message, 'Covariance data is missing in the extinction data pertaining to the StokesU parameter. Data, errors and covariances do not match. Aborting...' | |
312 | + tstcovqex = where((data_ext(testqex).sigextIQ) EQ la_undef() or (data_ext(testqex).sigextQU) EQ la_undef(), ctcovqex) | |
313 | + if ctcovqex NE 0 then message, 'Covariance data is missing in the extinction pertaining to the StokesQ parameter. Data, errors and covariances do not match. Aborting...' | |
314 | + | |
315 | + ;Matching both filter and spectrum points | |
316 | + match2,uext.wav,qext.wav,qexpts,uexpts | |
317 | + | |
318 | + ;removing -1 values from the indices (qpts & upts) | |
319 | + indnotqex = where(qexpts eq -1, cnotqex) | |
320 | + if cnotqex ne 0 then remove, indnotqex, qexpts | |
321 | + indnotuex = where(uexpts eq -1, cnotuex) | |
322 | + if cnotuex ne 0 then remove, indnotuex, uexpts | |
323 | + | |
324 | + match2, ext.wav, qexsed.wav(qexpts), qextmp, extpts | |
325 | + indnotx = where(extpts eq -1, cnotx) | |
326 | + if cnotx ne 0 then remove, indnotx, extpts | |
327 | + | |
328 | + instru_names = uext.instru_names(uexpts) | |
329 | + filt_names = uext.filt_names(uexpts) | |
330 | + wav = uext.wav(uexpts) | |
331 | + values = 0.5*atan(uext.values(uexpts),qext.values(qexpts))/degtorad | |
332 | + polar_variance_iqu2ippsi,ext.values(sedpts),qexsed.values(qexpts),uext.values(uexpts),(data_ext(testx).sigextII)(extpts),(data_ext(testqex).sigextQQ)(qexpts),(data_ext(testuex).sigextUU)(uexpts),(data_ext(testx).sigextIQ)(extpts),(data_ext(testx).sigextIU)(extpts),(data_ext(testx).sigextQU)(extpts),variance_smallp,variance_psi,variance_largep | |
333 | + sigma = sqrt(variance_psi) | |
334 | + psi_em={instru_names:instru_names,filt_names:filt_names,wav:wav,values:values,sigma:sigma} | |
335 | + | |
336 | + goto, pexzone ; the variances for polextPSI_EXT were already computed. | |
337 | + | |
338 | + pexzone: | |
339 | + | |
340 | + polext = psi_ext | |
341 | + polext.values = sqrt(uext.values(uexpts)^2+qexsed.values(qexpts)^2) | |
342 | + polext.sigma = sqrt(variance_largep) | |
343 | + goto, end_ext | |
344 | + | |
372 | 345 | end_ext: |
373 | 346 | ENDIF |
374 | 347 | ;stop | ... | ... |