Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset expression and fast api #368

Merged
merged 3 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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