Commit 849fd436314c44187859abf6ae73402069d72bf7
1 parent
d5838901
Exists in
master
improved
Showing
3 changed files
with
93 additions
and
44 deletions
Show diff stats
LabTools/IRAP/JPB/fit_phangs_ngc0628_nir_continuum.pro
... | ... | @@ -859,13 +859,13 @@ grid_brute_force: |
859 | 859 | ;stop |
860 | 860 | |
861 | 861 | Nvor=max(voronoi_id) |
862 | -GOs=fltarr(Nvor)+la_undef() | |
862 | +G0s=fltarr(Nvor)+la_undef() | |
863 | 863 | Ypahs=fltarr(Nvor)+la_undef() |
864 | 864 | YVSGs=fltarr(Nvor)+la_undef() |
865 | 865 | facts=fltarr(Nvor)+la_undef() |
866 | 866 | chi2s=fltarr(Nvor)+la_undef() |
867 | 867 | rchi2s=fltarr(Nvor)+la_undef() |
868 | -dGOs=fltarr(Nvor)+la_undef() | |
868 | +dG0s=fltarr(Nvor)+la_undef() | |
869 | 869 | dYpahs=fltarr(Nvor)+la_undef() |
870 | 870 | dYVSGs=fltarr(Nvor)+la_undef() |
871 | 871 | use_NHmap=NHCO ;used NH map in 1.e21 (from CO) |
... | ... | @@ -897,11 +897,26 @@ restore,file,/verb |
897 | 897 | ind=where(vor_class NE 0) |
898 | 898 | class_min=min(vor_class[ind]) |
899 | 899 | class_max=max(vor_class[ind]) |
900 | +restore,data_dir+'ngc0628_isrf_min_prediction.sav',/verb | |
901 | +;% RESTORE: Restored variable: ISRFS. | |
902 | +;% RESTORE: Restored variable: OBJECT_DISTANCE. | |
903 | +;% RESTORE: Restored variable: OBJECT_THICKNESS. | |
904 | +;% RESTORE: Restored variable: SOURCE_NAME. | |
900 | 905 | |
901 | 906 | ;For test |
902 | -class_min=14 | |
907 | +class_min=15 | |
903 | 908 | class_max=15 |
904 | 909 | |
910 | +bidon=dustem_get_wavelengths(isrf_wavelengths=isrf_wavelengths) | |
911 | + | |
912 | +fixed_parameters_description=['dustem_plugin_phangs_class_isrf_2'] ;This is the ISRF G0 factor | |
913 | + | |
914 | +file=!dustem_soft_dir+'/data/ISRF_MATHIS.DAT' | |
915 | +;file='/Users/jpb/Soft_Libraries/dustem_fortran/data/ISRF.DAT' | |
916 | +readcol,file,Mathis_wavs,Mathis_ISRF | |
917 | +Mathis_ISRF=interpol(Mathis_ISRF,Mathis_wavs,isrf_wavelengths) | |
918 | +Mathis_1mic=interpol(Mathis_ISRF,isrf_wavelengths,1.0) | |
919 | + | |
905 | 920 | FOR isrf_class=class_min,class_max DO BEGIN |
906 | 921 | ;==== This is to use the grid for this ISRF class |
907 | 922 | isrf_class_str='_isrfclass'+strtrim(isrf_class,2) |
... | ... | @@ -913,7 +928,10 @@ FOR isrf_class=class_min,class_max DO BEGIN |
913 | 928 | IF vvid mod 100 EQ 0 THEN BEGIN |
914 | 929 | message,'isrf#'+strtrim(isrf_class,2)+' Doing sed '+strtrim(vvid,2)+' '+strtrim(1.*vvid/Nvor_class*100.,2)+' %',/continue |
915 | 930 | ENDIF |
931 | + ;=== Get the G0 value for that vid | |
916 | 932 | vid=ind_class[vvid] |
933 | + G0=interpol(ISRFs[*,vid],isrf_wavelengths,1.0)/Mathis_1mic | |
934 | + fixed_parameters_values=[G0] | |
917 | 935 | sed=*seds_ptr[vid] |
918 | 936 | ;=== restrict sed to requested filters |
919 | 937 | sed=sed[ind_filters] |
... | ... | @@ -924,16 +942,25 @@ FOR isrf_class=class_min,class_max DO BEGIN |
924 | 942 | ind=where(sed.stokesI EQ la_undef(),count) |
925 | 943 | IF count EQ 0 THEN BEGIN |
926 | 944 | params=dustem_brute_force_fit(sed,table_name,use_filters,fact=fact,chi2=chi2,/normalize,rchi2=rchi2,show_sed=show_sed $ |
927 | - ,params_hit=params_hit,params_uncertainties=params_uncertainties,params_min=params_min,params_max=params_max) | |
928 | - GOs[vid]=params[0] | |
929 | - Ypahs[vid]=params[1]/fact ;extenssive quantities must be divided by normalization factor | |
930 | - Yvsgs[vid]=params[2]/fact | |
945 | + ,params_hit=params_hit,params_uncertainties=params_uncertainties,params_min=params_min,params_max=params_max $ | |
946 | + ,fixed_parameters_description=fixed_parameters_description,fixed_parameters_values=fixed_parameters_values) | |
947 | + ;This would be if there was no fixed_parameters | |
948 | + ;G0s[vid]=params[0] | |
949 | + ;Ypahs[vid]=params[1]/fact ;extenssive quantities must be divided by normalization factor | |
950 | + ;Yvsgs[vid]=params[2]/fact | |
951 | + G0s[vid]=G0 | |
952 | + Ypahs[vid]=params[0]/fact ;extenssive quantities must be divided by normalization factor | |
953 | + Yvsgs[vid]=params[1]/fact | |
931 | 954 | facts[vid]=fact |
932 | 955 | chi2s[vid]=chi2 |
933 | 956 | rchi2s[vid]=rchi2 |
934 | - dGOs[vid]=params_uncertainties[0] | |
935 | - dYpahs[vid]=params_uncertainties[1]/fact ;extenssive quantities must be devided by normalization factor | |
936 | - dYvsgs[vid]=params_uncertainties[2]/fact | |
957 | + ;This would be if there was no fixed_parameters | |
958 | + ;dG0s[vid]=params_uncertainties[0] | |
959 | + ;dYpahs[vid]=params_uncertainties[1]/fact ;extenssive quantities must be devided by normalization factor | |
960 | + ;dYvsgs[vid]=params_uncertainties[2]/fact | |
961 | + dG0s[vid]=0. ;should use difference between fixed param and nearest table neighbor | |
962 | + dYpahs[vid]=params_uncertainties[0]/fact ;extenssive quantities must be devided by normalization factor | |
963 | + dYvsgs[vid]=params_uncertainties[1]/fact | |
937 | 964 | ;print,params[0],params[1],params[2],fact,chi2 |
938 | 965 | ENDIF |
939 | 966 | ENDFOR |
... | ... | @@ -945,7 +972,7 @@ ENDFOR |
945 | 972 | ;stop |
946 | 973 | |
947 | 974 | ;save,GOs,Ypahs,Yvsgs,file=dir+source_name+'DBP90_JWST_G0_YPAH_YVSG.fits' |
948 | -save,GOs,Ypahs,Yvsgs,file=data_dir+source_name+'_DBP90_JWST_G0_YPAH_YVSG_ISRFclasses.fits' | |
975 | +save,G0s,Ypahs,Yvsgs,facts,chi2s,rchi2s,file=data_dir+source_name+'_DBP90_JWST_G0_YPAH_YVSG_ISRFclasses.fits' | |
949 | 976 | |
950 | 977 | ;Nvor=max(voronoi_id) |
951 | 978 | |
... | ... | @@ -953,20 +980,20 @@ save,GOs,Ypahs,Yvsgs,file=data_dir+source_name+'_DBP90_JWST_G0_YPAH_YVSG_ISRFcla |
953 | 980 | ;=== make maps of parameters |
954 | 981 | chi2_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
955 | 982 | rchi2_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
956 | -GO_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() | |
983 | +G0_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() | |
957 | 984 | Ypah_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
958 | 985 | YVSG_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
959 | -dGO_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() | |
986 | +dG0_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() | |
960 | 987 | dYpah_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
961 | 988 | dYVSG_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
962 | 989 | fact_map=fltarr(sxpar(href,'NAXIS1'),sxpar(href,'NAXIS2'))+la_undef() |
963 | 990 | FOR vid=0LL,Nvor-1 DO BEGIN |
964 | 991 | IF vid mod 100 EQ 0 THEN print,(1.*vid)/Nvor*100. |
965 | 992 | ;ind=where(voronoi_id EQ vid) |
966 | - GO_map[*all_seds_indices[vid]]=GOs[vid] | |
993 | + G0_map[*all_seds_indices[vid]]=G0s[vid] | |
967 | 994 | Ypah_map[*all_seds_indices[vid]]=Ypahs[vid] |
968 | 995 | YVSG_map[*all_seds_indices[vid]]=Yvsgs[vid] |
969 | - dGO_map[*all_seds_indices[vid]]=dGOs[vid] | |
996 | + dG0_map[*all_seds_indices[vid]]=dG0s[vid] | |
970 | 997 | dYpah_map[*all_seds_indices[vid]]=dYpahs[vid] |
971 | 998 | dYVSG_map[*all_seds_indices[vid]]=dYvsgs[vid] |
972 | 999 | chi2_map[*all_seds_indices[vid]]=chi2s[vid] |
... | ... | @@ -980,13 +1007,27 @@ ENDFOR |
980 | 1007 | ;FOR vid=0LL,Nvor-1 DO chi2_map[*all_seds_indices[vid]]=chi2s[vid] |
981 | 1008 | stop |
982 | 1009 | |
1010 | +;G0 histogram | |
983 | 1011 | win=0L |
1012 | +window,win,xsize=800,ysize=800 & win=win+1 | |
1013 | + | |
1014 | +ind=where(G0s NE la_undef()) | |
1015 | +res=histogram(G0s[ind],locations=xv) | |
1016 | +cgplot,xv,res,psym=10,title='G0s histogram',xtit='G0',ytit='Number',/ylog,yrange=[1,max(res)],/ysty | |
1017 | + | |
1018 | +ind=where(Ypahs NE la_undef()) | |
1019 | +res=histogram(Ypahs[ind],locations=xv) | |
1020 | +cgplot,xv,res,psym=10,title='Ypahs histogram',xtit='Ypah',ytit='Number',/ylog,yrange=[1,max(res)],/ysty | |
1021 | + | |
984 | 1022 | window,win,xsize=800,ysize=900 & win=win+1 |
985 | 1023 | |
986 | 1024 | obp=[1.1,0.,1.15,1] |
987 | -image_cont20,GO_map,Href,/square,imrange=[0.01,100],axis_color_table=1,image_color_table='jpbloadct',/silent,off_bar=obp,title='G0' | |
988 | -image_cont20,Ypah_map,Href,/square,imrange=[1,100]*1.e-3,image_color_table='jpbloadct',/silent | |
989 | -image_cont20,YVSG_map,Href,/square,imrange=[1,100]*1.e-3,image_color_table='jpbloadct',/silent | |
1025 | +image_cont20,G0_map,Href,/square,imrange=[-2,40],axis_color_table=1,image_color_table='jpbloadct',/silent,off_bar=obp,title='G0' | |
1026 | +image_cont20,la_log10(G0_map),,Href,/square,imrange=[-0.2,2],axis_color_table=1,image_color_table='jpbloadct',/silent,off_bar=obp,title='G0' | |
1027 | + | |
1028 | +image_cont20,la_log10(Ypah_map),Href,/square,imrange=[-2.,6],axis_color_table=1,image_color_table='jpbloadct',/silent,off_bar=obp,title='log10(Ypah)' | |
1029 | + | |
1030 | +image_cont20,la_log10(YVSG_map),Href,/square,imrange=[-2.,6],axis_color_table=1,image_color_table='jpbloadct',/silent,off_bar=obp,title='log10(Yvsg)' | |
990 | 1031 | |
991 | 1032 | image_cont20,chi2_map,Href,/square,imrange=[0.01,100]*1.e4,image_color_table='jpbloadct',/silent |
992 | 1033 | |
... | ... | @@ -1004,7 +1045,7 @@ image_cont20,jwst_4_coutours[*,*,0],href,/square,imrange=[-1.,10],image_color_ta |
1004 | 1045 | |
1005 | 1046 | window,0,xsize=800,ysize=1000 |
1006 | 1047 | aa=alog10(GO_map) |
1007 | -wset,0 & image_cont20,GO_map,href,/square,imrange=[-1.,100],image_color_table='jpbloadct',/silent,title='G0',off_bar=obp,axis_color_table=1 | |
1048 | +wset,0 & image_cont20,GO_map,href,/square,imrange=[-2.,100],image_color_table='jpbloadct',/silent,title='G0',off_bar=obp,axis_color_table=1 | |
1008 | 1049 | wset,0 & image_cont20,aa,href,/square,imrange=[0.5,2.5],image_color_table='jpbloadct',/silent,title='G0',off_bar=obp,axis_color_table=1,levels=levs |
1009 | 1050 | window,1,xsize=800,ysize=1000 |
1010 | 1051 | wset,1 & image_cont20,Ypah_map,href,/square,imrange=[-0.005,0.5],image_color_table='jpbloadct',/silent,title='Ypah',off_bar=obp,axis_color_table=1,levels=levs | ... | ... |
src/idl/dustem_brute_force_fit.pro
1 | 1 | FUNCTION dustem_brute_force_fit,sed $ |
2 | - ,table_name $ | |
3 | - ,filters $ | |
4 | - ,normalize=normalize $ | |
5 | - ,params_hit=params_hit $ | |
6 | - ,params_uncertainties=params_uncertainties $ | |
7 | - ,params_min=params_min $ | |
8 | - ,params_max=params_max $ | |
9 | - ,fact=fact $ | |
10 | - ,chi2=chi2 $ | |
11 | - ,rchi2=rchi2 $ | |
12 | - ,best_sed=best_sed $ | |
13 | - ,best_grid_sed=best_grid_sed $ | |
14 | - ,show_sed=show_sed $ | |
15 | - ,nostop=nostop $ | |
16 | - ,reset=reset | |
2 | + ,table_name $ | |
3 | + ,filters $ | |
4 | + ,fixed_parameters_description=fixed_parameters_description $ | |
5 | + ,fixed_parameters_values=fixed_parameters_values $ | |
6 | + ,normalize=normalize $ | |
7 | + ,params_hit=params_hit $ | |
8 | + ,params_uncertainties=params_uncertainties $ | |
9 | + ,params_min=params_min $ | |
10 | + ,params_max=params_max $ | |
11 | + ,fact=fact $ | |
12 | + ,chi2=chi2 $ | |
13 | + ,rchi2=rchi2 $ | |
14 | + ,best_sed=best_sed $ | |
15 | + ,best_grid_sed=best_grid_sed $ | |
16 | + ,show_sed=show_sed $ | |
17 | + ,nostop=nostop $ | |
18 | + ,reset=reset | |
17 | 19 | |
18 | 20 | ;+ |
19 | 21 | ; NAME: |
... | ... | @@ -29,7 +31,8 @@ FUNCTION dustem_brute_force_fit,sed $ |
29 | 31 | ; table_name = name of the fits file to be used as a grid (see dustem_make_sed_table.pro for creation) |
30 | 32 | ; filters = filters to be used in the grid table (only used if !dustem_grid does not exist or if /reset) |
31 | 33 | ; OPTIONAL INPUT PARAMETERS: |
32 | -; None | |
34 | +; fixed_parameters_description = if set, describes parameters of the table that should be considered fixed. | |
35 | +; fixed_parameters_values = values of parameters of the table that should be considered fixed. | |
33 | 36 | ; OUTPUTS: |
34 | 37 | ; res = best values of the free parameters. Not that linear parameters to the sed should be multiplied by fact. |
35 | 38 | ; OPTIONAL OUTPUT PARAMETERS: |
... | ... | @@ -79,6 +82,7 @@ IF exist EQ 0 or keyword_set(reset)THEN BEGIN |
79 | 82 | dustem_define_grid,table_name,filters |
80 | 83 | ENDIF |
81 | 84 | |
85 | +;=== Should marginalize table for fixed parameters, if any | |
82 | 86 | seds=!dustem_grid.seds |
83 | 87 | Nseds=!dustem_grid.Nsed |
84 | 88 | Nfilters=!dustem_grid.Nfilters |
... | ... | @@ -86,8 +90,12 @@ Nparams=!dustem_grid.Nparams |
86 | 90 | table_params=!dustem_grid.params |
87 | 91 | table_pmins=!dustem_grid.pmin_values |
88 | 92 | table_pmaxs=!dustem_grid.pmax_values |
89 | -;dustem_grid={Nsed:Nsed,Nfilters:Nfilters,Nparams:Ntparams,filters:filters,params:table_params,seds:st,pmin_values:table_pmins,pmax_values:table_pmaxs} | |
90 | 93 | |
94 | +IF keyword_set(fixed_parameters_description) THEN BEGIN | |
95 | + dustem_marginalize_grid,fixed_parameters_description,fixed_parameters_values,seds,Nseds,Nfilters,Nparams,table_params,table_pmins,table_pmaxs | |
96 | +ENDIF | |
97 | + | |
98 | +;=== These are the full arrays needed for calculations | |
91 | 99 | chi2s=dblarr(Nseds) |
92 | 100 | grid_seds=dblarr(Nseds,Nfilters) |
93 | 101 | total_seds=dblarr(Nseds) |
... | ... | @@ -109,7 +117,7 @@ ENDFOR |
109 | 117 | ;stop |
110 | 118 | |
111 | 119 | ;=== loop over grid lines to compute chi2s |
112 | -;we should actually store the total of grid sed for each grid sed into the grid fits file (!) | |
120 | +;we do actually store the total of grid sed for each grid sed into the grid fits file | |
113 | 121 | ;we could also store the total of observed seds in the observed sed save fits file (!) |
114 | 122 | facts=dblarr(Nseds) |
115 | 123 | facts[*]=1.d0 |
... | ... | @@ -119,12 +127,12 @@ IF keyword_set(normalize) THEN BEGIN |
119 | 127 | facts[i]=total(sed.stokesI)/total_seds[i] |
120 | 128 | this_sed=sed.stokesI/facts[i] |
121 | 129 | this_var=sed.sigmaII/facts[i]^2 |
122 | - ;chi2s[i]=total((sed.stokesI-grid_seds[i,*])^2/sed.sigmaII) | |
123 | - chi2s[i]=total((this_sed-grid_seds[i,*])^2/this_var) | |
130 | + ;chi2s[i]=total((sed.stokesI-grid_seds[i,*])^2/sed.sigmaII) | |
131 | + chi2s[i]=total((this_sed-grid_seds[i,*])^2/this_var) | |
124 | 132 | ENDFOR |
125 | 133 | ENDIF ELSE BEGIN |
126 | 134 | FOR i=0L,Nseds-1 DO BEGIN |
127 | - chi2s[i]=total((sed.stokesI-grid_seds[i,*])^2/sed.sigmaII) | |
135 | + chi2s[i]=total((sed.stokesI-grid_seds[i,*])^2/sed.sigmaII) | |
128 | 136 | ENDFOR |
129 | 137 | ENDELSE |
130 | 138 | ;stop |
... | ... | @@ -139,14 +147,14 @@ rchi2=chi2/Nfreedom ;This is the reduced chi2 |
139 | 147 | best_grid_sed=reform(grid_seds[ind[0],*]) ;This is the best SED fround in the grid. |
140 | 148 | best_sed=best_grid_sed*fact ;This is the best scaled grid SED matching the input SED. |
141 | 149 | |
142 | -;==== should check bumping to table edges there | |
150 | +;==== Check bumping to table edges. | |
143 | 151 | params_hit=intarr(Nparams) |
144 | 152 | FOR i=0L,Nparams-1 DO BEGIN |
145 | 153 | IF params[i] EQ table_pmins[i] THEN params_hit[i]=-1 |
146 | 154 | IF params[i] EQ table_pmaxs[i] THEN params_hit[i]=1 |
147 | 155 | ENDFOR |
148 | 156 | |
149 | -;==== should compute parameter uncertainties there | |
157 | +;==== Compute parameter uncertainties | |
150 | 158 | ;stop |
151 | 159 | conf_level=90./100. |
152 | 160 | ;print,Nfreedom,conf_level | ... | ... |
src/idl/dustem_define_grid.pro
... | ... | @@ -69,8 +69,8 @@ fname='bidon' |
69 | 69 | count=1 |
70 | 70 | WHILE count NE 0 DO BEGIN |
71 | 71 | fname=sxpar(h,'FNAME'+strtrim(i+1,2),count=count) |
72 | - IF count NE 0 THEN table_filters=[table_filters,strtrim(fname,2)] | |
73 | - i=i+1 | |
72 | + IF count NE 0 THEN table_filters=[table_filters,strtrim(fname,2)] | |
73 | + i=i+1 | |
74 | 74 | ENDWHILE |
75 | 75 | table_filters=table_filters[1:*] |
76 | 76 | Ntfilters=n_elements(table_filters) | ... | ... |