Blame view

src/idl/dustem_define_grid.pro 4.21 KB
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
1
2
PRO dustem_define_grid,table_name,filters,help=help, $
					   table_params=table_params,table_pmins=table_pmins,table_pmaxs=table_pmaxs,table_pnvals=table_pnvals,table_plogs=table_plogs
2b6fd350   Jean-Philippe Bernard   added pre-computi...
3
4
5
6
7
8
9
10
11

;+
; NAME:
;    dustem_define_grid
; PURPOSE:
;    loads an SED Grid table into !dustem_grid
; CATEGORY:
;    Dustem
; CALLING SEQUENCE:
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
12
;    dustem_define_grid,table_name,filters[,table_params=][,table_pmins=][,table_pmaxs=][,table_pnvals=][,table_plogs=]
2b6fd350   Jean-Philippe Bernard   added pre-computi...
13
14
15
16
17
18
19
20
; INPUTS:
;    table_name             : fits file name containing the grid
;    filters                : name of dustemwrap filters to be included in the GRID
; OPTIONAL INPUT PARAMETERS:
;    NONE
; OUTPUTS:
;    None
; OPTIONAL OUTPUT PARAMETERS:
25370043   Jean-Philippe Bernard   src/idl/dustem_ac...
21
22
23
24
25
;    table_params= parameter names in the grid table
;    table_pmins= parameter min values in the grid table
;    table_pmaxs= parameter max values in the grid table
;    table_pnvals= parameter number of values in the grid table
;    table_plogs= 1=parameter values in log in the grid table, 0=linear
2b6fd350   Jean-Philippe Bernard   added pre-computi...
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
; ACCEPTED KEY-WORDS:
;    help      = If set, print this help
; COMMON BLOCKS:
;    None
; SIDE EFFECTS:
;    !dustem_grid is updated
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
; PROCEDURE:
;    None
; EXAMPLES
;    dustem_make_sed_table,'DBP90',['(*!dustem_params).G0','(*!dustem_params).grains(0).mdust_o_mh'], $
;								[0.1,1.e-3],[100.,1.e-1],[10,3],filename='/tmp/IRAS_GO.fits',log=[1,0],/show_seds, $
;                              	filters=[dustem_instru2filters('IRAC'),dustem_instru2filters('SPIRE')]
;    dustem_define_grid,/tmp/IRAS_GO.fits',['IRAC3','SPIRE2']
;    help,!dustem_grid
; MODIFICATION HISTORY:
;    Written by J.-Ph. Bernard (2023)
;    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_define_grid'
  goto,the_end
ENDIF
6ff7d98f   Jean-Philippe Bernard   First commit
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

;=== read the grid table
message,'reading grid data from '+table_name,/continue
info=file_info(table_name)
IF info.exists THEN BEGIN
	st=mrdfits(table_name,1,h)
ENDIF ELSE BEGIN
	message,'grid data '+table_name+' not found',/continue
	stop
ENDELSE

;stop
;=== get filters and params names from grid table header
i=0L
table_filters=['']
fname='bidon'
count=1
WHILE count NE 0 DO BEGIN
	fname=sxpar(h,'FNAME'+strtrim(i+1,2),count=count)
849fd436   Jean-Philippe Bernard   improved
72
73
  IF count NE 0 THEN table_filters=[table_filters,strtrim(fname,2)]
  i=i+1
6ff7d98f   Jean-Philippe Bernard   First commit
74
75
76
77
78
ENDWHILE
table_filters=table_filters[1:*]
Ntfilters=n_elements(table_filters)

table_params=['']
2b6fd350   Jean-Philippe Bernard   added pre-computi...
79
80
81
82
table_pmins=[0.d0]
table_pmaxs=[0.d0]
table_pnvals=[0L]
table_plogs=[0]
6ff7d98f   Jean-Philippe Bernard   First commit
83
84
85
86
count=1
i=0L
WHILE count NE 0 DO BEGIN
	pname=sxpar(h,'PNAME'+strtrim(i+1,2),count=count)
2b6fd350   Jean-Philippe Bernard   added pre-computi...
87
88
89
90
91
92
93
94
95
96
97
    IF count NE 0 THEN BEGIN
    	table_params=[table_params,strtrim(pname,2)]
    	pmin=sxpar(h,'PMIN'+strtrim(i+1,2),count=count)
    	pmax=sxpar(h,'PMAX'+strtrim(i+1,2),count=count)
    	pnval=sxpar(h,'PNVAL'+strtrim(i+1,2),count=count)
    	plog=sxpar(h,'PLOG'+strtrim(i+1,2),count=count)
    	table_pmins=[table_pmins,pmin]
    	table_pmaxs=[table_pmaxs,pmax]
    	table_pnvals=[table_pnvals,pnval]
    	table_plogs=[table_plogs,plog]
    ENDIF
6ff7d98f   Jean-Philippe Bernard   First commit
98
99
100
    i=i+1
ENDWHILE
table_params=table_params[1:*]
2b6fd350   Jean-Philippe Bernard   added pre-computi...
101
102
103
104
table_pmins=table_pmins[1:*]
table_pmaxs=table_pmaxs[1:*]
table_pnvals=table_pnvals[1:*]
table_plogs=table_plogs[1:*]
6ff7d98f   Jean-Philippe Bernard   First commit
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Ntparams=n_elements(table_params)

;=== select only requested filters
;stop
Nfilters=n_elements(filters)
keep_tfilters=intarr(Ntfilters)
tags=tag_names(st)
FOR i=0L,Nfilters-1 DO BEGIN
    ind=where(table_filters EQ filters[i],count)
    IF count NE 0 THEN keep_tfilters[ind]=1
ENDFOR

;stop

2b6fd350   Jean-Philippe Bernard   added pre-computi...
119
;totals=st.total
6ff7d98f   Jean-Philippe Bernard   First commit
120
121
122
123
124
125
FOR i=0L,Ntfilters-1 DO BEGIN
	IF keep_tfilters[i] EQ 0 THEN BEGIN
		col_name=tags[i+Ntparams]
		st=structure_remove_column(st,col_name)
	ENDIF
ENDFOR
2b6fd350   Jean-Philippe Bernard   added pre-computi...
126
127
;==== recompute totals
Nlines=n_elements(st)
6ff7d98f   Jean-Philippe Bernard   First commit
128
Nsed=n_elements(st)
2b6fd350   Jean-Philippe Bernard   added pre-computi...
129
130
131
132
133
134
135
136
;==== recompute totals (needed if some columns have been removed)
FOR i=0L,Nsed-1 DO BEGIN
	this_total=0.d0
	FOR j=0L,Nfilters-1 DO BEGIN
		this_total=this_total+(st[i]).(j+Ntparams)
	ENDFOR
	st[i].total=this_total
ENDFOR
6ff7d98f   Jean-Philippe Bernard   First commit
137
138
139

;stop

2b6fd350   Jean-Philippe Bernard   added pre-computi...
140
dustem_grid={Nsed:Nsed,Nfilters:Nfilters,Nparams:Ntparams,filters:filters,params:table_params,seds:st,pmin_values:table_pmins,pmax_values:table_pmaxs}
6ff7d98f   Jean-Philippe Bernard   First commit
141
142
143
144

defsysv,'!dustem_grid',dustem_grid
message,'Defined !dustem_grid',/continue

2b6fd350   Jean-Philippe Bernard   added pre-computi...
145
146
the_end:

6ff7d98f   Jean-Philippe Bernard   First commit
147
END