Blame view

src/idl/dustem_read_fits_table.pro 5.24 KB
a1839067   Jean-Philippe Bernard   First commit
1
2
3
4
5
PRO dustem_read_fits_table,filename=filename,help=help,dustem_spectra_st=dustem_spectra_st

;+
; NAME:
;    dustem_read_fits_table
71e7375d   Annie Hughes   cosmetic changes ...
6
;
a1839067   Jean-Philippe Bernard   First commit
7
; PURPOSE:
201cf7e2   Annie Hughes   minor changes to ...
8
;    Reads a Dustem fits table into current DustEMWrap system variables
71e7375d   Annie Hughes   cosmetic changes ...
9
;
a1839067   Jean-Philippe Bernard   First commit
10
; CATEGORY:
90c53809   Annie Hughes   updated doc heade...
11
;    DustEMWrap, High-Level, Distributed, User convenience
71e7375d   Annie Hughes   cosmetic changes ...
12
;
a1839067   Jean-Philippe Bernard   First commit
13
14
; CALLING SEQUENCE:
;    dustem_read_fits_table[,filename=][,/help]
71e7375d   Annie Hughes   cosmetic changes ...
15
;
a1839067   Jean-Philippe Bernard   First commit
16
; INPUTS:
71e7375d   Annie Hughes   cosmetic changes ...
17
;
a1839067   Jean-Philippe Bernard   First commit
18
; OPTIONAL INPUT PARAMETERS:
201cf7e2   Annie Hughes   minor changes to ...
19
;    filename      = File name to be read (default='./dustemwrap_results.fits')
71e7375d   Annie Hughes   cosmetic changes ...
20
;
a1839067   Jean-Philippe Bernard   First commit
21
22
; OUTPUTS:
;    None
71e7375d   Annie Hughes   cosmetic changes ...
23
;
a1839067   Jean-Philippe Bernard   First commit
24
25
; OPTIONAL OUTPUT PARAMETERS:
;    dustem_spectra_st = emission and extinction spectra (total and for each grain type)
71e7375d   Annie Hughes   cosmetic changes ...
26
;
a1839067   Jean-Philippe Bernard   First commit
27
28
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
71e7375d   Annie Hughes   cosmetic changes ...
29
;
a1839067   Jean-Philippe Bernard   First commit
30
31
; COMMON BLOCKS:
;    None
71e7375d   Annie Hughes   cosmetic changes ...
32
;
a1839067   Jean-Philippe Bernard   First commit
33
; SIDE EFFECTS:
201cf7e2   Annie Hughes   minor changes to ...
34
;    DustEMWrap system variables are set
71e7375d   Annie Hughes   cosmetic changes ...
35
;
a1839067   Jean-Philippe Bernard   First commit
36
; RESTRICTIONS:
201cf7e2   Annie Hughes   minor changes to ...
37
;    The DustEMWrap IDL code must be installed
71e7375d   Annie Hughes   cosmetic changes ...
38
;
a1839067   Jean-Philippe Bernard   First commit
39
40
; PROCEDURE:
;    None
71e7375d   Annie Hughes   cosmetic changes ...
41
;
a1839067   Jean-Philippe Bernard   First commit
42
43
44
; EXAMPLES
;    
; MODIFICATION HISTORY:
1cf2bf59   Annie Hughes   updated dustem_da...
45
46
47
;    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
48
49
;-

a1839067   Jean-Philippe Bernard   First commit
50
51
52
53
54
55
56
57
58
59

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...
60
	file='./dustemwrap_results.fits'
a1839067   Jean-Philippe Bernard   First commit
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ENDELSE
message,'Reading '+file,/info

unit_input_sed=1
unit_predicted_sed=2
unit_predicted_spectra=3
unit_predicted_extinctions=4

;==== Write the observed SED in extension 1
str_input_SED=mrdfits(file,unit_input_sed,header_input_sed)
;==== add the predicted SED in extension 2
str_predicted_SED=mrdfits(file,unit_predicted_sed,header_predicted_SED)
;==== add the predicted total spectrum in extension 3
;str_predicted_spectrum_tot=mrdfits(file,3,header_predicted_spectrum_tot)

