Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/TCL_true_color #161

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions lambdas/raster_tiler/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,28 @@ def apply_annual_loss_filter(
year <= _end_year - 2000
)

red: ndarray = np.ones(intensity.shape).astype("uint8") * 228
# Construct RGBA bands with floating point values for precision
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you can describe in a comment the type of intensity.shape, and what the possible range of its values are? That would also make it clearer why float32 is the right choice for maintaining accuracy (and for instance, why you don't need to use float64).

red: np.ndarray = np.ones(intensity.shape).astype("float32") * 228
green: ndarray = (
np.ones(intensity.shape) * 102
np.ones(intensity.shape).astype("float32") * 102
+ (72 - zoom)
- (scaled_intensity * (3 / max(zoom, 1)))
).astype("uint8")
)
blue: ndarray = (
np.ones(intensity.shape) * 153 + (33 - zoom) - (intensity / max(zoom, 1))
).astype("uint8")
np.ones(intensity.shape).astype("float32") * 153
+ (33 - zoom)
- (intensity / max(zoom, 1))
)
alpha: ndarray = (
(scaled_intensity if zoom < 13 else intensity) * start_year_mask * end_year_mask
).astype("uint8")
).astype("float32")

return np.array([red, green, blue, alpha])
# Ensure GBA values are in [0, 255] range
green = np.clip(green, 0, 255).astype("uint8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to clip red to 255 as well? If not, can you put in a comment on why you don't need to clip it. (For instance, maybe intensity.shape is only a value between 0 and 1, so you know red is already between 0 and 228?)

blue = np.clip(blue, 0, 255).astype("uint8")
alpha = np.clip(alpha, 0, 255).astype("uint8")

return np.array([red.astype("uint8"), green, blue, alpha])


##############################
Expand Down Expand Up @@ -352,15 +360,15 @@ def read_tile_cache(dataset, version, implementation, x, y, z, **kwargs) -> ndar

arr = np.array(png)

return seperate_bands(arr)
return separat_bands(arr)


##########################
# Array functions
##########################


def seperate_bands(arr: ndarray) -> ndarray:
def separat_bands(arr: ndarray) -> ndarray:

logger.debug("Store bands in separate arrays")
# convert data from (height, width, bands) to (bands, height, width)
Expand Down
8 changes: 4 additions & 4 deletions tests/lambda/test_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
from lambdas.raster_tiler.lambda_function import (
array_to_img,
combine_bands,
seperate_bands,
separat_bands,
)


def test_seperate_bands():
def test_separat_bands():
data = np.array([[[1, 2, 3]], [[1, 2, 3]], [[1, 2, 3]]])

flip = seperate_bands(data)
flip = separat_bands(data)
assert flip.shape == (3, 1, 3)
assert np.all(flip[0] == 1)
assert np.all(flip[1] == 2)
assert np.all(flip[2] == 3)

data = np.array([[[1, 2, 3, 4]], [[1, 2, 3, 4]], [[1, 2, 3, 4]]])

flip = seperate_bands(data)
flip = separat_bands(data)
assert flip.shape == (4, 1, 3)
assert np.all(flip[0] == 1)
assert np.all(flip[1] == 2)
Expand Down
Loading