Skip to content

Commit

Permalink
add masked rescale algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed May 13, 2024
1 parent 8395421 commit b23cad3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions titiler/src/app/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ def __call__(self, img: ImageData) -> ImageData:
data = np.where(~mask, img.data, 0)
masked_array = np.ma.MaskedArray(data, mask=modified_mask)

return ImageData(
masked_array,
assets=img.assets,
crs=img.crs,
bounds=img.bounds,
)


class MaskedRescale(BaseAlgorithm):
'''
requires that the layer sets the buffer parameter &buffer=x
'''
input_nbands: int = 1
output_nbands: int = 1
output_dtype: str = "uint8"

min: float = -1
max: float = 1

def __call__(self, img: ImageData) -> ImageData:
mask = (np.isnan(img.data))[0]
img.rescale(
in_range=((self.min, self.max),),
out_range=((0, 255),)
)
data = np.where(~mask, img.data, 0)
modified_mask = np.where(mask, 255, 0)
masked_array = np.ma.MaskedArray(data, mask=modified_mask)
return ImageData(
masked_array,
assets=img.assets,
Expand All @@ -141,5 +169,6 @@ def __call__(self, img: ImageData) -> ImageData:
"stravaheatmap": StravaHeatmap,
"bboxstats": BBoxStats,
"stravaclahe": StravaCLAHE,
"masked-rescale": MaskedRescale,
})
PostProcessParams: Callable = algorithms.dependency

0 comments on commit b23cad3

Please sign in to comment.