72089d7a   Jean-Philippe Bernard   improved to save ...
76
used_model=strtrim(sxpar(header_predicted_SED,'MODEL'),2)
21467256   Jean-Philippe Bernard   fixed for polariz...
77
used_pol=long(strtrim(sxpar(header_predicted_SED,'POL'),2))
72089d7a   Jean-Philippe Bernard   improved to save ...
78
IF used_model NE 'DEFAULT' THEN BEGIN
3a8e4128   Jean-Philippe Bernard   fixed writing pol...
79
	dustem_init,model=used_model,pol=used_pol
72089d7a   Jean-Philippe Bernard   improved to save ...
80
81
82
83
84
85
86
ENDIF ELSE BEGIN
  	dustem_init,model=0
ENDELSE
!dustem_model=used_model

;stop
;==== This is to create (*!dustem_data).sed in case it does not exist already
a1839067   Jean-Philippe Bernard   First commit
87
Nsed=n_elements(str_input_SED)
72089d7a   Jean-Philippe Bernard   improved to save ...
88
89
90
sed=dustem_initialize_internal_sed(Nsed)
(*!dustem_data).sed=ptr_new(sed)

1cf2bf59   Annie Hughes   updated dustem_da...
91
92
93
94
95
(*(*!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
a1839067   Jean-Philippe Bernard   First commit
96
97

IF !run_pol NE 0 THEN BEGIN
3a8e4128   Jean-Philippe Bernard   fixed writing pol...
98
99
100
101
102
103
104
105
106
107
108
109
110
	;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
a1839067   Jean-Philippe Bernard   First commit
111
112
113
114
115
116
117
118
ENDIF

;predicted_I_sed=str_predicted_spectrum_tot.I

best_fit_chi2=sxpar(header_predicted_SED,'CHI2')
best_fit_rchi2=sxpar(header_predicted_SED,'RCHI2')

;===== Fill in header with parameter values
72089d7a   Jean-Philippe Bernard   improved to save ...
119
120
121
122
123
124
;parameters_desc=*(*!dustem_fit).PARAM_DESCS
;parameters_init_values=*(*!dustem_fit).PARAM_INIT_VALUES
;best_parameters=*(*!dustem_fit).CURRENT_PARAM_VALUES
;best_parameters_uncertainties=*(*!dustem_fit).CURRENT_PARAM_ERRORS
;best_fit_chi2=(*!dustem_fit).CHI2
;best_fit_rchi2=(*!dustem_fit).RCHI2
a1839067   Jean-Philippe Bernard   First commit
125
126
127
128
129
130

Nparams=sxpar(header_predicted_SED,'NPARAMS')
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 ...
131
parameters_func_values=dblarr(Nparams)
a1839067   Jean-Philippe Bernard   First commit
132
133
134
135
136
FOR i=0L,Nparams-1 DO BEGIN
	parameters_desc[i]=sxpar(header_predicted_SED,'PARN'+strtrim(i+1,2))
	best_parameters[i]=sxpar(header_predicted_SED,'PARV'+strtrim(i+1,2))
	best_parameters_uncertainties[i]=sxpar(header_predicted_SED,'PARU'+strtrim(i+1,2))
	best_parameters_init_values[i]=sxpar(header_predicted_SED,'PARI'+strtrim(i+1,2))
72089d7a   Jean-Philippe Bernard   improved to save ...
137
	parameters_func_values[i]=sxpar(header_predicted_SED,'PARI'+strtrim(i+1,2))
a1839067   Jean-Philippe Bernard   First commit
138
139
ENDFOR

72089d7a   Jean-Philippe Bernard   improved to save ...
140
141
142
143
144
145
146
(*!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
147
148
149

;=== 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 ....
21467256   Jean-Philippe Bernard   fixed for polariz...
150
;stop
a1839067   Jean-Philippe Bernard   First commit
151
152
153
154
155
dustem_predicted_sed=dustem_compute_sed(*(*!dustem_fit).current_param_values,out_st=dustem_spectra_st)

;==== get the predicted emission spectra from extension 4
toto=mrdfits(file,unit_predicted_spectra,header_predicted_spectra)
dustem_spectra_st.sed=toto
90c53809   Annie Hughes   updated doc heade...
156

a1839067   Jean-Philippe Bernard   First commit
157
158
159
160
161
162
163
164
165
;==== get the predicted extinction spectra from extension 5
toto=mrdfits(file,unit_predicted_extinctions,header_predicted_extinctions)
dustem_spectra_st.ext=toto

;stop

the_end:

END