-
Notifications
You must be signed in to change notification settings - Fork 46
Point In Face & Get Faces Containing Point #1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 96 commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
75b88e8
Initial work
aaronzedwick 998aa99
Switched to projection method
aaronzedwick 7d7be67
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick e38ca24
Updated test cases, fixed spherical bug
aaronzedwick 92bab4a
Added test cases
aaronzedwick 354f821
Increased performance
aaronzedwick 5fc59aa
Update test_geometry.py
aaronzedwick c4a4979
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 3b09973
updated api
aaronzedwick f7cb51c
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick 22e84d5
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 4043c8b
Updated detection method
aaronzedwick 95a0dea
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 5dbed72
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick c1eae89
Implemented new ray casting method
aaronzedwick 586c8ad
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick b33326d
Added node crossing and point on edge checks
aaronzedwick 0acaa2b
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 807ce07
Added docstrings, test case
aaronzedwick b4eba94
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick fa6fd8c
Update test_geometry.py
aaronzedwick 0092258
Fixed point conversion bug
aaronzedwick 1f6f51b
Update geometry.py
aaronzedwick 5e0477b
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick acce252
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick d88d69f
Converted functions to numba, updated tests accordingly
aaronzedwick a379a1a
Added max face radius function
aaronzedwick fefe1e7
Added baseplate code for polygon containing code
aaronzedwick cc9f943
Added reference point setter
aaronzedwick 73a1be4
Updated to use constructed edges
aaronzedwick 8392e2c
Debugging
aaronzedwick 6fea25e
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 200f4bb
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick e86e81c
Merge branch 'main' into zedwick/point-in-polygon
philipc2 a6b0dcc
Added unique face test cases
aaronzedwick 36ef299
Fixed test cases, changed to `point_in_face`
aaronzedwick dc153dc
Convert face containing point to use updated function
aaronzedwick c5ed371
Added inverse indices, complete get_faces_containing_point
aaronzedwick d7318de
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick ab18797
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick 47843d8
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 845cca6
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 88a602f
Updated to use inverse face indices
aaronzedwick c28772a
Fixed failing tests
aaronzedwick e055327
Moved function location
aaronzedwick 46cecc4
Fixed circular import
aaronzedwick 5dba109
Update grid.py
aaronzedwick d297a9e
updated comment
aaronzedwick bff6cd5
updated max_face_radius to handle variable face sizes
aaronzedwick 67ea7b2
updated haversine and added test
aaronzedwick ce354fd
Added benchmark, made max_face_radius attribute for better performance
aaronzedwick 7eeef4e
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 98a676d
Fixed benchmark
aaronzedwick 66fba3d
added property, update benchmark
aaronzedwick f1caa3f
updated benchmark
aaronzedwick bfa621b
CI debugging
aaronzedwick 274591c
Fixed indexing problem
aaronzedwick 5f66225
added normalize to ensure consistency
aaronzedwick 4c97d18
Add spherical support for `faces_containing_point`, added docs, api, …
aaronzedwick a14286a
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 60964fe
Fixed test cases
aaronzedwick e7721ae
Fixed test attempt #2
aaronzedwick a16b652
Fixed error with improper coordinates
aaronzedwick 8239123
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 5ea0911
Updated method of subsetting and test case
aaronzedwick bbb7b90
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick 23cdc74
pre-commit
aaronzedwick 32ecaf4
fixed tests
aaronzedwick a3ba55c
Update test_grid.py
aaronzedwick f974db4
Added notebook
aaronzedwick 2d7dcc7
Update point_in_face.ipynb
aaronzedwick ebfb0dd
Merge branch 'main' into zedwick/point-in-polygon
philipc2 0638cfb
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick bcb9f17
Merge branch 'main' into zedwick/point-in-polygon
philipc2 37feaee
Merge branch 'main' into zedwick/point-in-polygon
rajeeja fdb28e4
Merge branch 'main' into zedwick/point-in-polygon
philipc2 568689c
Merge branch 'main' into zedwick/point-in-polygon
philipc2 44406e2
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 3175c53
Added tests, updated numba, fixed bug
aaronzedwick 683e2cc
Merge branch 'zedwick/point-in-polygon' of https://github.com/UXARRAY…
aaronzedwick ef22d37
Merge branch 'main' into zedwick/point-in-polygon
philipc2 6557c93
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick a93b79a
Addressed review comments
aaronzedwick 76acbc9
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick c20a147
Added error tolerance for points close to nodes
aaronzedwick 2e3dc71
turned numba on
aaronzedwick 63d6d8d
Fixed numba issues, updated error tolerance
aaronzedwick 4937cd2
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick 34067b0
Update uxarray/grid/grid.py
aaronzedwick aeb88a9
Update uxarray/grid/grid.py
aaronzedwick f904b8f
Update uxarray/grid/grid.py
aaronzedwick 7c3cda3
Merge branch 'main' into zedwick/point-in-polygon
philipc2 e9e63fb
Updated warning and docstring
aaronzedwick a42fa2f
Added better comments
aaronzedwick 33cf087
Merge branch 'main' into zedwick/point-in-polygon
aaronzedwick d9d2fcc
Updated docstrings
aaronzedwick b69af29
Updated method to take both coordinate systems, updated tests and doc…
aaronzedwick 406dfd8
Merge branch 'main' into zedwick/point-in-polygon
philipc2 d09dbcd
Update docs/userguide.rst
aaronzedwick 1b3699b
Added examples to docstring
aaronzedwick b6c194d
Update docs/userguide.rst
aaronzedwick 820c0c2
update example in docstring
philipc2 31b6e0f
Update grid.py
aaronzedwick 250d318
Update uxarray/grid/grid.py
aaronzedwick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "336fe698-c5a1-481e-9aea-9de158174a96", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Point In Face" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "a5dbe362-99b5-4c2d-a148-cd3816cb3334", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import uxarray as ux\n", | ||
| "import numpy as np\n", | ||
| "from uxarray.grid.utils import _get_cartesian_face_edge_nodes\n", | ||
| "from uxarray.grid.geometry import point_in_face\n", | ||
| "\n", | ||
| "grid_path = \"../../test/meshfiles/ugrid/quad-hexagon/grid.nc\"\n", | ||
| "grid = ux.open_grid(grid_path)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "30c4cff2-f760-46d3-9ff9-11f48a51cea8", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "The function `point_in_face` determines whether or not a given face contains a point. The function parameters are as follows:\n", | ||
| "\n", | ||
| "* `edges_xyz` are the supplied edges of the face, with shape [n_edges, 2]\n", | ||
| "* `point_xyz` the cartesian point which is being checked. The dtype should be `np.float64`\n", | ||
| "* `inclusive` bool flag indicating whether to classify a point that lies on either the edges or nodes as within the face" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5e70681b-e7c3-4817-bcdc-3241c0f3e46e", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "We can take a face and check to see if it's face center lies within the face." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "c8c6f19a-38f2-4211-8a7b-d5f383eb5dc5", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Get the face edge arrays of each face in the grid\n", | ||
| "faces_edge_cartesian = _get_cartesian_face_edge_nodes(\n", | ||
| " grid.face_node_connectivity.values,\n", | ||
| " grid.n_face,\n", | ||
| " grid.n_max_face_nodes,\n", | ||
| " grid.node_x.values,\n", | ||
| " grid.node_y.values,\n", | ||
| " grid.node_z.values,\n", | ||
| ")\n", | ||
| "\n", | ||
| "face_center = np.array(\n", | ||
| " [grid.face_x.values[0], grid.face_y.values[0], grid.face_z.values[0]],\n", | ||
| " dtype=np.float64,\n", | ||
| ")\n", | ||
| "point_in_face(faces_edge_cartesian[0], face_center, inclusive=True)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5a656ef1-3898-4586-8ca7-3d43f7517adc", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "We can do something similar but with the nodes of the face, to showcase the inclusive flag use." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "7e686262-da40-4b86-84af-9ac2a10887ca", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "face_node = np.array(\n", | ||
| " [grid.node_x.values[0], grid.node_y.values[0], grid.node_z.values[0]],\n", | ||
| " dtype=np.float64,\n", | ||
| ")\n", | ||
| "inclusive = point_in_face(faces_edge_cartesian[0], face_node, inclusive=True)\n", | ||
| "non_inclusive = point_in_face(faces_edge_cartesian[0], face_node, inclusive=False)\n", | ||
| "\n", | ||
| "print(\n", | ||
| " f\"Node is in the face when inclusive is set to True: {inclusive}\\nNode is not in the face when inclusive is set to False: {non_inclusive}\"\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "c3e3ead1-40cf-44c7-84b2-ca7b4c4bbdac", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Get Faces Containing Point" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "632c7222-154e-459a-b063-98b4260729e8", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "Inside UXarray we can also retrieve any faces that contain a given point. By simply passing in a point, the function will return an array that contains the indices of the faces that the point is contained within. A point can be contained within many faces if the point is on a node or an edge. This is because many different faces may use the same node, and an edge will likely have two faces saddling it. This function considers these points as part of the faces that contain that edge or node. If an empty array is returned, this is likely because the grid is a partial and the point is within a region that has no faces. " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "3f2277e6-0073-4432-a424-e86efbaee1b8", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Face center\n", | ||
| "grid.get_faces_containing_point(face_center)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "39ee9098-d639-4605-b15b-9d73085498a9", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Node which is apart of 3 different faces\n", | ||
| "grid.get_faces_containing_point(face_node)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "daa70b10-514c-4942-ba7b-1b76bef626f9", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Pole point which this partial grid does not cover\n", | ||
| "random_xyz = np.array([0, 0, 1], dtype=np.float64)\n", | ||
| "grid.get_faces_containing_point(random_xyz)" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3 (ipykernel)", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.2" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.