Commit 4d392534e8995babfcf22dd8bc4f9c6cf0c64720

Authored by Jean-Philippe Bernard
1 parent 56fada2b
Exists in master

First commit

Showing 1 changed file with 202 additions and 0 deletions   Show diff stats
src/idl/dustem_define_grid_v1.pro 0 → 100644
@@ -0,0 +1,202 @@ @@ -0,0 +1,202 @@
  1 +PRO dustem_define_grid_v1,table_name $
  2 + ,filters=filters $
  3 + ,help=help $
  4 + ,table_params=table_params $
  5 + ,table_pmins=table_pmins $
  6 + ,table_pmaxs=table_pmaxs $
  7 + ,table_pnvals=table_pnvals $
  8 + ,table_plogs=table_plogs
  9 +
  10 +;+
  11 +; NAME:
  12 +; dustem_define_grid_v1
  13 +; PURPOSE:
  14 +; loads an SED Grid table into !dustem_grid. This is for initial versions of grid tables. Used to convert them to new convention.
  15 +; CATEGORY:
  16 +; Dustem
  17 +; CALLING SEQUENCE:
  18 +; dustem_define_grid,table_name,filters[,table_params=][,table_pmins=][,table_pmaxs=][,table_pnvals=][,table_plogs=]
  19 +; INPUTS:
  20 +; table_name : fits file name containing the grid
  21 +; filters : name of dustemwrap filters to be included in the GRID
  22 +; OPTIONAL INPUT PARAMETERS:
  23 +; NONE
  24 +; OUTPUTS:
  25 +; None
  26 +; OPTIONAL OUTPUT PARAMETERS:
  27 +; table_params= parameter names in the grid table
  28 +; table_pmins= parameter min values in the grid table
  29 +; table_pmaxs= parameter max values in the grid table
  30 +; table_pnvals= parameter number of values in the grid table
  31 +; table_plogs= 1=parameter values in log in the grid table, 0=linear
  32 +; ACCEPTED KEY-WORDS:
  33 +; help = If set, print this help
  34 +; COMMON BLOCKS:
  35 +; None
  36 +; SIDE EFFECTS:
  37 +; !dustem_grid is updated
  38 +; RESTRICTIONS:
  39 +; The DustEM fortran code must be installed
  40 +; The DustEMWrap IDL code must be installed
  41 +; PROCEDURE:
  42 +; None
  43 +; EXAMPLES
  44 +; dustem_make_sed_table,'DBP90',['(*!dustem_params).G0','(*!dustem_params).grains(0).mdust_o_mh'], $
  45 +; [0.1,1.e-3],[100.,1.e-1],[10,3],filename='/tmp/IRAS_GO.fits',log=[1,0],/show_seds, $
  46 +; filters=[dustem_instru2filters('IRAC'),dustem_instru2filters('SPIRE')]
  47 +; dustem_define_grid,/tmp/IRAS_GO.fits',['IRAC3','SPIRE2']
  48 +; help,!dustem_grid
  49 +; MODIFICATION HISTORY:
  50 +; Written by J.-Ph. Bernard (2023)
  51 +; Evolution details on the DustEMWrap gitlab.
  52 +; See http://dustemwrap.irap.omp.eu/ for FAQ and help.
  53 +;-
  54 +
  55 +IF keyword_set(help) THEN BEGIN
  56 + doc_library,'dustem_define_grid_v1'
  57 + goto,the_end
  58 +ENDIF
  59 +
  60 +;=== read the grid table
  61 +message,'reading grid data from '+table_name,/continue
  62 +;stop
  63 +info=file_info(table_name)
  64 +IF info.exists THEN BEGIN
  65 + st=mrdfits(table_name,1,h)
  66 +ENDIF ELSE BEGIN
  67 + message,'grid data '+table_name+' not found',/continue
  68 + stop
  69 +ENDELSE
  70 +
  71 +;stop
  72 +;=== get filters and params names from grid table header
  73 +i=0L
  74 +table_filters=['']
  75 +fname='bidon'
  76 +count=1
  77 +WHILE count NE 0 DO BEGIN
  78 + fname=sxpar(h,'FNAME'+strtrim(i+1,2),count=count)
  79 + IF count NE 0 THEN table_filters=[table_filters,strtrim(fname,2)]
  80 + i=i+1
  81 +ENDWHILE
  82 +table_filters=table_filters[1:*]
  83 +Ntfilters=n_elements(table_filters)
  84 +
  85 +table_params=['']
  86 +table_pmins=[0.d0]
  87 +table_pmaxs=[0.d0]
  88 +table_pnvals=[0L]
  89 +table_plogs=[0]
  90 +count=1
  91 +i=0L
  92 +WHILE count NE 0 DO BEGIN
  93 + pname=sxpar(h,'PNAME'+strtrim(i+1,2),count=count)
  94 + IF count NE 0 THEN BEGIN
  95 + table_params=[table_params,strtrim(pname,2)]
  96 + pmin=sxpar(h,'PMIN'+strtrim(i+1,2),count=count)
  97 + pmax=sxpar(h,'PMAX'+strtrim(i+1,2),count=count)
  98 + pnval=sxpar(h,'PNVAL'+strtrim(i+1,2),count=count)
  99 + plog=sxpar(h,'PLOG'+strtrim(i+1,2),count=count)
  100 + table_pmins=[table_pmins,pmin]
  101 + table_pmaxs=[table_pmaxs,pmax]
  102 + table_pnvals=[table_pnvals,pnval]
  103 + table_plogs=[table_plogs,plog]
  104 + ENDIF
  105 + i=i+1
  106 +ENDWHILE
  107 +table_params=table_params[1:*]
  108 +table_pmins=table_pmins[1:*]
  109 +table_pmaxs=table_pmaxs[1:*]
  110 +table_pnvals=table_pnvals[1:*]
  111 +table_plogs=table_plogs[1:*]
  112 +Ntparams=n_elements(table_params)
  113 +
  114 +;=== select only requested filters
  115 +;stop
  116 +use_filters=table_filters ;default is to keep all filters
  117 +IF keyword_set(filters) THEN use_filters=filters
  118 +
  119 +Nfilters=n_elements(use_filters)
  120 +keep_tfilters=intarr(Ntfilters)
  121 +tags=tag_names(st)
  122 +FOR i=0L,Nfilters-1 DO BEGIN
  123 + ind=where(table_filters EQ use_filters[i],count)
  124 + IF count NE 0 THEN keep_tfilters[ind]=1
  125 +ENDFOR
  126 +
  127 +;stop
  128 +
  129 +;totals=st.total
  130 +FOR i=0L,Ntfilters-1 DO BEGIN
  131 + IF keep_tfilters[i] EQ 0 THEN BEGIN
  132 + col_name=tags[i+Ntparams]
  133 + st=structure_remove_column(st,col_name)
  134 + ENDIF
  135 +ENDFOR
  136 +
  137 +;separate structure into parameters and seds
  138 +st_seds=st
  139 +tags=tag_names(st)
  140 +FOR i=0L,Ntparams-1 DO BEGIN
  141 + col_name=tags[i]
  142 + st_seds=structure_remove_column(st_seds,col_name)
  143 +ENDFOR
  144 +;stop
  145 +st_seds=structure_remove_column(st_seds,'TOTAL')
  146 +st_params=st
  147 +FOR i=0L,Nfilters-1 DO BEGIN
  148 + col_name=tags[i+Ntparams]
  149 + st_params=structure_remove_column(st_params,col_name)
  150 +ENDFOR
  151 +st_params=structure_remove_column(st_params,'TOTAL')
  152 +sed_totals=st.(Nfilters+Ntparams-1)
  153 +
  154 +;stop
  155 +
  156 +;==== recompute totals
  157 +Nsed=n_elements(st)
  158 +;==== recompute totals (needed if some columns have been removed)
  159 +FOR i=0L,Nsed-1 DO BEGIN
  160 + this_total=0.d0
  161 + FOR j=0L,Nfilters-1 DO BEGIN
  162 + ;this_total=this_total+(st[i]).(j+Ntparams)
  163 + this_total=this_total+st_seds[i].(j)
  164 + ENDFOR
  165 + ;st[i].total=this_total
  166 + sed_totals[i]=this_total
  167 +ENDFOR
  168 +
  169 +;stop
  170 +
  171 +dustem_grid={Nsed:Nsed $ ;
  172 + ,Nfilters:Nfilters $ ;
  173 + ,Nparams:Ntparams $ ;
  174 + ,filters:use_filters $ ;
  175 + ,params:table_params $;
  176 + ,st_seds:st_seds $ ;
  177 + ,st_params:st_params $ ;
  178 + ,sed_totals:sed_totals $ ;
  179 +; ,seds:st $ ;meant to disapear
  180 + ,pmin_values:table_pmins $ ;
  181 + ,pmax_values:table_pmaxs $ ;
  182 + }
  183 +
  184 +defsysv,'!dustem_grid',ptr_new(dustem_grid)
  185 +message,'Defined !dustem_grid',/continue
  186 +
  187 +;help,!dustem_grid
  188 +;** Structure <9b80dc08>, 10 tags, length=3760784, data length=3760780, refs=2:
  189 +; NSED LONG 20000
  190 +; NFILTERS LONG 42
  191 +; NPARAMS LONG 3
  192 +; FILTERS STRING Array[42]
  193 +; PARAMS STRING Array[3]
  194 +; ST_SEDS STRUCT -> <Anonymous> Array[20000]
  195 +; ST_PARAMS STRUCT -> <Anonymous> Array[20000]
  196 +; SED_TOTALS DOUBLE Array[20000]
  197 +; PMIN_VALUES DOUBLE Array[3]
  198 +; PMAX_VALUES DOUBLE Array[3]
  199 +
  200 +the_end:
  201 +
  202 +END
0 \ No newline at end of file 203 \ No newline at end of file