Skip to content

Legacy expression translation misclassifies B11/B12 as b11/b12 #187

@hrodmn

Description

@hrodmn

Summary

Legacy rasterio expressions using uppercase two-digit asset names are not translated to rio-tiler bN references.

Reported by Minnie Wong when testing out the v1.0 API for WorldView.

The upgrade to rio-tiler>=9 brought a change to the way bands/assets are expressed in expression statements: all bands were stripped of their names and must be referred to as bX where X is the sequential number of the provided dataset.

Rather than introducing a separate breaking change to force users to use this approach we installed some code to check the input expression for semantic band names and translate it into sequential band names for rio-tiler. Users can also provide the expression using the sequential band names if they prefer.

e.g. these two requests are functionally equivalent:

  • assets=B11&assets=B12&expression=(B11-B12)/(B11+B12)
  • assets=B11&assets=B12&expression=(b1-b2)/(b1+b2)

where b1 and b2 are the sequential band names for the assets in the order in which they were entered

I think this bug is worth patching for now but we should consider deprecating the expression translation logic and force users to use sequential band names.

Current behavior

A request like:

/rasterio/tiles/...&assets=B11&assets=B12&expression=(B11-B12)/(B11+B12)

returns:

400 {"detail":"Invalid band/asset name 'b11'"}

Expected behavior

(B11-B12)/(B11+B12) should be translated to (b1-b2)/(b1+b2) when assets=B11&assets=B12 are provided.

Cause

CMRAssetsExprParams uses a case-insensitive ^b[1-9][0-9]*$ check when deciding whether an identifier is already a rio-tiler band reference. That incorrectly treats B11 and B12 as already-translated names, so the legacy expression rewrite is skipped.

Acceptance criteria

  • Uppercase asset names like B11 and B12 are translated correctly in legacy expressions.
  • A regression test covers assets=["B11", "B12"] with expression (B11-B12)/(B11+B12).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions