Blame view

src/idl/dustem_read_fits_table.pro 10.7 KB
762cbe48   Jean-Philippe Bernard   modifed to cope f...
1
PRO dustem_read_fits_table,filename=filename,dustem_st=dustem_st,help=help
a1839067   Jean-Philippe Bernard   First commit
2
3
4
5

;+
; NAME:
;    dustem_read_fits_table
a1839067   Jean-Philippe Bernard   First commit
6
; PURPOSE:
201cf7e2   Annie Hughes   minor changes to ...
7
;    Reads a Dustem fits table into current DustEMWrap system variables
a1839067   Jean-Philippe Bernard   First commit
8
; CATEGORY:
90c53809   Annie Hughes   updated doc heade...
9
;    DustEMWrap, High-Level, Distributed, User convenience
a1839067   Jean-Philippe Bernard   First commit
10
11
; CALLING SEQUENCE:
;    dustem_read_fits_table[,filename=][,/help]
a1839067   Jean-Philippe Bernard   First commit
12
; INPUTS:
a1839067   Jean-Philippe Bernard   First commit
13
; OPTIONAL INPUT PARAMETERS:
201cf7e2   Annie Hughes   minor changes to ...
14
;    filename      = File name to be read (default='./dustemwrap_results.fits')
a1839067   Jean-Philippe Bernard   First commit
15
16
; OUTPUTS:
;    None
a1839067   Jean-Philippe Bernard   First commit
17
; OPTIONAL OUTPUT PARAMETERS:
762cbe48   Jean-Philippe Bernard   modifed to cope f...
18
;    dustem_st = emission and extinction dustem output structure (total and for each grain type)
a1839067   Jean-Philippe Bernard   First commit
19
20
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
a1839067   Jean-Philippe Bernard   First commit
21
22
; COMMON BLOCKS:
;    None
a1839067   Jean-Philippe Bernard   First commit
23
; SIDE EFFECTS:
201cf7e2   Annie Hughes   minor changes to ...
24
;    DustEMWrap system variables are set
a1839067   Jean-Philippe Bernard   First commit
25
; RESTRICTIONS:
201cf7e2   Annie Hughes   minor changes to ...
26
;    The DustEMWrap IDL code must be installed
a1839067   Jean-Philippe Bernard   First commit
27
28
; PROCEDURE:
;    None
a1839067   Jean-Philippe Bernard   First commit
29
30
31
; EXAMPLES
;    
; MODIFICATION HISTORY:
1cf2bf59   Annie Hughes   updated dustem_da...
32
33
34
;    Written by J.-Ph. Bernard July 2022
;    Evolution details on the DustEMWrap gitlab.
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
a1839067   Jean-Philippe Bernard   First commit
35
36
;-

a1839067   Jean-Philippe Bernard   First commit
37
38
39
40
41
42
43
44
45
46

IF keyword_set(help) THEN BEGIN
  doc_library,'dustem_read_fits_table'
  goto,the_end
ENDIF

;write final file
IF keyword_set(filename) THEN BEGIN
	file=filename
ENDIF ELSE BEGIN
1cf2bf59   Annie Hughes   updated dustem_da...
47
	file='./dustemwrap_results.fits'
a1839067   Jean-Philippe Bernard   First commit
48
49
50
ENDELSE
message,'Reading '+file,/info

762cbe48   Jean-Philippe Bernard   modifed to cope f...
51
toto=mrdfits(file,0,main_header)
a1839067   Jean-Philippe Bernard   First commit
52

762cbe48   Jean-Philippe Bernard   modifed to cope f...
53
54
55
56
57
58
59
60
61
62
63
64
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
;stop
;get extention numbers from main header
current_ext=1
ext_names=['']
exts=[-1]
finished=0
WHILE not finished DO BEGIN
	ext_name=sxpar(main_header,'EXT'+strtrim(current_ext,2),count=count)
	IF count NE 0 THEN BEGIN
		ext_names=[ext_names,ext_name]
		exts=[exts,current_ext]
		current_ext=current_ext+1
	ENDIF ELSE BEGIN
		finished=1
	ENDELSE
ENDWHILE
ext_names=ext_names[1:*]
exts=exts[1:*]
Nextensions=n_elements(exts)

message,'================================================',/info
message,'Reading '+file,/info
message,'File extensions detected are: ',/info
FOR i=0L,Nextensions-1 DO BEGIN
	message,'extension '+strtrim(exts[i],2)+' : '+strtrim(ext_names[i],2),/info
ENDFOR
message,'================================================',/info

