Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation for blending_fv3.py #517

Merged
merged 7 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ sphinx_rtd_theme
docutils==0.16
numpy
netCDF4
raymond
xarray
matplotlib
38 changes: 38 additions & 0 deletions ush/blending_fv3.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
"""This script performs blending between regional and global weather
forecast model restarts using the Fortran module raymond. The Raymond
filter is a sixth-order tangent low-pass implicit filter and can be
controlled via the cutoff length scale (Lx).

"""
import numpy as np
from netCDF4 import Dataset
import raymond
import sys

def check_file_nans(test_nc, vars_fg, vars_bg, name):
"""Check for NaN values in specified variables of a netCDF file.

This function iterates over a list of variables and checks for NaN values in the provided
netCDF file. It prints the count of NaNs found for each variable and indicates whether
any NaNs were detected.

Again, if there are any NaNs found, I wanted to catch that here
instead of later when the model is running. I don't think there is
any reason to expect NaNs.

Parameters:
test_nc: Dataset
The test netCDF file containing the variables to be checked for NaN values.
vars_fg: list of str
A list of variable names from the regional model (foreground) to check.
vars_bg: list of str
A corresponding list of variable names from the global model (background) to check.
name: str
A string representing the context (e.g., 'glb' for global or 'reg' for regional)
to identify the source of the variables being checked.

Returns:
bool
Returns True if any NaN values are found in the specified variables;
otherwise, returns False.

"""
nans = False
for (var_fg, var_bg) in zip(vars_fg, vars_bg):
i = vars_fg.index(var_fg)
Expand All @@ -20,6 +53,11 @@ def check_file_nans(test_nc, vars_fg, vars_bg, name):
return nans

def err_check(err):
"""
Check for error.

err: Error code.
"""
if err > 0:
print(f"An error ocurred in {sys.argv[0]}. Blending failed!!!")
print(f"err={err}")
Expand Down
Loading