Skip to content

Commit

Permalink
wrfpreprocessor variable added to experiment.wrf4g (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
fernanqv committed Mar 22, 2023
1 parent 8ed98b1 commit 6b57168
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions wrf4g/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ class JobCodeError():
WRF_FAILED = 20
POSTPROCESSOR_FAILED = 21
COPY_OUTPUT_FILE = 22
WRFPREPROCESSOR_FAILED = 23

class Job( object ):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
set -e
# Processor to insert CO2 level corresponding to date into NOAH-MP, via the
# MPTABLE.TBL file

sformateddate=$1 # initial date to process as YYYY-MM-DD_HH:MM:SS (Ex. 1983-08-27_00:00:00)
eformateddate=$2 # end date to process
tblpath=$3 # run directory where CAMtr_volume_mixing_ratio and MPTABLE.TBL are located

read iyy imm trash <<< `echo $sformateddate | tr '_T:-' ' '`
read fyy fmm trash <<< `echo $eformateddate | tr '_T:-' ' '`

# Extract CO2 level for current chunk (just the year, no interpolation)
co2ppm=$(awk '$1 == '${iyy}' {print $2}' ${tblpath}/CAMtr_volume_mixing_ratio)
co2ppm=$(grep ^$iyy CAMtr_volume_mixing_ratio | awk {'print $2'})
#co2ppm=$(awk '$1 == '${iyy}' {print $2}' CAMtr_volume_mixing_ratio)

# Replace CO2 level in MPTABLE
sed -i -e 's/ CO2 = .*e-06/ CO2 = '${co2ppm}'e-06/' ${tblpath}/MPTABLE.TBL
sed -i -e 's/ CO2 = .*e-06/ CO2 = '${co2ppm}'e-06/' MPTABLE.TBL
31 changes: 31 additions & 0 deletions wrf4g/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def __init__(self, json=None, root_path=None):
self.domain_path = resource_cfg["domain_path"]
self.app = resource_cfg.get("app", "")
self.preprocessor = resource_cfg["preprocessor"]
self.wrfpreprocessor = resource_cfg.get("wrfpreprocessor", "")
self.postprocessor = resource_cfg.get("postprocessor", "")
self.ungribprocessor = resource_cfg.get("ungribprocessor", "")
self.clean_after_run = resource_cfg.get("clean_after_run", "no")
Expand Down Expand Up @@ -1286,6 +1287,36 @@ def run_wrf(self, binaries):
wrf_exe = binaries.wrf_exe
# Change the directory to wrf run path
os.chdir(params.wrf_run_path)

if params.wrfpreprocessor:

for pp in params.wrfpreprocessor.replace(" ", "").split(","):
if pp != "":
logging.info("Running wrfpreprocessor.%s" % pp)

if not which("wrfpreprocessor.%s" % pp):
raise JobError(
"wrfpreprocessor '%s' does not exist" % pp,
Job.CodeError.WRFPREPROCESSOR_FAILED,
)
preprocessor_log = join(
params.log_path, "wrfpreprocessor.%s.log" % pp
)
code, output = exec_cmd(
"wrfpreprocessor.%s %s %s> %s" % (
pp,
datetime2datewrf(params.chunk_rdate),
datetime2datewrf(params.chunk_edate),
preprocessor_log)
)
if code:
logging.info(output)
raise JobError(
"wrfpreprocessor '%s' has failed" % pp,
Job.CodeError.WRFPREPROCESSOR_FAILED,
)


##
# Start a thread to monitor wrf
##
Expand Down

0 comments on commit 6b57168

Please sign in to comment.