;extensions_strs=['INPUT_EMISSION_SED','DUSTEM_PREDICTED_SED', $
;				 'INPUT_EXTINCTION_SED','DUSTEM_PREDICTED_EXTINCTION_SED', $
;				 'DUSTEM_PREDICTED_EMISSION_SPECTRA','DUSTEM_PREDICTED_EXTINCTION_SPECTRA', $
;				 'DUSTEM_PREDICTED_EMISSION_SPECTRA_POL','DUSTEM_PREDICTED_EXTINCTION_SPECTRA_POL']

ind=where(ext_names EQ 'INPUT_EMISSION_SED',count)
IF count NE 0 THEN BEGIN
	unit_input_emission_sed=exts[ind[0]]
	print,unit_input_emission_sed
ENDIF ELSE BEGIN
    unit_input_emission_sed=-1
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_SED',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_sed=exts[ind[0]]
	print,unit_dustem_predicted_sed
ENDIF ELSE BEGIN
    unit_dustem_predicted_sed=-1
ENDELSE

ind=where(ext_names EQ 'INPUT_EXTINCTION_SED',count)
IF count NE 0 THEN BEGIN
	unit_input_extinction_sed=exts[ind[0]]
	print,unit_input_extinction_sed
ENDIF ELSE BEGIN
    unit_input_extinction_sed=-1
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_EXTINCTION_SED',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_extinction_sed=exts[ind[0]]
	print,unit_dustem_predicted_extinction_sed
ENDIF ELSE BEGIN
	unit_dustem_predicted_extinction_sed=-1   ;That would be abnormal
ENDELSE

