-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fcd564
commit ce98003
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""titiler.core.algorithm Ops.""" | ||
|
||
from typing import Sequence | ||
|
||
import numpy | ||
from rio_tiler.models import ImageData | ||
|
||
from titiler.core.algorithm.base import BaseAlgorithm | ||
|
||
__all__ = ["CastToInt", "Ceil", "Floor"] | ||
|
||
|
||
class CastToInt(BaseAlgorithm): | ||
"""Cast data to Integer.""" | ||
|
||
title: str = "Cast data to Integer" | ||
description: str = "Cast data to Integer." | ||
|
||
# metadata | ||
output_dtype: str = "uint8" | ||
output_min: Sequence[int] = [0] | ||
output_max: Sequence[int] = [255] | ||
|
||
def __call__(self, img: ImageData) -> ImageData: | ||
"""Cast Data.""" | ||
return ImageData( | ||
img.array.astype("uint8"), | ||
assets=img.assets, | ||
crs=img.crs, | ||
bounds=img.bounds, | ||
band_names=img.band_names, | ||
metadata=img.metadata, | ||
cutline_mask=img.cutline_mask, | ||
) | ||
|
||
|
||
class Ceil(BaseAlgorithm): | ||
"""Round data to the smallest integer.""" | ||
|
||
title: str = "Round data to the smallest integer" | ||
description: str = "Round data to the smallest integer." | ||
|
||
# metadata | ||
output_dtype: str = "uint8" | ||
output_min: Sequence[int] = [0] | ||
output_max: Sequence[int] = [255] | ||
|
||
def __call__(self, img: ImageData) -> ImageData: | ||
"""Cast Data.""" | ||
return ImageData( | ||
numpy.ceil(img.array).astype("uint8"), | ||
assets=img.assets, | ||
crs=img.crs, | ||
bounds=img.bounds, | ||
band_names=img.band_names, | ||
metadata=img.metadata, | ||
cutline_mask=img.cutline_mask, | ||
) | ||
|
||
|
||
class Floor(BaseAlgorithm): | ||
"""Round data to the largest integer.""" | ||
|
||
title: str = "Round data to the largest integer" | ||
description: str = "Round data to the largest integer." | ||
|
||
# metadata | ||
output_dtype: str = "uint8" | ||
output_min: Sequence[int] = [0] | ||
output_max: Sequence[int] = [255] | ||
|
||
def __call__(self, img: ImageData) -> ImageData: | ||
"""Cast Data.""" | ||
return ImageData( | ||
numpy.floor(img.array).astype("uint8"), | ||
assets=img.assets, | ||
crs=img.crs, | ||
bounds=img.bounds, | ||
band_names=img.band_names, | ||
metadata=img.metadata, | ||
cutline_mask=img.cutline_mask, | ||
) |