Commit fd1511759c30eb5d443a093a23769b9ca5bf4bc8

Authored by Jean-Philippe Bernard
1 parent 91b30c4c
Exists in master

first commit

Showing 1 changed file with 168 additions and 0 deletions   Show diff stats
src/idl/dustem_grids_extend_parameter_range.pro 0 → 100644
... ... @@ -0,0 +1,168 @@
  1 +PRO dustem_grids_extend_parameter_range,input_table_name,pd_add,Nv_add,what_do_we_add=what_do_we_add $
  2 + ,show_seds=show_seds $
  3 + ,print_params=print_params $
  4 + ,force_grain_keywords=force_grain_keywords $
  5 + ,output_table_name=output_table_name
  6 +
  7 +;input_table_name='/Volumes/PILOT_FLIGHT1/PHANGS//ISRF/GRIDS/DL07_logn_MuseISRF_JWST_adaptedG0_Ypah1added_Yvsgadded_4Phangs_noionis_isrfclass26.fits'
  8 +;force_grain_keywords=['logn','logn',replicate('?',3)]
  9 +;dustem_grids_extend_parameter_range,input_table_name,'(*!dustem_params).grains[1].MDUST_O_MH',2,force_grain_keywords=force_grain_keywords
  10 +
  11 + dustem_read_grid_table2arrays,input_table_name $
  12 + ,Ngrains,model,old_Ncomb,NFparams,INCSP,use_polar,use_double $
  13 + ,old_parameter_description,old_parameter_pmin,old_parameter_pmax,old_parameter_pnval,old_parameter_plog,old_fparameter_description,old_fparameter_value $
  14 + ,old_param_values,old_Nparams,old_seds,filters,Nfilters,wavs,Nwavs $
  15 + ,old_I_tot_vec,old_ext_tot_vec,old_I_grains_vec,old_ext_grains_vec,grain_keywords=old_grain_keywords
  16 + ;stop
  17 + ;print,Ngrains,model,old_Ncomb,NFparams
  18 + ;print,old_parameter_description,old_parameter_pmin,old_parameter_pmax,old_parameter_pnval,old_parameter_plog
  19 +
  20 + ;=== decide which dustemwrap parameters are linear
  21 + ind_non_linear=dustem_where_non_linear(old_parameter_description,count_non_linear,complement=ind_linear,Ncomplement=count_linear,non_linear_mask=non_linear_mask)
  22 +
  23 + use_what_do_we_add='larger'
  24 + IF keyword_set(what_do_we_add) THEN use_what_do_we_add=strlowcase(what_do_we_add)
  25 +
  26 + ind_add=where(old_parameter_description EQ pd_add,count_add)
  27 + param_is_non_linear=non_linear_mask[ind_add[0]] ;This is 1 if the parameter to be added is non-linear
  28 +
  29 + IF count_add EQ 0 THEN BEGIN
  30 + message,'parameter description to be added not found in grid parameter description',/continue
  31 + stop
  32 + ENDIF ELSE BEGIN
  33 + old_add_parameter_pmin=old_parameter_pmin[ind_add[0]]
  34 + old_add_parameter_pmax=old_parameter_pmax[ind_add[0]]
  35 + old_add_parameter_pnval=old_parameter_pnval[ind_add[0]]
  36 + old_add_parameter_plog=old_parameter_plog[ind_add[0]]
  37 + old_add_param_values=old_param_values.(ind_add[0])
  38 + order=sort(old_add_param_values)
  39 + old_add_param_values=old_add_param_values[order]
  40 + un=uniq(old_add_param_values)
  41 + old_add_param_values=old_add_param_values[un]
  42 + ENDELSE
  43 + add_parameter_values=fltarr(Nv_add)
  44 +
  45 + CASE use_what_do_we_add OF
  46 + 'lower':BEGIN
  47 + iv_max=old_add_parameter_pmin
  48 + iv_Nvalues=Nv_add+1
  49 + add_plog=old_add_parameter_plog
  50 + IF add_plog EQ 1 THEN BEGIN
  51 + use_values=alog10(old_add_param_values)
  52 + ENDIF ELSE BEGIN
  53 + use_values=old_add_param_values
  54 + ENDELSE
  55 + vvec=use_values-shift(use_values,1)
  56 + dv=median(vvec)
  57 + IF add_plog EQ 1 THEN BEGIN
  58 + iv_min=10.^(alog10(iv_max)-dv*iv_Nvalues)
  59 + ENDIF ELSE BEGIN
  60 + iv_min=iv_max-dv*iv_Nvalues
  61 + ENDELSE
  62 + ;iv_min=
  63 + add_parameter_values_ptr=dustem_param_range2param_values([iv_min],[iv_max],[iv_Nvalues],Nc=Nc,log=[add_plog])
  64 + ifrom=0L
  65 + ito=Nv_add-1
  66 + FOR i=ifrom,ito DO BEGIN
  67 + add_parameter_values[i-ifrom]=*add_parameter_values_ptr[i]
  68 + ENDFOR
  69 + print,old_add_param_values
  70 + print,add_parameter_values
  71 + ;stop
  72 + END
  73 + 'larger':BEGIN
  74 + iv_min=old_add_parameter_pmax
  75 + iv_Nvalues=Nv_add+1
  76 + add_plog=old_add_parameter_plog
  77 + IF add_plog EQ 1 THEN BEGIN
  78 + use_values=alog10(old_add_param_values)
  79 + ENDIF ELSE BEGIN
  80 + use_values=old_add_param_values
  81 + ENDELSE
  82 + vvec=use_values-shift(use_values,1)
  83 + dv=median(vvec)
  84 + IF add_plog EQ 1 THEN BEGIN
  85 + iv_max=10.^(alog10(iv_min)+dv*iv_Nvalues)
  86 + ENDIF ELSE BEGIN
  87 + iv_max=iv_min+dv*iv_Nvalues
  88 + ENDELSE
  89 + ;iv_min=
  90 + add_parameter_values_ptr=dustem_param_range2param_values([iv_min],[iv_max],[iv_Nvalues],Nc=Nc,log=[add_plog])
  91 + ifrom=1L
  92 + ito=Nv_add
  93 + FOR i=ifrom,ito DO BEGIN
  94 + add_parameter_values[i-ifrom]=*add_parameter_values_ptr[i]
  95 + ENDFOR
  96 + print,old_add_param_values
  97 + print,add_parameter_values
  98 + ;stop
  99 + END
  100 + ENDCASE
  101 + ;=== Compute the min and max values for parameter to be extended
  102 + add_iv_min=add_parameter_values[0]
  103 + add_iv_max=add_parameter_values[Nv_add-1]
  104 +
  105 + ;=== merge parameter range values
  106 + add_model=model
  107 + add_parameters_description=old_parameter_description
  108 + add_iv_min=old_parameter_pmin
  109 + add_iv_min[ind_add]=iv_min
  110 + add_iv_max=old_parameter_pmax
  111 + add_iv_max[ind_add]=iv_max
  112 + add_iv_Nvalues=old_parameter_pnval
  113 + add_iv_Nvalues[ind_add]=Nv_add
  114 + add_plog=old_add_parameter_plog
  115 + add_fpd=old_fparameter_description
  116 + add_fiv=old_fparameter_value
  117 + add_grain_keywords=old_grain_keywords
  118 + IF keyword_set(force_grain_keywords) THEN BEGIN
  119 + add_grain_keywords=force_grain_keywords
  120 + ENDIF
  121 + add_filters=filters
  122 + add_plog=old_parameter_plog
  123 +
  124 + ;try_add_parameter_values=dustem_param_range2param_values(add_iv_min,add_iv_max,add_iv_Nvalues,Nc=Nc,log=add_plog)
  125 + ;stop
  126 + add_table_name='/tmp/add_grid.fits'
  127 + ;=== decide which parameters are linear
  128 + ;IF param_is_non_linear THEN BEGIN ;This is if the parameter to be added is non-linear
  129 + ;== make table for non-linear parameters
  130 + message,'========================== Making added grid for non-linear parameters ...',/continue
  131 + dustem_make_sed_table,add_model $
  132 + ,add_parameters_description[ind_non_linear] $
  133 + ,add_iv_min[ind_non_linear] $
  134 + ,add_iv_max[ind_non_linear] $
  135 + ,add_iv_Nvalues[ind_non_linear] $
  136 + ,fpd=add_fpd $
  137 + ,fiv=add_fiv $
  138 + ,grain_keywords=add_grain_keywords $
  139 + ,filename=add_table_name $
  140 + ,filters=add_filters $
  141 + ,plog=add_plog[ind_non_linear] $
  142 + ,show_seds=show_seds $
  143 + ,print_params=print_params $
  144 + ,help=help
  145 + ;== extend table for linear parameter
  146 + message,'========================== Making added grid for linear parameters ...',/continue
  147 + dustem_add_linear_params2grid,add_table_name $
  148 + ,add_parameters_description[ind_linear] $
  149 + ,add_iv_min[ind_linear] $
  150 + ,add_iv_max[ind_linear] $
  151 + ,add_iv_Nvalues[ind_linear] $
  152 + ,out_filename=add_table_name $
  153 + ,plog=add_plog[ind_linear] $
  154 + ,show_seds=show_seds
  155 + ;ENDIF ELSE BEGIN
  156 +
  157 + ;ENDELSE
  158 +
  159 + ;=== merge tables
  160 + use_output_table_name='/tmp/add_ext_grid.fits'
  161 + IF keyword_set(output_table_name) THEN use_output_table_name=output_table_name
  162 +
  163 + message,'========================== Merging grids ...',/continue
  164 + dustem_merge_grids,input_table_name,add_table_name,output_table_name
  165 +
  166 + stop
  167 +
  168 +END
0 169 \ No newline at end of file
... ...