ind=where(ext_names EQ 'DUSTEM_PREDICTED_EMISSION_SPECTRA',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_emission_spectra=exts[ind[0]]
	print,unit_dustem_predicted_emission_spectra
ENDIF ELSE BEGIN
	unit_dustem_predicted_emission_spectra=-1   ;That would be abnormal
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_EXTINCTION_SPECTRA',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_extinction_spectra=exts[ind[0]]
	print,unit_dustem_predicted_extinction_spectra
ENDIF ELSE BEGIN
	unit_dustem_predicted_extinction_spectra=-1   ;That would be abnormal
ENDELSE

ind=where(ext_names EQ 'DUSTEM_PREDICTED_EMISSION_SPECTRA_POL',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_emission_spectra_pol=exts[ind[0]]
	print,unit_dustem_predicted_emission_spectra_pol
ENDIF ELSE BEGIN
	unit_dustem_predicted_emission_spectra_pol=-1
ENDELSE
ind=where(ext_names EQ 'DUSTEM_PREDICTED_EXTINCTION_SPECTRA_POL',count)
IF count NE 0 THEN BEGIN
	unit_dustem_predicted_extinction_spectra_pol=exts[ind[0]]
	print,unit_dustem_predicted_extinction_spectra_pol
ENDIF ELSE BEGIN
	unit_dustem_predicted_extinction_spectra_pol=-1
ENDELSE

;stop

; unit_input_sed=sxpar(main_header,'INPUT_EMISSION_SED')
; unit_predicted_sed=sxpar(main_header,'DUSTEM_PREDICTED_SED')
; unit_predicted_spectra=sxpar(main_header,'DUSTEM_PREDICTED_EMISSION')
; unit_predicted_extinctions=sxpar(main_header,'DUSTEM_PREDICTED_EXTINCTION')
; unit_predicted_spectra_pol=sxpar(main_header,'DUSTEM_PREDICTED_EMISSION_POL')
; unit_predicted_extinctions_pol=sxpar(main_header,'DUSTEM_PREDICTED_EXTINCTION_POL')

;==== read the observed SED (if any)
IF unit_input_emission_sed NE -1 THEN BEGIN
	str_input_SED=mrdfits(file,unit_input_emission_sed,header_input_sed)
ENDIF ELSE BEGIN
ENDELSE
;==== read the predicted SED (if any)
IF unit_dustem_predicted_sed NE -1 THEN BEGIN
	str_predicted_SED=mrdfits(file,unit_dustem_predicted_sed,header_predicted_SED)
ENDIF ELSE BEGIN
ENDELSE
IF unit_input_extinction_sed NE -1 THEN BEGIN
	str_input_EXT=mrdfits(file,unit_input_extinction_sed,header_input_ext)
ENDIF ELSE BEGIN
ENDELSE
IF unit_dustem_predicted_extinction_sed NE -1 THEN BEGIN
	str_predicted_EXT=mrdfits(file,unit_input_extinction_sed,header_input_ext)
ENDIF ELSE BEGIN
ENDELSE
a1839067   Jean-Philippe Bernard   First commit
173

762cbe48   Jean-Philippe Bernard   modifed to cope f...
174
175
176
used_model=strtrim(sxpar(main_header,'MODEL'),2)
used_pol=long(strtrim(sxpar(main_header,'POL'),2))
used_version=strtrim(sxpar(main_header,'WRAP_V'),2)
72089d7a   Jean-Philippe Bernard   improved to save ...
177
IF used_model NE 'DEFAULT' THEN BEGIN
3a8e4128   Jean-Philippe Bernard   fixed writing pol...
178
	dustem_init,model=used_model,pol=used_pol
72089d7a   Jean-Philippe Bernard   improved to save ...
179
180
181
182
ENDIF ELSE BEGIN
  	dustem_init,model=0
ENDELSE
!dustem_model=used_model
762cbe48   Jean-Philippe Bernard   modifed to cope f...
183
184
185
186
187
IF !dustem_version.version NE used_version THEN BEGIN
	message,'Caution: fits file was not created with the same Dustemwrap version as your current version',/continue
	message,'Fits dustemwrap version is    :'+used_version,/continue
	message,'current dustemwrap version is :'+!dustem_version.version,/continue
	stop
a1839067   Jean-Philippe Bernard   First commit
188
189
ENDIF

762cbe48   Jean-Philippe Bernard   modifed to cope f...
190
191
best_fit_chi2=sxpar(main_header,'CHI2')
best_fit_rchi2=sxpar(main_header,'RCHI2')
a1839067   Jean-Philippe Bernard   First commit
192

762cbe48   Jean-Philippe Bernard   modifed to cope f...
193
194
;==== get parameter values
Nparams=sxpar(main_header,'NPARAMS')
a1839067   Jean-Philippe Bernard   First commit
195
196
197
198
parameters_desc=strarr(Nparams)
best_parameters=dblarr(Nparams)
best_parameters_init_values=dblarr(Nparams)
best_parameters_uncertainties=dblarr(Nparams)
72089d7a   Jean-Philippe Bernard   improved to save ...
199
parameters_func_values=dblarr(Nparams)
a1839067   Jean-Philippe Bernard   First commit
200
FOR i=0L,Nparams-1 DO BEGIN
762cbe48   Jean-Philippe Bernard   modifed to cope f...
201
202
203
204
205
	parameters_desc[i]=sxpar(main_header,'PARN'+strtrim(i+1,2))
	best_parameters[i]=sxpar(main_header,'PARV'+strtrim(i+1,2))
	best_parameters_uncertainties[i]=sxpar(main_header,'PARU'+strtrim(i+1,2))
	best_parameters_init_values[i]=sxpar(main_header,'PARI'+strtrim(i+1,2))
	parameters_func_values[i]=sxpar(main_header,'PARI'+strtrim(i+1,2))
a1839067   Jean-Philippe Bernard   First commit
206
207
ENDFOR

72089d7a   Jean-Philippe Bernard   improved to save ...
208
209
210
211
212
213
214
(*!dustem_fit).PARAM_DESCS=ptr_new(parameters_desc)
(*!dustem_fit).PARAM_INIT_VALUES=ptr_new(best_parameters_init_values)
(*!dustem_fit).CURRENT_PARAM_VALUES=ptr_new(best_parameters)
(*!dustem_fit).CURRENT_PARAM_ERRORS=ptr_new(best_parameters_uncertainties)
(*!dustem_fit).CHI2=best_fit_chi2
(*!dustem_fit).RCHI2=best_fit_rchi2
(*!dustem_fit).PARAM_FUNC=ptr_new(parameters_func_values)
a1839067   Jean-Philippe Bernard   First commit
215

762cbe48   Jean-Philippe Bernard   modifed to cope f...
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
242
243
244
245
246
247
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
274

;stop
;==== This is to create (*!dustem_data).sed in case it does not exist already
IF unit_input_emission_sed NE -1 THEN BEGIN
	Nsed=n_elements(str_input_SED)
	sed=dustem_initialize_internal_sed(Nsed)
	(*!dustem_data).sed=ptr_new(sed)

	(*(*!dustem_data).sed).instru_names=dustem_filter2instru(str_input_SED.filter)
	(*(*!dustem_data).sed).filt_names=str_input_SED.filter
	(*(*!dustem_data).sed).wav=str_input_SED.wavelength
	(*(*!dustem_data).sed).values=str_input_SED.I
	(*(*!dustem_data).sed).sigma=str_input_SED.varianceII

	IF used_pol THEN BEGIN
		;stop
		(*!dustem_data).qsed=ptr_new(sed)
		(*!dustem_data).used=ptr_new(sed)
		(*(*!dustem_data).qsed).instru_names=dustem_filter2instru(str_input_SED.filter)
		(*(*!dustem_data).qsed).filt_names=str_input_SED.filter
		(*(*!dustem_data).qsed).wav=str_input_SED.wavelength
		(*(*!dustem_data).qsed).values=str_input_SED.Q
		(*(*!dustem_data).qsed).sigma=str_input_SED.varianceQQ
		(*(*!dustem_data).used).instru_names=dustem_filter2instru(str_input_SED.filter)
		(*(*!dustem_data).used).filt_names=str_input_SED.filter
		(*(*!dustem_data).used).wav=str_input_SED.wavelength
		(*(*!dustem_data).used).values=str_input_SED.U
		(*(*!dustem_data).used).sigma=str_input_SED.varianceUU
	ENDIF
ENDIF

IF unit_input_extinction_sed NE -1 THEN BEGIN
	Next=n_elements(str_input_EXT)
	ext=dustem_initialize_internal_sed(Next)
	(*!dustem_data).ext=ptr_new(ext)

	(*(*!dustem_data).ext).instru_names=dustem_filter2instru(str_input_EXT.filter)
	(*(*!dustem_data).ext).filt_names=str_input_EXT.filter
	(*(*!dustem_data).ext).wav=str_input_EXT.wavelength
	(*(*!dustem_data).ext).values=str_input_EXT.I
	(*(*!dustem_data).ext).sigma=str_input_EXT.varianceII

	IF used_pol THEN BEGIN
		;stop
		(*!dustem_data).qext=ptr_new(ext)
		(*!dustem_data).uext=ptr_new(ext)
		(*(*!dustem_data).qext).instru_names=dustem_filter2instru(str_input_EXT.filter)
		(*(*!dustem_data).qext).filt_names=str_input_EXT.filter
		(*(*!dustem_data).qext).wav=str_input_EXT.wavelength
		(*(*!dustem_data).qext).values=str_input_EXT.Q
		(*(*!dustem_data).qext).sigma=str_input_EXT.varianceQQ
		(*(*!dustem_data).uext).instru_names=dustem_filter2instru(str_input_EXT.filter)
		(*(*!dustem_data).uext).filt_names=str_input_EXT.filter
		(*(*!dustem_data).uext).wav=str_input_EXT.wavelength
		(*(*!dustem_data).uext).values=str_input_EXT.U
		(*(*!dustem_data).uext).sigma=str_input_EXT.varianceUU
	ENDIF
ENDIF

a1839067   Jean-Philippe Bernard   First commit
275
276
;=== Below is only to get the same output form as dustem_compute_sed
;Note: If the same model is used, the outputs should be the same as what is in the fits file ....
762cbe48   Jean-Philippe Bernard   modifed to cope f...
277
278
279
280
281
282
IF unit_input_emission_sed NE -1 THEN BEGIN
	recomputed_dustem_predicted_emission_sed=dustem_compute_sed(*(*!dustem_fit).current_param_values,st=dustem_st)
ENDIF ELSE BEGIN
	recomputed_dustem_predicted_ext_sed=dustem_compute_ext(*(*!dustem_fit).current_param_values,st=dustem_st)
ENDELSE

21467256   Jean-Philippe Bernard   fixed for polariz...
283
;stop
1548011c   Jean-Philippe Bernard   Merge branch 'mas...
284
<<<<<<< HEAD
762cbe48   Jean-Philippe Bernard   modifed to cope f...
285
286
287
288
289
dustem_predicted_em=mrdfits(file,unit_dustem_predicted_emission_spectra,header_predicted_emission)
dustem_predicted_ext= mrdfits(file,unit_dustem_predicted_extinction_spectra,header_predicted_extinction)

;help,dustem_st.sed,dustem_predicted_em,/str
;help,dustem_st.ext,dustem_predicted_ext,/str
1548011c   Jean-Philippe Bernard   Merge branch 'mas...
290
=======
32f7f3f4   Annie Hughes   updated out_st to...
291
dustem_predicted_sed=dustem_compute_sed(*(*!dustem_fit).current_param_values,st=dustem_spectra_st)
1548011c   Jean-Philippe Bernard   Merge branch 'mas...
292
>>>>>>> 3d0f6b674607769b0cbaf3703a82f722877e253d
a1839067   Jean-Philippe Bernard   First commit
293

762cbe48   Jean-Philippe Bernard   modifed to cope f...
294
295
dustem_st.sed=dustem_predicted_em
dustem_st.ext=dustem_predicted_ext
90c53809   Annie Hughes   updated doc heade...
296

762cbe48   Jean-Philippe Bernard   modifed to cope f...
297
298
299
300
301
302
303
IF used_pol THEN BEGIN
	toto=mrdfits(file,unit_dustem_predicted_emission_spectra_pol,header_predicted_spectra_pol)
	;help,dustem_st.polsed,toto,/str
	dustem_st.polsed=toto
	toto=mrdfits(file,unit_dustem_predicted_extinction_spectra_pol,header_predicted_extinctions_pol)
    dustem_st.polext=toto
ENDIF
a1839067   Jean-Philippe Bernard   First commit
304
305
306
307
308
309

;stop

the_end:

END