From aaaa97887c754f697218c671a58b643f0f360beb Mon Sep 17 00:00:00 2001 From: kohlhaasrebecca <rebecca.kohlhaas@outlook.com> Date: Mon, 9 Dec 2024 17:01:02 +0100 Subject: [PATCH] Fix test_plot_metamodel_3d --- .../post_processing/post_processing.py | 2 +- tests/test_PostProcessing.py | 23 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/bayesvalidrox/post_processing/post_processing.py b/src/bayesvalidrox/post_processing/post_processing.py index 73df97ef2..31941207f 100644 --- a/src/bayesvalidrox/post_processing/post_processing.py +++ b/src/bayesvalidrox/post_processing/post_processing.py @@ -933,7 +933,7 @@ class PostProcessing: # ------------------------------------------------------------------------- def plot_metamodel_3d(self, n_samples=10): """ - Visualize the results of a PCE MetaModel as a 3D surface over two input + Visualize the results of a MetaModel as a 3D surface over two input parameters. Parameters diff --git a/tests/test_PostProcessing.py b/tests/test_PostProcessing.py index 33589c2c4..57610598f 100644 --- a/tests/test_PostProcessing.py +++ b/tests/test_PostProcessing.py @@ -130,7 +130,8 @@ def pce_engine_3d_plot(): 'Z': [[0.4], [0.5], [0.3], [0.4]], 'Y': [[0.35], [0.45], [0.40], [0.38]] } - expdes.x_values = [0, 0] # Example x-values (could be used for visualization or plotting) + expdes.X = np.array([[0,0], [1,0], [0.5,0.3], [0.3,0.7]]) + expdes.x_values = [0] # Example x-values (could be used for visualization or plotting) # Create and fit the Polynomial Chaos Expansion model (PCE) mm = PCE(inp) # Initialize the PCE model @@ -144,11 +145,7 @@ def pce_engine_3d_plot(): engine.emulator = True # Indicate that the engine is emulating a trained model engine.trained = True # Mark the engine as trained - # Initialize the InputSpace (ensure this is defined correctly for your context) - mm.InputSpace = InputSpace(mm.input_obj, mm.meta_model_type) - return engine # Return the configured engine - return engine @pytest.fixture def gpe_engine(): @@ -409,18 +406,8 @@ def test_plot_metamodel_3d_pce(pce_engine_3d_plot) -> None: post = PostProcessing(engine) post.plot_metamodel_3d() # Check if the plot was created and saved - assert os.path.exists(f"./{engine.out_dir}/Metamodel_3D.{engine.out_format}") - -def test_plot_metamodel_3d_with_invalid_data(pce_engine_3d_plot) -> None: - """ - Test the plot_metamodel_3d method with invalid data - """ - engine = pce_engine_3d_plot - engine.ExpDesign.X = [] - post = PostProcessing(engine) - with pytest.raises(ValueError) as excinfo: - post.plot_metamodel_3d() - assert "Input data cannot be empty" in str(excinfo.value) + assert os.path.exists(f"./{post.out_dir}/3DPlot_MetaModel_Z0.{post.out_format}") + assert os.path.exists(f"./{post.out_dir}/3DPlot_MetaModel_Y0.{post.out_format}") #%% _plot_validation_multi only for PCE @@ -431,7 +418,7 @@ def test_plot_validation_multi(pce_engine_3d_plot): engine = pce_engine_3d_plot post = PostProcessing(engine) y_val = {'Z': [1, 2, 3, 4, 5]} - y_val_std = {'Y': [0.1, 0.2, 0.3, 0.4, 0.5]} + y_val_std = {'Z': [0.1, 0.2, 0.3, 0.4, 0.5]} post._plot_validation_multi(y_val, y_val_std) # Check if the plot was created and saved assert os.path.exists(f"./{engine.out_dir}/Model_vs_Model_key1.{engine.out_format}") -- GitLab