-
Notifications
You must be signed in to change notification settings - Fork 8
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
add arrow_data_to_origin option #217
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduced in this pull request enhance the functionality of mesh visualization by consolidating display logic, adding new features for visualizing vector data, and improving arrow data handling. A new option for directing arrow data to the origin is added, along with modifications to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Gus
participant Mesh
participant Options
User->>Gus: Request to show meshes
Gus->>Mesh: Prepare triangle and quad meshes
Mesh->>Options: Check arrow data options
Options-->>Mesh: Return arrow_data_to_origin setting
Mesh->>Mesh: Assign random coordinates to vertex data
Mesh->>Gus: Visualize meshes with arrows
Gus-->>User: Display updated visualization
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (3)
- examples/show_faces.py (1 hunks)
- gustaf/helpers/options.py (2 hunks)
- gustaf/show.py (2 hunks)
Additional comments not posted (8)
examples/show_faces.py (3)
61-61
: LGTM!Consolidating the display logic into a single
gus.show()
function improves the organization and readability of the code.
63-69
: LGTM!The loop that assigns random coordinates to the vertex data and visualizes the data as arrows is a great addition. It allows for a more dynamic representation of the mesh data and enhances the interactivity of the visualization.
71-74
: LGTM!The loop that sets the
arrow_data_to_origin
option toTrue
for both mesh types is consistent with the PR objective of introducing a new option to allow arrows to point towards the origin. The code changes align with the provided example and contribute to the overall functionality of the project.gustaf/helpers/options.py (2)
156-156
: LGTM!The added space before the type declaration for
label_font
improves readability and consistency in the documentation format.
183-189
: Looks good!The new
arrow_data_to_origin
option is a valuable addition to the "vedo" options. It enhances the flexibility in visualizing data relationships by allowing users to choose the direction of the arrows.The option is well-defined with an appropriate name, description, and allowed types. The implementation looks correct and consistent with the existing options.
gustaf/show.py (3)
370-371
: LGTM!Introducing the
a_data_dim
variable improves code readability by avoiding repeated calls toarrow_data_value.shape[1]
. Good refactoring!
371-374
: LGTM!The dimensionality check has been updated to use the
a_data_dim
variable, which is consistent with the previous change. The updated error message provides clearer feedback to the user by specifying the dimensionality of the requested data. Good improvement!
383-391
: LGTM!The new conditional block adds flexibility to the visualization options by allowing users to choose the direction of the arrows. The logic for calculating the shift and adjusting the vertices appears to be correct. This enhancement improves the functionality of the
make_showable
function and provides users with more intuitive options for visualizing arrow data.
mesh.vertex_data["coords"] = np.random.default_rng().random( | ||
tri.vertices.shape | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The code segment that assigns random coordinates to the coords
attribute of the vertex_data
dictionary for each mesh is correct and contributes to the dynamic visualization of the mesh data.
To improve the code readability, consider extracting the random coordinate generation logic into a separate function or variable. For example:
def generate_random_coords(shape):
return np.random.default_rng().random(shape)
for mesh in [tri, quad]:
mesh.vertex_data["coords"] = generate_random_coords(mesh.vertices.shape)
This change is not necessary but can make the code more readable and maintainable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thank you for the feature.
b805312
to
9ff7bcb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @j042, for your work on this. Can this be merged? Looks good to me. If you have nothing further, I will merge as soon as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (3)
- examples/show_faces.py (1 hunks)
- gustaf/helpers/options.py (2 hunks)
- gustaf/show.py (2 hunks)
🔇 Additional comments (5)
examples/show_faces.py (3)
61-61
: LGTM! Clear and well-structured visualization call.
The use of labeled mesh objects with the consolidated gus.show()
function improves code clarity.
68-69
: LGTM! Clear demonstration of arrow data visualization.
The code effectively shows how to configure and display vector data as arrows using the show_options
method.
71-76
: Excellent demonstration of the new arrow_data_to_origin feature!
The code provides a clear example of how to use the new option, with descriptive labels that help users understand the visual changes. This aligns perfectly with the PR objective.
gustaf/helpers/options.py (1)
156-156
: LGTM! Improved type annotation formatting.
The added space before the type annotation follows PEP 484 conventions and improves readability.
gustaf/show.py (1)
384-391
: Ensure Safe Reshaping of Arrow Vertices
Ensure that as_edges.vertices
has a shape compatible with reshaping to (-1, 2, a_data_dim)
. If the number of vertices is not even, this could result in a reshaping error.
Consider adding a check to confirm that the number of vertices is even before reshaping:
if as_edges.vertices.shape[0] % 2 != 0:
raise ValueError("Number of vertices must be even to reshape for arrow adjustment.")
gus.show(["triangles", tri], ["quads", quad]) | ||
|
||
# plot data - plots vector data as arrows | ||
for mesh in [tri, quad]: | ||
mesh.vertex_data["coords"] = np.random.default_rng().random( | ||
tri.vertices.shape | ||
) | ||
mesh.show_options(arrow_data="coords") | ||
gus.show(["triangles with arrows", tri], ["quads with arrows", quad]) | ||
|
||
# point data to origin | ||
for mesh in [tri, quad]: | ||
mesh.show_options(arrow_data_to_origin=True) | ||
gus.show( | ||
["triangles arrows to origin", tri], ["quads arrows to origin", quad] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider enhancing the example with more documentation.
This example effectively demonstrates three different visualization modes (basic, arrows, arrows-to-origin). Consider adding comments before each visualization block to:
- Explain what users should expect to see
- Highlight the visual differences between modes
- Document typical use cases for each mode
This would make the example more valuable as a tutorial.
Option( | ||
"vedo", | ||
"arrow_data_to_origin", | ||
"Points arrow data to geometric origin." | ||
"Equivalent to shifting arrows backwards with their own magitudes.", | ||
(bool,), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Fix typo and enhance documentation.
The implementation looks good and aligns well with the PR objectives. However, there are a few minor improvements needed:
- Fix the typo "magitudes" → "magnitudes"
- Consider enhancing the description to clarify:
- The default behavior (arrows point away from origin)
- The relationship with other arrow options (
arrow_data
andarrow_data_scale
)
Here's the suggested improvement:
Option(
"vedo",
"arrow_data_to_origin",
- "Points arrow data to geometric origin."
- "Equivalent to shifting arrows backwards with their own magitudes.",
+ "Points arrow data to geometric origin. By default, arrows point away from origin. "
+ "When enabled, arrows are shifted backwards by their own magnitudes. "
+ "Works in conjunction with arrow_data and arrow_data_scale options.",
(bool,),
),
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Option( | |
"vedo", | |
"arrow_data_to_origin", | |
"Points arrow data to geometric origin." | |
"Equivalent to shifting arrows backwards with their own magitudes.", | |
(bool,), | |
), | |
Option( | |
"vedo", | |
"arrow_data_to_origin", | |
"Points arrow data to geometric origin. By default, arrows point away from origin. " | |
"When enabled, arrows are shifted backwards by their own magnitudes. " | |
"Works in conjunction with arrow_data and arrow_data_scale options.", | |
(bool,), | |
), |
if a_data_dim not in (2, 3): | ||
raise ValueError( | ||
"Only 2D or 3D data can be shown.", | ||
f"Requested data is {arrow_data_value.shape[1]}", | ||
f"Requested data is {a_data_dim}D.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine Error Messages into a Single String
When raising the ValueError
, it's better to combine the error messages into a single string to ensure that the complete message is displayed correctly.
Apply this diff to combine the error message:
if a_data_dim not in (2, 3):
raise ValueError(
- "Only 2D or 3D data can be shown.",
- f"Requested data is {a_data_dim}D.",
+ f"Only 2D or 3D data can be shown. Requested data is {a_data_dim}D."
)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if a_data_dim not in (2, 3): | |
raise ValueError( | |
"Only 2D or 3D data can be shown.", | |
f"Requested data is {arrow_data_value.shape[1]}", | |
f"Requested data is {a_data_dim}D.", | |
if a_data_dim not in (2, 3): | |
raise ValueError( | |
f"Only 2D or 3D data can be shown. Requested data is {a_data_dim}D." | |
) |
arrow_shift = np.diff( | ||
as_edges.vertices.reshape(-1, 2, a_data_dim), axis=1 | ||
) | ||
as_edges.vertices[:] = ( | ||
as_edges.vertices.reshape(-1, 2, a_data_dim) - arrow_shift | ||
).reshape(-1, a_data_dim) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor Arrow Adjustment Code for Clarity
Consider refactoring the code that adjusts the arrow vertices to improve readability and efficiency.
Apply this diff to simplify the code:
- arrow_shift = np.diff(
- as_edges.vertices.reshape(-1, 2, a_data_dim), axis=1
- )
- as_edges.vertices[:] = (
- as_edges.vertices.reshape(-1, 2, a_data_dim) - arrow_shift
- ).reshape(-1, a_data_dim)
+ arrow_vertices = as_edges.vertices.reshape(-1, 2, a_data_dim)
+ arrow_shift = np.diff(arrow_vertices, axis=1)
+ arrow_vertices -= arrow_shift
+ as_edges.vertices = arrow_vertices.reshape(-1, a_data_dim)
This refactoring reduces the number of reshapes and makes the code easier to understand.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
arrow_shift = np.diff( | |
as_edges.vertices.reshape(-1, 2, a_data_dim), axis=1 | |
) | |
as_edges.vertices[:] = ( | |
as_edges.vertices.reshape(-1, 2, a_data_dim) - arrow_shift | |
).reshape(-1, a_data_dim) | |
arrow_vertices = as_edges.vertices.reshape(-1, 2, a_data_dim) | |
arrow_shift = np.diff(arrow_vertices, axis=1) | |
arrow_vertices -= arrow_shift | |
as_edges.vertices = arrow_vertices.reshape(-1, a_data_dim) |
Adds option to point arrow to origin. For example:
You can, for example, use it to plot boundary conditions or force acting on boundary.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation