NOAA-ORR-ERD / cell_tree2d

Cell Tree data structure for fast searching of an unstructured grid for the polygon containing the specified point
16 stars 11 forks source link

Draft: Package restructuring and wheel building #15

Open MuellerSeb opened 2 months ago

MuellerSeb commented 2 months ago

I'd like to use gridded and would like to see pypi releases of it and I noted, that this dependency is probably the reason it is not on pypi. I updated the repo accordingly to be able to build wheels with github actions.

This PR updates the whole package in the following way:

Issues:

Click to expand the test log ``` tests/test_cell_tree2d.py::test_init PASSED [ 8%] tests/test_cell_tree2d.py::test_lists PASSED [ 16%] tests/test_cell_tree2d.py::test_types PASSED [ 25%] tests/test_cell_tree2d.py::test_shape_error PASSED [ 33%] tests/test_cell_tree2d.py::test_bounds_errors PASSED [ 41%] tests/test_cell_tree2d.py::test_triangle_lookup PASSED [ 50%] tests/test_cell_tree2d.py::test_poly_lookup PASSED [ 58%] tests/test_cell_tree2d.py::test_multi_poly_lookup FAILED [ 66%] tests/test_cell_tree2d.py::test_multi_poly_1D_lookup FAILED [ 75%] tests/test_cell_tree2d.py::test_edge_cases PASSED [ 83%] tests/test_cell_tree2d.py::test_multipoint FAILED [ 91%] tests/test_quad_grid.py::test_build_tree_from_coords FAILED [100%] =========================================================================================================== FAILURES ============================================================================================================ ____________________________________________________________________________________________________ test_multi_poly_lookup _____________________________________________________________________________________________________ def test_multi_poly_lookup(): # A simple quad grid nodes = np.array([[0.0, 0.0], #0 [0.0, 2.0], #1 [2.0, 0.0], #2 [2.0, 2.0], #3 [4.0, 0.0], #4 [4.0, 2.0], #5 [6.0, 0.0], #6 [6.0, 2.0], #7 [0.0,4.0], #8 [2.0,4.0], #9 [4.0,4.0], #10 [6.0,4.0] #11 ]) faces = np.array([[0, 8, 9, 5, 2], [9, 11, 7, 5, -1], [4, 7 ,6, -1, -1] ], dtype=np.intc) tree = CellTree(nodes, faces, num_buckets = 2, cells_per_leaf = 1) point = np.array([1., 1.]) # in POLY 1 result = tree.locate(point) > assert result == 0 E assert array([-1], dtype=int32) == 0 tests/test_cell_tree2d.py:229: AssertionError ___________________________________________________________________________________________________ test_multi_poly_1D_lookup ___________________________________________________________________________________________________ def test_multi_poly_1D_lookup(): # A simple quad grid nodes = np.array([[0.0, 0.0], #0 [0.0, 2.0], #1 [2.0, 0.0], #2 [2.0, 2.0], #3 [4.0, 0.0], #4 [4.0, 2.0], #5 [6.0, 0.0], #6 [6.0, 2.0], #7 [0.0,4.0], #8 [2.0,4.0], #9 [4.0,4.0], #10 [6.0,4.0] #11 ]) faces = np.array([0, 8, 9, 5, 2, 9, 11, 7, 5, 4, 7, 6] , dtype=np.intc) n_verts_arr = np.array([5,4,3],dtype=np.ubyte) tree = CellTree(nodes, faces, len_arr = n_verts_arr, num_buckets = 2, cells_per_leaf = 1) point = np.array([1., 1.]) # in POLY 1 result = tree.locate(point) > assert result == 0 E assert array([-1], dtype=int32) == 0 tests/test_cell_tree2d.py:265: AssertionError ________________________________________________________________________________________________________ test_multipoint ________________________________________________________________________________________________________ def test_multipoint(): tree = CellTree(nodes21, faces21) points = [(4.2, 3.0), (7.7, 13.5), (3.4, 7.000000001), (7.0, 5.0), # out of bounds points (8.66, 10.99), (7.3, 0.74), (2.5, 5.5), (9.8, 12.3), ] correct_indexes = (1, 20, 7, -1, -1, -1, -1, -1) ind = tree.locate(points) > assert np.array_equal(ind, correct_indexes) E assert False E + where False = (array([-1, -1, -1, -1, -1, -1, -1, -1], dtype=int32), (1, 20, 7, -1, -1, -1, ...)) E + where = np.array_equal tests/test_cell_tree2d.py:309: AssertionError __________________________________________________________________________________________________ test_build_tree_from_coords __________________________________________________________________________________________________ def test_build_tree_from_coords(): """ this tests using a structured grid with cell coordinates converting it to a flattened grid with nodes and cells defined as indexes to those nodes as much as anything else, this surves as example code for how to do that. """ x, y = curv_grid(n_x=3, n_y=3, center=(0.0, 0.0), min_radius=9.0, max_radius=18.0, angle=np.pi / 4.0 ) nodes, faces = nodes_from_coords(x, y) # these range from (30., 20.) to (31.1, 21.1) tree = CellTree(nodes, faces) # try to find some points # points outside the domain: result = tree.locate([(0.0, 0.0), (19.0, 5.0), (17.0, -1.0), (9.0, 10.0), ], ) assert np.all(result == -1) # points inside the domain result = tree.locate([(10.0, 1.0), (9.0, 3.0), (8.0, 6.0), (13.0, 1.0), (12.0, 4.0), (11.0, 7.0), (16.0, 1.0), (15.0, 8.0), (13.0, 11.0), ] ) > assert np.array_equal(result, [0, 1, 2, 3, 4, 5, 6, 7, 8]) E assert False E + where False = (array([-1, -1, -1, -1, -1, -1, -1, 7, -1], dtype=int32), [0, 1, 2, 3, 4, 5, ...]) E + where = np.array_equal tests/test_quad_grid.py:96: AssertionError ==================================================================================================== short test summary info ==================================================================================================== FAILED tests/test_cell_tree2d.py::test_multi_poly_lookup - assert array([-1], dtype=int32) == 0 FAILED tests/test_cell_tree2d.py::test_multi_poly_1D_lookup - assert array([-1], dtype=int32) == 0 FAILED tests/test_cell_tree2d.py::test_multipoint - assert False FAILED tests/test_quad_grid.py::test_build_tree_from_coords - assert False ================================================================================================== 4 failed, 8 passed in 0.39s ================================================================================================== ```
MuellerSeb commented 2 months ago

I had to revert the fix for #13 since the tests were failing with it and the buk variables were not declared.

MuellerSeb commented 2 months ago

CI workflow can be seen here for example: https://github.com/MuellerSeb/cell_tree2d/actions/runs/8839642612

MuellerSeb commented 2 months ago

The PyPI publishing stage relies on API tokens: https://pypi.org/help/#apitoken

But it seems that this approach is outdated and one should use trusted publishers

Either way, this is up to you, since this would require some work from you. I can just say it is very convenient and I use it for all my projects.