Nodata is not respected when using expression #487
-
I'm using an expression where I only select pixels of above X value. If the evaluation is true, the original band value is returned and if the evaluation is false the nodata value is returned. The expression looks like:
When rendering the map, the nodata values returned by the expression are not ignored, while the original nodata values are still handled correctly. Even when overwriting the nodata value, the nodata values in the returned expression array are not respected. The input parameters are:
Is it possible to handle the -999 values of the expression array as actual nodata values? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The One possible solution is to use the from dataclasses import dataclass
import numpy
from enum import Enum
from titiler.core import dependencies
from fastapi import Query
def b1mask(data: numpy.ndarray, mask: numpy.ndarray):
b1_mask = numpy.where(data[0] > 10, numpy.uint8(255), numpy.uint8(0))
mask = numpy.all([mask, b1_mask], axis=0).astype(numpy.uint8) * 255
return data, mask
available_processes = {
"b1mask": b1mask
}
Process = Enum( # type: ignore
"Process", [(a, p) for a, p in available_processes.items()]
)
@dataclass
class DatasetParams(dependencies.DatasetParams):
post_process: Process = Query(None, alias="p") #
def __post_init__(self):
"""Post Init."""
super().__post_init__()
if self.post_process:
self.post_process = Process.value # noqa |
Beta Was this translation helpful? Give feedback.
The
issue
here is in rio-tiler. The expression applied after data reading and we have no way to know if themask
was created from nodata / mask / alpha band, which is why we can'tupdate
theMask
https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/io/cogeo.py#L417-L432One possible solution is to use the
post_process
option of rio-tiler Reader (https://cogeotiff.github.io/rio-tiler/readers/#read-options) and to pass it via thedataset_dependency
which default to: