Avoid out-of-bounds values in Lambert interpolation parameters #718
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.
Calling
kikuchipy.signals.util._master_pattern_project_single_pattern_from_master_pattern()
, sometimes results in the kernel dying without any error message.The outputs nii, nij, niip and nijp of
_get_lambert_interpolation_parameters()
define the indices used by the function_get_pixel_from_master_pattern()
to select a pixel from a master pattern hemisphere in the Lambert projection.Normally, trying to access out of bounds indices would result in an
IndexError
; however, the function_get_pixel_from_master_pattern()
is optimized with Numba and according to the Numba docs, by default, noIndexError
is raised and either invalid values are returned or an access violation error occurs.In order to avoid this, we need to make a small change to
_get_lambert_interpolation_parameters()
. The parameters nii and niip must be in the range 0 <= n < npy and nij and nijp must be in the range 0 <= n < npx. The outputs nii and nij are automatically in these ranges; however, niip and nijp may not be and we need to exclude indices which are < 0 or >= npx or >= npy.Description of the change
Previously,
_get_lambert_interpolation_parameters()
checked ifniip > npy
andnijp > npx
, which led to some values being out of bounds. This has now been changed toniip >= npy
andnijp >= npx
to avoid returning out-of-bounds indices. The function_get_lambert_interpolation_parameters()
now only outputs indices which are in range for the master pattern and therefore no further problems in the Numba-optimized_get_pixel_from_master_pattern()
are caused.Progress of the PR
Minimal example of the bug fix or new feature
For reviewers
__init__.py
.section in
CHANGELOG.rst
.kikuchipy/__init__.py
and.zenodo.json
.