From c75b12776c0d2bc19f4fd2382b38624af74dee11 Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Thu, 5 Mar 2015 16:12:23 +0800 Subject: Update 'chandra_gensbpreg.sh'. * 'chandra_gensbpreg.sh': - Add '1' to denominators when calculate STN to avoid division by zero - Add script description * 'empty_v3.json': - Add 'Unified Name' field * Rename 'calc_lx_simple_v2.sh' -> 'calc_lx_simple.sh'. --- files/empty_v3.json | 1 + scripts/calc_lx_simple.sh | 130 +++++++++++++++++++++++++++++++++++++++++++ scripts/calc_lx_simple_v2.sh | 127 ------------------------------------------ scripts/chandra_gensbpreg.sh | 40 ++++++++++--- 4 files changed, 163 insertions(+), 135 deletions(-) create mode 100755 scripts/calc_lx_simple.sh delete mode 100755 scripts/calc_lx_simple_v2.sh diff --git a/files/empty_v3.json b/files/empty_v3.json index 1095c1e..c150611 100644 --- a/files/empty_v3.json +++ b/files/empty_v3.json @@ -1,6 +1,7 @@ { "Obs. ID": , "Source Name": "", + "Unified Name": "", "Obs. Date": "", "Detector": "", "Exposure (ks)": , diff --git a/scripts/calc_lx_simple.sh b/scripts/calc_lx_simple.sh new file mode 100755 index 0000000..a13c67b --- /dev/null +++ b/scripts/calc_lx_simple.sh @@ -0,0 +1,130 @@ +#!/bin/sh +# +unalias -a +export LC_COLLATE=C +# fix path for python +export PATH="/usr/bin:$PATH" +########################################################### +## calc_lx in BATCH mode ## +## ## +## LIweitiaNux ## +## August 31, 2012 ## +## ## +## ChangeLog: ## +## 2014/06/18: use env variable 'MASS_PROFILE_DIR' ## +########################################################### + +UPDATED="2014/06/18" + +## usage, `path_conffile' is the configuration file +## which contains the `path' to each `repro/mass' directory +if [ $# -ne 1 ]; then + printf "usage:\n" + printf " `basename $0` \n" + printf "\nNOTE:\n" + printf " script cannot handle \`~' in path\n" + printf "\nVersion: ${UPDATED}\n" + exit 1 +fi + +## set the path to the script {{{ +if [ -n "${MASS_PROFILE_DIR}" ]; then + CALCLX_SCRIPT="${MASS_PROFILE_DIR}/calc_lx" + CFCALC_SCRIPT="${MASS_PROFILE_DIR}/coolfunc_calc.sh" + FIT_TPRO="${MASS_PROFILE_DIR}/fit_wang2012_model" +else + printf "ERROR: environment variable 'MASS_PROFILE_DIR' not set.\n" + exit 2 +fi + +if [ -z "${CALCLX_SCRIPT}" ]; then + printf "ERROR: \`CALCLX_SCRIPT' not set\n" + exit 250 +elif [ ! -r ${CALCLX_SCRIPT} ]; then + printf "ERROR: CANNOT access script \`${CALCLX_SCRIPT}'\n" + exit 251 +fi +## script path }}} + +# result lines +RES_LINE=100 +# process dir +MDIR="$1" +# mass fitting conf +MCONF="fitting_mass.conf" + +# process +cd ${MDIR} +printf "Entered dir: \``pwd`'\n" +# conf file +if [ ! -r "${MCONF}" ]; then + printf "ERROR: configuration file \`${MCONF}' not accessiable\n" +else + LOGFILE="calclx_`date '+%Y%m%d%H'`.log" + [ -e "${LOGFILE}" ] && mv -fv ${LOGFILE} ${LOGFILE}_bak + TOLOG="tee -a ${LOGFILE}" + # fitting_mass logfile, get R500 from it + MLOG=`ls ${MCONF%.[confgCONFG]*}*.log | tail -n 1` + R500_VAL=`tail -n ${RES_LINE} ${MLOG} | grep '^r500' | awk '{ print $2 }'` + R200_VAL=`tail -n ${RES_LINE} ${MLOG} | grep '^r200' | awk '{ print $2 }'` + # radius_sbp_file {{{ + RSBP=`grep '^radius_sbp_file' ${MCONF} | awk '{ print $2 }'` + TMP_RSBP="_tmp_rsbp.txt" + [ -e "${TMP_RSBP}" ] && rm -f ${TMP_RSBP} + cat ${RSBP} | sed 's/#.*$//' | grep -Ev '^\s*$' > ${TMP_RSBP} + RSBP="${TMP_RSBP}" + # rsbp }}} + TPRO_TYPE=`grep '^t_profile' ${MCONF} | awk '{ print $2 }'` + TPRO_DATA=`grep '^t_data_file' ${MCONF} | awk '{ print $2 }'` + TPRO_PARA=`grep '^t_param_file' ${MCONF} | awk '{ print $2 }'` + SBP_CONF=`grep '^sbp_cfg' ${MCONF} | awk '{ print $2 }'` + ABUND=`grep '^abund' ${MCONF} | awk '{ print $2 }'` + NH=`grep '^nh' ${MCONF} | awk '{ print $2 }'` + Z=`grep '^z' ${SBP_CONF} | awk '{ print $2 }'` + cm_per_pixel=`grep '^cm_per_pixel' ${SBP_CONF} | awk '{ print $2 }'` + CF_FILE=`grep '^cfunc_file' ${SBP_CONF} | awk '{ print $2 }'` + printf "## use logfile: \`${LOGFILE}'\n" + printf "## working directory: \``pwd -P`'\n" | ${TOLOG} + printf "## use configuration files: \`${MCONF}, ${SBP_CONF}'\n" | ${TOLOG} + printf "## use radius_sbp_file: \`${RSBP}'\n" | ${TOLOG} + printf "## R500 (kpc): \`${R500_VAL}'\n" | ${TOLOG} + printf "## R200 (kpc): \`${R200_VAL}'\n" | ${TOLOG} + printf "## redshift: \`${Z}'\n" | ${TOLOG} + printf "## abund: \`${ABUND}'\n" | ${TOLOG} + printf "## nh: \`${NH}'\n" | ${TOLOG} + printf "## T_profile type: \`${TPRO_TYPE}'\n" | ${TOLOG} + printf "## cfunc_file: \`${CF_FILE}'\n" | ${TOLOG} + ## fit temperature profile {{{ + T_FILE="_tpro_dump.qdp" + if [ "${TPRO_TYPE}" = "wang2012" ]; then + printf "fitting temperature profile (wang2012) ...\n" + [ -e "wang2012_dump.qdp" ] && mv -fv wang2012_dump.qdp wang2012_dump.qdp_bak + [ -e "fit_result.qdp" ] && mv -fv fit_result.qdp fit_result.qdp_bak + ${FIT_TPRO} ${TPRO_DATA} ${TPRO_PARA} ${cm_per_pixel} 2> /dev/null + mv -fv wang2012_dump.qdp ${T_FILE} + [ -e "wang2012_dump.qdp_bak" ] && mv -fv wang2012_dump.qdp_bak wang2012_dump.qdp + [ -e "fit_result.qdp_bak" ] && mv -fv fit_result.qdp_bak fit_result.qdp + else + printf "ERROR: invalid tprofile type: \`${TPRO_TYPE}'\n" + exit 10 + fi + ## tprofile }}} + ## calc `flux_ratio' {{{ + printf "calc flux_ratio ...\n" + CF_FILE="_cf_data.txt" + FLUX_RATIO="__flux_cnt_ratio.txt" + [ -e "flux_cnt_ratio.txt" ] && mv -fv flux_cnt_ratio.txt flux_cnt_ratio.txt_bak + printf "## CMD: sh ${CFCALC_SCRIPT} ${T_FILE} ${ABUND} ${NH} ${Z} ${CF_FILE}\n" | ${TOLOG} + sh ${CFCALC_SCRIPT} ${T_FILE} ${ABUND} ${NH} ${Z} ${CF_FILE} + mv -fv flux_cnt_ratio.txt ${FLUX_RATIO} + [ -e "flux_cnt_ratio.txt_bak" ] && mv -fv flux_cnt_ratio.txt_bak flux_cnt_ratio.txt + ## flux_ratio }}} + printf "## CMD: ${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R500_VAL} ${TPRO_DATA}\n" | ${TOLOG} + printf "## CMD: ${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R200_VAL} ${TPRO_DATA}\n" | ${TOLOG} + L500=`${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R500_VAL} ${TPRO_DATA} | grep '^Lx' | awk '{ print $2,$3,$4 }'` + L200=`${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R200_VAL} ${TPRO_DATA} | grep '^Lx' | awk '{ print $2,$3,$4 }'` + printf "L500= ${L500} erg/s\n" | ${TOLOG} + printf "L200= ${L200} erg/s\n" | ${TOLOG} +fi +printf "\n++++++++++++++++++++++++++++++++++++++\n" + diff --git a/scripts/calc_lx_simple_v2.sh b/scripts/calc_lx_simple_v2.sh deleted file mode 100755 index 576a43e..0000000 --- a/scripts/calc_lx_simple_v2.sh +++ /dev/null @@ -1,127 +0,0 @@ -#!/bin/sh -# -unalias -a -export LC_COLLATE=C -# fix path for python -export PATH="/usr/bin:$PATH" -########################################################### -## calc_lx in BATCH mode ## -## ## -## LIweitiaNux ## -## August 31, 2012 ## -## ## -## ChangeLog: ## -## 2014/06/18: use env variable 'MASS_PROFILE_DIR' ## -########################################################### - -## usage, `path_conffile' is the configuration file -## which contains the `path' to each `repro/mass' directory -if [ $# -ne 1 ]; then - printf "usage:\n" - printf " `basename $0` \n" - printf "\nNOTE:\n" - printf " script cannot handle \`~' in path\n" - exit 1 -fi - -## set the path to the script {{{ -if [ -n "${MASS_PROFILE_DIR}" ]; then - CALCLX_SCRIPT="${MASS_PROFILE_DIR}/calc_lx" - CFCALC_SCRIPT="${MASS_PROFILE_DIR}/coolfunc_calc.sh" - FIT_TPRO="${MASS_PROFILE_DIR}/fit_wang2012_model" -else - printf "ERROR: environment variable 'MASS_PROFILE_DIR' not set.\n" - exit 2 -fi - -if [ -z "${CALCLX_SCRIPT}" ]; then - printf "ERROR: \`CALCLX_SCRIPT' not set\n" - exit 250 -elif [ ! -r ${CALCLX_SCRIPT} ]; then - printf "ERROR: CANNOT access script \`${CALCLX_SCRIPT}'\n" - exit 251 -fi -## script path }}} - -# result lines -RES_LINE=100 -# process dir -MDIR="$1" -# mass fitting conf -MCONF="fitting_mass.conf" - -# process -cd ${MDIR} -printf "Entered dir: \``pwd`'\n" -# conf file -if [ ! -r "${MCONF}" ]; then - printf "ERROR: configuration file \`${MCONF}' not accessiable\n" -else - LOGFILE="calclx_`date '+%Y%m%d%H'`.log" - [ -e "${LOGFILE}" ] && mv -fv ${LOGFILE} ${LOGFILE}_bak - TOLOG="tee -a ${LOGFILE}" - # fitting_mass logfile, get R500 from it - MLOG=`ls ${MCONF%.[confgCONFG]*}*.log | tail -n 1` - R500_VAL=`tail -n ${RES_LINE} ${MLOG} | grep '^r500' | awk '{ print $2 }'` - R200_VAL=`tail -n ${RES_LINE} ${MLOG} | grep '^r200' | awk '{ print $2 }'` - # radius_sbp_file {{{ - RSBP=`grep '^radius_sbp_file' ${MCONF} | awk '{ print $2 }'` - TMP_RSBP="_tmp_rsbp.txt" - [ -e "${TMP_RSBP}" ] && rm -f ${TMP_RSBP} - cat ${RSBP} | sed 's/#.*$//' | grep -Ev '^\s*$' > ${TMP_RSBP} - RSBP="${TMP_RSBP}" - # rsbp }}} - TPRO_TYPE=`grep '^t_profile' ${MCONF} | awk '{ print $2 }'` - TPRO_DATA=`grep '^t_data_file' ${MCONF} | awk '{ print $2 }'` - TPRO_PARA=`grep '^t_param_file' ${MCONF} | awk '{ print $2 }'` - SBP_CONF=`grep '^sbp_cfg' ${MCONF} | awk '{ print $2 }'` - ABUND=`grep '^abund' ${MCONF} | awk '{ print $2 }'` - NH=`grep '^nh' ${MCONF} | awk '{ print $2 }'` - Z=`grep '^z' ${SBP_CONF} | awk '{ print $2 }'` - cm_per_pixel=`grep '^cm_per_pixel' ${SBP_CONF} | awk '{ print $2 }'` - CF_FILE=`grep '^cfunc_file' ${SBP_CONF} | awk '{ print $2 }'` - printf "## use logfile: \`${LOGFILE}'\n" - printf "## working directory: \``pwd -P`'\n" | ${TOLOG} - printf "## use configuration files: \`${MCONF}, ${SBP_CONF}'\n" | ${TOLOG} - printf "## use radius_sbp_file: \`${RSBP}'\n" | ${TOLOG} - printf "## R500 (kpc): \`${R500_VAL}'\n" | ${TOLOG} - printf "## R200 (kpc): \`${R200_VAL}'\n" | ${TOLOG} - printf "## redshift: \`${Z}'\n" | ${TOLOG} - printf "## abund: \`${ABUND}'\n" | ${TOLOG} - printf "## nh: \`${NH}'\n" | ${TOLOG} - printf "## T_profile type: \`${TPRO_TYPE}'\n" | ${TOLOG} - printf "## cfunc_file: \`${CF_FILE}'\n" | ${TOLOG} - ## fit temperature profile {{{ - T_FILE="_tpro_dump.qdp" - if [ "${TPRO_TYPE}" = "wang2012" ]; then - printf "fitting temperature profile (wang2012) ...\n" - [ -e "wang2012_dump.qdp" ] && mv -fv wang2012_dump.qdp wang2012_dump.qdp_bak - [ -e "fit_result.qdp" ] && mv -fv fit_result.qdp fit_result.qdp_bak - ${FIT_TPRO} ${TPRO_DATA} ${TPRO_PARA} ${cm_per_pixel} 2> /dev/null - mv -fv wang2012_dump.qdp ${T_FILE} - [ -e "wang2012_dump.qdp_bak" ] && mv -fv wang2012_dump.qdp_bak wang2012_dump.qdp - [ -e "fit_result.qdp_bak" ] && mv -fv fit_result.qdp_bak fit_result.qdp - else - printf "ERROR: invalid tprofile type: \`${TPRO_TYPE}'\n" - exit 10 - fi - ## tprofile }}} - ## calc `flux_ratio' {{{ - printf "calc flux_ratio ...\n" - CF_FILE="_cf_data.txt" - FLUX_RATIO="__flux_cnt_ratio.txt" - [ -e "flux_cnt_ratio.txt" ] && mv -fv flux_cnt_ratio.txt flux_cnt_ratio.txt_bak - printf "## CMD: sh ${CFCALC_SCRIPT} ${T_FILE} ${ABUND} ${NH} ${Z} ${CF_FILE}\n" | ${TOLOG} - sh ${CFCALC_SCRIPT} ${T_FILE} ${ABUND} ${NH} ${Z} ${CF_FILE} - mv -fv flux_cnt_ratio.txt ${FLUX_RATIO} - [ -e "flux_cnt_ratio.txt_bak" ] && mv -fv flux_cnt_ratio.txt_bak flux_cnt_ratio.txt - ## flux_ratio }}} - printf "## CMD: ${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R500_VAL} ${TPRO_DATA}\n" | ${TOLOG} - printf "## CMD: ${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R200_VAL} ${TPRO_DATA}\n" | ${TOLOG} - L500=`${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R500_VAL} ${TPRO_DATA} | grep '^Lx' | awk '{ print $2,$3,$4 }'` - L200=`${CALCLX_SCRIPT} ${RSBP} ${FLUX_RATIO} ${Z} ${R200_VAL} ${TPRO_DATA} | grep '^Lx' | awk '{ print $2,$3,$4 }'` - printf "L500= ${L500} erg/s\n" | ${TOLOG} - printf "L200= ${L200} erg/s\n" | ${TOLOG} -fi -printf "\n++++++++++++++++++++++++++++++++++++++\n" - diff --git a/scripts/chandra_gensbpreg.sh b/scripts/chandra_gensbpreg.sh index df56501..ecc1fe9 100755 --- a/scripts/chandra_gensbpreg.sh +++ b/scripts/chandra_gensbpreg.sh @@ -1,19 +1,41 @@ #!/bin/sh -# -# v2.0, 2013/03/06, LIweitiaNux -# add param `-t' to test STN -# -########################################################### +## +## This script generate a series of regions for the extraction of +## radial surface brightness profile (SBP). +## +## Regions geneartion algorithm: +## (1) innermost 10 regions, we require a mininal of 5 pixel as well +## as 50 counts within the 0.7-7.0 keV range. +## (2) following regions: R_out = R_in * 1.2, and require STN > 1.5. +## +## Reference: +## [1] region generate algorithm ??? (TODO) +## +## Author: Zhenghao ZHU +## Created: ??? (TODO) +## +## ChangeLogs: +## v2.1, 2015/02/13, Weitian LI +## * added '1' to denominators when calculate STN to avoid division by zero +## * added script description +## v2.0, 2013/03/06, Weitian LI +## * added the parameter `-t' to print STN results for testing +## + +UPDATED="2015/02/13" # minimal counts CNT_MIN=50 + # energy: 700-7000eV -- channel 49:479 CH_LOW=49 CH_HI=479 + # energy 9.5-12keV -- channel 651:822 CH_BKG_LOW=651 CH_BKG_HI=822 + if [ $# -lt 6 ]; then printf "usage:\n" printf " `basename $0` \n" @@ -57,6 +79,7 @@ X=$3 Y=$4 BKGSPC=$5 REG_OUT=$6 + [ -f "${REG_OUT}" ] && mv -fv ${REG_OUT} ${REG_OUT}_bak echo "EVT: ${EVT}" echo "EVT_E: ${EVT_E}" @@ -117,10 +140,11 @@ while [ `echo "${STN} > 1.5" | bc -l` -eq 1 ]; do COUNT_SRC=`dmstat "${TMP_SPC}[channel=${CH_LOW}:${CH_HI}][cols counts]" | grep "sum:" | awk '{print $2}'` COUNT_BKG=`dmstat "${BKGSPC}[channel=${CH_LOW}:${CH_HI}][cols counts]" | grep "sum:" | awk '{print $2}'` - # echo "CNT_SRC: ${COUNT_SRC}, IDX_SRC: ${INDEX_SRC}, CNT_BKG: ${COUNT_BKG}, IDX_BKG: ${INDEX_BKG}" - # exit + #echo "CNT_SRC: ${COUNT_SRC}, IDX_SRC: ${INDEX_SRC}, CNT_BKG: ${COUNT_BKG}, IDX_BKG: ${INDEX_BKG}" + #exit 99 - STN=`echo ${COUNT_SRC} ${INDEX_SRC} ${COUNT_BKG} ${INDEX_BKG} | awk '{ printf("%f",$1/$2/$3*$4) }'` + # Add '1' to the denominators to avoid division by zero. + STN=`echo ${COUNT_SRC} ${INDEX_SRC} ${COUNT_BKG} ${INDEX_BKG} | awk '{ printf("%f", ($1 / ($2 + 1)) / ($3 / ($4 + 1))) }'` CNT=`dmlist "${EVT_E}[sky=${TMP_REG}]" blocks | grep 'EVENTS' | awk '{ print $8 }'` echo "CNT: ${CNT}" echo "CNT_MIN: ${CNT_MIN}" -- cgit v1.2.2