Commits

Tom Roche committed 84a813e

drivers allow user to override "included" regrid_utils

GEIA_driver still clones regrid_utils if not already present, but only
* uses helpers in current directory=$WORK_DIR/
* pulls helpers from $WORK_DIR/regrid_utils/ to $WORK_DIR if not already present in latter

uber_driver::file copies helpers from $WORK_DIR/ instead of $WORK_DIR/regrid_utils/ thus respecting user edits.

This allows user to make changes to regrid_utils, which s/he probably must for bash_utilities. Also:

* check_conservation.ncl, retemp_reunit.ncl do NCL::load using env var.

Tested on terrae/EMVL from 'uber_driver.sh' in fresh terminal.

TODO:
* all regrids: how to nudge off/onshore as required? e.g., soil or burning emissions should never be offshore, marine emissions should never be onshore.
* all regrid maps: add Caribbean islands (esp Bahamas! for offshore burning), Canadian provinces, Mexican states
* test on
** tlrPanP5 (which now has R package=ncdf4, but readAsciiTable of input .txt's is very slow compared to terrae)
** HPCC (once problem with ncdf4 on amad1 is debugged: in process with JOB and KMF)

  • Participants
  • Parent commits 62f9d9f

Comments (0)

Files changed (4)

File GEIA_driver.sh

 # A top-level driver for creating an inventory of marine N2O emissions over the AQMEII-NA domain from the GEIA global inventory.
 # Converts GEIA marine N2O emissions in native format, spatiotemporality, and units to netCDF over AQMEII in CMAQ-preferred units.
 
-# See https://bitbucket.org/tlroche/aqmeii_ag_soil
+# See https://bitbucket.org/tlroche/geia_regrid
 
 # Expects to run on linux. Utility dependencies include:
 
 # * ultimately
 
 # ** basename, dirname
+# ** cp
 # ** unzip
 # ** curl or wget (latter {preferred, coded} for ability to deal with redirects)
 # ** ncdump
 export REGRID_UTILS_FP="${WORK_DIR}/${REGRID_UTILS_PN}" # folder, not file
 
 export BASH_UTILS_FN='bash_utilities.sh'
-export BASH_UTILS_FP="${REGRID_UTILS_FP}/${BASH_UTILS_FN}"
+# export BASH_UTILS_FP="${REGRID_UTILS_FP}/${BASH_UTILS_FN}"
+# no, allow user to override repo code: see `get_bash_utils`
+export BASH_UTILS_FP="${WORK_DIR}/${BASH_UTILS_FN}"
 
 export PLOT_FUNCS_FN='plotLayersForTimestep.r'
-export PLOT_FUNCS_FP="${REGRID_UTILS_FP}/${PLOT_FUNCS_FN}"
+export PLOT_FUNCS_FP="${WORK_DIR}/${PLOT_FUNCS_FN}"
 
 export STATS_FUNCS_FN='netCDF.stats.to.stdout.r'
-export STATS_FUNCS_FP="${REGRID_UTILS_FP}/${STATS_FUNCS_FN}"
+export STATS_FUNCS_FP="${WORK_DIR}/${STATS_FUNCS_FN}"
 
 export SUMMARIZE_FUNCS_FN='summarize.ncl'
-export SUMMARIZE_FUNCS_FP="${REGRID_UTILS_FP}/${SUMMARIZE_FUNCS_FN}"
+export SUMMARIZE_FUNCS_FP="${WORK_DIR}/${SUMMARIZE_FUNCS_FN}"
 
 export TIME_FUNCS_FN='time.ncl'
-export TIME_FUNCS_FP="${REGRID_UTILS_FP}/${TIME_FUNCS_FN}"
+export TIME_FUNCS_FP="${WORK_DIR}/${TIME_FUNCS_FN}"
 
 export VIS_FUNCS_FN='visualization.r'
-export VIS_FUNCS_FP="${REGRID_UTILS_FP}/${VIS_FUNCS_FN}"
+export VIS_FUNCS_FP="${WORK_DIR}/${VIS_FUNCS_FN}"
 
 ## Raw input data
 
     'get_stats_funcs' \
     'get_summarize_funcs' \
     'get_time_funcs' \
-    'get_vis_funcs' \
     'get_reformat' \
     'get_regrid' \
     'get_retemp' \
 #   fi
 } # end function get_geia_regrid
 
