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

call .read() only once when dataset do not have nodata #355

Merged
merged 2 commits into from Feb 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
@@ -1,3 +1,7 @@
## 2.0.3 (2021-02-19)

* Reduce the number of `.read()` calls for dataset without nodata value (https://github.com/cogeotiff/rio-tiler/pull/355)
* replace deprecated `numpy.float` by `numpy.float64`

## 2.0.2 (2021-02-17)

Expand Down
21 changes: 14 additions & 7 deletions rio_tiler/reader.py
Expand Up @@ -81,19 +81,26 @@ def read(
vrt_params.update(vrt_options)

with WarpedVRT(src_dst, **vrt_params) as vrt:
data = vrt.read(
indexes=indexes, window=window, out_shape=out_shape, resampling=resampling,
)
if ColorInterp.alpha in vrt.colorinterp:
idx = vrt.colorinterp.index(ColorInterp.alpha) + 1
mask = vrt.read(
indexes=idx,
indexes = tuple(indexes) + (idx,)
if out_shape:
out_shape = (len(indexes), height, width)

data = vrt.read(
indexes=indexes,
window=window,
out_shape=mask_out_shape,
out_shape=out_shape,
resampling=resampling,
out_dtype="uint8",
)
data, mask = data[0:-1], data[-1].astype("uint8")
else:
data = vrt.read(
indexes=indexes,
window=window,
out_shape=out_shape,
resampling=resampling,
)
mask = vrt.dataset_mask(
window=window, out_shape=mask_out_shape, resampling=resampling,
)
Expand Down
2 changes: 1 addition & 1 deletion rio_tiler/utils.py
Expand Up @@ -262,7 +262,7 @@ def linear_rescale(
imin, imax = in_range
omin, omax = out_range
image = numpy.clip(image, imin, imax) - imin
image = image / numpy.float(imax - imin)
image = image / numpy.float64(imax - imin)
return image * (omax - omin) + omin


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -20,7 +20,7 @@
]

extra_reqs = {
"test": ["pytest", "pytest-benchmark", "pytest-cov", "rio-cogeo"],
"test": ["pytest", "pytest-asyncio", "pytest-benchmark", "pytest-cov", "rio-cogeo"],
"dev": [
"pytest",
"pytest-benchmark",
Expand Down