diff --git a/CHANGES.rst b/CHANGES.rst index fcb4996a..fb0be9bd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ Changelog of threedigrid-builder 1.17.2 (unreleased) ------------------- -- Nothing changed yet. +- Support 225 schema migration (boundary conditions and laterals). 1.17.1 (2024-09-02) diff --git a/setup.py b/setup.py index 3226d18f..ef662f7c 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==0.225.*", "shapely>=2", "pyproj>=3", "condenser[geo]>=0.1.1", diff --git a/threedigrid_builder/grid/boundary_conditions.py b/threedigrid_builder/grid/boundary_conditions.py index 09860abe..633fec0d 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 @@ -97,15 +97,15 @@ def apply(self, grid): class BoundaryCondition2D: id: int - boundary_type: BoundaryType - the_geom: shapely.Geometry + type: BoundaryType + 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) @@ -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.boundary_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 boundary_type_is_groundwater(type: BoundaryType) -> bool: + return type in { BoundaryType.GROUNDWATERLEVEL, BoundaryType.GROUNDWATERDISCHARGE, } @@ -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) diff --git a/threedigrid_builder/interface/db.py b/threedigrid_builder/interface/db.py index a6cdf546..96095e5a 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 @@ -347,7 +347,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) @@ -363,13 +363,13 @@ def get_boundary_conditions_2d(self) -> BoundaryConditions2D: arr = ( session.query( models.BoundaryConditions2D.id, - models.BoundaryConditions2D.boundary_type, - models.BoundaryConditions2D.the_geom, + models.BoundaryConditions2D.type, + 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}) diff --git a/threedigrid_builder/tests/test_boundary_conditions.py b/threedigrid_builder/tests/test_boundary_conditions.py index f616978c..f7a1683f 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,8 +278,8 @@ def test_2d_boundary_condition( ): boundary_conditions_2d = BoundaryConditions2D( id=range(len(bc_coords)), - boundary_type=[3] * len(bc_coords), - the_geom=shapely.linestrings(bc_coords), + type=[3] * len(bc_coords), + geom=shapely.linestrings(bc_coords), ) nodes, lines = boundary_conditions_2d.get_nodes_and_lines( @@ -319,8 +319,8 @@ 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), - the_geom=shapely.linestrings(bc_coords), + type=[3] * len(bc_coords), + geom=shapely.linestrings(bc_coords), ) with pytest.raises(SchematisationError, match=expected_message): @@ -383,8 +383,8 @@ 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], - the_geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])], + type=[boundary_type], + geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])], ) nodes, lines = boundary_conditions_2d.get_nodes_and_lines( grid2d_gw.nodes, @@ -411,8 +411,8 @@ 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], - the_geom=[shapely.linestrings([(12.0, 3.0), (12.0, 8.0)])] * 2, + type=[BoundaryType.WATERLEVEL, BoundaryType.GROUNDWATERLEVEL], + 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 d0dedcd5..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): @@ -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