aboutsummaryrefslogtreecommitdiffstats
path: root/mass_profile/fit_beta_entropy.sh
blob: f52e4a11cec24058b4f11a882e50ba2066b23a8b (plain)
1
2
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash

echo $#
if [ $# -eq 2 ]
then
    :
else
    echo "Usage:$0 <cfg file> <radius in kpc>"
    exit
fi
export PGPLOT_FONT=`locate grfont.dat|head -1`

mkdir -p entropy_files

cfg_file=$1
base_path=`dirname $0`
echo $base_path
#initialize profile type name
t_profile_type=`grep t_profile $cfg_file|awk '{print $2}'`
#initialize data file name
t_data_file=`grep t_data_file $cfg_file|awk '{print $2}'`
#initialize sbp config file
sbp_cfg=`grep sbp_cfg $cfg_file|awk '{print $2}'`
#initialize the temperature profile file
T_file=`grep '^T_file' $sbp_cfg|awk '{print $2}'`
#echo $t_profile_type
cm_per_pixel=`grep '^cm_per_pixel' $sbp_cfg|awk '{print $2}'`

#determine which temperature profile to be used, and fit the T profile
if [ $t_profile_type == zyy ]
then
    t_param_file=`grep t_param_file $cfg_file|awk '{print $2}'`
    $base_path/fit_zyy_model $t_data_file $t_param_file $cm_per_pixel
    mv -f zyy_dump.qdp ${T_file}
elif [ $t_profile_type == m0603246 ]
then
    $base_path/fit_m0603246 $t_data_file $cm_per_pixel
    mv -f m0603246_dump.qdp ${T_file}
elif [ $t_profile_type == wang2012 ]
then
    t_param_file=`grep t_param_file $cfg_file|awk '{print $2}'`
    $base_path/fit_wang2012_model $t_data_file $t_param_file $cm_per_pixel
    mv -f wang2012_dump.qdp ${T_file}
elif [ $t_profile_type == allen ]
then
    $base_path/fit_allen_model $t_data_file $cm_per_pixel
    mv -f allen_dump.qdp ${T_file}
elif [ $t_profile_type == zzl ]
then
    t_param_file=`grep t_param_file $cfg_file|awk '{print $2}'`
    $base_path/fit_zzl_model $t_data_file $t_param_file
    mv -f zzl_dump.qdp ${T_file}
else
    echo temperature profile name invalid!
    exit
fi

cfunc_file=`grep '^cfunc_file' ${sbp_cfg} |awk '{print $2}'`
z=`grep  '^z' ${sbp_cfg}|awk '{print $2}'`
abund=`grep '^abund' ${cfg_file} |awk '{print $2}'`
nh=`grep '^nh' ${cfg_file} |awk '{print $2}'`
$base_path/coolfunc_calc.sh ${T_file} $abund $nh $z $cfunc_file
mv flux_cnt_ratio.txt flux_cnt_ratio_center_entropy.txt
#fit sbp
$base_path/fit_beta_sbp $sbp_cfg
echo $cfunc_file
#exit

#store central valu
mv sbp_fit.qdp sbp_fit_center_entropy.qdp
mv mass_int.qdp mass_int_center_entropy.qdp
mv overdensity.qdp overdensity_center_entropy.qdp
mv gas_mass_int.qdp gas_mass_int_center_entropy.qdp
mv entropy.qdp entropy_center.qdp
sbp_data_file=`grep sbp_file $sbp_cfg|awk '{print $2}'`
radius_sbp_file=`grep radius_sbp_file ${cfg_file}|awk '{print $2}'`

if [ x"$radius_sbp_file" == x ]
then
    echo "Error, must have radius_sbp_file assigned, this file should be a 4-column file, which contains the radius, radius err, sbp, and sbp err"
    exit
fi

cat ${radius_sbp_file} | sed 's/#.*$//' | grep -Ev '^\s*$' > .tmp.txt
mv .tmp.txt ${radius_sbp_file}

rm -f summary_entropy.qdp
#100 times of Monte-carlo simulation to determine error
#just repeat above steps
for i in `seq 1 100`
do
    echo $t_data_file
    $base_path/shuffle_T.py $t_data_file temp_shuffled_t.dat
    $base_path/shuffle_sbp.py $sbp_data_file temp_shuffled_sbp.dat
    
#exit
    if [ $t_profile_type == zyy ]
    then
	t_param_file=`grep t_param_file $cfg_file|awk '{print $2}'`
	$base_path/fit_zyy_model temp_shuffled_t.dat $t_param_file $cm_per_pixel
	mv -f zyy_dump.qdp ${T_file}
    elif [ $t_profile_type == m0603246 ]
    then
	$base_path/fit_m0603246 temp_shuffled_t.dat $cm_per_pixel
	mv -f m0603246_dump.qdp ${T_file}
    elif [ $t_profile_type == wang2012 ]
    then
	t_param_file=`grep t_param_file $cfg_file|awk '{print $2}'`
	$base_path/fit_wang2012_model temp_shuffled_t.dat $t_param_file $cm_per_pixel
    mv -f wang2012_dump.qdp ${T_file}
    elif [ $t_profile_type == allen ]
    then
	$base_path/fit_allen_model temp_shuffled_t.dat $cm_per_pixel
	mv -f allen_dump.qdp ${T_file}
    elif [ $t_profile_type == zzl ]
    then
	t_param_file=`grep t_param_file $cfg_file|awk '{print $2}'`
    $base_path/fit_zzl_model temp_shuffled_t.dat $t_param_file
    mv -f zzl_dump.qdp ${T_file}
    else
	echo temperature profile name invalid!
	exit
    fi
    
#exit
    echo >temp_sbp.cfg
    
    cat $sbp_cfg|while read l
do
    if echo $l|grep sbp_file >/dev/null
    then
	echo sbp_file temp_shuffled_sbp.dat >>temp_sbp.cfg
    elif echo $l|grep T_file >/dev/null
    then
	echo T_file ${T_file} >>temp_sbp.cfg
    else
	echo $l >>temp_sbp.cfg
    fi
    
done

#$base_path/coolfunc_calc.sh ${T_file} $abund $nh $z $cfunc_file

$base_path/fit_beta_sbp temp_sbp.cfg

cat entropy.qdp >>summary_entropy.qdp
echo no no no >>summary_entropy.qdp
done

$base_path/analyze_entropy_profile.py $2 |tee entropy_result.txt