Blame view

src/idl/dustem_make_fits_predicted_sed.pro 5.23 KB
b7dca888   Jean-Philippe Bernard   improved to recov...
1
2
3
4
5
6
FUNCTION dustem_make_fits_predicted_sed ,syst_var $
									    ,dustem_predicted_sed $
									    ,str_input_sed=str_input_sed $
									    ,dustem_predicted_Qsed=dustem_predicted_Qsed $
									    ,dustem_predicted_Used=dustem_predicted_Used $
									    ,help=help
244eeac8   Jean-Philippe Bernard   First commit
7
8
9
10
11
12
13
14
15
16
17
18
19

;+
; NAME:
;    dustem_make_fits_predicted_sed
; PURPOSE:
;    extracts dustemwrap predicted SED from dustem system variable syst_var, to be put into fits files
; CATEGORY:
;    DustEMWrap, Distributed, High-Level, User Convenience
; CALLING SEQUENCE:
;    str_predicted_SED=dustem_make_fits_predicted_sed(syst_var,dustem_predicted_sed[,str_input_sed=])
;    see dustem_write_fits_table.pro
; INPUTS:
;    syst_var  : dustem system variable (*!dustem_data or *!dustem_show)
b7dca888   Jean-Philippe Bernard   improved to recov...
20
;    what      = which tag of syst_var must be treated (can be sed, qsed, used, ...)
244eeac8   Jean-Philippe Bernard   First commit
21
22
;    dustem_predicted_sed : dustemwrap predicted SED as output by dustem_compute_sed.pro
; OPTIONAL INPUT PARAMETERS:
b7dca888   Jean-Philippe Bernard   improved to recov...
23
24
;    dustem_predicted_Qsed : Stokes Q SED
;    dustem_predicted_Used : Stokes U SED
244eeac8   Jean-Philippe Bernard   First commit
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
; OUTPUTS:
;    str_predicted_SED : dustemwrap predicted SED as used to store into fits file
; OPTIONAL OUTPUT PARAMETERS:
;    str_input_sed : dustem wrap input SED
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    None
; RESTRICTIONS:
;    The DustEMWrap IDL code must be installed
; PROCEDURE:
;    None
; EXAMPLES:
;    str_predicted_SED=dustem_make_fits_predicted_sed(*!dustem_data,dustem_predicted_sed,str_input_sed=str_input_sed)
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard Dec 2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_make_fits_predicted_sed'
  str_predicted_SED=-1
  goto,the_end
ENDIF

;example:
;str_predicted_SED=dustem_make_fits_predicted_sed(*!dustem_data,str_input_sed=str_input_sed)

;===== define structures containing input and predicted SEDs
one_str_input_SED={FILTER:'',Wavelength:la_undef(4),STOKESI:la_undef(5),STOKESQ:la_undef(5),STOKESU:la_undef(5),varianceII:la_undef(5),varianceQQ:la_undef(5),varianceUU:la_undef(5)}
one_str_predicted_SED={FILTER:'',Wavelength:la_undef(4),STOKESI:la_undef(5),STOKESQ:la_undef(5),STOKESU:la_undef(5)}

b7dca888   Jean-Philippe Bernard   improved to recov...
60
61
62
63
64
;tags=tag_names(syst_var)
;ind_what=where(tags EQ strupcase(what),count_what)

;stop

244eeac8   Jean-Philippe Bernard   First commit
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
Nsed=n_elements((*syst_var.sed).filt_names)
str_input_SED=replicate(one_str_input_SED,Nsed)
str_input_SED.FILTER=(*syst_var.sed).filt_names
str_input_SED.Wavelength=(*syst_var.sed).wav
str_input_SED.STOKESI=(*syst_var.sed).values
str_input_SED.varianceII=la_power((*syst_var.sed).sigma,2)   ;This is the variance

