|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Author: Jordan Schnell, CIRES/NOAA GSL |
| 4 | +# |
| 5 | +# This script prepares the emissions for an MPAS Aerosols simulation based on |
| 6 | +# user selections/task name, MPAS domain, and time period. |
| 7 | +# |
| 8 | +# The script first checks to see if emissions are already available |
| 9 | +# (regridded for the domain and time period) and links to the ${DATA} (i.e., the main run directory) |
| 10 | +# If emissions are not available, the program attempts to create them. |
| 11 | +# |
| 12 | +## Required Input Arguments |
| 13 | +# |
| 14 | +# 1. EMIS_SECTOR_TO_PROCESS -- which emission sector is this task performing? (anthro, pollen, dust) |
| 15 | +# 2. ANTHRO_EMISINV -- undecided, may merge for custom dataset, or leave option to combine |
| 16 | +# 3. DATADIR_CHEM -- location of interpolated files, ready to be used |
| 17 | +# 4. MESH_NAME -- name of the MPAS domain, required to know if we have weights or data intepolated to the domain |
| 18 | +# 5. FCST_LENGTH -- nhours of forecast |
| 19 | +# |
| 20 | +# shellcheck disable=SC1091,SC2153,SC2154,SC2034 |
| 21 | +declare -rx PS4='+ $(basename ${BASH_SOURCE[0]:-${FUNCNAME[0]:-"Unknown"}})[${LINENO}]: ' |
| 22 | +set -x |
| 23 | +nt=${SLURM_NTASKS} |
| 24 | +cpreq=${cpreq:-cpreq} |
| 25 | +cd "${DATA}" || exit 1 |
| 26 | +# |
| 27 | +# ... Set some date variables |
| 28 | +# |
| 29 | +timestr=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%Y-%m-%d_%H.%M.%S) |
| 30 | +YYYY=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%Y) |
| 31 | +MM=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%m) |
| 32 | +DD=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%d) |
| 33 | +HH=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%H) |
| 34 | +DOW=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%u) # 1-7, Monday-Sunday |
| 35 | +# |
| 36 | +YYYY_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours" +%Y) |
| 37 | +MM_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours" +%m) |
| 38 | +DD_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours" +%d) |
| 39 | +HH_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours" +%H) |
| 40 | +DOW_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours " +%A) # 1-7, Monday-Sunday |
| 41 | +# |
| 42 | +YYYYp=$(date -d "${CDATE:0:8} ${CDATE:8:2} - 1 day" +%Y) |
| 43 | +MMp=$(date -d "${CDATE:0:8} ${CDATE:8:2} - 1 day" +%m) |
| 44 | +DDp=$(date -d "${CDATE:0:8} ${CDATE:8:2} - 1 day" +%d) |
| 45 | +HHp=$(date -d "${CDATE:0:8} ${CDATE:8:2}- 1 day" +%H) |
| 46 | +# |
| 47 | +current_day=$(date -d "${YYYY}${MM}${DD}") |
| 48 | +current_hh=$(date -d "${HH}" +"%H") |
| 49 | +# |
| 50 | +prev_hh=$(date -d "$current_hh -24 hour" +"%H") |
| 51 | +previous_day=$(date '+%C%y%m%d' -d "$current_day-1 days") |
| 52 | +previous_day="${previous_day} ${prev_hh}" |
| 53 | +# |
| 54 | +if [[ ${DOW} -le 5 ]]; then |
| 55 | + DOW_STRING=weekdy |
| 56 | +elif [[ ${DOW} -eq 6 ]]; then |
| 57 | + DOW_STRING=satdy |
| 58 | +else |
| 59 | + DOW_STRING=sundy |
| 60 | +fi |
| 61 | +if [[ ${DOW_END} -le 5 ]]; then |
| 62 | + DOW_END_STRING=weekdy |
| 63 | +elif [[ ${DOW_END} -eq 6 ]]; then |
| 64 | + DOW_END_STRING=satdy |
| 65 | +else |
| 66 | + DOW_END_STRING=sundy |
| 67 | +fi |
| 68 | +# |
| 69 | +MOY=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%B) # full month name (e.g., January) |
| 70 | +MOY_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours" +%B) # full month name (e.g., January) |
| 71 | +DOY=$(date -d "${CDATE:0:8} ${CDATE:8:2}" +%j) # Julian day |
| 72 | +# |
| 73 | +if [[ "${DOY}" -ne 0 ]]; then |
| 74 | + DOY_m1=$((DOY-1)) |
| 75 | +else |
| 76 | + DOY_m1=0 |
| 77 | +fi |
| 78 | +# |
| 79 | +DOY_END=$(date -d "${CDATE:0:8} ${CDATE:8:2} + ${FCST_LENGTH} hours" +%j) # Julian day |
| 80 | +# |
| 81 | +# Set the init/mesh file name and link here:\ |
| 82 | +if [[ -r "${UMBRELLA_PREP_IC_DATA}"/init.nc ]]; then |
| 83 | + ln -sf "${UMBRELLA_PREP_IC_DATA}"/init.nc init.nc |
| 84 | + INIT_FILE=./${MESH_NAME}.init.nc |
| 85 | +else |
| 86 | + echo "WARNING: NO Init File available, cannot reinterpolate if files are missing, did you run the task out of order?" |
| 87 | +fi |
| 88 | + |
| 89 | +# |
| 90 | +SCRIPT=${USHrrfs}/chem_regrid.py |
| 91 | +VINTERP_SCRIPT=${USHrrfs}/chem_vinterp.py |
| 92 | +INTERP_WEIGHTS_DIR=${DATADIR_CHEM}/grids/interpolation_weights/ |
| 93 | +# |
| 94 | +# Set a few things for the CONDA environment |
| 95 | +export REGRID_WRAPPER_LOG_DIR=${DATA} |
| 96 | +regrid_wrapper_dir=${REGRID_WRAPPER_DIR} #/lfs5/BMC/rtwbl/rap-chem/mpas_rt/working/ben_interp/regrid-wrapper/ |
| 97 | +PYTHONDIR=${regrid_wrapper_dir}/src |
| 98 | +regrid_conda_env=${REGRID_CONDA_ENV} #CONDAENV=/lfs5/BMC/rtwbl/rap-chem/miniconda/envs/regrid-wrapper |
| 99 | +export PATH=${regrid_conda_env}/bin:${PATH} |
| 100 | +export ESMFMKFILE=${regrid_conda_env}/lib/esmf.mk |
| 101 | +export PYTHONPATH=${PYTHONDIR}:${PYTHONPATH} |
| 102 | +# |
| 103 | +#==================================================================================================# |
| 104 | +if [[ "${EMIS_SECTOR_TO_PROCESS}" == "smoke" ]]; then |
| 105 | + source "${USHrrfs}"/prep_smoke.sh |
| 106 | +fi |
| 107 | + |
| 108 | +if [[ "${EMIS_SECTOR_TO_PROCESS}" == "rwc" ]]; then |
| 109 | + source "${USHrrfs}"/prep_rwc.sh |
| 110 | +fi #rwc |
| 111 | + |
| 112 | +if [[ "${EMIS_SECTOR_TO_PROCESS}" == "anthro" ]]; then |
| 113 | + source "${USHrrfs}"/prep_anthro.sh |
| 114 | +fi # anthro |
| 115 | + |
| 116 | +if [[ "${EMIS_SECTOR_TO_PROCESS}" == "pollen" ]]; then |
| 117 | + source "${USHrrfs}"/prep_pollen.sh |
| 118 | +fi # bio/pollen |
| 119 | + |
| 120 | +if [[ "${EMIS_SECTOR_TO_PROCESS}" == "dust" ]]; then |
| 121 | + source "${USHrrfs}"/prep_dust.sh |
| 122 | +fi # dust |
0 commit comments