diff options
author | Weitian LI <liweitianux@gmail.com> | 2014-06-24 15:30:24 +0800 |
---|---|---|
committer | Weitian LI <liweitianux@gmail.com> | 2014-06-24 15:30:24 +0800 |
commit | f65dcae0b995c26fceba31a5ca30a988a4eb02b1 (patch) | |
tree | 89fc2e722b91d66c0a25612db914ddd480446587 /scripts | |
parent | e3923265d0d6949407a83726e9a9bd5d97079221 (diff) | |
download | chandra-acis-analysis-f65dcae0b995c26fceba31a5ca30a988a4eb02b1.tar.bz2 |
Updated scripts and added some files
* Updated 'ciao_calc_csb.sh', 'ciao_calc_ct.sh'
* Added 'make_infojson.sh' for wjy's data
* Added some files:
- fitting_mass.conf
- fitting_sbp.conf
- wang2012_param.txt
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/ciao_calc_csb.sh | 41 | ||||
-rwxr-xr-x | scripts/ciao_calc_ct.sh | 27 | ||||
-rwxr-xr-x | scripts/ciao_r500avgt_v3.sh | 26 | ||||
-rwxr-xr-x | scripts/make_infojson.sh | 157 |
4 files changed, 205 insertions, 46 deletions
diff --git a/scripts/ciao_calc_csb.sh b/scripts/ciao_calc_csb.sh index 92741b1..c50c908 100755 --- a/scripts/ciao_calc_csb.sh +++ b/scripts/ciao_calc_csb.sh @@ -21,16 +21,6 @@ ERR_Z=21 ERR_CNT=22 ## }}} -## cosmology claculator {{{ -## write the path of cosmo claculator here -BASE_PATH=`dirname $0` -COSMO_CALC=`which cosmo_calc` -if [ -z "${COSMO_CALC}" ] || [ ! -x ${COSMO_CALC} ] ; then - printf "ERROR: ${COSMO_CALC} neither executable nor specified\n" - exit ${ERR_CALC} -fi -## }}} - ## usage, help {{{ case "$1" in -[hH]*|--[hH]*) @@ -42,6 +32,16 @@ case "$1" in esac ## usage, help }}} +## cosmology claculator {{{ +## write the path of cosmo claculator here +BASE_PATH=`dirname $0` +COSMO_CALC="`which cosmo_calc calc_distance 2>/dev/null | head -n 1`" +if [ -z "${COSMO_CALC}" ] || [ ! -x ${COSMO_CALC} ] ; then + printf "ERROR: ${COSMO_CALC} neither executable nor specified\n" + exit ${ERR_CALC} +fi +## }}} + ## default parameters {{{ # default basedir relative to 'spc/profile' DFT_BASEDIR="../.." @@ -81,13 +81,13 @@ getopt_keyval() { getopt_keyval "$@" # basedir -if [ -d "${basedir}" ] && ls ${basedir}/*repro_evt2.fits > /dev/null 2>&1; then +if [ -d "${basedir}" ]; then BASEDIR=${basedir} -elif [ -d "${DFT_BASEDIR}" ] && ls ${DFT_BASEDIR}/*repro_evt2.fits > /dev/null 2>&1; then +elif [ -d "${DFT_BASEDIR}" ]; then BASEDIR=${DFT_BASEDIR} else read -p "> basedir (contains info json): " BASEDIR - if [ ! -d "${BASEDIR}" ] || ! ls ${BASEDIR}/*repro_evt2.fits >/dev/null 2>&1; then + if [ ! -d "${BASEDIR}" ]; then printf "ERROR: given \`${BASEDIR}' invalid!\n" exit ${ERR_DIR} fi @@ -159,7 +159,7 @@ Z=`grep -i '"redshift"' ${JSON_FILE} | awk -F':' '{ print $2 }' | tr -d ' ,'` R500=`grep '"R500.*kpc' ${JSON_FILE} | awk -F':' '{ print $2 }' | tr -d ' ,'` OBS_ID=`grep '"Obs.*ID' ${JSON_FILE} | awk -F':' '{ print $2 }' | tr -d ' ,'` OBJ_NAME=`grep '"Source\ Name' ${JSON_FILE} | awk -F':' '{ print $2 }' | sed -e 's/\ *"//' -e 's/"\ *,$//'` -CT=`grep '"Cooling_time' ${JSON_FILE} | awk -F':' '{ print $2 }' | tr -d ' ,'` +#CT=`grep '"Cooling_time' ${JSON_FILE} | awk -F':' '{ print $2 }' | tr -d ' ,'` cd ${IMG_DIR} printf "entered img directory\n" @@ -172,8 +172,9 @@ 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 }'` -RC_PIX=`echo "scale=2; 0.048 * ${R500} / ${KPC_PER_PIXEL}" | bc -l` +#KPC_PER_PIX=`${COSMO_CALC} ${Z} | grep 'kpc/pixel' | awk '{ print $3 }'` +KPC_PER_PIX=`${COSMO_CALC} ${Z} | grep 'kpc.*pix' | tr -d 'a-zA-Z_#=(),:/ '` +RC_PIX=`echo "scale=2; 0.048 * ${R500} / ${KPC_PER_PIX}" | bc -l` # test counts_in_0.048R500<500? RC_REG="pie(${X},${Y},0,${RC_PIX},0,360)" punlearn dmlist @@ -189,8 +190,8 @@ fi TMP_REG="_tmp_csb.reg" TMP_S="_tmp_csb.fits" -R1=`echo "scale=2; 40 / ${KPC_PER_PIXEL}" | bc -l` -R2=`echo "scale=2; 400 / ${KPC_PER_PIXEL}" | bc -l` +R1=`echo "scale=2; 40 / ${KPC_PER_PIX}" | bc -l` +R2=`echo "scale=2; 400 / ${KPC_PER_PIX}" | bc -l` cat > ${TMP_REG} << _EOF_ pie(${X},${Y},0,${R1},0,360) pie(${X},${Y},0,${R2},0,360) @@ -227,8 +228,8 @@ printf "S1=${S1}, S2=${S2} (sur_flux)\n" | tee -a ${CSB_RES} printf "C_sb: ${CSB}\n" | tee -a ${CSB_RES} [ "x${F_WZ}" = "xtrue" ] && printf "${WZ}\n" | tee -a ${CSB_RES} [ "x${F_WC}" = "xtrue" ] && printf "${WC}\n" | tee -a ${CSB_RES} -printf "# OBS_ID,OBJ_NAME,Z,R500,RC_PIX,CNT_RC,CT,R1_PIX,R2_PIX,S1,S2,CSB,WZ,WC,WR\n" | tee -a ${CSB_RES} -printf "# $OBS_ID,$OBJ_NAME,$Z,$R500,$RC_PIX,$CNT_RC,$CT,$R1,$R2,$S1,$S2,$CSB,$WZ,$WC,$WR\n\n" | tee -a ${CSB_RES} +printf "# OBS_ID,OBJ_NAME,Z,R500,RC_PIX,CNT_RC,R1_PIX,R2_PIX,S1,S2,CSB,WZ,WC,WR\n" | tee -a ${CSB_RES} +printf "# $OBS_ID,$OBJ_NAME,$Z,$R500,$RC_PIX,$CNT_RC,$R1,$R2,$S1,$S2,$CSB,$WZ,$WC,$WR\n\n" | tee -a ${CSB_RES} ## main }}} exit 0 diff --git a/scripts/ciao_calc_ct.sh b/scripts/ciao_calc_ct.sh index 6fb1d79..926c785 100755 --- a/scripts/ciao_calc_ct.sh +++ b/scripts/ciao_calc_ct.sh @@ -19,18 +19,6 @@ export LC_COLLATE=C ## 2014/06/18: 'cooling_time2.sh' -> 'ciao_calc_ct.sh' ########################################################### -## 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`" -if [ -z "${COSCALC}" ] || [ ! -x ${COSCALC} ]; then - printf "ERROR: \`COSCALC: ${COSCALC}' neither specified nor executable\n" - exit 255 -fi -## }}} - ## about, used in `usage' {{{ VERSION="v1.1" UPDATE="2012-08-26" @@ -57,7 +45,7 @@ ERR_UNI=61 case "$1" in -[hH]*|--[hH]*) printf "usage:\n" - printf " `basename $0` evt=<evt2_clean> r500=<r500_kpc> regin=<input_reg> regout=<output_reg> bkgd=<blank_evt | lbkg_reg | bkg_spec> nh=<nH> z=<redshift> arf=<warf_file> rmf=<wrmf_file> [ grpcmd=<grppha_cmd> log=<log_file> ]\n" + printf " `basename $0` basedir=<repro_dir> evt=<evt2_clean> r500=<r500_kpc> regin=<input_reg> regout=<output_reg> bkgd=<blank_evt | lbkg_reg | bkg_spec> nh=<nH> z=<redshift> arf=<warf_file> rmf=<wrmf_file> [ grpcmd=<grppha_cmd> log=<log_file> ]\n" printf "\nversion:\n" printf "${VERSION}, ${UPDATE}\n" exit ${ERR_USG} @@ -65,6 +53,18 @@ case "$1" in esac ## usage, help }}} +## 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 2>/dev/null | head -n 1`" +if [ -z "${COSCALC}" ] || [ ! -x ${COSCALC} ]; then + printf "ERROR: \`COSCALC: ${COSCALC}' neither specified nor executable\n" + exit 255 +fi +## }}} + ## default parameters {{{ # default `event file' which used to match `blanksky' files #DFT_EVT="_NOT_EXIST_" @@ -208,6 +208,7 @@ if [ -d "${basedir}" ]; then else BASEDIR=${DFT_BASEDIR} fi +# json file if [ ! -z "${json}" ] && [ -r "${BASEDIR}/${json}" ]; then JSON_FILE="${BASEDIR}/${json}" elif [ `ls ${BASEDIR}/${DFT_JSON_PAT} 2> /dev/null | wc -l` -eq 1 ]; then diff --git a/scripts/ciao_r500avgt_v3.sh b/scripts/ciao_r500avgt_v3.sh index 3c9be08..9a8dffd 100755 --- a/scripts/ciao_r500avgt_v3.sh +++ b/scripts/ciao_r500avgt_v3.sh @@ -34,19 +34,6 @@ export LC_COLLATE=C ## modify for new process ########################################################### -## comology calculator {{{ -## XXX: MODIFY THIS TO YOUR OWN CASE -## and make sure this `calc' is executable -## NOTES: use `$HOME' instead of `~' in path -COSCALC="`which cosmo_calc calc_distance | head -n 1`" -# COSCALC="_path_to_calc_distance_" -# COSCALC="$HOME/bin/mass/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="v3.0" UPDATE="2013-02-09" @@ -82,6 +69,19 @@ case "$1" in esac ## usage, help }}} +## comology calculator {{{ +## XXX: MODIFY THIS TO YOUR OWN CASE +## and make sure this `calc' is executable +## NOTES: use `$HOME' instead of `~' in path +COSCALC="`which cosmo_calc calc_distance 2>/dev/null | head -n 1`" +# COSCALC="_path_to_calc_distance_" +# COSCALC="$HOME/bin/mass/calc_distance" +if [ -z "${COSCALC}" ] || [ ! -x ${COSCALC} ]; then + printf "ERROR: \`COSCALC: ${COSCALC}' neither specified nor executable\n" + exit 255 +fi +## }}} + ## default parameters {{{ # default `event file' which used to match `blanksky' files #DFT_EVT="_NOT_EXIST_" diff --git a/scripts/make_infojson.sh b/scripts/make_infojson.sh new file mode 100755 index 0000000..34f9f7c --- /dev/null +++ b/scripts/make_infojson.sh @@ -0,0 +1,157 @@ +#!/bin/sh +# +# This script is used to make a bare '_INFO.json' file +# placed under directory 'repro/', +# thus scripts 'ciao_calc_ct.sh' and 'ciao_calc_csb.sh' +# can get required information from this file. +# +# Run this script in directory 'repro/'. +# +# Weitian LI <liweitianux@gmail.com> +# 2014/06/24 +# + +## usage, help {{{ +case "$1" in + -[hH]*|--[hH]*) + printf "usage:\n" + printf " `basename $0` evtdir=<evt_dir> spcdir=<spc_dir> imgdir=<img_dir> massdir=<mass_dir> json=<info_json>\n" + printf "NOTE: run this script in dir 'repro/'\n" + exit 1 + ;; +esac +## usage, help }}} + +## default parameters {{{ +# basedir: . (run this script under basedir) +BASEDIR=`pwd -P` +# +## directory structure of wjy's data +# default evtdir relative to 'basedir' +DFT_EVTDIR="../evt2/evt" +# default spcdir relative to 'basedir' +DFT_SPCDIR="../evt2/spc/profile" +# default imgdir relative to 'basedir' +DFT_IMGDIR="../evt2/img" +# default massdir relative to 'basedir' +DFT_MASSDIR="../evt2/mass" +## }}} + +## functions {{{ +# process commandline arguments +# cmdline arg format: `KEY=VALUE' +getopt_keyval() { + until [ -z "$1" ] + do + key=${1%%=*} # extract key + val=${1#*=} # extract value + keyval="${key}=\"${val}\"" + echo "## getopt: eval '${keyval}'" + eval ${keyval} + shift # shift, process next one + done +} +## functions }}} + +## parameters {{{ +# process cmdline args using `getopt_keyval' +getopt_keyval "$@" + +# evt dir +if [ ! -z "${evtdir}" ] && [ -d "${BASEDIR}/${evtdir}" ]; then + EVT_DIR=`( cd ${BASEDIR}/${evtdir} && pwd -P )` +elif [ -d "${BASEDIR}/${DFT_EVTDIR}" ]; then + EVT_DIR=`( cd ${BASEDIR}/${DFT_EVTDIR} && pwd -P )` +else + read -p "> evt dir (relative to basedir): " EVT_DIR + if [ ! -d "${BASEDIR}/${EVT_DIR}" ]; then + printf "ERROR: given \`${EVT_DIR}' invalid\n" + exit 20 + else + EVT_DIR="${BASEDIR}/${EVT_DIR}" + fi +fi +printf "## use evtdir: \`${EVT_DIR}'\n" + +# spc dir +if [ ! -z "${spcdir}" ] && [ -d "${BASEDIR}/${spcdir}" ]; then + SPC_DIR=`( cd ${BASEDIR}/${spcdir} && pwd -P )` +elif [ -d "${BASEDIR}/${DFT_SPCDIR}" ]; then + SPC_DIR=`( cd ${BASEDIR}/${DFT_SPCDIR} && pwd -P )` +else + read -p "> spc dir (relative to basedir): " SPC_DIR + if [ ! -d "${BASEDIR}/${SPC_DIR}" ]; then + printf "ERROR: given \`${SPC_DIR}' invalid\n" + exit 21 + else + SPC_DIR="${BASEDIR}/${SPC_DIR}" + fi +fi +printf "## use spcdir: \`${SPC_DIR}'\n" + +# img dir +if [ ! -z "${imgdir}" ] && [ -d "${BASEDIR}/${imgdir}" ]; then + IMG_DIR=`( cd ${BASEDIR}/${imgdir} && pwd -P )` +elif [ -d "${BASEDIR}/${DFT_IMGDIR}" ]; then + IMG_DIR=`( cd ${BASEDIR}/${DFT_IMGDIR} && pwd -P )` +else + read -p "> img dir (relative to basedir): " IMG_DIR + if [ ! -d "${BASEDIR}/${IMG_DIR}" ]; then + printf "ERROR: given \`${IMG_DIR}' invalid\n" + exit 22 + else + IMG_DIR="${BASEDIR}/${IMG_DIR}" + fi +fi +printf "## use imgdir: \`${IMG_DIR}'\n" + +# mass dir +if [ ! -z "${massdir}" ] && [ -d "${BASEDIR}/${massdir}" ]; then + MASS_DIR=`( cd ${BASEDIR}/${massdir} && pwd -P )` +elif [ -d "${BASEDIR}/${DFT_MASSDIR}" ]; then + MASS_DIR=`( cd ${BASEDIR}/${DFT_MASSDIR} && pwd -P )` +else + read -p "> mass dir (relative to basedir): " MASS_DIR + if [ ! -d "${BASEDIR}/${MASS_DIR}" ]; then + printf "ERROR: given \`${MASS_DIR}' invalid\n" + exit 22 + else + MASS_DIR="${BASEDIR}/${MASS_DIR}" + fi +fi +printf "## use massdir: \`${MASS_DIR}'\n" +## }}} + +# set files +EVT2_CLEAN=`readlink -f ${EVT_DIR}/evt2*_clean*.fits | head -n 1` +MASS_SBP_CFG=`readlink -f ${MASS_DIR}/source.cfg` +MASS_RES=`readlink -f ${MASS_DIR}/final_result*.txt` +SPC_CFG=`readlink -f ${IMG_DIR}/spc_fit.cfg` + +# get needed data +punlearn dmkeypar +OBSID=`dmkeypar "${EVT2_CLEAN}" OBS_ID echo=yes` +NAME=`dmkeypar "${EVT2_CLEAN}" OBJECT echo=yes` +Z=`grep -E '^z\s+' ${MASS_SBP_CFG} | awk '{ print $2 }'` +NH=`grep -E '^nh\s+' ${SPC_CFG} | awk '{ print $2 }'` +R500=`grep -E '^r500=' ${MASS_RES} | awk '{ print $2 }'` + +# generate info json file +if [ ! -z "${json}" ]; then + JSON_FILE="${json}" +else + JSON_FILE="oi${OBSID}_INFO.json" +fi +printf "## info json_filename: \`${JSON_FILE}'\n" + +cat > ${JSON_FILE} << _EOF_ +{ + "Obs. ID": ${OBSID}, + "Source Name": "${NAME}", + "nH (10^22 cm^-2)": ${NH}, + "redshift": ${Z}, + "R500 (kpc)": ${R500}, + "Comment": "Bare info json file created by `basename $0`" +}, +_EOF_ + |