Skip to content

Commit

Permalink
call .read() only once when dataset do not have nodata (#355)
Browse files Browse the repository at this point in the history
* call .read() only once when dataset do not have nodata

* update changelog
  • Loading branch information
vincentsarago committed Feb 19, 2021
1 parent 1373edd commit d4c2763
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
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

0 comments on commit d4c2763

Please sign in to comment.