Skip to content

Commit

Permalink
[uwtools_integration] A handful of housekeeping items (#269)
Browse files Browse the repository at this point in the history
Includes:

* A change in the Rocoto YAMLS to use && to link commands together.
* Added documentation to the default_config.yaml.
* Updates to machine YAMLs so we might expect the same behavior on all machines.
* An update for the latest uwtools UPP config (using control_file task).
* Linted and applied black to the whole scripts directory (ignoring a couple of out-of-scope files with pylint disable tags)
* Turned on GH actions for this branch to keep our files linted.
* Removed files and default variables that are no longer used.
  • Loading branch information
christinaholtNOAA authored Nov 7, 2024
1 parent 491b4e5 commit 38b165b
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 1,738 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/python_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- develop
- 'release/*'
- uwtools_integration
pull_request:
branches:
- develop
Expand Down Expand Up @@ -43,6 +44,7 @@ jobs:
pylint ush/generate_FV3LAM_wflow.py
pylint ush/set_fv3nml*.py
pylint ush/update_input_nml.py
pylint scripts/*.py
- name: Run python unittests
run: |
Expand Down
4 changes: 2 additions & 2 deletions parm/wflow/coldstart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ metatask_run_ensemble:
<<: *default_task
command:
cyclestr:
value: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} ; &SCRIPTSdir;/chgres_cube.py
value: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} && &SCRIPTSdir;/chgres_cube.py
-c &GLOBAL_VAR_DEFNS_FP;
--cycle @Y-@m-@dT@H:@M:@S
--key-path task_make_ics
Expand Down Expand Up @@ -155,7 +155,7 @@ metatask_run_ensemble:
<<: *default_task
command:
cyclestr:
value: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} ; &SCRIPTSdir;/chgres_cube.py
value: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} && &SCRIPTSdir;/chgres_cube.py
-c &GLOBAL_VAR_DEFNS_FP;
--cycle @Y-@m-@dT@H:@M:@S
--key-path task_make_lbcs
Expand Down
2 changes: 1 addition & 1 deletion parm/wflow/post.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metatask_run_ens_post:
maxtries: '2'
command:
cyclestr:
value: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} ; &SCRIPTSdir;/upp.py
value: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} && &SCRIPTSdir;/upp.py
-c &GLOBAL_VAR_DEFNS_FP;
--cycle @Y-@m-@dT@H:@M:@S
--leadtime #fhr#:00:00
Expand Down
4 changes: 2 additions & 2 deletions parm/wflow/prep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ task_make_grid:

task_make_orog:
<<: *default_task
command: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} ; &SCRIPTSdir;/make_orog.py
command: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} && &SCRIPTSdir;/make_orog.py
-c &GLOBAL_VAR_DEFNS_FP;
--key-path task_make_orog'
join:
Expand All @@ -52,7 +52,7 @@ task_make_orog:

task_make_sfc_climo:
<<: *default_task
command: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }}; &SCRIPTSdir;/make_sfc_climo.py
command: 'source &USHdir;/load_modules_wflow.sh {{ user.MACHINE }} && &SCRIPTSdir;/make_sfc_climo.py
-c &GLOBAL_VAR_DEFNS_FP;
--key-path task_make_sfc_climo'
join:
Expand Down
116 changes: 58 additions & 58 deletions scripts/exregional_integration_test.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
#!/usr/bin/env python3

################################################################################
#### Python Script Documentation Block
#
# Script name: exregional_integration_test.py
# Script description: Ensures the correct number of netcdf files are generated
# for each experiment
#
# Author: Eddie Snyder Org: NOAA EPIC Date: 2024-02-05
#
# Instructions: 1. Pass the appropriate info for the required arguments:
# --fcst_dir=/path/to/forecast/files
# --fcst_len=<forecast length as Int>
# 2. Run script with arguments
#
# Notes/future work: - Currently SRW App only accepts netcdf as the UFS WM
# output file format. If that changes, then additional
# logic is needed to address the other file formats.
# - SRW App doesn't have a variable that updates the
# forecast increment. The UFS WM does with the
# output_fh variable, which can be found in the
# model_configure file. If it becomes available with
# the SRW App, then logic is needed to account for the
# forecast increment variable.
#
################################################################################
"""
Python Script Documentation Block
Script name: exregional_integration_test.py
Script description: Ensures the correct number of netcdf files are generated
for each experiment
Author: Eddie Snyder Org: NOAA EPIC Date: 2024-02-05
Instructions: 1. Pass the appropriate info for the required arguments:
--fcst_dir=/path/to/forecast/files
--fcst_len=<forecast length as Int>
2. Run script with arguments
Notes/future work: - Currently SRW App only accepts netcdf as the UFS WM
output file format. If that changes, then additional
logic is needed to address the other file formats.
- SRW App doesn't have a variable that updates the
forecast increment. The UFS WM does with the
output_fh variable, which can be found in the
model_configure file. If it becomes available with
the SRW App, then logic is needed to account for the
forecast increment variable.
"""

# -------------Import modules --------------------------#
import os
import sys
import logging
import argparse
import logging
import sys
import unittest
from pathlib import Path

# --------------Define some functions ------------------#


class TestExptFiles(unittest.TestCase):
fcst_dir = ''
filename_list = ''
"""
Set up the test for expected output files.
"""

fcst_dir = ""
filename_list = ""

def test_fcst_files(self):

"""
Test that expected files exist.
"""
for filename in self.filename_list:
filename_fp = "{0}/{1}".format(self.fcst_dir, filename)
filename_fp = self.fcst_dir / filename
logging.info(f"Checking existence of: {str(filename_fp)}")
err_msg = f"Missing file: {str(filename_fp)}"
self.assertTrue(filename_fp.exists(), err_msg)

logging.info("Checking existence of: {0}".format(filename_fp))
err_msg = "Missing file: {0}".format(filename_fp)
self.assertTrue(os.path.exists(filename_fp), err_msg)

def setup_logging(debug=False):

"""Calls initialization functions for logging package, and sets the
user-defined level for logging in the script."""

Expand All @@ -71,11 +76,13 @@ def setup_logging(debug=False):
"--fcst_dir",
help="Directory to forecast files.",
required=True,
type=Path,
)
parser.add_argument(
"--fcst_len",
help="Forecast length.",
required=True,
type=int,
)
parser.add_argument(
"--fcst_inc",
Expand All @@ -89,46 +96,39 @@ def setup_logging(debug=False):
help="Print debug messages.",
required=False,
)
parser.add_argument('unittest_args', nargs='*')
parser.add_argument("unittest_args", nargs="*")
args = parser.parse_args()
sys.argv[1:] = args.unittest_args

fcst_dir = str(args.fcst_dir)
fcst_len = int(args.fcst_len)
fcst_inc = int(args.fcst_inc)

# Start logger
setup_logging()

# Check if model_configure exists
model_configure_fp = "{0}/model_configure".format(fcst_dir)
MODEL_CONFIGURE_FP = args.fcst_dir / "model_configure"

if not os.path.isfile(model_configure_fp):
logging.error("Experiments model_configure file is missing! Exiting!")
if not MODEL_CONFIGURE_FP.is_file():
logging.error("Experiment's model_configure file is missing! Exiting!")
sys.exit(1)

# Loop through model_configure file to find the netcdf base names
f = open(model_configure_fp, 'r')

for line in f:
if line.startswith("filename_base"):
filename_base_1 = line.split("'")[1]
filename_base_2 = line.split("'")[3]
break
f.close()
with open(MODEL_CONFIGURE_FP, "r", encoding="utf-8") as f:
for line in f:
if line.startswith("filename_base"):
filename_base_1 = line.split("'")[1]
filename_base_2 = line.split("'")[3]
break

# Create list of expected filenames from the experiment
fcst_len = fcst_len + 1
filename_list = []

for x in range(0, fcst_len, fcst_inc):
for x in range(0, args.fcst_len + 1, args.fcst_inc):
fhour = str(x).zfill(3)
filename_1 = "{0}f{1}.nc".format(filename_base_1, fhour)
filename_2 = "{0}f{1}.nc".format(filename_base_2, fhour)
filename_1 = f"{filename_base_1}f{fhour}.nc"
filename_2 = f"{filename_base_2}f{fhour}.nc"
filename_list.append(filename_1)
filename_list.append(filename_2)

# Call unittest class
TestExptFiles.fcst_dir = fcst_dir
# Call unittest class
TestExptFiles.fcst_dir = args.fcst_dir
TestExptFiles.filename_list = filename_list
unittest.main()
Loading

0 comments on commit 38b165b

Please sign in to comment.