Skip to content

Added edge handling in LUT interp with pre-built LUT#701

Merged
pgbrodrick merged 4 commits into
isofit:devfrom
evan-greenbrg:debug/lut_interp
Jun 9, 2025
Merged

Added edge handling in LUT interp with pre-built LUT#701
pgbrodrick merged 4 commits into
isofit:devfrom
evan-greenbrg:debug/lut_interp

Conversation

@evan-greenbrg

Copy link
Copy Markdown
Collaborator

Isofit errors out when using a pre-built lut grid, and the interpolated value (as noted in the "interp" key) is at, or smaller than the smallest value in the lut dimension for that key. See example for "surface_elevation_km" below:

                 "lut_names": {
                        "AERFRAC_2": {
                            "gte": 0.001,
                            "lte": 1.0
                        },
                        "H2OSTR": {
                            "gte": 0.05,
                            "lte": 5.0
                        },
                        "observer_zenith": {
                            "gte": 2.2024,
                            "lte": 18.9262
                        },
                        "relative_azimuth": {
                            "gte": 0.0002,
                            "lte": 86.0982
                        },
                        "surface_elevation_km": {
                            "interp": 0.0
                        }
                    },

As noted in #697, we may not want to support run cases when the scene-value is lower than the LUT value, but at the bare minimum we have to support cases when the scene-value is at the LUT grid minimum, which currently fails.

The root of the issue is with how we slice the LUT dimension. For example, when the interpolated value (val) is equal to the smallest value in the lut grid (dim[0]):

b = np.searchsorted(dim * orientation, val * orientation)

returns 0 and

slice(b - 1, b + 1)

returns a slice, which always indexes to an empty list.

Interestingly, the inverse is not true. If the interpolated value is greater than the largest value in the lut grid (val > dim[-1]):

b = np.searchsorted(dim * orientation, val * orientation)

returns len(dim) and

slice(b - 1, b + 1)

returns a slice for the last LUT dim value. It looks like we actually currently allow for scene-values for LUT elements to be greater than the maximum value within the LUT grid.

The proposed changes are to:

  1. Handle the specific cases directly when the interpolated values are at the minimum and maximum LUT grid dimension values.
  2. To be discussed, but we could raise exceptions when the interpolation is trying to resolve values outside of the LUT grid dimension values. Not sure how necessary this is given that it should be an edge case, and in test cases when using pre-built LUTs it may be advantageous to run outside the bounds.

@evan-greenbrg evan-greenbrg marked this pull request as draft May 27, 2025 17:47
Comment thread isofit/core/isofit.py
@evan-greenbrg evan-greenbrg marked this pull request as ready for review May 27, 2025 18:27
@pgbrodrick pgbrodrick merged commit a33c37f into isofit:dev Jun 9, 2025
17 checks passed
@evan-greenbrg evan-greenbrg deleted the debug/lut_interp branch May 22, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants