Skip to content

Commit

Permalink
DAS-2276: Use OPAQUE and TRANSPARENT. Reword comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
flamingbear committed Dec 12, 2024
1 parent bbd1891 commit 97086e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions hybig/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ def create_browse_imagery(
def convert_mulitband_to_raster(data_array: DataArray) -> ndarray[uint8]:
"""Convert multiband to a raster image.
Return a raster of a 4-band data set, the existing alpha layer is presumed to be the
missing data mask.
Return a 4-band raster, where the alpha layer is presumed to be the missing
data mask.
Convert 3-band data into a 4-band raster by generating an alpha layer from
any missing data in the RGB bands.
Expand All @@ -242,7 +242,7 @@ def convert_mulitband_to_raster(data_array: DataArray) -> ndarray[uint8]:
if data_array.rio.count == 4:
return convert_to_uint8(bands, original_dtype(data_array))

# Create a nan-based alpha layer where input NaN values are transparent.
# Input NaNs in any of the RGB bands are made transparent.
nan_mask = np.isnan(bands).any(axis=0)
nan_alpha = np.where(nan_mask, TRANSPARENT, OPAQUE)

Expand Down Expand Up @@ -277,8 +277,8 @@ def convert_to_uint8(bands: ndarray, dtype: str | None) -> ndarray[uint8]:
def original_dtype(data_array: DataArray) -> str | None:
"""Return the original input data's type.
The input dtype is retained in the encoding dictionary and can be used to
understand what kind of casts are safe.
rastero_optn retains the input dtype in the encoding dictionary and is used
to understand what kind of casts are safe.
"""
return data_array.encoding.get('dtype') or data_array.encoding.get('rasterio_dtype')
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/test_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,15 @@ def test_convert_4_multiband_uint16_to_raster(self):
g_data = r_data.copy()
b_data = r_data.copy()

a_data = np.ones_like(self.data) * 255
a_data[0, 0] = 0
a_data = np.ones_like(self.data) * OPAQUE
a_data[0, 0] = TRANSPARENT

to_numpy_result = np.stack([r_data, g_data, b_data, a_data])

ds.to_numpy.return_value = to_numpy_result

# expect the input data to have 0 to 400 to be scaled into 0 to 255
# expect the input data to have the data values from 0 to 400 to be
# scaled into the range 0 to 255.
expected_raster = np.around(
np.interp(to_numpy_result, (0, 400), (0.0, 1.0)) * 255.0
).astype('uint8')
Expand Down

0 comments on commit 97086e5

Please sign in to comment.