Is nodata applied before expressions? #976
-
Hi there, I have a band with values from 0.0 to 1.0. I'm attempting to make any values below 0.15 transparent by doing the following:
It seems to apply the expression correctly, but makes the areas where b15 is < 0.15 black (the lowest color in the colormap) instead of transparent. I'm guessing nodata is evaluated before the expression maybe? Is there something else I could be doing to make this work? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @agasparovic Thanks for starting this discussion. The mask is created for the data itself, expression won't update the mask. Can you tell a bit more of what you're doing: what rescaling or colormap you are using?
Custom Algorithm might solve this for you (https://developmentseed.org/titiler/advanced/Algorithms/, https://developmentseed.org/titiler/examples/code/tiler_with_custom_algorithm/) 👇 not tested so might be wrong import numpy
from titiler.core.algorithm import BaseAlgorithm
from rio_tiler.models import ImageData
class Correct(BaseAlgorithm):
input_nbands: int = 1
output_nbands: int = 1
def __call__(self, img: ImageData) -> ImageData:
new_mask = numpy.where(im.array >= 0.15, False, True)
img.array.mask = numpy.bitwise_or(new_mask, self.mask)
return img |
Beta Was this translation helpful? Give feedback.
Hi @agasparovic
Thanks for starting this discussion.
The mask is created for the data itself, expression won't update the mask.
Can you tell a bit more of what you're doing: what rescaling or colormap you are using?
Custom Algorithm might solve this for you (https://developmentseed.org/titiler/advanced/Algorithms/, https://developmentseed.org/titiler/examples/code/tiler_with_custom_algorithm/)
👇 not tested so might be wrong