From 070d14c3ce03427ff58356b853a7d745dbcd9e28 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 14:27:12 +0200 Subject: [PATCH 01/12] replace boundary_type with type for boundary conditions --- threedigrid_builder/grid/boundary_conditions.py | 6 +++--- threedigrid_builder/interface/db.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index 09860abe..10707f6f 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -24,7 +24,7 @@ class BoundaryCondition1D: id: int - boundary_type: BoundaryType + type: BoundaryType connection_node_id: int @@ -35,7 +35,7 @@ def apply(self, grid): Fields on nodes/lines that have a boundary condition be adjusted: - nodes.calculation_type: set (overridden) to BOUNDARY_NODE - nodes.boundary_id: from BoundaryConditions1D.id - - nodes.boundary_type: from BoundaryConditions1D.boundary_type + - nodes.boundary_type: from BoundaryConditions1D.type - nodes.node_type: set to NODE_1D_BOUNDARIES - lines.boundary_id: from BoundaryConditions1D.id @@ -89,7 +89,7 @@ def apply(self, grid): # set node attributes grid.nodes.calculation_type[idx] = CalculationType.BOUNDARY_NODE grid.nodes.boundary_id[idx] = self.id - grid.nodes.boundary_type[idx] = self.boundary_type + grid.nodes.boundary_type[idx] = self.type grid.nodes.node_type[idx] = NodeType.NODE_1D_BOUNDARIES # set line attributes grid.lines.is_1d_boundary[line_idx] = 1 diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index 4d9217f9..c7f4f497 100644 --- a/threedigrid_builder/interface/db.py +++ b/threedigrid_builder/interface/db.py @@ -359,7 +359,7 @@ def get_boundary_conditions_2d(self) -> BoundaryConditions2D: arr = ( session.query( models.BoundaryConditions2D.id, - models.BoundaryConditions2D.boundary_type, + models.BoundaryConditions2D.type, models.BoundaryConditions2D.the_geom, ) .order_by(models.BoundaryConditions2D.id) From 09d5e7b244ab20db6aecb98774d5a26f3d083aca Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 14:37:56 +0200 Subject: [PATCH 02/12] replace the_geom with geom for boundary conditions --- threedigrid_builder/grid/boundary_conditions.py | 4 ++-- threedigrid_builder/interface/db.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index 10707f6f..fa13d9dc 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -98,14 +98,14 @@ def apply(self, grid): class BoundaryCondition2D: id: int boundary_type: BoundaryType - the_geom: shapely.Geometry + geom: shapely.Geometry class BoundaryConditions2D(Array[BoundaryCondition2D]): def get_intersecting_node_idx( self, idx: int, cell_tree: shapely.STRtree ) -> np.ndarray: - bc_geom = self.the_geom[idx] + bc_geom = self.geom[idx] x1, y1, x2, y2 = shapely.bounds(bc_geom) is_horizontal = (x2 - x1) > (y2 - y1) diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index c7f4f497..5fabedea 100644 --- a/threedigrid_builder/interface/db.py +++ b/threedigrid_builder/interface/db.py @@ -360,12 +360,12 @@ def get_boundary_conditions_2d(self) -> BoundaryConditions2D: session.query( models.BoundaryConditions2D.id, models.BoundaryConditions2D.type, - models.BoundaryConditions2D.the_geom, + models.BoundaryConditions2D.geom, ) .order_by(models.BoundaryConditions2D.id) .as_structarray() ) - arr["the_geom"] = self.reproject(arr["the_geom"]) + arr["geom"] = self.reproject(arr["geom"]) # transform to a BoundaryConditions1D object return BoundaryConditions2D(**{name: arr[name] for name in arr.dtype.names}) From 494320cdd66c085de79cf9501213c8096a570571 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 14:43:02 +0200 Subject: [PATCH 03/12] replace remaining boundary_type with type --- threedigrid_builder/grid/boundary_conditions.py | 2 +- threedigrid_builder/interface/db.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index fa13d9dc..0ddb9ffe 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -97,7 +97,7 @@ def apply(self, grid): class BoundaryCondition2D: id: int - boundary_type: BoundaryType + type: BoundaryType geom: shapely.Geometry diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index 5fabedea..e7ba6d0f 100644 --- a/threedigrid_builder/interface/db.py +++ b/threedigrid_builder/interface/db.py @@ -343,7 +343,7 @@ def get_boundary_conditions_1d(self) -> BoundaryConditions1D: arr = ( session.query( models.BoundaryCondition1D.id, - models.BoundaryCondition1D.boundary_type, + models.BoundaryCondition1D.type, models.BoundaryCondition1D.connection_node_id, ) .order_by(models.BoundaryCondition1D.id) From e22a87393c90d87ef5fa6a4a38532adac8e90336 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 14:49:23 +0200 Subject: [PATCH 04/12] rename boundarytype function --- threedigrid_builder/grid/boundary_conditions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index 0ddb9ffe..e7099097 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -187,7 +187,7 @@ def get_neighoring_node_idx( return node_idx[before if is_before else after], is_before def adapt_node_idx_groundwater(self, idx: int, nodes: Nodes, node_idx): - is_groundwater = self.boundary_type_is_groundwater(self.boundary_type[idx]) + is_groundwater = self.type_is_groundwater(self.type[idx]) if is_groundwater: n_groundwater_cells = nodes.n_groundwater_cells if n_groundwater_cells == 0: @@ -266,8 +266,8 @@ def is_groundwater(kcu: LineType) -> bool: } @staticmethod - def boundary_type_is_groundwater(boundary_type: BoundaryType) -> bool: - return boundary_type in { + def type_is_groundwater(type: BoundaryType) -> bool: + return type in { BoundaryType.GROUNDWATERLEVEL, BoundaryType.GROUNDWATERDISCHARGE, } From ad10c90724c096c4e7223abe4804b978d975f242 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 14:52:16 +0200 Subject: [PATCH 05/12] replace another boundary_type with type --- threedigrid_builder/grid/boundary_conditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index e7099097..b4697769 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -296,7 +296,7 @@ def create_boundary_cells( itertools.islice(node_id_counter, len(boundary_cells)) ) boundary_cells.boundary_id[:] = self.id[idx] - boundary_cells.boundary_type[:] = self.boundary_type[idx] + boundary_cells.boundary_type[:] = self.type[idx] boundary_cells.node_type[:] = ( NodeType.NODE_2D_GROUNDWATER_BOUNDARIES if self.is_groundwater(kcu) From c3415486ebf3a084f8361e8286d3039f14c78971 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 15:15:26 +0200 Subject: [PATCH 06/12] replace boundary_type with type in tests --- threedigrid_builder/tests/test_boundary_conditions.py | 10 +++++----- threedigrid_builder/tests/test_db.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/threedigrid_builder/tests/test_boundary_conditions.py b/threedigrid_builder/tests/test_boundary_conditions.py index f616978c..075b3cf6 100644 --- a/threedigrid_builder/tests/test_boundary_conditions.py +++ b/threedigrid_builder/tests/test_boundary_conditions.py @@ -39,7 +39,7 @@ def grid1d(): def test_1d_apply(grid1d): boundary_conditions_1d = BoundaryConditions1D( id=[10, 22], - boundary_type=[2, 3], + type=[2, 3], connection_node_id=[9, 5], ) boundary_conditions_1d.apply(grid1d) @@ -278,7 +278,7 @@ def test_2d_boundary_condition( ): boundary_conditions_2d = BoundaryConditions2D( id=range(len(bc_coords)), - boundary_type=[3] * len(bc_coords), + type=[3] * len(bc_coords), the_geom=shapely.linestrings(bc_coords), ) @@ -319,7 +319,7 @@ def test_2d_boundary_condition( def test_2d_boundary_condition_err(grid2d, bc_coords, expected_message): boundary_conditions_2d = BoundaryConditions2D( id=range(len(bc_coords)), - boundary_type=[3] * len(bc_coords), + type=[3] * len(bc_coords), the_geom=shapely.linestrings(bc_coords), ) @@ -383,7 +383,7 @@ def grid2d_gw(): def test_2d_boundary_condition_types(grid2d_gw, boundary_type, node_type, kcu, line): boundary_conditions_2d = BoundaryConditions2D( id=[1], - boundary_type=[boundary_type], + type=[boundary_type], the_geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])], ) nodes, lines = boundary_conditions_2d.get_nodes_and_lines( @@ -411,7 +411,7 @@ def test_2d_boundary_condition_types(grid2d_gw, boundary_type, node_type, kcu, l def test_2d_boundary_condition_combined(grid2d_gw): boundary_conditions_2d = BoundaryConditions2D( id=[1, 2], - boundary_type=[BoundaryType.WATERLEVEL, BoundaryType.GROUNDWATERLEVEL], + type=[BoundaryType.WATERLEVEL, BoundaryType.GROUNDWATERLEVEL], the_geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])] * 2, ) diff --git a/threedigrid_builder/tests/test_db.py b/threedigrid_builder/tests/test_db.py index d0dedcd5..325aa969 100644 --- a/threedigrid_builder/tests/test_db.py +++ b/threedigrid_builder/tests/test_db.py @@ -75,7 +75,7 @@ def test_get_boundary_conditions_1d(db): # some test samples assert len(boundary_conditions_1d) == 4 assert boundary_conditions_1d.id[1] == 2 - assert boundary_conditions_1d.boundary_type[2] == BoundaryType.DISCHARGE + assert boundary_conditions_1d.type[2] == BoundaryType.DISCHARGE assert boundary_conditions_1d.connection_node_id[3] == 59 From b85a8486b470e08a63b8a6eab93c537f98a5a49e Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 22 Aug 2024 15:29:42 +0200 Subject: [PATCH 07/12] replace the_geom with geom in tests, update sqlite version --- threedigrid_builder/interface/db.py | 2 +- threedigrid_builder/tests/test_boundary_conditions.py | 8 ++++---- threedigrid_builder/tests/test_db.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index e7ba6d0f..9c093009 100644 --- a/threedigrid_builder/interface/db.py +++ b/threedigrid_builder/interface/db.py @@ -43,7 +43,7 @@ # hardcoded source projection SOURCE_EPSG = 4326 -MIN_SQLITE_VERSION = 224 +MIN_SQLITE_VERSION = 225 DAY_IN_SECONDS = 24.0 * 3600.0 diff --git a/threedigrid_builder/tests/test_boundary_conditions.py b/threedigrid_builder/tests/test_boundary_conditions.py index 075b3cf6..f7a1683f 100644 --- a/threedigrid_builder/tests/test_boundary_conditions.py +++ b/threedigrid_builder/tests/test_boundary_conditions.py @@ -279,7 +279,7 @@ def test_2d_boundary_condition( boundary_conditions_2d = BoundaryConditions2D( id=range(len(bc_coords)), type=[3] * len(bc_coords), - the_geom=shapely.linestrings(bc_coords), + geom=shapely.linestrings(bc_coords), ) nodes, lines = boundary_conditions_2d.get_nodes_and_lines( @@ -320,7 +320,7 @@ def test_2d_boundary_condition_err(grid2d, bc_coords, expected_message): boundary_conditions_2d = BoundaryConditions2D( id=range(len(bc_coords)), type=[3] * len(bc_coords), - the_geom=shapely.linestrings(bc_coords), + geom=shapely.linestrings(bc_coords), ) with pytest.raises(SchematisationError, match=expected_message): @@ -384,7 +384,7 @@ def test_2d_boundary_condition_types(grid2d_gw, boundary_type, node_type, kcu, l boundary_conditions_2d = BoundaryConditions2D( id=[1], type=[boundary_type], - the_geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])], + geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])], ) nodes, lines = boundary_conditions_2d.get_nodes_and_lines( grid2d_gw.nodes, @@ -412,7 +412,7 @@ def test_2d_boundary_condition_combined(grid2d_gw): boundary_conditions_2d = BoundaryConditions2D( id=[1, 2], type=[BoundaryType.WATERLEVEL, BoundaryType.GROUNDWATERLEVEL], - the_geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])] * 2, + geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])] * 2, ) nodes, lines = boundary_conditions_2d.get_nodes_and_lines( diff --git a/threedigrid_builder/tests/test_db.py b/threedigrid_builder/tests/test_db.py index 325aa969..fe2f12ec 100644 --- a/threedigrid_builder/tests/test_db.py +++ b/threedigrid_builder/tests/test_db.py @@ -37,7 +37,7 @@ def test_init(tmp_path): with mock.patch( "threedigrid_builder.interface.db.ThreediDatabase" ) as db, mock.patch.object(SQLite, "get_version") as get_version: - get_version.return_value = 224 + get_version.return_value = 225 sqlite = SQLite(path) db.assert_called_with(path) @@ -65,7 +65,7 @@ def test_init_bad_version(tmp_path): def test_get_version(db): - assert db.get_version() == 224 + assert db.get_version() == 225 def test_get_boundary_conditions_1d(db): From 3024b52084a8e74793c48d41ce5144fabadded33 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 5 Sep 2024 12:03:08 +0200 Subject: [PATCH 08/12] update changelog --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 5d5814c1..9341f3ca 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ Changelog of threedigrid-builder 1.17.1 (unreleased) ------------------- -- Nothing changed yet. +- Support 225 schema migration (boundary conditions and laterals). 1.17.0 (2024-08-16) From 6b39fcffa03fb660084deba67b6fe4ec12704fe5 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 5 Sep 2024 12:03:29 +0200 Subject: [PATCH 09/12] temporarily depend on github branch of threedi-schema --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3226d18f..92d7bc80 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ def get_version(): install_requires = [ "numpy>=1.15,<3.0", - "threedi-schema==0.224.*", + "threedi-schema @ https://github.com/nens/threedi-schema/archive/eli-laterals-and-boundary-conditions.zip", "shapely>=2", "pyproj>=3", "condenser[geo]>=0.1.1", From 60c52d43eb177cf319736d37ec639ab4b1b8609c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eli=20Sall=C3=A9?= Date: Thu, 5 Sep 2024 12:21:49 +0200 Subject: [PATCH 10/12] revert changed method name Co-authored-by: margrietpalm --- threedigrid_builder/grid/boundary_conditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index b4697769..7cdcf503 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -266,7 +266,7 @@ def is_groundwater(kcu: LineType) -> bool: } @staticmethod - def type_is_groundwater(type: BoundaryType) -> bool: + def boundary_type_is_groundwater(type: BoundaryType) -> bool: return type in { BoundaryType.GROUNDWATERLEVEL, BoundaryType.GROUNDWATERDISCHARGE, From b8a519c85c5b42325f9782517a66ee6ececa7bc2 Mon Sep 17 00:00:00 2001 From: elisalle Date: Thu, 5 Sep 2024 12:25:12 +0200 Subject: [PATCH 11/12] fix broken test --- threedigrid_builder/grid/boundary_conditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index 7cdcf503..633fec0d 100644 --- a/threedigrid_builder/grid/boundary_conditions.py +++ b/threedigrid_builder/grid/boundary_conditions.py @@ -187,7 +187,7 @@ def get_neighoring_node_idx( return node_idx[before if is_before else after], is_before def adapt_node_idx_groundwater(self, idx: int, nodes: Nodes, node_idx): - is_groundwater = self.type_is_groundwater(self.type[idx]) + is_groundwater = self.boundary_type_is_groundwater(self.type[idx]) if is_groundwater: n_groundwater_cells = nodes.n_groundwater_cells if n_groundwater_cells == 0: From 8f0751a44d2a117589c88b0475c8803e95e453b9 Mon Sep 17 00:00:00 2001 From: elisalle Date: Mon, 9 Sep 2024 10:25:45 +0200 Subject: [PATCH 12/12] set threedi-schema version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92d7bc80..ef662f7c 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,7 @@ def get_version(): install_requires = [ "numpy>=1.15,<3.0", - "threedi-schema @ https://github.com/nens/threedi-schema/archive/eli-laterals-and-boundary-conditions.zip", + "threedi-schema==0.225.*", "shapely>=2", "pyproj>=3", "condenser[geo]>=0.1.1",