Add class functions to simplify kGrid creation#597
Draft
Conversation
- Implemented `from_geometry` method to create a kWaveGrid based on domain size and minimum element width. - Implemented `from_domain` method to create a kWaveGrid using physical dimensions and acoustic properties. - Added input validation for parameters in both methods to ensure positive values.
- Updated the grid creation process to utilize the new `from_domain` method for better clarity and efficiency. - Adjusted sensor mask and data reshaping to align with the new grid structure. - Ensured consistent usage of grid properties throughout the example for improved readability and maintainability.
- Updated the grid creation to use the new `from_domain` method for improved clarity and efficiency. - Adjusted sensor mask and data reshaping to utilize properties from the kWaveGrid instance. - Enhanced consistency in grid property usage throughout the example for better readability and maintainability.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #597 +/- ##
==========================================
- Coverage 73.61% 73.35% -0.27%
==========================================
Files 50 50
Lines 6929 6970 +41
Branches 1315 1323 +8
==========================================
+ Hits 5101 5113 +12
- Misses 1283 1312 +29
Partials 545 545
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the kWaveGrid class by adding two new factory methods and utility properties, and refactoring example scripts to simplify grid creation and improve code consistency.
- Introduces factory methods: from_geometry and from_domain in kWaveGrid
- Adds utility properties: x_max, y_max, and z_max
- Refactors grid initialization in at_circular_piston_3D.py and at_focused_bowl_3D.py to use the new factory methods
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| kwave/kgrid.py | Adds new factory methods and utility properties; broadcasts spacing if single-element |
| examples/at_focused_bowl_3D/at_focused_bowl_3D.py | Replaces manual grid creation with kWaveGrid.from_domain and updates sensor mask and data reshaping |
| examples/at_circular_piston_3D/at_circular_piston_3D.py | Refactors grid initialization to use kWaveGrid.from_domain and updates grid-based indices |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Removed redundant properties for x_max, y_max, and z_max from kWaveGrid to streamline the class. - Updated the at_focused_bowl_3D example to define position vectors more clearly, improving readability and maintainability. - Introduced a new x_ref calculation for better accuracy in grid representation.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces enhancements to the
kWaveGridclass, including new factory methods and utility properties. It also refactors grid initialization and usage in theat_circular_piston_3Dandat_focused_bowl_3Dexamples, improving code readability and reusability by leveraging new factory methods in thekWaveGridclass. It alsoEnhancements to
kWaveGridClass:New Factory Methods:
from_geometryandfrom_domainclass methods to simplify the creation ofkWaveGridinstances based on physical domain dimensions, acoustic properties, and resolution requirements. These methods encapsulate grid spacing and size calculations.Utility Properties:
x_max,y_max, andz_maxproperties to provide easy access to the maximum extents of the grid in each dimension.Refactoring in Example Scripts:
Simplified Grid Initialization:
kWaveGrid.from_domainfactory method inat_circular_piston_3D.pyandat_focused_bowl_3D.py. This reduces redundant code and ensures consistency in grid creation. [1] [2]Improved Input Handling:
__init__method to handle single-element spacing inputs more gracefully by broadcasting them to match the grid dimensionality.