From d83e0d82d7f5978b8efe08a715175cf021c8451e Mon Sep 17 00:00:00 2001 From: dominiquef Date: Wed, 21 Feb 2024 12:07:26 -0800 Subject: [PATCH 1/4] Reset input file on geoh5 change. Augment tests --- geoapps/driver_base/params.py | 8 +++++ tests/run_tests/octree_creation_test.py | 39 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/geoapps/driver_base/params.py b/geoapps/driver_base/params.py index c3413ca2a..de743792b 100644 --- a/geoapps/driver_base/params.py +++ b/geoapps/driver_base/params.py @@ -280,6 +280,14 @@ def geoh5(self, val): if val is None: self._geoh5 = val return + + if self.input_file is not None and self.input_file.geoh5 is not None: + self.input_file = InputFile( + ui_json=self._default_ui_json, + validations=self.validations, + validate=False, + ) + self.setter_validator( "geoh5", val, diff --git a/tests/run_tests/octree_creation_test.py b/tests/run_tests/octree_creation_test.py index 60885478f..f4eb3d311 100644 --- a/tests/run_tests/octree_creation_test.py +++ b/tests/run_tests/octree_creation_test.py @@ -398,3 +398,42 @@ def test_octree_diagonal_balance( assert (values == np.array(exp_values)).all() assert (counts == np.array(exp_counts)).all() + + +def test_app_change_geoh5(tmp_path: Path, setup_test_octree): + ( + cell_sizes, + depth_core, + horizontal_padding, + locations, + minimum_level, + refinement, + _, + vertical_padding, + ) = setup_test_octree + + with Workspace.create(tmp_path / "testOctree.geoh5") as workspace: + points = Points.create(workspace, vertices=locations) + refinements = { + "Refinement A object": points.uid, + "Refinement A levels": refinement, + "Refinement A type": "surface", + "Refinement B object": None, + "minimum_level": minimum_level, + } + app = OctreeMesh( + geoh5=workspace, + objects=str(points.uid), + u_cell_size=cell_sizes[0], + v_cell_size=cell_sizes[1], + w_cell_size=cell_sizes[2], + horizontal_padding=horizontal_padding, + vertical_padding=vertical_padding, + diagonal_balance=False, + depth_core=depth_core, + **refinements, + ) + new_workspace = Workspace.create(tmp_path / "testOctree_new.geoh5") + new_workspace.close() + + app.h5file = new_workspace.h5file From 2f83df2d8d1451a999a22e04189c75bd31a567a0 Mon Sep 17 00:00:00 2001 From: dominiquef Date: Fri, 23 Feb 2024 15:06:59 -0800 Subject: [PATCH 2/4] Fix tests --- geoapps/inversion/driver.py | 3 ++- tests/params_test.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/geoapps/inversion/driver.py b/geoapps/inversion/driver.py index 65f3b3c3c..8796cb56d 100644 --- a/geoapps/inversion/driver.py +++ b/geoapps/inversion/driver.py @@ -490,6 +490,7 @@ def get_path(self, filepath: str | Path) -> str: if __name__ == "__main__": - file = str(Path(sys.argv[1]).resolve()) + # file = str(Path(sys.argv[1]).resolve()) + file = r"C:\Users\dominiquef\Desktop\test_tem_crash_full.ui.json" InversionDriver.start(file) sys.stdout.close() diff --git a/tests/params_test.py b/tests/params_test.py index 80a93ca84..a6679f455 100644 --- a/tests/params_test.py +++ b/tests/params_test.py @@ -206,6 +206,14 @@ def test_default_input_file(tmp_path: Path): assert all(check) +def test_validate_geoh5(): + ifile = grav_params.input_file + with pytest.raises(ValueError, match="Input 'geoh5' must be a valid"): + grav_params.geoh5 = 4 + + assert grav_params.input_file != ifile + + def test_update(): new_params = { "starting_model": 99.0, @@ -714,15 +722,6 @@ def test_validate_n_cpu(): grav_params.input_file.geoh5.open() -def test_validate_geoh5(): - with pytest.raises(TypeValidationError) as excinfo: - grav_params.geoh5 = 4 - - assert all( - [k in str(excinfo.value) for k in ["geoh5", "Type", "int", "str", "Workspace"]] - ) - - def test_validate_out_group(): param = "out_group" newval = "test_" From dea4068f4abbd7783b2d5754fbdd7011640faa2e Mon Sep 17 00:00:00 2001 From: dominiquef Date: Sat, 24 Feb 2024 08:11:12 -0800 Subject: [PATCH 3/4] Revert "Fix tests" This reverts commit 2f83df2d8d1451a999a22e04189c75bd31a567a0. --- geoapps/inversion/driver.py | 3 +-- tests/params_test.py | 17 +++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/geoapps/inversion/driver.py b/geoapps/inversion/driver.py index 8796cb56d..65f3b3c3c 100644 --- a/geoapps/inversion/driver.py +++ b/geoapps/inversion/driver.py @@ -490,7 +490,6 @@ def get_path(self, filepath: str | Path) -> str: if __name__ == "__main__": - # file = str(Path(sys.argv[1]).resolve()) - file = r"C:\Users\dominiquef\Desktop\test_tem_crash_full.ui.json" + file = str(Path(sys.argv[1]).resolve()) InversionDriver.start(file) sys.stdout.close() diff --git a/tests/params_test.py b/tests/params_test.py index a6679f455..80a93ca84 100644 --- a/tests/params_test.py +++ b/tests/params_test.py @@ -206,14 +206,6 @@ def test_default_input_file(tmp_path: Path): assert all(check) -def test_validate_geoh5(): - ifile = grav_params.input_file - with pytest.raises(ValueError, match="Input 'geoh5' must be a valid"): - grav_params.geoh5 = 4 - - assert grav_params.input_file != ifile - - def test_update(): new_params = { "starting_model": 99.0, @@ -722,6 +714,15 @@ def test_validate_n_cpu(): grav_params.input_file.geoh5.open() +def test_validate_geoh5(): + with pytest.raises(TypeValidationError) as excinfo: + grav_params.geoh5 = 4 + + assert all( + [k in str(excinfo.value) for k in ["geoh5", "Type", "int", "str", "Workspace"]] + ) + + def test_validate_out_group(): param = "out_group" newval = "test_" From 6ac84fd4364e601905c3cc8628587b739aa345be Mon Sep 17 00:00:00 2001 From: dominiquef Date: Sat, 24 Feb 2024 08:16:47 -0800 Subject: [PATCH 4/4] Revert changes to driver, remove setting of geoh5 on params by app --- geoapps/driver_base/params.py | 7 ------- geoapps/octree_creation/application.py | 1 - 2 files changed, 8 deletions(-) diff --git a/geoapps/driver_base/params.py b/geoapps/driver_base/params.py index de743792b..e1a2d2c9e 100644 --- a/geoapps/driver_base/params.py +++ b/geoapps/driver_base/params.py @@ -281,13 +281,6 @@ def geoh5(self, val): self._geoh5 = val return - if self.input_file is not None and self.input_file.geoh5 is not None: - self.input_file = InputFile( - ui_json=self._default_ui_json, - validations=self.validations, - validate=False, - ) - self.setter_validator( "geoh5", val, diff --git a/geoapps/octree_creation/application.py b/geoapps/octree_creation/application.py index 6c0ee4ff7..277515e12 100644 --- a/geoapps/octree_creation/application.py +++ b/geoapps/octree_creation/application.py @@ -236,7 +236,6 @@ def workspace(self, workspace): ), f"Workspace must be of class {Workspace}" self.base_workspace_changes(workspace) self.update_objects_choices() - self.params.geoh5 = workspace def update_objects_choices(self): # Refresh the list of objects for all