forked from developmentseed/eoAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include swir datasetparams for custom swir band stretching.
- Loading branch information
1 parent
58da44d
commit 8457367
Showing
2 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from titiler.core import dependencies | ||
from dataclasses import dataclass | ||
import numpy | ||
from fastapi import Query | ||
|
||
from typing import Tuple, Optional | ||
|
||
# https://github.com/cogeotiff/rio-tiler/blob/master/rio_tiler/reader.py#L35-L37 | ||
|
||
import math | ||
|
||
|
||
def swir(data, mask) -> Tuple[numpy.ndarray, numpy.ndarray]: | ||
low_value = math.e | ||
high_value = 255 | ||
|
||
low_threshold = math.log(1000) | ||
high_threshold = math.log(7500) | ||
|
||
data = numpy.log(data) | ||
data[numpy.where(data <= low_threshold)] = low_value | ||
data[numpy.where(data >= high_threshold)] = high_value | ||
indices = numpy.where( | ||
(data > low_value) & (data < high_value) | ||
) | ||
data[indices] = ( | ||
high_value * (data[indices] - low_threshold) / (high_threshold - low_threshold) | ||
) | ||
return data.astype("uint8"), mask | ||
|
||
|
||
pp_methods = { | ||
"swir": swir, | ||
} | ||
|
||
|
||
@dataclass | ||
class DatasetParams(dependencies.DatasetParams): | ||
post_process: Optional[str] = Query(None, description="Post Process Name.") | ||
|
||
def __post_init__(self): | ||
super().__post_init__() | ||
|
||
if self.post_process is not None: | ||
self.post_process = pp_methods.get(self.post_process) # type: ignore |