compare_time-series.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #!/usr/bin/env bash
  2. #==============================================================
  3. #
  4. # B A R A K U D A
  5. #
  6. # An OCEAN MONITORING python environment for NEMO
  7. #
  8. # L. Brodeau, 2009-2017
  9. #
  10. #===============================================================
  11. export script=compare_time-series
  12. [ -z ${BARAKUDA_ROOT+x} ] && export BARAKUDA_ROOT=${PWD}
  13. export FIG_FORMAT='png'
  14. #export FIG_FORMAT='svg'
  15. # Supported ORCA grids:
  16. ORCA_LIST="ORCA025.L75 ORCA1.L75 ORCA1.L46 ORCA1.L42 ORCA2 ORCA2_L46"
  17. # Display available configs:
  18. list_conf="`\ls ${BARAKUDA_ROOT}/configs/config_*.sh | sed -e "s|${BARAKUDA_ROOT}/configs\/config_||g" -e s/'.sh'/''/g`"
  19. # User configs, potentially in the directory from which barakuda.sh is called:
  20. list_conf+=" `\ls ./config_*.sh 2>/dev/null | sed -e "s|.\/config_||g" -e s/'.sh'/''/g`"
  21. # Important bash functions:
  22. . ${BARAKUDA_ROOT}/src/bash/bash_functions.bash
  23. usage()
  24. {
  25. echo
  26. echo "USAGE: ${0} -C <config> -R <exp1,exp2,...,expN> (options)"
  27. echo
  28. echo " Available configs are:"
  29. for cc in ${list_conf}; do
  30. echo " * ${cc}"
  31. done
  32. echo
  33. echo " OPTIONS:"
  34. echo " -y <YYYY> => force initial year to YYYY"
  35. echo
  36. echo " -O <cnfg1,cnfg2,...,cnfgN> => list of ORCA configs corresponding to"
  37. echo " <exp1,exp2,...,expN> in case they are"
  38. echo " not all on the same ORCA grid"
  39. echo
  40. # echo " -c <exp> => 2D comparison diagnostics are performed against exp <exp>"
  41. # echo " instead of a climatology"
  42. # echo
  43. echo " -f => forces creation of diagnostic page eventhough treatment "
  44. echo " of output files is not finished"
  45. echo
  46. echo " -e => create the HTML diagnostics page on local or remote server"
  47. echo
  48. echo " -h => print this message"
  49. echo
  50. exit
  51. }
  52. CEXPS="" ; # list of experiments separated by ","
  53. CORCS="" ; # corresponding list of ORCA configs in case CEXPS are not on the same ORCA grid!!!
  54. YEAR0="" ; iforcey0=0
  55. IPREPHTML=0
  56. IFORCENEW=0
  57. while getopts C:R:O:y:feh option ; do
  58. case $option in
  59. C) CONFIG=${OPTARG};;
  60. R) CEXPS=${OPTARG};;
  61. O) CORCS=${OPTARG};;
  62. y) YEAR0=${OPTARG} ; iforcey0=1 ;;
  63. f) IFORCENEW=1;;
  64. e) IPREPHTML=1;;
  65. h) usage;;
  66. \?) usage ;;
  67. esac
  68. done
  69. if [ -z ${CONFIG} ] || [ -z ${CEXPS} ]; then usage ; exit ; fi
  70. for og in ${ORCA_LIST}; do
  71. ca=""; ca=`echo ${CONFIG} | grep ${og}` ; if [ "${ca}" != "" ]; then ORCA=${og}; fi
  72. done
  73. if [ -z ${ORCA} ]; then echo "ORCA grid of config ${CONFIG} not supported yet"; exit; fi
  74. echo
  75. if [ -f ./config_${CONFIG}.sh ]; then
  76. # sourcing local configuration file if present:
  77. fconfig=./config_${CONFIG}.sh
  78. else
  79. # sourcing barakuda-distribution configuration file:
  80. fconfig=${BARAKUDA_ROOT}/configs/config_${CONFIG}.sh
  81. fi
  82. if [ -f ${fconfig} ]; then
  83. echo "Sourcing configuration file: ${fconfig} !"
  84. . ${fconfig}
  85. else
  86. echo "PROBLEM: cannot find file ${fconfig} !"; exit
  87. fi
  88. echo
  89. LEXPS=`echo ${CEXPS} | sed -e s/'\,'/'\ '/g -e s/'\, '/'\ '/g`
  90. echo; echo "Experiments to be treated: ${LEXPS}"
  91. nbr=`echo ${LEXPS} | wc -w` ; echo " => number of experiments to compare = ${nbr}"
  92. if [ "${CORCS}" = "" ]; then
  93. if [ ! "${ORCA}" = "${CONF}" ]; then echo "ERROR: ORCA and CONF disagree! => ${ORCA} ${CONF}"; exit; fi
  94. export ORCA=${CONF}
  95. else
  96. LORCS=`echo ${CORCS} | sed -e s/'\,'/'\ '/g -e s/'\, '/'\ '/g`
  97. fi
  98. # Should be set from bash_fucntions:
  99. PYTH="${PYTHON_HOME}/bin/python -W ignore" ; # which Python installation to use
  100. export PYTHONPATH=${PYTHON_HOME}/lib/python2.7/site-packages:${BARAKUDA_ROOT}/python/modules ; # PATH to python barakuda modules
  101. PYBRKD_EXEC_PATH=${BARAKUDA_ROOT}/python/exec ; # PATH to python barakuda executable
  102. #-------------------
  103. echo " NEMO grid = ${ORCA}";
  104. echo " reading config into: ${fconfig}"
  105. echo; echo
  106. #NEXPS="${ORCA}-`echo ${LEXPS} | sed -e 's/\ /_/g'`"
  107. NEXPS="`echo ${LEXPS} | sed -e 's/\ /_/g'`"
  108. echo " Label to be used: ${NEXPS}" ; echo
  109. BASE_NAME="comp_${NEXPS}"
  110. DIAG_COMP_DIR=${DIAG_DIR}/${BASE_NAME} ; rm -rf ${DIAG_COMP_DIR} ; mkdir -p ${DIAG_COMP_DIR}
  111. YEAR_INI=4000
  112. YEAR_END=0
  113. # just that they become arrays...
  114. VEXPS=( ${LEXPS} ) ; VCONFEXPS=( ${LEXPS} ) ; VDIAGS=( ${LEXPS} ) ;
  115. if [ "${CORCS}" = "" ]; then
  116. VORCS=( ${LEXPS} )
  117. else
  118. VORCS=( ${LORCS} )
  119. fi
  120. jr=0
  121. for exp in ${LEXPS}; do
  122. echo; echo " EXP ${exp} "
  123. EXP="${exp}"
  124. echo " => ORCA = ${ORCA}"
  125. if [ "${CORCS}" = "" ]; then
  126. VORCS[${jr}]=${ORCA}
  127. fi
  128. CONFEXP=${VORCS[${jr}]}-${EXP}
  129. echo " => CONFEXP = ${CONFEXP}"
  130. VCONFEXPS[${jr}]=${CONFEXP}
  131. DIAG_D="${DIAG_DIR}/${CONFEXP}"
  132. VDIAGS[${jr}]=${DIAG_D}
  133. echo " => DIAG_D = ${DIAG_D} "; echo ; echo
  134. if [ ! -d ${DIAG_D} ]; then
  135. echo "PROBLEM: ${DIAG_D} does not exist!"
  136. echo " => you must run barakuda for ${exp} prior to comparison!"
  137. exit
  138. fi
  139. # Guessing initial and last year:
  140. check_if_file ${DIAG_D}/first_year.info
  141. iy=`cat ${DIAG_D}/first_year.info`
  142. if [ ${iy} -lt ${YEAR_INI} ]; then export YEAR_INI=${iy}; fi
  143. check_if_file ${DIAG_D}/last_year_done.info
  144. iy=`cat ${DIAG_D}/last_year_done.info`
  145. if [ ${iy} -gt ${YEAR_END} ]; then export YEAR_END=${iy}; fi
  146. ((jr++))
  147. done
  148. echo
  149. echo " Global YEAR_INI = ${YEAR_INI}"
  150. echo " Global YEAR_END = ${YEAR_END}"
  151. echo
  152. #echo " VEXPS => ${VEXPS[*]} "
  153. #echo " VORCS => ${VORCS[*]} "
  154. #echo " VCONFEXPS => ${VCONFEXPS[*]} "
  155. #echo " VDIAGS => ${VDIAGS[*]} "
  156. export LIST_EXPS=${LEXPS}
  157. export LIST_CONF=${VORCS[*]}
  158. echo
  159. echo "LIST_EXPS = ${LIST_EXPS}"
  160. echo "LIST_CONF = ${LIST_CONF}"
  161. echo
  162. cd ${DIAG_COMP_DIR}/
  163. ${PYTH} ${PYBRKD_EXEC_PATH}/compare_time_series.py ${YEAR_INI} ${YEAR_END}
  164. # Starting to configure HTML index file:
  165. if [ "${EXTRA_CONF}" = "" ]; then echo "Problem, variable EXTRA_CONF is not set!" ; exit; fi
  166. TITLE="Ocean diagnostics<br>Comparison of experiments: \"${VEXPS[*]}\"<br>Configurations: \"${LIST_CONF}\""
  167. #if [ ${ece_exp} -gt 0 ]; then TITLE="${TITLE}<br>Atmospheric model: ${ATMO_INFO}"; fi
  168. export CONFEXP="Comparison"
  169. . ${BARAKUDA_ROOT}/src/bash/build_html.bash
  170. parse_html ${BARAKUDA_ROOT}/src/html/conf_start.html index.html
  171. list_figs=`\ls -v *.${FIG_FORMAT}`
  172. for ff in ${list_figs}; do
  173. echo "<br><br><big> `echo ${ff} | sed -e s/.${FIG_FORMAT}//g -e s/_comparison//g` </big><br>" >> index.html
  174. echo " <img style=\"border: 0px solid\" alt=\"\" src=\"${ff}\"> <br>" >> index.html
  175. done
  176. cat ${BARAKUDA_ROOT}/src/html/conf_end.html >> index.html ; # Closing HTML file...
  177. cp ${BARAKUDA_ROOT}/src/html/conf_*.html .
  178. if [ ${ece_exp} -eq 0 ]; then
  179. cp ${BARAKUDA_ROOT}/src/html/logo.*g .
  180. else
  181. cp ${BARAKUDA_ROOT}/src/html/logo_ece.svg ./logo.svg
  182. cp ${BARAKUDA_ROOT}/src/html/logo_ece.png ./logo.png
  183. fi
  184. echo; echo
  185. if [ ${ihttp} -eq 0 ]; then
  186. echo "Diagnostic page installed in `pwd`"
  187. echo " => view this directory with a web browser (index.html)..."
  188. else
  189. ssh ${RUSER}@${RHOST} "mkdir -p ${RWWWD}"
  190. if [ ${ihttp} -eq 1 ]; then
  191. echo "Preparing to export to remote host!"; echo
  192. cd ../
  193. tar cvf ${BASE_NAME}.tar ${BASE_NAME}
  194. scp ${BASE_NAME}.tar ${RUSER}@${RHOST}:${RWWWD}/
  195. ssh ${RUSER}@${RHOST} "cd ${RWWWD}/; rm -rf ${BASE_NAME}; tar xf ${BASE_NAME}.tar 2>/dev/null; rm -f ${BASE_NAME}.tar; chmod -R a+r ${BASE_NAME}"
  196. rm -f ${BASE_NAME}.tar
  197. echo; echo
  198. echo "Diagnostic page installed on remote host ${RHOST} in ${RWWWD}/${BASE_NAME}!"
  199. echo "( Also browsable on local host in `pwd`/${BASE_NAME} )"
  200. else
  201. echo "Error: \"ihttp\" is either 0 or 1 !"
  202. fi
  203. fi
  204. rm -rf ${COMP_DIR}
  205. echo; echo