Repository navigation
Improves 3D interpolation and adds KD-tree-based alternative to the existing Delaunay method - #149
Merged
Merged
Conversation
…spect ratio issues in 3D -- uses same convention as scipy.interpolate.griddata rescale=True
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #149 +/- ##
===========================================
+ Coverage 89.48% 89.60% +0.12%
===========================================
Files 67 67
Lines 13200 13339 +139
===========================================
+ Hits 11812 11953 +141
+ Misses 1388 1386 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Improves 3D interpolation in
mfsetup.interpolateand adds a KD-tree-based alternative to the existing Delaunay method, with accompanying tests and documentation. This is helpful for large 3D parent grids whose vertical dimension is small relative to their horizontal extent, where the Delaunay triangulation can become ill-conditioned.Fixes #140
This PR implements the rescaling described in #140, but also goes beyond the original issue scope by also adding an optional KD-tree inverse-distance interpolation method as an alternative for the same high-aspect-ratio grids.
Changes
mfsetup/interpolate.pyinterp_weights. Ford == 3, coordinates are now centered at their mean and divided by their per-dimension peak-to-peak range (matchingscipy.interpolate.griddata(rescale=True)) before the Delaunay triangulation. Dimensions with zero range are left unscaled to avoid division by zero. Because the same scaling is applied to both source and destination points, the interpolation remains equivalent while making the tessellation tractable. The 2D path is unchanged.interp_weights_kdtree(xyz, uvw, d, k). Computes weights from theknearest source points using ascipy.spatial.cKDTreewith inverse-distance weighting.kdefaults tod + 1(the vertex count of a simplex). Coordinates are rescaled the same way as above. Includes handling for exact matches (distance 0 gets full weight) and thek == 1nearest-neighbor case. Returns indices and normalized weights that sum to 1 per row.Interpolatoroptions. Addedweight_method('delaunay'default, or'kdtree') andkarguments that routeinterp_weightsto the appropriate function, with weight caching unchanged.interpolatedocstring notes thatfill_valueis unused for KD-tree weights (all weights are positive).mfsetup/tests/test_interpolation.pytest_interp_weights_3d_rescaling: verifies the 3Dinterp_weightsoutput matchesgriddata(rescale=True)on a high-aspect-ratio point cloud, and confirms this differs from the unscaled (rescale=False) result so the assertion is meaningful.k = d + 1), the exact-match path, thek == 1nearest-neighbor path, and routingInterpolator(weight_method='kdtree').docs/source/concepts/perimeter-bcs.rstinterpolation_method('linear'vs'kdtree') andinterpolation_k, with a YAML example.interpolation_k: 1gives pure nearest-neighbor interpolation and thatinterpolation_kmust be a positive integer.Notes
weight_methoddefaults to'delaunay'and the 2D path is untouched, so existing usage should produce the same results.