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

DAS-2259 fix opera rtc browse images. #34

Merged
merged 18 commits into from
Oct 17, 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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ HyBIG follows semantic versioning. All notable changes to this project will be
documented in this file. The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).

## [v2.0.2] - 2024-10-15

### Fixed

**DAS-2259**
- Corrects bug with RGBA input tifs.

## [v2.0.1] - 2024-10-06

### Changed
Expand Down Expand Up @@ -70,7 +77,8 @@ outlined by the NASA open-source guidelines.
For more information on internal releases prior to NASA open-source approval,
see legacy-CHANGELOG.md.

[unreleased]:https://github.com/nasa/harmony-browse-image-generator/compare/2.0.1..HEAD
[unreleased]:https://github.com/nasa/harmony-browse-image-generator/compare/2.0.2..HEAD
[v2.0.2]:https://github.com/nasa/harmony-browse-image-generator/compare/2.0.1..2.0.2
[v2.0.1]:https://github.com/nasa/harmony-browse-image-generator/compare/2.0.0..2.0.1
[v2.0.0]:https://github.com/nasa/harmony-browse-image-generator/compare/1.2.2..2.0.0
[v1.2.2]: https://github.com/nasa/harmony-browse-image-generator/compare/1.2.1..1.2.2
Expand Down
2 changes: 1 addition & 1 deletion docker/service_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.0.2
6 changes: 3 additions & 3 deletions hybig/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ def convert_mulitband_to_raster(data_array: DataArray) -> ndarray:
)

if image_alpha is not None:
# merge nan alpha with the image alpha prefering transparency to
# opaqueness.
alpha = np.minimum(nan_alpha, image_alpha)
# merge missing alpha with the image alpha band prefering transparency
# to opaqueness.
alpha = np.minimum(nan_alpha, image_alpha).astype(np.uint8)
else:
alpha = nan_alpha

Expand Down
53 changes: 53 additions & 0 deletions tests/unit/test_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,59 @@ def test_convert_4_multiband_to_raster(self):
actual_raster = convert_mulitband_to_raster(ds)
assert_array_equal(expected_raster, actual_raster.data)

def test_convert_4_multiband_masked_to_raster(self):
"""Input data is selected from a subset of a real OPERA RTC input data
file that has masked the alpha layer and as a result as a datatype of
float32.

"""
ds = Mock(DataArray)
ds.rio.count = 4
nan = np.nan
input_array = np.array(
[
[
[nan, nan, nan, 234.0],
[nan, nan, nan, 225.0],
[nan, nan, 255.0, 215.0],
[nan, nan, 217.0, 255.0],
],
[
[nan, nan, nan, 255.0],
[nan, nan, nan, 255.0],
[nan, nan, 255.0, 255.0],
[nan, nan, 255.0, 255.0],
],
[
[nan, nan, nan, 234.0],
[nan, nan, nan, 225.0],
[nan, nan, 255.0, 215.0],
[nan, nan, 217.0, 255.0],
],
[
[0.0, 0.0, 0.0, 255.0],
[0.0, 0.0, 0.0, 255.0],
[0.0, 0.0, 255.0, 255.0],
[0.0, 0.0, 255.0, 255.0],
],
],
dtype=np.float32,
)
ds.to_numpy.return_value = input_array

expected_raster = np.ma.array(
data=[
[[0, 0, 0, 121], [0, 0, 0, 64], [0, 0, 255, 0], [0, 0, 13, 255]],
[[0, 0, 0, 255], [0, 0, 0, 255], [0, 0, 255, 255], [0, 0, 255, 255]],
[[0, 0, 0, 121], [0, 0, 0, 64], [0, 0, 255, 0], [0, 0, 13, 255]],
[[0, 0, 0, 255], [0, 0, 0, 255], [0, 0, 255, 255], [0, 0, 255, 255]],
],
dtype=np.uint8,
)

actual_raster = convert_mulitband_to_raster(ds)
assert_array_equal(expected_raster.data, actual_raster.data)

def test_convert_5_multiband_to_raster(self):
ds = Mock(DataArray)
ds.rio.count = 5
Expand Down