-# isa regrid_utils
+# isa regrid_utils from https://bitbucket.org/tlroche/regrid_utils
+# To override, copy/mod to ${BASH_UTILS_FP} before running this script.
 function get_bash_utils {
   if [[ -z "${BASH_UTILS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: BASH_UTILS_FP not defined"
     exit 18
   fi
   if [[ ! -r "${BASH_UTILS_FP}" ]] ; then
+    # copy from downloaded regrid_utils
+    for CMD in \
+      "cp ${REGRID_UTILS_FP}/${BASH_UTILS_FN} ${BASH_UTILS_FP}" \
+    ; do
+      echo -e "$ ${CMD}"
+      eval "${CMD}"
+    done
+  fi
+  if [[ ! -r "${BASH_UTILS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: BASH_UTILS_FP=='${BASH_UTILS_FP}' not readable"
     exit 19
   fi
   # ... for its functions to be available later in this script
 } # end function get_bash_utils
 
-# isa regrid_utils
+# isa regrid_utils from https://bitbucket.org/tlroche/regrid_utils
+# To override, copy/mod to ${PLOT_FUNCS_FP} before running this script.
 function get_plot_funcs {
   if [[ -z "${PLOT_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: PLOT_FUNCS_FP not defined"
     exit 20
   fi
   if [[ ! -r "${PLOT_FUNCS_FP}" ]] ; then
+    # copy from downloaded regrid_utils
+    for CMD in \
+      "cp ${REGRID_UTILS_FP}/${PLOT_FUNCS_FN} ${PLOT_FUNCS_FP}" \
+    ; do
+      echo -e "$ ${CMD}"
+      eval "${CMD}"
+    done
+  fi
+  if [[ ! -r "${PLOT_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: PLOT_FUNCS_FP=='${PLOT_FUNCS_FP}' not readable"
     exit 21
   fi
 } # end function get_plot_funcs
 
-# isa regrid_utils
+# isa regrid_utils from https://bitbucket.org/tlroche/regrid_utils
+# To override, copy/mod to ${STATS_FUNCS_FP} before running this script.
 function get_stats_funcs {
   if [[ -z "${STATS_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: STATS_FUNCS_FP not defined"
     exit 22
   fi
   if [[ ! -r "${STATS_FUNCS_FP}" ]] ; then
+    # copy from downloaded regrid_utils
+    for CMD in \
+      "cp ${REGRID_UTILS_FP}/${STATS_FUNCS_FN} ${STATS_FUNCS_FP}" \
+    ; do
+      echo -e "$ ${CMD}"
+      eval "${CMD}"
+    done
+  fi
+  if [[ ! -r "${STATS_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: STATS_FUNCS_FP=='${STATS_FUNCS_FP}' not readable"
     exit 23
   fi
 } # end function get_stats_funcs
 
-# isa regrid_utils
+# isa regrid_utils from https://bitbucket.org/tlroche/regrid_utils
+# To override, copy/mod to ${SUMMARIZE_FUNCS_FP} before running this script.
 function get_summarize_funcs {
   if [[ -z "${SUMMARIZE_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: SUMMARIZE_FUNCS_FP not defined"
     exit 24
   fi
   if [[ ! -r "${SUMMARIZE_FUNCS_FP}" ]] ; then
+    # copy from downloaded regrid_utils
+    for CMD in \
+      "cp ${REGRID_UTILS_FP}/${SUMMARIZE_FUNCS_FN} ${SUMMARIZE_FUNCS_FP}" \
+    ; do
+      echo -e "$ ${CMD}"
+      eval "${CMD}"
+    done
+  fi
+  if [[ ! -r "${SUMMARIZE_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: SUMMARIZE_FUNCS_FP=='${SUMMARIZE_FUNCS_FP}' not readable"
     exit 25
   fi
 } # end function get_summarize_funcs
 
-# isa regrid_utils
+# isa regrid_utils from https://bitbucket.org/tlroche/regrid_utils
+# To override, copy/mod to ${TIME_FUNCS_FP} before running this script.
 function get_time_funcs {
   if [[ -z "${TIME_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: TIME_FUNCS_FP not defined"
     exit 26
   fi
   if [[ ! -r "${TIME_FUNCS_FP}" ]] ; then
+    # copy from downloaded regrid_utils
+    for CMD in \
+      "cp ${REGRID_UTILS_FP}/${TIME_FUNCS_FN} ${TIME_FUNCS_FP}" \
+    ; do
+      echo -e "$ ${CMD}"
+      eval "${CMD}"
+    done
+  fi
+  if [[ ! -r "${TIME_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: TIME_FUNCS_FP=='${TIME_FUNCS_FP}' not readable"
     exit 27
   fi
 } # end function get_time_funcs
 
-# isa regrid_utils
-function get_vis_funcs {
-  if [[ -z "${VIS_FUNCS_FP}" ]] ; then
-    echo -e "${THIS_FN}: ERROR: VIS_FUNCS_FP not defined"
-    exit 28
-  fi
-  if [[ ! -r "${VIS_FUNCS_FP}" ]] ; then
-    echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: VIS_FUNCS_FP=='${VIS_FUNCS_FP}' not readable"
-    exit 29
-  fi
-} # end function get_vis_funcs
+# # isa regrid_utils from https://bitbucket.org/tlroche/regrid_utils
+# # To override, copy/mod to ${VIS_FUNCS_FP} before running this script.
+# function get_vis_funcs {
+#   if [[ -z "${VIS_FUNCS_FP}" ]] ; then
+#     echo -e "${THIS_FN}: ERROR: VIS_FUNCS_FP not defined"
+#     exit 28
+#   fi
+#   if [[ ! -r "${VIS_FUNCS_FP}" ]] ; then
+#     # copy from downloaded regrid_utils
+#     for CMD in \
+#       "cp ${REGRID_UTILS_FP}/${VIS_FUNCS_FN} ${VIS_FUNCS_FP}" \
+#     ; do
+#       echo -e "$ ${CMD}"
+#       eval "${CMD}"
+#     done
+#   fi
+#   if [[ ! -r "${VIS_FUNCS_FP}" ]] ; then
+#     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: VIS_FUNCS_FP=='${VIS_FUNCS_FP}' not readable"
+#     exit 29
+#   fi
+# } # end function get_vis_funcs
 
 function get_reformat {
   if [[ -z "${CALL_REFORMAT_FP}" ]] ; then

File check_conservation.ncl

 ; print(time_fp)
 ; print(tostring(time_fp))
 ; load tostring(time_fp)+""
-load "./time.ncl"
+load "$TIME_FUNCS_FP"
 
 ; If len < 0, blanks pad before `str`.
 ; If len > 0, blanks pad after `str`.

File retemp_reunit.ncl

 ;----------------------------------------------------------------------
 
 ; can't call `getenv` before `begin`?
-load "./summarize.ncl"
-load "./time.ncl"
+load "$SUMMARIZE_FUNCS_FP"
+load "$TIME_FUNCS_FP"
 
 ;----------------------------------------------------------------------
 ; code

File uber_driver.sh

 
 # if [[ "${ACCESS}" == 'file' ]], you'll need
 FILE_LIST="./${DRIVER_FN} \
-    ./regrid_utils/* \
+    ./bash_utilities.sh \
+    ./netCDF.stats.to.stdout.r \
+    ./plotLayersForTimestep.r \
+    ./summarize.ncl \
+    ./time.ncl \
     ./check_conservation.ncl \
     ./reformat_GEIA_to_netCDF.r \
     ./regrid_global_to_AQMEII.r \