From 0a383a9006e8fc27eb5a3b6f2ef4bd6c5d59bb08 Mon Sep 17 00:00:00 2001 From: robbievanleeuwen Date: Wed, 21 Dec 2022 18:08:23 +1100 Subject: [PATCH 1/4] Fix shapely imports; fix test_filter_non_polygons --- docs/source/requirements_docs.txt | 2 +- .../01-advanced/05_trapz_approximation.py | 2 +- sectionproperties/analysis/section.py | 5 ++-- sectionproperties/pre/bisect_section.py | 14 +++++------ sectionproperties/pre/geometry.py | 24 +++++++++---------- .../pre/library/bridge_sections.py | 2 +- .../pre/library/nastran_sections.py | 2 +- .../pre/library/primitive_sections.py | 2 +- .../pre/library/steel_sections.py | 2 +- sectionproperties/pre/rhino.py | 2 +- sectionproperties/tests/test_offset.py | 2 +- sectionproperties/tests/test_sections.py | 20 ++++++++-------- sectionproperties/tests/test_validation.py | 2 +- setup.cfg | 2 +- 14 files changed, 41 insertions(+), 42 deletions(-) diff --git a/docs/source/requirements_docs.txt b/docs/source/requirements_docs.txt index c3afa800..bff054b3 100644 --- a/docs/source/requirements_docs.txt +++ b/docs/source/requirements_docs.txt @@ -1,6 +1,6 @@ scipy numpy -shapely +shapely>=2.0 matplotlib>=3.4 more_itertools triangle diff --git a/examples/01-advanced/05_trapz_approximation.py b/examples/01-advanced/05_trapz_approximation.py index 3ca7a401..336e9d84 100644 --- a/examples/01-advanced/05_trapz_approximation.py +++ b/examples/01-advanced/05_trapz_approximation.py @@ -25,7 +25,7 @@ # Shapely `Polygon` object. import numpy as np import matplotlib.pyplot as plt -from shapely.geometry import Polygon +from shapely import Polygon import sectionproperties.pre.geometry as geometry import sectionproperties.pre.pre as pre import sectionproperties.pre.library.primitive_sections as sections diff --git a/sectionproperties/analysis/section.py b/sectionproperties/analysis/section.py index 5a19615e..195b6ff9 100644 --- a/sectionproperties/analysis/section.py +++ b/sectionproperties/analysis/section.py @@ -27,9 +27,8 @@ import sectionproperties.analysis.solver as solver import sectionproperties.post.post as post -from shapely.geometry import Polygon +from shapely import Polygon, Point from shapely.strtree import STRtree -from shapely.geometry import Point class Section: @@ -2262,7 +2261,7 @@ def get_stress_at_points( query_geom = Point(pt) tri_ids = [ self.poly_mesh_idx[id(poly)] - for poly in self.mesh_search_tree.query(query_geom) + for poly in self.mesh_search_tree.query(query_geom) # TODO if poly.intersects(query_geom) ] if len(tri_ids) == 0: diff --git a/sectionproperties/pre/bisect_section.py b/sectionproperties/pre/bisect_section.py index 44b414a7..5f1e0116 100644 --- a/sectionproperties/pre/bisect_section.py +++ b/sectionproperties/pre/bisect_section.py @@ -1,7 +1,7 @@ from typing import Tuple, Union, List, Optional import numpy as np -import shapely +from shapely import LineString, GeometryCollection, Polygon def create_line_segment( @@ -23,19 +23,19 @@ def create_line_segment( scale_factor_1 = (b_1 - p_x) / vector[0] y_1 = scale_factor_1 * vector[1] + p_y - return shapely.geometry.LineString([(b_1, y_1), (b_2, y_2)]) + return LineString([(b_1, y_1), (b_2, y_2)]) else: # Vertical line scale_factor_2 = (b_2 - p_y) / vector[1] x_2 = scale_factor_2 * vector[0] + p_x scale_factor_1 = (b_1 - p_y) / vector[1] x_1 = scale_factor_1 * vector[0] + p_x - return shapely.geometry.LineString([(x_1, b_1), (x_2, b_2)]) + return LineString([(x_1, b_1), (x_2, b_2)]) def group_top_and_bottom_polys( - polys: shapely.geometry.GeometryCollection, - line: shapely.geometry.LineString, + polys: GeometryCollection, + line: LineString, ) -> Tuple[list, list]: """ Returns tuple of two lists representing the list of Polygons in 'polys' on the "top" side of 'line' and the @@ -67,7 +67,7 @@ def group_top_and_bottom_polys( def line_mx_plus_b( - line: shapely.geometry.LineString, + line: LineString, ) -> Tuple[float, float]: """ Returns a tuple representing the values of "m" and "b" from the definition of 'line' as "y = mx + b". @@ -120,7 +120,7 @@ def line_intersection( def sum_poly_areas( - lop: List[shapely.geometry.Polygon], + lop: List[Polygon], ) -> float: """ Returns a float representing the total area of all polygons diff --git a/sectionproperties/pre/geometry.py b/sectionproperties/pre/geometry.py index 32bcb3dd..cd096cdf 100644 --- a/sectionproperties/pre/geometry.py +++ b/sectionproperties/pre/geometry.py @@ -7,17 +7,17 @@ import pathlib import more_itertools import numpy as np -from shapely.geometry import ( +from shapely import ( Polygon, MultiPolygon, LineString, LinearRing, Point, - box, GeometryCollection, + box, + affinity, ) from shapely.ops import split, unary_union -import shapely import matplotlib import matplotlib.pyplot as plt import sectionproperties.pre.pre as pre @@ -51,7 +51,7 @@ class Geometry: def __init__( self, - geom: shapely.geometry.Polygon, + geom: Polygon, material: pre.Material = pre.DEFAULT_MATERIAL, control_points: Optional[Union[Point, List[float, float]]] = None, tol=12, @@ -544,11 +544,11 @@ def shift_section( # Move assigned control point new_ctrl_point = None if self.assigned_control_point: - new_ctrl_point = shapely.affinity.translate( + new_ctrl_point = affinity.translate( self.assigned_control_point, x_offset, y_offset ).coords[0] new_geom = Geometry( - shapely.affinity.translate(self.geom, x_offset, y_offset), + affinity.translate(self.geom, x_offset, y_offset), self.material, new_ctrl_point, ) @@ -585,11 +585,11 @@ def rotate_section( rotate_point = rot_point if rot_point == "center": rotate_point = box(*self.geom.bounds).centroid - new_ctrl_point = shapely.affinity.rotate( + new_ctrl_point = affinity.rotate( self.assigned_control_point, angle, rotate_point, use_radians ).coords[0] new_geom = Geometry( - shapely.affinity.rotate(self.geom, angle, rot_point, use_radians), + affinity.rotate(self.geom, angle, rot_point, use_radians), self.material, new_ctrl_point, ) @@ -625,13 +625,13 @@ def mirror_section( x_mirror = -x_mirror elif axis == "y": y_mirror = -y_mirror - mirrored_geom = shapely.affinity.scale( + mirrored_geom = affinity.scale( self.geom, xfact=y_mirror, yfact=x_mirror, zfact=1.0, origin=mirror_point ) new_ctrl_point = None if self.assigned_control_point: - new_ctrl_point = shapely.affinity.scale( + new_ctrl_point = affinity.scale( self.assigned_control_point, xfact=y_mirror, yfact=x_mirror, @@ -677,7 +677,7 @@ def split_section( The following example splits a 200PFC section about the y-axis:: import sectionproperties.pre.library.steel_sections as steel_sections - from shapely.geometry import LineString + from shapely import LineString geometry = steel_sections.channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8) right_geom, left_geom = geometry.split_section((0, 0), (0, 1)) @@ -1672,7 +1672,7 @@ def split_section( The following example splits a 200PFC section about the y-axis:: import sectionproperties.pre.library.steel_sections as steel_sections - from shapely.geometry import LineString + from shapely import LineString geometry = steel_sections.channel_section(d=200, b=75, t_f=12, t_w=6, r=12, n_r=8) right_geom, left_geom = geometry.split_section((0, 0), (0, 1)) diff --git a/sectionproperties/pre/library/bridge_sections.py b/sectionproperties/pre/library/bridge_sections.py index 35c7b8fd..ca266db3 100644 --- a/sectionproperties/pre/library/bridge_sections.py +++ b/sectionproperties/pre/library/bridge_sections.py @@ -1,5 +1,5 @@ import numpy as np -from shapely.geometry import Polygon +from shapely import Polygon import sectionproperties.pre.geometry as geometry import sectionproperties.pre.pre as pre diff --git a/sectionproperties/pre/library/nastran_sections.py b/sectionproperties/pre/library/nastran_sections.py index 6d7611e1..1da789c0 100644 --- a/sectionproperties/pre/library/nastran_sections.py +++ b/sectionproperties/pre/library/nastran_sections.py @@ -1,5 +1,5 @@ import numpy as np -from shapely.geometry import Polygon +from shapely import Polygon import sectionproperties.pre.geometry as geometry import sectionproperties.pre.pre as pre from sectionproperties.pre.library.utils import draw_radius diff --git a/sectionproperties/pre/library/primitive_sections.py b/sectionproperties/pre/library/primitive_sections.py index 2c5b91f5..20008448 100644 --- a/sectionproperties/pre/library/primitive_sections.py +++ b/sectionproperties/pre/library/primitive_sections.py @@ -1,5 +1,5 @@ import numpy as np -from shapely.geometry import Polygon +from shapely import Polygon import sectionproperties.pre.geometry as geometry import sectionproperties.pre.pre as pre from sectionproperties.pre.library.utils import draw_radius diff --git a/sectionproperties/pre/library/steel_sections.py b/sectionproperties/pre/library/steel_sections.py index 1d0d0c77..a3837833 100644 --- a/sectionproperties/pre/library/steel_sections.py +++ b/sectionproperties/pre/library/steel_sections.py @@ -1,5 +1,5 @@ import numpy as np -from shapely.geometry import Polygon +from shapely import Polygon import sectionproperties.pre.geometry as geometry import sectionproperties.pre.pre as pre from sectionproperties.pre.library.utils import draw_radius, rotate diff --git a/sectionproperties/pre/rhino.py b/sectionproperties/pre/rhino.py index 8d0a855a..70ce8ad2 100644 --- a/sectionproperties/pre/rhino.py +++ b/sectionproperties/pre/rhino.py @@ -1,6 +1,6 @@ import pathlib from typing import List, Union -from shapely.geometry.polygon import Polygon +from shapely import Polygon from rhino_shapely_interop.importers import RhImporter diff --git a/sectionproperties/tests/test_offset.py b/sectionproperties/tests/test_offset.py index 41adecff..e5e04af5 100644 --- a/sectionproperties/tests/test_offset.py +++ b/sectionproperties/tests/test_offset.py @@ -3,7 +3,7 @@ import sectionproperties.pre.library.primitive_sections as sections import sectionproperties.pre.library.steel_sections as steel_sections from sectionproperties.analysis.section import Section -from shapely.geometry import Polygon +from shapely import Polygon from sectionproperties.pre.geometry import Geometry diff --git a/sectionproperties/tests/test_sections.py b/sectionproperties/tests/test_sections.py index a61484d3..f79a987f 100644 --- a/sectionproperties/tests/test_sections.py +++ b/sectionproperties/tests/test_sections.py @@ -8,15 +8,15 @@ from sectionproperties.analysis.section import Section from sectionproperties.pre.pre import DEFAULT_MATERIAL, Material from sectionproperties.pre.rhino import load_3dm, load_brep_encoding -from shapely.geometry import ( +from shapely import ( Polygon, MultiPolygon, LineString, Point, GeometryCollection, box, + wkt, ) -from shapely import wkt import json big_sq = rectangular_section(d=300, b=250) @@ -133,7 +133,7 @@ def test_geometry_from_points(): holes=holes, material=material, ) - wkt_test_geom = shapely.wkt.loads( + wkt_test_geom = wkt.loads( "POLYGON ((6 10, 6 -10, -6 -10, -6 10, 6 10), (-4 4, 4 4, 4 8, -4 8, -4 4), (4 -8, 4 -4, -4 -4, -4 -8, 4 -8))" ) assert (new_geom.geom - wkt_test_geom) == Polygon() @@ -195,7 +195,7 @@ def test_compound_geometry_from_points(): new_geom = CompoundGeometry.from_points( points, facets, control_points, materials=materials ) - wkt_test_geom = shapely.wkt.loads( + wkt_test_geom = wkt.loads( "MULTIPOLYGON (((-0.05 -2, 0.05 -2, 0.05 -0.05, 1 -0.05, 1 0.05, -0.05 0.05, -0.05 -2)), ((-1 -2, 1 -2, 1 -2.1, -1 -2.1, -1 -2)))" ) assert (new_geom.geom - wkt_test_geom) == Polygon() @@ -283,7 +283,7 @@ def test_multi_nested_compound_geometry_from_points(): holes=holes, materials=materials, ) - wkt_test_geom = shapely.wkt.loads( + wkt_test_geom = wkt.loads( "MULTIPOLYGON (((50 50, 50 -50, -50 -50, -50 50, 50 50), (12.5 12.5, -12.5 12.5, -12.5 -12.5, 12.5 -12.5, 12.5 12.5)), ((-37.5 -37.5, -37.5 37.5, 37.5 37.5, 37.5 -37.5, -37.5 -37.5), (12.5 12.5, -12.5 12.5, -12.5 -12.5, 12.5 -12.5, 12.5 12.5)), ((-25 -25, -25 25, 25 25, 25 -25, -25 -25), (12.5 12.5, -12.5 12.5, -12.5 -12.5, 12.5 -12.5, 12.5 12.5)))" ) assert (nested_compound.geom - wkt_test_geom) == Polygon() @@ -447,17 +447,17 @@ def test_mirror_section(): def test_filter_non_polygons(): - point1 = Point([0, 0]) - point2 = Point([1, 1]) - point3 = Point([1, 0]) + point1 = (0, 0) + point2 = (1, 1) + point3 = (1, 0) line = LineString([point1, point2]) poly = Polygon([point1, point2, point3]) multi_poly = MultiPolygon([poly, poly]) - collection = GeometryCollection([poly, point1, line]) + collection = GeometryCollection([poly, Point(point1), line]) out = filter_non_polygons(collection) assert filter_non_polygons(poly) == poly assert filter_non_polygons(multi_poly) == multi_poly - assert filter_non_polygons(point1) == Polygon() + assert filter_non_polygons(Point(point1)) == Polygon() assert filter_non_polygons(line) == Polygon() assert filter_non_polygons(collection) == poly diff --git a/sectionproperties/tests/test_validation.py b/sectionproperties/tests/test_validation.py index b4066266..44a3a920 100644 --- a/sectionproperties/tests/test_validation.py +++ b/sectionproperties/tests/test_validation.py @@ -1,5 +1,5 @@ import pytest_check as check -from shapely.geometry import Polygon +from shapely import Polygon from sectionproperties.pre.geometry import Geometry import sectionproperties.pre.library.primitive_sections as sections import sectionproperties.pre.library.steel_sections as steel_sections diff --git a/setup.cfg b/setup.cfg index 38440504..ce08f27e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires = scipy more_itertools matplotlib>=3.4 - shapely + shapely>=2.0 triangle cad_to_shapely>=0.3 rich From 6e00eae42bb1f546c05f6e0c3e6cd3c28096d327 Mon Sep 17 00:00:00 2001 From: robbievanleeuwen Date: Wed, 21 Dec 2022 18:18:02 +1100 Subject: [PATCH 2/4] Update codecov.yml --- codecov.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 7ccc155f..e2f7ee34 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,6 +6,12 @@ coverage: round: down range: "70...100" status: + project: + default: + # basic + target: auto + threshold: 5% + base: auto patch: off parsers: @@ -16,4 +22,4 @@ parsers: method: no macro: no -comment: false +comment: false \ No newline at end of file From 4bad00ede4bda70fd2494a8c186b7021a38dc6f1 Mon Sep 17 00:00:00 2001 From: Norman JN Richardson Date: Tue, 27 Dec 2022 17:36:52 -0800 Subject: [PATCH 3/4] Update STRtree api to shapely 2.0 --- sectionproperties/analysis/section.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sectionproperties/analysis/section.py b/sectionproperties/analysis/section.py index 195b6ff9..27367dd8 100644 --- a/sectionproperties/analysis/section.py +++ b/sectionproperties/analysis/section.py @@ -193,7 +193,6 @@ def __init__( Polygon(self.geometry.mesh["vertices"][tri][0:3]) for tri in self.geometry.mesh["triangles"] ] - self.poly_mesh_idx = dict((id(poly), i) for i, poly in enumerate(p_mesh)) self.mesh_search_tree = STRtree(p_mesh) # initialise class storing section properties @@ -2259,11 +2258,7 @@ def get_stress_at_points( for pt in pts: query_geom = Point(pt) - tri_ids = [ - self.poly_mesh_idx[id(poly)] - for poly in self.mesh_search_tree.query(query_geom) # TODO - if poly.intersects(query_geom) - ] + tri_ids = self.mesh_search_tree.query(query_geom, predicate="intersects" ) if len(tri_ids) == 0: sig = None elif len(tri_ids) == 1: From bb58e4bcc67955d596f12264998e47d89e60600f Mon Sep 17 00:00:00 2001 From: Norman JN Richardson Date: Tue, 27 Dec 2022 17:56:24 -0800 Subject: [PATCH 4/4] blackify --- sectionproperties/analysis/section.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sectionproperties/analysis/section.py b/sectionproperties/analysis/section.py index 27367dd8..d3d36668 100644 --- a/sectionproperties/analysis/section.py +++ b/sectionproperties/analysis/section.py @@ -2258,7 +2258,7 @@ def get_stress_at_points( for pt in pts: query_geom = Point(pt) - tri_ids = self.mesh_search_tree.query(query_geom, predicate="intersects" ) + tri_ids = self.mesh_search_tree.query(query_geom, predicate="intersects") if len(tri_ids) == 0: sig = None elif len(tri_ids) == 1: