From f3dad5a208cace4864ee7c4da94da0f279260a4a Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 8 Jun 2016 21:53:00 +0800 Subject: Merge branch 'cosmo_calc' --- mass_profile/coolfunc_calc.sh | 102 +++++++++------------- mass_profile/coolfunc_calc2.sh | 173 +++++++++++++++++++++++++++++++++++++ mass_profile/coolfunc_calc_bolo.sh | 139 +++++++++++++++++++++++++++++ mass_profile/cooling_time2.sh | 52 ++++++----- mass_profile/csb_calc_lwt.sh | 18 ++-- mass_profile/fit_nfwmass.sh | 4 +- mass_profile/fit_sbp.sh | 2 +- 7 files changed, 402 insertions(+), 88 deletions(-) create mode 100755 mass_profile/coolfunc_calc2.sh create mode 100755 mass_profile/coolfunc_calc_bolo.sh diff --git a/mass_profile/coolfunc_calc.sh b/mass_profile/coolfunc_calc.sh index 9a01648..c4935b7 100755 --- a/mass_profile/coolfunc_calc.sh +++ b/mass_profile/coolfunc_calc.sh @@ -1,32 +1,39 @@ #!/bin/sh -## -## Calculate the 'cooling function' profile with respect to the -## given 'temperature profile' and the average abundance, redshift, -## and column density nH, using the XSPEC model 'wabs*apec'. -## -## Weitian LI -## Created: 2012-08-17 -## Updated: 2016-06-08 -## +# +# unalias -a +# +########################################################### +## Task: ## +## Calc `cooling function' data according to ## +## given `temperature profile' ## +## ## +## NOTE: ## +## given `tprofile': ## +## calc `cooling function' by invoking `XSPEC' ## +## using model `wabs*apec' ## +## ## +## LIweitiaNux ## +## August 17, 2012 ## +########################################################### ## cmdline arguments {{{ -if [ $# -eq 5 ]; then - : -elif [ $# -eq 6 ]; then - COOLFUNC_BOLO="$6" - [ -e "${COOLFUNC_BOLO}" ] && rm -f ${COOLFUNC_BOLO} -else +if [ $# -ne 5 ]; then printf "usage:\n" - printf " `basename $0` [coolfunc_bolo]\n" + printf " `basename $0` \n" exit 1 fi +base_path=`dirname $0` TPROFILE=$1 ABUND_VAL=$2 N_H=$3 REDSHIFT=$4 -NORM=`cosmo_calc ${REDSHIFT} | grep 'norm.*cooling_function' | awk -F':' '{ print $2 }'` +NORM=`$base_path/calc_distance $REDSHIFT|grep norm|awk '{print $2}'` + +echo $NORM + + COOLFUNC_DAT=$5 -COOLFUNC_DAT_RATIO="flux_cnt_ratio.txt" +COOLFUNC_DAT_RATIO=flux_cnt_ratio.txt if [ ! -r "${TPROFILE}" ]; then printf "ERROR: given tprofile '${TPROFILE}' NOT accessiable\n" @@ -44,14 +51,15 @@ XSPEC_CF_XCM="_coolfunc_calc.xcm" ## generate xspec script {{{ cat >> ${XSPEC_CF_XCM} << _EOF_ ## XSPEC Tcl script -## Calculate the cooling function profile w.r.t the temperature profile +## calc cooling function data ## -## Generated by: `basename $0` -## Date: `date` +## generated by: `basename $0` +## date: `date` set xs_return_results 1 set xs_echo_script 0 # set tcl_precision 12 +dummyrsp .01 100 4096 ## set basic data {{{ set nh ${N_H} set redshift ${REDSHIFT} @@ -65,18 +73,19 @@ chatter 0 # debug }}} query yes abund grsa -dummyrsp 0.01 100.0 4096 linear +dummyrsp 0.3 11.0 1024 # load model 'wabs*apec' to calc cooling function model wabs*apec & \${nh} & 1.0 & \${abund_val} & \${redshift} & \${norm} & /* ## xspec }}} -## set input and output filename & open files +## set input and output filename set tpro_fn "${TPROFILE}" set cf_fn "${COOLFUNC_DAT}" set cff_fn "${COOLFUNC_DAT_RATIO}" if { [ file exists \${cf_fn} ] } { exec rm -fv \${cf_fn} } + if { [ file exists \${cff_fn} ] } { exec rm -fv \${cff_fn} } @@ -86,21 +95,6 @@ set tpro_fd [ open \${tpro_fn} r ] set cf_fd [ open \${cf_fn} w ] set cff_fd [ open \${cff_fn} w ] -_EOF_ - -if [ ! -z "${COOLFUNC_BOLO}" ]; then - cat >> ${XSPEC_CF_XCM} << _EOF_ -# coolfunc bolometric -set cfbolo_fn "${COOLFUNC_BOLO}" -if { [ file exists \${cfbolo_fn} ] } { - exec rm -fv \${cfbolo_fn} -} -set cfbolo_fd [ open \${cfbolo_fn} w ] - -_EOF_ -fi - -cat >> ${XSPEC_CF_XCM} << _EOF_ ## read data from tprofile line by line while { [ gets \${tpro_fd} tpro_line ] != -1 } { # gets one line @@ -118,37 +112,27 @@ while { [ gets \${tpro_fd} tpro_line ] != -1 } { tclout flux 1 scan \${xspec_tclout} "%f %f %f %f" cff_data holder holder holder puts \${cff_fd} "\${radius} [expr \${cff_data}/\${cf_data}]" -_EOF_ -if [ ! -z "${COOLFUNC_BOLO}" ]; then - cat >> ${XSPEC_CF_XCM} << _EOF_ - # coolfunc bolometric - set cfbolo_data \$cff_data - #puts "cfbolo_data: \${cfbolo_data}" - puts \${cfbolo_fd} "\${radius} \${cfbolo_data}" -_EOF_ -fi -cat >> ${XSPEC_CF_XCM} << _EOF_ } ## close opened files close \${tpro_fd} close \${cf_fd} -_EOF_ - -if [ ! -z "${COOLFUNC_BOLO}" ]; then - cat >> ${XSPEC_CF_XCM} << _EOF_ -# coolfunc bolometric -close \${cfbolo_fd} - -_EOF_ -fi -cat >> ${XSPEC_CF_XCM} << _EOF_ ## exit tclexit _EOF_ -## generate xcm }}} + +## extract xcm }}} ## invoke xspec to calc printf "invoking XSPEC to calculate cooling function data ...\n" +# xspec - ${XSPEC_CF_XCM} xspec - ${XSPEC_CF_XCM} > /dev/null + +## clean +# if [ -e "${XSPEC_CF_XCM}" ]; then +# rm -f ${XSPEC_CF_XCM} +# fi + +exit 0 + diff --git a/mass_profile/coolfunc_calc2.sh b/mass_profile/coolfunc_calc2.sh new file mode 100755 index 0000000..c469619 --- /dev/null +++ b/mass_profile/coolfunc_calc2.sh @@ -0,0 +1,173 @@ +#!/bin/sh +# +# unalias -a +# +########################################################### +## Task: ## +## Calc `cooling function' data according to ## +## given `temperature profile' ## +## ## +## NOTE: ## +## given `tprofile': ## +## calc `cooling function' by invoking `XSPEC' ## +## using model `wabs*apec' ## +## ## +## LIweitiaNux ## +## August 17, 2012 ## +########################################################### + +## cmdline arguments {{{ +if [ $# -eq 5 ]; then + : +elif [ $# -eq 6 ]; then + COOLFUNC_BOLO=$6 + [ -e "${COOLFUNC_BOLO}" ] && rm -f ${COOLFUNC_BOLO} +else + printf "usage:\n" + printf " `basename $0` [coolfunc_bolo]\n" + exit 1 +fi +base_path=`dirname $0` +TPROFILE=$1 +ABUND_VAL=$2 +N_H=$3 +REDSHIFT=$4 +NORM=`$base_path/calc_distance $REDSHIFT | grep norm | awk '{ print $2 }'` +COOLFUNC_DAT=$5 +COOLFUNC_DAT_RATIO="flux_cnt_ratio.txt" + +if [ ! -r "${TPROFILE}" ]; then + printf "ERROR: given tprofile '${TPROFILE}' NOT accessiable\n" + exit 2 +fi +[ -e "${COOLFUNC_DAT}" ] && rm -f ${COOLFUNC_DAT} +[ -e "${COOLFUNC_DAT_RATIO}" ] && rm -f ${COOLFUNC_DAT_RATIO} +## arguments }}} + +## specify variable name outside while loop +## otherwise the inside vars invisible +XSPEC_CF_XCM="_coolfunc_calc.xcm" +[ -e "${XSPEC_CF_XCM}" ] && rm -f ${XSPEC_CF_XCM} + +## generate xspec script {{{ +cat >> ${XSPEC_CF_XCM} << _EOF_ +## XSPEC Tcl script +## calc cooling function data +## +## generated by: `basename $0` +## date: `date` + +set xs_return_results 1 +set xs_echo_script 0 +# set tcl_precision 12 +dummyrsp .01 100 4096 +## set basic data {{{ +set nh ${N_H} +set redshift ${REDSHIFT} +set abund_val ${ABUND_VAL} +set norm ${NORM} +## basic }}} + +## xspec related {{{ +# debug settings {{{ +chatter 0 +# debug }}} +query yes +abund grsa +dummyrsp 0.3 11.0 1024 +# load model 'wabs*apec' to calc cooling function +model wabs*apec & \${nh} & 1.0 & \${abund_val} & \${redshift} & \${norm} & /* +## xspec }}} + +## set input and output filename & open files +set tpro_fn "${TPROFILE}" +set cf_fn "${COOLFUNC_DAT}" +set cff_fn "${COOLFUNC_DAT_RATIO}" +if { [ file exists \${cf_fn} ] } { + exec rm -fv \${cf_fn} +} +if { [ file exists \${cff_fn} ] } { + exec rm -fv \${cff_fn} +} + +## open files +set tpro_fd [ open \${tpro_fn} r ] +set cf_fd [ open \${cf_fn} w ] +set cff_fd [ open \${cff_fn} w ] + +_EOF_ + +if [ ! -z "${COOLFUNC_BOLO}" ]; then + cat >> ${XSPEC_CF_XCM} << _EOF_ +# coolfunc bolometric +set cfbolo_fn "${COOLFUNC_BOLO}" +if { [ file exists \${cfbolo_fn} ] } { + exec rm -fv \${cfbolo_fn} +} +set cfbolo_fd [ open \${cfbolo_fn} w ] + +_EOF_ +fi + +cat >> ${XSPEC_CF_XCM} << _EOF_ +## read data from tprofile line by line +while { [ gets \${tpro_fd} tpro_line ] != -1 } { + # gets one line + scan \${tpro_line} "%f %f" radius temp_val + #puts "radius: \${radius}, temperature: \${temp_val}" + # set temperature value + newpar 2 \${temp_val} + # calc flux & tclout + flux 0.7 7.0 + tclout flux 1 + scan \${xspec_tclout} "%f %f %f %f" holder holder holder cf_data + #puts "cf_data: \${cf_data}" + puts \${cf_fd} "\${radius} \${cf_data}" + flux 0.01 100.0 + tclout flux 1 + scan \${xspec_tclout} "%f %f %f %f" cff_data holder holder holder + puts \${cff_fd} "\${radius} [expr \${cff_data}/\${cf_data}]" +_EOF_ +if [ ! -z "${COOLFUNC_BOLO}" ]; then + cat >> ${XSPEC_CF_XCM} << _EOF_ + # coolfunc bolometric + set cfbolo_data \$cff_data + #puts "cfbolo_data: \${cfbolo_data}" + puts \${cfbolo_fd} "\${radius} \${cfbolo_data}" +_EOF_ +fi +cat >> ${XSPEC_CF_XCM} << _EOF_ +} + +## close opened files +close \${tpro_fd} +close \${cf_fd} +_EOF_ + +if [ ! -z "${COOLFUNC_BOLO}" ]; then + cat >> ${XSPEC_CF_XCM} << _EOF_ +# coolfunc bolometric +close \${cfbolo_fd} + +_EOF_ +fi + +cat >> ${XSPEC_CF_XCM} << _EOF_ +## exit +tclexit +_EOF_ + +## extract xcm }}} + +## invoke xspec to calc +printf "invoking XSPEC to calculate cooling function data ...\n" +# xspec - ${XSPEC_CF_XCM} +xspec - ${XSPEC_CF_XCM} > /dev/null + +## clean +# if [ -e "${XSPEC_CF_XCM}" ]; then +# rm -f ${XSPEC_CF_XCM} +# fi + +exit 0 + diff --git a/mass_profile/coolfunc_calc_bolo.sh b/mass_profile/coolfunc_calc_bolo.sh new file mode 100755 index 0000000..5c4ef5d --- /dev/null +++ b/mass_profile/coolfunc_calc_bolo.sh @@ -0,0 +1,139 @@ +#!/bin/sh +# +# unalias -a +# +########################################################### +## Task: ## +## Calc `cooling function' data according to ## +## given `temperature profile' ## +## ## +## NOTE: ## +## given `tprofile': ## +## calc `cooling function' by invoking `XSPEC' ## +## using model `wabs*apec' ## +## ## +## LIweitiaNux ## +## August 17, 2012 ## +########################################################### + +## cmdline arguments {{{ +if [ $# -ne 5 ]; then + printf "usage:\n" + printf " `basename $0` \n" + exit 1 +fi +base_path=`dirname $0` +TPROFILE=$1 +ABUND_VAL=$2 +N_H=$3 +REDSHIFT=$4 +NORM=`$base_path/calc_distance $REDSHIFT|grep norm|awk '{print $2}'` + +echo $NORM + + +COOLFUNC_DAT=$5 +#COOLFUNC_DAT_RATIO=flux_cnt_ratio.txt + +if [ ! -r "${TPROFILE}" ]; then + printf "ERROR: given tprofile '${TPROFILE}' NOT accessiable\n" + exit 2 +fi +[ -e "${COOLFUNC_DAT}" ] && rm -f ${COOLFUNC_DAT} +#[ -e "${COOLFUNC_DAT_RATIO}" ] && rm -f ${COOLFUNC_DAT_RATIO} +## arguments }}} + +## specify variable name outside while loop +## otherwise the inside vars invisible +XSPEC_CF_XCM="_coolfunc_calc.xcm" +[ -e "${XSPEC_CF_XCM}" ] && rm -f ${XSPEC_CF_XCM} + +## generate xspec script {{{ +cat >> ${XSPEC_CF_XCM} << _EOF_ +## XSPEC Tcl script +## calc cooling function data +## +## generated by: `basename $0` +## date: `date` + +set xs_return_results 1 +set xs_echo_script 0 +# set tcl_precision 12 +dummyrsp .01 100 4096 +## set basic data {{{ +set nh ${N_H} +set redshift ${REDSHIFT} +set abund_val ${ABUND_VAL} +set norm ${NORM} +## basic }}} + +## xspec related {{{ +# debug settings {{{ +chatter 0 +# debug }}} +query yes +abund grsa +dummyrsp 0.3 11.0 1024 +# load model 'wabs*apec' to calc cooling function +#model wabs*apec & \${nh} & 1.0 & \${abund_val} & \${redshift} & \${norm} & +model wabs*apec & 0 & 1.0 & \${abund_val} & \${redshift} & \${norm} & +## xspec }}} + +## set input and output filename +set tpro_fn "${TPROFILE}" +set cf_fn "${COOLFUNC_DAT}" +##set cff_fn "${COOLFUNC_DAT_RATIO}" +if { [ file exists \${cf_fn} ] } { + exec rm -fv \${cf_fn} +} + +#if { [ file exists \${cff_fn} ] } { +# exec rm -fv \${cff_fn} +#} + +## open files +set tpro_fd [ open \${tpro_fn} r ] +set cf_fd [ open \${cf_fn} w ] +#set cff_fd [ open \${cff_fn} w ] + +## read data from tprofile line by line +while { [ gets \${tpro_fd} tpro_line ] != -1 } { + # gets one line + scan \${tpro_line} "%f %f" radius temp_val + #puts "radius: \${radius}, temperature: \${temp_val}" + # set temperature value + newpar 2 \${temp_val} + # calc flux & tclout + flux 0.01 100.0 + tclout flux 1 + scan \${xspec_tclout} "%f %f %f %f" cf_data holder holder holder + #puts "cf_data: \${cf_data}" + puts \${cf_fd} "\${radius} \${cf_data}" +# flux 0.01 100.0 +# tclout flux 1 +# scan \${xspec_tclout} "%f %f %f %f" cff_data holder holder holder +# puts \${cff_fd} "\${radius} [expr \${cff_data}/\${cf_data}]" +} + +## close opened files +close \${tpro_fd} +close \${cf_fd} + +## exit +tclexit +_EOF_ + +## extract xcm }}} + +## invoke xspec to calc +printf "invoking XSPEC to calculate cooling function data ...\n" +# xspec - ${XSPEC_CF_XCM} +xspec - ${XSPEC_CF_XCM} > /dev/null + +## clean +# if [ -e "${XSPEC_CF_XCM}" ]; then +# rm -f ${XSPEC_CF_XCM} +# fi + +exit 0 + diff --git a/mass_profile/cooling_time2.sh b/mass_profile/cooling_time2.sh index 775e175..cb0a55e 100755 --- a/mass_profile/cooling_time2.sh +++ b/mass_profile/cooling_time2.sh @@ -2,26 +2,38 @@ # unalias -a export LC_COLLATE=C -## -## based on `ciao_r500avgt' -## for calculating the `cooling time' -## within (0.-0.048 r500) region -## -## Junhua Gu -## August 22, 2012 -## -## Weitian LI -## 2013-04-28 -## -## -## Change logs: -## 2016-05-28: -## * Remove 'COSCALC', just use 'cosmo_calc' -## +########################################################### +## based on `ciao_r500avgt' ## +## for calculating the `cooling time ' ## +## within (0.-0.048 r500) region ## +## ## +## Junhua Gu ## +## August 22, 2012 ## +## ## +## LIweitiaNux ## +## 2013/04/28 ## +########################################################### + +########################################################### +## ChangeLogs +########################################################### + +## comology calculator {{{ +## XXX: MODIFY THIS TO YOUR OWN CASE +## and make sure this `calc' is executable +## NOTES: use `$HOME' instead of `~' in path +BASE_PATH=`dirname $0` +# COSCALC="`which cosmo_calc calc_distance | head -n 1`" +COSCALC="${BASE_PATH}/calc_distance" +if [ -z "${COSCALC}" ] || [ ! -x ${COSCALC} ]; then + printf "ERROR: \`COSCALC: ${COSCALC}' neither specified nor executable\n" + exit 255 +fi +## }}} ## about, used in `usage' {{{ -VERSION="v2.0" -UPDATE="2016-05-28" +VERSION="v1.1" +UPDATE="2012-08-26" ## about }}} ## error code {{{ @@ -230,7 +242,7 @@ case "${R500_UNI}" in ;; *) printf "## units in \`kpc', convert to \`Chandra pixel'\n" | ${TOLOG} - KPC_PER_PIX=`cosmo_calc ${REDSHIFT} | grep 'kpc.*pix' | tr -d 'a-zA-Z_#=(),:/ '` + KPC_PER_PIX=`${COSCALC} ${REDSHIFT} | grep 'kpc.*pix' | tr -d 'a-zA-Z_#=(),:/ '` # convert scientific notation for `bc' KPC_PER_PIX_B=`echo ${KPC_PER_PIX} | sed 's/[eE]/\*10\^/' | sed 's/+//'` printf "## calculated \`kpc/pixel': ${KPC_PER_PIX_B}\n" @@ -395,7 +407,7 @@ printf "## use grppha cmd: \`${GRP_CMD}'\n" | ${TOLOG} ################################################## #### main ## D_A -D_A_CM=`cosmo_calc ${REDSHIFT} | grep 'Angular_diameter_distance' | awk -F'[=,]' '{ print $2 }' | tr -d '[cm] ' +D_A_CM=`${COSCALC} ${REDSHIFT} | grep '^d_a_cm' | awk '{ print $2 }'` printf "D_A_CM(${REDSHIFT})= ${D_A_CM}\n" ## region related {{{ diff --git a/mass_profile/csb_calc_lwt.sh b/mass_profile/csb_calc_lwt.sh index fa6e654..381c545 100755 --- a/mass_profile/csb_calc_lwt.sh +++ b/mass_profile/csb_calc_lwt.sh @@ -1,10 +1,6 @@ #!/bin/sh # -# Calculate the surface brightness concentration (C_SB) for objects -# meet the conditions: 'z>0.3' or 'counts_in_0.048R500<500'. -# -# Aaron LI -# Updated: 2016-05-28 +# for 'z>0.3' or 'counts_in_0.048R500<500' # ERR_CALC=1 @@ -13,6 +9,16 @@ ERR_JSON=3 ERR_Z=4 ERR_CNT=5 +## cosmology claculator {{{ +## write the path of cosmo claculator here +BASE_PATH=`dirname $0` +COSMO_CALC="${BASE_PATH}/cosmo_calc" +if [ -z "${COSMO_CALC}" ] || [ ! -x ${COSMO_CALC} ] ; then + printf "ERROR: ${COSMO_CALC} neither executable nor specified\n" + exit ${ERR_CALC} +fi +## }}} + # default basedir relative to 'spc/profile' DFT_BASEDIR="../.." # default imgdir relative to 'basedir' @@ -109,7 +115,7 @@ if [ `echo "${Z} < 0.3" | bc -l` -eq 1 ]; then # exit ${ERR_Z} fi -KPC_PER_PIXEL=`cosmo_calc ${Z} | grep 'kpc/pixel' | awk '{ print $3 }'` +KPC_PER_PIXEL=`${COSMO_CALC} ${Z} | grep 'kpc/pixel' | awk '{ print $3 }'` RC_PIX=`echo "scale=2; 0.048 * ${R500} / ${KPC_PER_PIXEL}" | bc -l` # test counts_in_0.048R500<500? RC_REG="pie(${X},${Y},0,${RC_PIX},0,360)" diff --git a/mass_profile/fit_nfwmass.sh b/mass_profile/fit_nfwmass.sh index c6e8b8c..7cab66a 100755 --- a/mass_profile/fit_nfwmass.sh +++ b/mass_profile/fit_nfwmass.sh @@ -134,7 +134,7 @@ mv -fv ${T_dump} ${T_file_center} mv -fv fit_result.qdp ${T_file_center} # temp profile }}} -$base_path/coolfunc_calc.sh ${T_file_center} $abund $nh $z $cfunc_file cfunc_bolo.dat +$base_path/coolfunc_calc2.sh ${T_file_center} $abund $nh $z $cfunc_file cfunc_bolo.dat cfunc_file_center="coolfunc_data_center.txt" cp -f ${cfunc_file} ${cfunc_file_center} mv -fv flux_cnt_ratio.txt flux_cnt_ratio_center.txt @@ -213,7 +213,7 @@ for i in `seq 1 ${MC_TIMES}`; do printf "## ${i} / ${MC_TIMES} ##\n" printf "## `pwd -P` ##\n" - ${base_path}/coolfunc_calc.sh ${T_file} ${abund} ${nh} ${z} ${cfunc_file} + ${base_path}/coolfunc_calc2.sh ${T_file} ${abund} ${nh} ${z} ${cfunc_file} ${base_path}/${SBP_PROG} ${TMP_SBP_CFG} 2> /dev/null cat ${RES_SBPFIT} $base_path/fit_nfw_mass mass_int.dat ${z} ${nfw_rmin_kpc} 2> /dev/null diff --git a/mass_profile/fit_sbp.sh b/mass_profile/fit_sbp.sh index 60c5fca..666be2f 100755 --- a/mass_profile/fit_sbp.sh +++ b/mass_profile/fit_sbp.sh @@ -42,7 +42,7 @@ fi $base_path/fit_wang2012_model $t_data_file $t_param_file $cm_per_pixel 2> /dev/null cp wang2012_dump.qdp $T_file if [ ! -f ${cfunc_file} ]; then - $base_path/coolfunc_calc.sh $T_file $abund $nh $z $cfunc_file + $base_path/coolfunc_calc2.sh $T_file $abund $nh $z $cfunc_file fi $base_path/$PROG $sbp_cfg printf "## MODEL: ${MODEL}\n" -- cgit v1.2.2