Skip to content

Commit

Permalink
Bringing over xrcmp to test output of actions. Removing apt-install p…
Browse files Browse the repository at this point in the history
…ackages that aren't needed.
  • Loading branch information
scrasmussen committed Apr 24, 2024
1 parent 9dfcdf3 commit 74cf286
Show file tree
Hide file tree
Showing 4 changed files with 498 additions and 8 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,16 @@ jobs:
&& sudo apt-get install -yq --no-install-recommends \
wget \
curl \
emacs-nox \
bzip2 \
ca-certificates \
vim \
libhdf5-dev \
gfortran \
g++ \
valgrind \
m4 \
make \
libswitch-perl \
git \
nano \
tcsh \
bc \
less \
openmpi-bin openmpi-common libopenmpi-dev \
libxml2-dev \
libnetcdf-dev \
Expand Down Expand Up @@ -121,13 +115,32 @@ jobs:
make run-croton-${{ matrix.configuration }}
- name: Compare Outputs
- name: Compare Restart Output with xrcmp
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
for file in output_${{ matrix.configuration }}/HYDRO_RST.*; do\
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/candidate/build/Run/$file \
--log_file $file_diff.txt; \
done
for file in output_${{ matrix.configuration }}/RESTART.*; do\
python ${GITHUB_WORKSPACE}/candidate/tests/utils/xrcmp.py \
--candidate $file \
--reference $GITHUB_WORKSPACE/candidate/build/Run/$file \
--log_file $file_diff.txt; \
done
# for file in output_${{ matrix.configuration }}/HYDRO_RST.*; do\
# --log_file $file_diff.txt; \
# done
- name: Compare Output with compare_output
run: |
cd $GITHUB_WORKSPACE/candidate/build/Run
mkdir output_diff
python -c \
"import sys; \
sys.path.append('${GITHUB_WORKSPACE}/candidate/tests'); \
sys.path.append('${GITHUB_WORKSPACE}/candidate/tests/utils'); \
import compare_output; \
from pathlib import Path; \
compare_output.plot_diffs('${GITHUB_WORKSPACE}/candidate/build/Run/output_diff', \
Expand Down
65 changes: 65 additions & 0 deletions tests/utils/compare_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os
from pathlib import Path
import time


def plot_diffs(output_dir, candidatename, referencename, testname, feature_ids=None):
"""
Function to create diff plots
Args:
output_dir: The output directory for this configuration
candidatename: The name of the candidate run. Must match the name of the
model output directory
referencename: The name of the reference run. Must match the name of the
model output directory
testname: The name of the test being run. Plots will be placed in this
named directory
feature_ids: A dict containing a list of channels and lake ids to create diff
plots for, or None. If defined, should be {'channels': [], 'lakes': []}
"""
output_dir = Path(output_dir)
candidatename = Path(candidatename)
referencename = Path(referencename)
testname = Path(testname)

candidate = output_dir / candidatename
reference = output_dir / referencename
plots = output_dir / "diff_plots" / testname
# script_dir = output_dir / "../candidate_can_pytest/tests/local/utils"
# output_dir is at build/Run/output
script_dir = output_dir / "../../../tests/local/utils"
if not script_dir.is_dir():
script_dir.mkdir(parents=True)

gen_script = script_dir / "generate_diff_plots.py"
thresholds = script_dir / "thresholds.csv"


cmd = f"python {gen_script} -o {plots} -d " + \
f"-b {reference} -B {referencename} -c {candidate} -C {candidatename} " + \
f"-n -t {thresholds}"

ldas_vars = ['ACCET','SFCRNOF','UGDRNOFF','SOIL_M','SNEQV','FSA','FIRA','TRAD','GRDFLX','LH','HFX']

cmd_gridded = cmd + " -f ldas:" + (",".join(ldas_vars)) + " -f rtout"

print("\nPlotting gridded model diffs...")
os.system(cmd_gridded)

if feature_ids is None:
return

if 'channels' in feature_ids:
cmd_feature = cmd + " -f chrtout -i '" + ",".join(feature_ids['channels']) + "'"
print("\nPlotting channel model diffs...")
os.system(cmd_feature)

if 'lakes' in feature_ids:
cmd_feature = cmd + " -f lakeout -i '" + ",".join(feature_ids['lakes']) + "'"
print("\nPlotting lake model diffs...")
os.system(cmd_feature)

if 'gwout' in feature_ids:
cmd_feature = cmd + " -f gwout -i '" + ",".join(feature_ids['gwout']) + "'"
print("\nPlotting gwout model diffs...")
os.system(cmd_feature)
Loading

0 comments on commit 74cf286

Please sign in to comment.