Skip to content

Commit

Permalink
Asset expression and fast api (developmentseed#368)
Browse files Browse the repository at this point in the history
* update fastapi max version

* add asset_expression in depdencies

* add tests for multiBand
  • Loading branch information
vincentsarago authored Sep 7, 2021
1 parent d1f4f41 commit 3236719
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes

## 0.3.9 (2021-09-07)

### titiler.core

- update FastAPI requirements to `>=0.65,<0.68` (ref: https://github.com/developmentseed/titiler/issues/366)
- surface `asset_expression` and `band_expression` in Multi*TilerFactory (ref: https://github.com/developmentseed/titiler/issues/367)

## 0.3.8 (2021-09-02)

### titiler.core
Expand Down
2 changes: 1 addition & 1 deletion src/titiler/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
long_description = f.read()

inst_reqs = [
"fastapi>=0.65,<0.66",
"fastapi>=0.65,<0.68",
"geojson-pydantic",
"jinja2>=2.11.2,<3.0.0",
"morecantile",
Expand Down
18 changes: 18 additions & 0 deletions src/titiler/core/tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ def test_MultiBaseTilerFactory(rio):
assert meta["dtype"] == "int32"
assert meta["count"] == 3

response = client.get(
f"/preview.tif?url={DATA_DIR}/item.json&assets=B01&asset_expression=b1,b1,b1&return_mask=false"
)
assert response.status_code == 200
assert response.headers["content-type"] == "image/tiff; application=geotiff"
meta = parse_img(response.content)
assert meta["dtype"] == "int32"
assert meta["count"] == 3

# GET - statistics
response = client.get(f"/statistics?url={DATA_DIR}/item.json&assets=B01,B09")
assert response.status_code == 200
Expand Down Expand Up @@ -644,6 +653,15 @@ def test_MultiBandTilerFactory():
assert meta["dtype"] == "int32"
assert meta["count"] == 3

response = client.get(
f"/preview.tif?url={DATA_DIR}&bands=B01&band_expression=b1,b1,b1&return_mask=false"
)
assert response.status_code == 200
assert response.headers["content-type"] == "image/tiff; application=geotiff"
meta = parse_img(response.content)
assert meta["dtype"] == "int32"
assert meta["count"] == 3

# GET - statistics
response = client.get(f"/statistics?url={DATA_DIR}&bands=B01,B09")
assert response.status_code == 200
Expand Down
18 changes: 16 additions & 2 deletions src/titiler/core/titiler/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,16 @@ class AssetsBidxExprParams(DefaultDependency):
expression: Optional[str] = Query(
None,
title="Band Math expression",
description="rio-tiler's band math expression (e.g B1/B2)",
description="rio-tiler's band math expression between assets (e.g asset1/asset2)",
)
bidx: Optional[str] = Query(
None, title="Band indexes", description="comma (',') delimited band indexes",
)
asset_expression: Optional[str] = Query(
None,
title="Band Math expression to apply to each asset",
description="rio-tiler's band math expression (e.g b1/b2)",
)

def __post_init__(self):
"""Post Init."""
Expand All @@ -174,6 +179,8 @@ def __post_init__(self):
self.kwargs["assets"] = self.assets.split(",")
if self.expression is not None:
self.kwargs["expression"] = self.expression
if self.asset_expression is not None:
self.kwargs["asset_expression"] = self.asset_expression
if self.bidx is not None:
self.kwargs["indexes"] = tuple(
int(s) for s in re.findall(r"\d+", self.bidx)
Expand Down Expand Up @@ -204,7 +211,12 @@ class BandsExprParams(DefaultDependency):
expression: Optional[str] = Query(
None,
title="Band Math expression",
description="rio-tiler's band math expression.",
description="rio-tiler's band math expression between Band asset.",
)
band_expression: Optional[str] = Query(
None,
title="Band Math expression",
description="rio-tiler's band math expression to apply to each band file.",
)

def __post_init__(self):
Expand All @@ -218,6 +230,8 @@ def __post_init__(self):
self.kwargs["bands"] = self.bands.split(",")
if self.expression is not None:
self.kwargs["expression"] = self.expression
if self.band_expression is not None:
self.kwargs["band_expression"] = self.band_expression


@dataclass
Expand Down

0 comments on commit 3236719

Please sign in to comment.