How to handle division by zero (inf/nan) edge cases in statistics endpoint #1314
Unanswered
dimplejaiin
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
@dimplejaiin could you share a minimal reproducible example with data please 🙏 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using the
/stac/statisticsendpoint with expressions that can produce division by zero (resulting ininfornanvalues), the endpoint returns a 500 error with "index out of bounds" during histogram computation.Simple Example
Expression: (B06 - B05) / (B06 + B05)
If pixel has: B06 = 50, B05 = -50
Then: (50 - (-50)) / (50 + (-50)) = 100/0 = infinity
When any pixel results in infinity, TiTiler crashes while computing histogram.
Steps to Reproduce
Use an expression with potential division by zero:
expression=705 + 35 * ((B04 + B07)/2 - B05) / (B06 - B05)
When some pixels have
B06 == B05, the denominator becomes zero, producinginfvalues.Request:
GET /stac/statistics?url=&expression=&histogram_bins=5&asset_as_band=true
Response:
{ "detail": "index -9223372036854775808 is out of bounds for axis 0 with size 6" }Expected Behavior
Similar to how QGIS/GDAL handles this:
Request for Guidance
Could you please advise if there is an existing solution for this, or would any of these approaches be feasible?
Thank you for your time and support! @vincentsarago
Beta Was this translation helpful? Give feedback.
All reactions