Blame view

src/idl/dustem_grids_extend_parameter_range.pro 6.8 KB
dbfbb985   Jean-Philippe Bernard   improved
1
2
PRO dustem_grids_extend_parameter_range,input_table_name,pd_add,Nv_add $
									   ,what_do_we_add=what_do_we_add $
fd151175   Jean-Philippe Bernard   first commit
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
									   ,show_seds=show_seds $
									   ,print_params=print_params $
									   ,force_grain_keywords=force_grain_keywords $
									   ,output_table_name=output_table_name

;input_table_name='/Volumes/PILOT_FLIGHT1/PHANGS//ISRF/GRIDS/DL07_logn_MuseISRF_JWST_adaptedG0_Ypah1added_Yvsgadded_4Phangs_noionis_isrfclass26.fits'
;force_grain_keywords=['logn','logn',replicate('?',3)]
;dustem_grids_extend_parameter_range,input_table_name,'(*!dustem_params).grains[1].MDUST_O_MH',2,force_grain_keywords=force_grain_keywords

	dustem_read_grid_table2arrays,input_table_name $
								  ,Ngrains,model,old_Ncomb,NFparams,INCSP,use_polar,use_double $
								  ,old_parameter_description,old_parameter_pmin,old_parameter_pmax,old_parameter_pnval,old_parameter_plog,old_fparameter_description,old_fparameter_value $
								  ,old_param_values,old_Nparams,old_seds,filters,Nfilters,wavs,Nwavs $
								  ,old_I_tot_vec,old_ext_tot_vec,old_I_grains_vec,old_ext_grains_vec,grain_keywords=old_grain_keywords
    ;stop
    ;print,Ngrains,model,old_Ncomb,NFparams
    ;print,old_parameter_description,old_parameter_pmin,old_parameter_pmax,old_parameter_pnval,old_parameter_plog

    ;=== decide which dustemwrap parameters are linear
    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)
    
	use_what_do_we_add='larger'
	IF keyword_set(what_do_we_add) THEN use_what_do_we_add=strlowcase(what_do_we_add)

    ind_add=where(old_parameter_description EQ pd_add,count_add)
    param_is_non_linear=non_linear_mask[ind_add[0]]               ;This is 1 if the parameter to be added is non-linear

    IF count_add EQ 0 THEN BEGIN
    	message,'parameter description to be added not found in grid parameter description',/continue
    	stop
    ENDIF ELSE BEGIN
    	old_add_parameter_pmin=old_parameter_pmin[ind_add[0]]
    	old_add_parameter_pmax=old_parameter_pmax[ind_add[0]]
    	old_add_parameter_pnval=old_parameter_pnval[ind_add[0]]
    	old_add_parameter_plog=old_parameter_plog[ind_add[0]]
    	old_add_param_values=old_param_values.(ind_add[0])
    	order=sort(old_add_param_values)
    	old_add_param_values=old_add_param_values[order]
    	un=uniq(old_add_param_values)
    	old_add_param_values=old_add_param_values[un]
    ENDELSE
    add_parameter_values=fltarr(Nv_add)

    CASE use_what_do_we_add OF
    	'lower':BEGIN
    	   iv_max=old_add_parameter_pmin
    	   iv_Nvalues=Nv_add+1
    	   add_plog=old_add_parameter_plog
    	   IF add_plog EQ 1 THEN BEGIN
    	   	 use_values=alog10(old_add_param_values)
    	   ENDIF ELSE BEGIN
    	   	 use_values=old_add_param_values
    	   ENDELSE
    	   vvec=use_values-shift(use_values,1)
    	   dv=median(vvec)
    	   IF add_plog EQ 1 THEN BEGIN
    	   	 iv_min=10.^(alog10(iv_max)-dv*iv_Nvalues)
    	   ENDIF ELSE BEGIN
    	   	iv_min=iv_max-dv*iv_Nvalues
    	   ENDELSE
    	   ;iv_min=
    	   add_parameter_values_ptr=dustem_param_range2param_values([iv_min],[iv_max],[iv_Nvalues],Nc=Nc,log=[add_plog])
    	   ifrom=0L
    	   ito=Nv_add-1
           FOR i=ifrom,ito DO BEGIN
           	 add_parameter_values[i-ifrom]=*add_parameter_values_ptr[i]
           ENDFOR
fd151175   Jean-Philippe Bernard   first commit
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    	END
    	'larger':BEGIN
    	   iv_min=old_add_parameter_pmax
    	   iv_Nvalues=Nv_add+1
    	   add_plog=old_add_parameter_plog
    	   IF add_plog EQ 1 THEN BEGIN
    	   	 use_values=alog10(old_add_param_values)
    	   ENDIF ELSE BEGIN
    	   	 use_values=old_add_param_values
    	   ENDELSE
    	   vvec=use_values-shift(use_values,1)
    	   dv=median(vvec)
    	   IF add_plog EQ 1 THEN BEGIN
    	   	 iv_max=10.^(alog10(iv_min)+dv*iv_Nvalues)
    	   ENDIF ELSE BEGIN
    	   	iv_max=iv_min+dv*iv_Nvalues
    	   ENDELSE
    	   ;iv_min=
    	   add_parameter_values_ptr=dustem_param_range2param_values([iv_min],[iv_max],[iv_Nvalues],Nc=Nc,log=[add_plog])
    	   ifrom=1L
    	   ito=Nv_add
           FOR i=ifrom,ito DO BEGIN
           	 add_parameter_values[i-ifrom]=*add_parameter_values_ptr[i]
           ENDFOR
fd151175   Jean-Philippe Bernard   first commit
94
95
96
    	   ;stop
    	END
    ENDCASE
d66cda05   Jean-Philippe Bernard   fxed a bug
97
98
99
    print,old_add_param_values
    print,add_parameter_values
    ;stop
fd151175   Jean-Philippe Bernard   first commit
100
    ;=== Compute the min and max values for parameter to be extended
d66cda05   Jean-Philippe Bernard   fxed a bug
101
102
    one_add_iv_min=add_parameter_values[0]
    one_add_iv_max=add_parameter_values[Nv_add-1]
fd151175   Jean-Philippe Bernard   first commit
103
104
105
106
107

    ;=== merge parameter range values
    add_model=model
    add_parameters_description=old_parameter_description
	add_iv_min=old_parameter_pmin
d66cda05   Jean-Philippe Bernard   fxed a bug
108
	add_iv_min[ind_add]=one_add_iv_min
fd151175   Jean-Philippe Bernard   first commit
109
	add_iv_max=old_parameter_pmax
d66cda05   Jean-Philippe Bernard   fxed a bug
110
	add_iv_max[ind_add]=one_add_iv_max
fd151175   Jean-Philippe Bernard   first commit
111
112
    add_iv_Nvalues=old_parameter_pnval
    add_iv_Nvalues[ind_add]=Nv_add
fd151175   Jean-Philippe Bernard   first commit
113
114
115
116
117
118
119
120
121
	add_fpd=old_fparameter_description
	add_fiv=old_fparameter_value
	add_grain_keywords=old_grain_keywords
	IF keyword_set(force_grain_keywords) THEN BEGIN
		add_grain_keywords=force_grain_keywords
	ENDIF
    add_filters=filters
    add_plog=old_parameter_plog
    
724c5af6   Jean-Philippe Bernard   fixed
122
    message,'Parameter values for the added grid',/continue
d66cda05   Jean-Philippe Bernard   fxed a bug
123
124
125
    print,add_iv_min,add_iv_max,add_iv_Nvalues,add_plog
    ;stop

fd151175   Jean-Philippe Bernard   first commit
126
127
128
129
    ;try_add_parameter_values=dustem_param_range2param_values(add_iv_min,add_iv_max,add_iv_Nvalues,Nc=Nc,log=add_plog)
    ;stop
    add_table_name='/tmp/add_grid.fits'
    ;=== decide which parameters are linear
cd2aaf3e   Jean-Philippe Bernard   improved
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
    ;== make table for non-linear parameters
	message,'========================== Making added grid for non-linear parameters ...',/continue
	;In priciple, if non-linear parameters are already in the input table, there should be no reason to do that, but anyway ...
	dustem_make_sed_table,add_model $
					     ,add_parameters_description[ind_non_linear] $
						 ,add_iv_min[ind_non_linear] $
					     ,add_iv_max[ind_non_linear] $
						 ,add_iv_Nvalues[ind_non_linear] $
					  	 ,fpd=add_fpd $
					  	 ,fiv=add_fiv $
					  	 ,grain_keywords=add_grain_keywords $
					  	 ,filename=add_table_name $
					  	 ,filters=add_filters $
					  	 ,plog=add_plog[ind_non_linear] $
					  	 ,show_seds=show_seds $
					  	 ,print_params=print_params $
					  	 ,help=help
    ;== extend table for linear parameters
	message,'========================== Making added grid for linear parameters ...',/continue
    dustem_add_linear_params2grid,add_table_name $
    							 ,add_parameters_description[ind_linear] $
    							 ,add_iv_min[ind_linear] $
    							 ,add_iv_max[ind_linear] $
    							 ,add_iv_Nvalues[ind_linear] $
    							 ,out_filename=add_table_name $
    							 ,plog=add_plog[ind_linear] $
    							 ,show_seds=show_seds
fd151175   Jean-Philippe Bernard   first commit
157
158
159
160
161
162

    ;=== merge tables
    use_output_table_name='/tmp/add_ext_grid.fits'
    IF keyword_set(output_table_name) THEN use_output_table_name=output_table_name

    message,'========================== Merging grids ...',/continue
cd2aaf3e   Jean-Philippe Bernard   improved
163
	dustem_merge_grids,input_table_name,add_table_name,use_output_table_name
fd151175   Jean-Philippe Bernard   first commit
164
	
4dc787ce   Jean-Philippe Bernard   fixed
165
	;stop
fd151175   Jean-Philippe Bernard   first commit
166
167
						  				
END