N_predicted_sed=n_elements(dustem_predicted_sed)
str_predicted_SED=replicate(one_str_predicted_SED,N_predicted_sed)
;str_predicted_EXT=replicate(one_str_predicted_SED,N_predicted_sed)
fully_undefined_sed=str_predicted_SED
str_predicted_SED.FILTER=(*syst_var.sed).filt_names    ;taken from input SED
str_predicted_SED.Wavelength=(*syst_var.sed).wav       ;taken from input SED
str_predicted_SED.STOKESI=dustem_predicted_sed    
;stop
IF !run_pol THEN BEGIN
	qsed=aos2soa(*syst_var.qsed)
	ind=where(qsed.filt_names NE 'SPECTRUM',count,complement=inds,Ncomplement=counts)
	IF count NE 0 THEN BEGIN
		qsed=qsed[ind]
		FOR i=0L,n_elements(qsed.wav)-1 DO BEGIN
			ind=where(str_input_SED.FILTER EQ qsed[i].filt_names,count)
			IF count NE 0 THEN BEGIN
				str_input_SED[ind[0]].STOKESQ=qsed[i].values
				str_input_SED[ind[0]].varianceQQ=la_power(qsed[i].sigma,2.)
			ENDIF
			str_predicted_SED[ind[0]].STOKESQ=dustem_predicted_Qsed[i]
		ENDFOR
	ENDIF
	qsed=aos2soa(*syst_var.qsed)
	IF counts NE 0 THEN BEGIN
		qsed=qsed[inds]
		ind2=where(str_predicted_SED.filter EQ 'SPECTRUM',count2)
		str_predicted_SED[ind2].STOKESQ=interpol(qsed.values,qsed.wav,str_predicted_SED[ind2].Wavelength)
		str_predicted_SED[ind2].varianceQQ=interpol(la_power(qsed.sigma,2.),qsed.wav,str_predicted_SED[ind2].Wavelength)
	ENDIF
	used=aos2soa(*syst_var.used)
	ind=where(used.filt_names NE 'SPECTRUM',count,complement=inds,Ncomplement=counts)
	IF count NE 0 THEN BEGIN
		used=used[ind]
		FOR i=0L,n_elements(used.wav)-1 DO BEGIN
			ind=where(str_input_SED.FILTER EQ used[i].filt_names,count)
			IF count NE 0 THEN BEGIN
				str_input_SED[ind[0]].STOKESU=used[i].values
				str_input_SED[ind[0]].varianceUU=la_power(used[i].sigma,2.)
			ENDIF
			str_predicted_SED[ind[0]].STOKESU=dustem_predicted_Used[i]
		ENDFOR
	ENDIF
	used=aos2soa(*syst_var.used)
	IF counts NE 0 THEN BEGIN
		used=used[inds]
		ind2=where(str_predicted_SED.filter EQ 'SPECTRUM',count2)
		str_predicted_SED[ind2].STOKESU=interpol(used.values,used.wav,str_predicted_SED[ind2].Wavelength)
		str_predicted_SED[ind2].varianceUU=interpol(la_power(used.sigma,2.),used.wav,str_predicted_SED[ind2].Wavelength)
	ENDIF
    ;stop
	;str_predicted_SED.Q=dustem_predicted_Qsed
	;str_predicted_SED.U=dustem_predicted_Used
	;str_predicted_SED.Q=interpol(dustem_predicted_Qsed,(*(*!dustem_data).qsed).wav,(*(*!dustem_data).sed).wav)
	;str_predicted_SED.U=interpol(dustem_predicted_Used,(*(*!dustem_data).used).wav,(*(*!dustem_data).sed).wav)
	;ENDFOR
ENDIF ELSE BEGIN
	str_predicted_SED.STOKESQ=fully_undefined_sed.STOKESQ
	str_predicted_SED.STOKESU=fully_undefined_sed.STOKESU
ENDELSE

the_end:

RETURN,str_predicted_SED

END