Repository: parflow/parflow (language: python)

Issue:
hypre dependency on MPI in configure
hypre has a dependency on MPI so include MPI libs in configure test for working hypre library


Discussion / hints:
Looks OK and passing


Fix patch:
diff --git a/pftools/python/parflow/tools/core.py b/pftools/python/parflow/tools/core.py
index 9358db98d..dfd7556dd 100644
--- a/pftools/python/parflow/tools/core.py
+++ b/pftools/python/parflow/tools/core.py
@@ -13,6 +13,8 @@
 import sys
 import argparse
 
+import numpy as np
+
 from . import settings
 from .fs import get_absolute_path
 from .io import (
@@ -512,6 +514,39 @@ def run(self, working_directory=None, skip_validation=False):
         if not success or error_count > 0:
             sys.exit(1)
 
+    def check_nans(self, working_directory, include_forcing=True):
+        """Check the input files for NaNs.
+
+        Args:
+            working_directory: The working directory of the ParFlow run.
+            include_forcing (bool): If set to True, forcing files are going
+                to be checked.
+
+        Raises:
+            ValueError: If an input file contains a NaN.
+        """
+
+        runscript_path, _ = self.write(file_format="yaml")
+        all_files = []
+        with open(runscript_path, "r") as f:
+            for line in f:
+                line = line.strip()
+                if line.startswith("FileName: ") and line.endswith(".pfb"):
+                    path = os.path.join(working_directory, line.split()[1])
+                    all_files.append(path)
+
+        if include_forcing:
+            run = self.__class__.from_definition(runscript_path)
+            forcing_dir = run.Solver.CLM.MetFilePath
+            for file in os.listdir(forcing_dir):
+                if file.endswith(".pfb"):
+                    all_files.append(os.path.join(forcing_dir, file))
+
+        for file in all_files:
+            data = read_pfb(file)
+            if np.any(np.isnan(data)):
+                raise ValueError(f"{file} contains NaN values.")
+
     def dist(self, pfb_file, **kwargs):
         """Distribute a PFB file using the P/Q/R settings from the run
         or override them with the provided arguments.


Test patch:
diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt
index 518f125dc..8df29b2ed 100644
--- a/test/python/CMakeLists.txt
+++ b/test/python/CMakeLists.txt
@@ -165,5 +165,5 @@ add_subdirectory (key_validation)
 
 if (${PARFLOW_HAVE_CLM})
   add_subdirectory (clm)
-#  add_subdirectory (washita)
+  add_subdirectory (washita)
 endif(${PARFLOW_HAVE_CLM})
diff --git a/test/python/washita/LW_Test.py b/test/python/washita/LW_Test.py
index cd2e059cf..72de32862 100644
--- a/test/python/washita/LW_Test.py
+++ b/test/python/washita/LW_Test.py
@@ -4,8 +4,12 @@
 # Arugments are 1) runname 2) year
 # -----------------------------------------------------------------------------
 
+import os
+import numpy as np
 from parflow import Run
 from parflow.tools.fs import mkdir, cp, chdir, get_absolute_path
+from parflow.tools.io import read_pfb, write_pfb
+
 
 LW_Test = Run("LW_Test", __file__)
 
@@ -561,4 +565,20 @@
 # Run Simulation
 # -----------------------------------------------------------------------------
 
+# Corrupt the indicator file and run check_nans()
+corrupted_indicator = read_pfb(os.path.join(dir_name, "IndicatorFile_Gleeson.50z.pfb"))
+corrupted_indicator[0, 0, 0] = np.nan
+write_pfb(os.path.join(dir_name, "corrupted_indicator.pfb"), corrupted_indicator)
+LW_Test.Geom.indi_input.FileName = "corrupted_indicator.pfb"
+try:
+    LW_Test.check_nans(working_directory=dir_name)
+    raise AssertionError("ValueError was not raised for corrupted indicator file.")
+except ValueError as e:
+    assert "corrupted_indicator.pfb" in str(e)
+
+# Restore the original
+LW_Test.Geom.indi_input.FileName = "IndicatorFile_Gleeson.50z.pfb"
+
+# Check NaNs for original inputs
+LW_Test.check_nans(working_directory=dir_name)
 LW_Test.run(working_directory=dir_name)