Skip to content

Commit

Permalink
Add documentation to ush/HWP_tools.py (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett authored Oct 9, 2024
1 parent bcdcf3c commit 5ae5382
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
sphinxcontrib-bibtex
sphinx_rtd_theme
docutils==0.16
docutils==0.16
numpy
xarray
matplotlib
netCDF4
matplotlib
52 changes: 52 additions & 0 deletions ush/HWP_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
This file provides Hourly Wildfire Potential (HWP) tools.
"""

import numpy as np
import os
import datetime as dt
Expand All @@ -7,6 +12,14 @@
import fnmatch

def check_restart_files(hourly_hwpdir, fcst_dates):
"""Check the restart files.
Args:
hourly_hwpdir: the directory where the RESTART data is copied (nwges/HOURLY_HWP)
fcst_dates: Forecast dates
Returns:
lists of hours with and without available RESTART files
"""
hwp_avail_hours = []
hwp_non_avail_hours = []

Expand All @@ -25,6 +38,29 @@ def check_restart_files(hourly_hwpdir, fcst_dates):
return(hwp_avail_hours, hwp_non_avail_hours)

def copy_missing_restart(nwges_dir, hwp_non_avail_hours, hourly_hwpdir):
"""Check the restart files.
The script loops through hwp_non_avail_hours (missing files in
nwges/HOURLY_HWP) and determines if an alternative RESTART file in
nwges/fcst_fv3lam/RESTART is available instead. If so, it is
appended to restart_avail_hours.
Args:
nwges_dir: holds the boundary, INPUT, and RESTART files (e.g,
described here:
[ufs-community/ufs-srweather-app#654](https://github.com/ufs-community/ufs-srweather-app/issues/654))
The use of NWGES is a bit of a legacy variable name in
production. It is often used to define a directory holding
DA-relevant files (such as first guess and analysis files)
outside of the main COM output directory.
hwp_non_avail_hours: a list of hours without available RESTART files
hourly_hwpdir: the directory where the RESTART data is copied (nwges/HOURLY_HWP)
Returns:
list of::
- restart_avail_hours
- restart_nonavail_hours_test which is a subset of hwp_non_avail_hours.
"""
restart_avail_hours = []
restart_nonavail_hours_test = []

Expand Down Expand Up @@ -79,6 +115,22 @@ def copy_missing_restart(nwges_dir, hwp_non_avail_hours, hourly_hwpdir):
return(restart_avail_hours, restart_nonavail_hours_test)

def process_hwp(fcst_dates, hourly_hwpdir, cols, rows, intp_dir, rave_to_intp):
"""Check the restart files.
Args:
fcst_dates: a list of forecasts (for production/ops/ebb=2, it is {current_day - 25 hours: current_day-1hours}, for ebb=1, it is current_day:current_day+24 hours)
hourly_hwpdir: the directory where the RESTART data is copied (nwges/HOURLY_HWP)
cols: hard coded dimension for the RRFS_NA_3km and RRFS_CONUS_3km domains:: cols = 2700 if predef_grid == 'RRFS_NA_3km' else 1092
rows: hard coded dimension for the RRFS_NA_3km and RRFS_CONUS_3km domains:: rows = 3950 if predef_grid == 'RRFS_NA_3km' else 1820
intp_dir: the working directory for smoke processing (${CYCLE_DIR}/process_smoke)
rave_to_intp: a string based on the grid name:: rave_to_intp = predef_grid+"intp"
Returns:
list of::
- average (through time) of HWP_AVE in the available RESTART files
- hwp_ave_arr converted to an xarray DataArray
- the total precipitation vector (totprcp) reshaped to the 2D grid
- totprcp_ave_arr converted to an xarray DataArray
"""
hwp_ave = []
totprcp = np.zeros((cols*rows))
var1, var2 = 'rrfs_hwp_ave', 'totprcp_ave'
Expand Down

0 comments on commit 5ae5382

Please sign in to comment.