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

use new expression format in COGReader 🤦 #483

Merged
merged 1 commit into from
Feb 18, 2022
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
10 changes: 5 additions & 5 deletions rio_tiler/io/cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
NoOverviewWarning,
TileOutsideBounds,
)
from ..expression import apply_expression, parse_expression
from ..expression import apply_expression, get_expression_blocks, parse_expression
from ..models import BandStatistics, ImageData, Info
from ..types import BBox, DataMaskType, Indexes, NoData, NumType
from ..utils import (
Expand Down Expand Up @@ -417,7 +417,7 @@ def part(
)

if expression:
blocks = expression.lower().split(",")
blocks = get_expression_blocks(expression)
bands = [f"b{bidx}" for bidx in indexes]
data = apply_expression(blocks, bands, data)

Expand Down Expand Up @@ -482,7 +482,7 @@ def preview(
)

if expression:
blocks = expression.lower().split(",")
blocks = get_expression_blocks(expression)
bands = [f"b{bidx}" for bidx in indexes]
data = apply_expression(blocks, bands, data)

Expand Down Expand Up @@ -539,7 +539,7 @@ def point(
)

if expression:
blocks = expression.lower().split(",")
blocks = get_expression_blocks(expression)
bands = [f"b{bidx}" for bidx in indexes]
point = apply_expression(blocks, bands, numpy.array(point)).tolist()

Expand Down Expand Up @@ -631,7 +631,7 @@ def read(
data, mask = reader.read(self.dataset, indexes=indexes, **kwargs)

if expression:
blocks = expression.lower().split(",")
blocks = get_expression_blocks(expression)
bands = [f"b{bidx}" for bidx in indexes]
data = apply_expression(blocks, bands, data)

Expand Down
22 changes: 14 additions & 8 deletions rio_tiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .colormap import apply_cmap
from .constants import WEB_MERCATOR_CRS
from .errors import RioTilerError
from .expression import get_expression_blocks
from .types import BBox, ColorMapType, IntervalTuple


Expand Down Expand Up @@ -66,7 +67,7 @@ def get_bands_names(
) -> List[str]:
"""Define bands names based on expression, indexes or band count."""
if expression:
return expression.split(",")
return get_expression_blocks(expression)

elif indexes:
return [str(idx) for idx in indexes]
Expand Down Expand Up @@ -258,28 +259,33 @@ def get_vrt_transform(
tuple: VRT transform (affine.Affine), width (int) and height (int)

"""
dst_transform, _, _ = calculate_default_transform(
src_dst.crs, dst_crs, src_dst.width, src_dst.height, *src_dst.bounds
)
if src_dst.crs != dst_crs:
dst_transform, _, _ = calculate_default_transform(
src_dst.crs, dst_crs, src_dst.width, src_dst.height, *src_dst.bounds
)
else:
dst_transform = src_dst.transform

# If bounds window is aligned with the dataset internal tile we align the bounds with the pixels.
# This is to limit the number of internal block fetched.
if _requested_tile_aligned_with_internal_tile(
src_dst, bounds, height, width, dst_crs
):
# Get Window for the input bounds
# e.g Window(col_off=17920.0, row_off=11007.999999999998, width=255.99999999999636, height=256.0000000000018)
col_off, row_off, w, h = windows.from_bounds(
*bounds,
transform=src_dst.transform,
width=width,
height=height,
*bounds, transform=dst_transform
).flatten()

# Round Window
w = windows.Window(
round(col_off, window_precision),
round(row_off, window_precision),
round(w, window_precision),
round(h, window_precision),
)

# Get Bounds for the rounded window
bounds = src_dst.window_bounds(w)

w, s, e, n = bounds
Expand Down
11 changes: 5 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
[metadata]
version = attr: rio_tiler.__version__

[bumpversion]
current_version = 3.0.3
commit = True
tag = True
tag_name = {new_version}
parse =
parse =
(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
((?P<pre>a|b|rc)(?P<prenum>\d+))?
serialize =
serialize =
{major}.{minor}.{patch}{pre}{prenum}
{major}.{minor}.{patch}

[bumpversion:file:setup.py]
search = version="{current_version}"
replace = version="{new_version}"

[bumpversion:file:rio_tiler/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

setup(
name="rio-tiler",
version="3.0.3",
python_requires=">=3.7",
description="User friendly Rasterio plugin to read raster datasets.",
long_description=readme,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_io_cogeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_tile_valid_default():
assert not mask.all()

# Expression
img = cog.tile(43, 24, 7, expression="b1*2,b1-100")
img = cog.tile(43, 24, 7, expression="b1*2;b1-100")
assert img.data.shape == (2, 256, 256)
assert img.band_names == ["b1*2", "b1-100"]

Expand Down Expand Up @@ -245,7 +245,7 @@ def test_point_valid():
pts = cog.point(lon, lat)
assert len(pts) == 1

pts = cog.point(lon, lat, expression="b1*2,b1-100")
pts = cog.point(lon, lat, expression="b1*2;b1-100")
assert len(pts) == 2

with pytest.warns(ExpressionMixingWarning):
Expand Down Expand Up @@ -285,7 +285,7 @@ def test_area_valid():
data, mask = cog.part(bbox, max_size=30)
assert data.shape == (1, 9, 30)

img = cog.part(bbox, expression="b1*2,b1-100")
img = cog.part(bbox, expression="b1*2;b1-100")
assert img.data.shape == (2, 11, 40)
assert img.band_names == ["b1*2", "b1-100"]

Expand Down Expand Up @@ -318,7 +318,7 @@ def test_preview_valid():
data, mask = cog.preview()
assert data.shape == (1, 1024, 1021)

img = cog.preview(max_size=128, expression="b1*2,b1-100")
img = cog.preview(max_size=128, expression="b1*2;b1-100")
assert img.data.shape == (2, 128, 128)
assert img.band_names == ["b1*2", "b1-100"]

Expand Down Expand Up @@ -387,7 +387,7 @@ def test_statistics():

# Check results for expression
with COGReader(COGEO) as cog:
stats = cog.statistics(expression="b1,b1*2")
stats = cog.statistics(expression="b1;b1*2")
assert stats["b1"]
assert stats["b1*2"]
assert stats["b1"].min == stats["b1*2"].min / 2
Expand Down Expand Up @@ -622,7 +622,7 @@ def test_feature_valid():
img = cog.feature(feature, max_size=30)
assert img.data.shape == (1, 11, 30)

img = cog.feature(feature, expression="b1*2,b1-100", max_size=1024)
img = cog.feature(feature, expression="b1*2;b1-100", max_size=1024)
assert img.data.shape == (2, 348, 1024)
assert img.band_names == ["b1*2", "b1-100"]

Expand Down