From 97086e59e54e6800871570e4a4c99a2727fd6445 Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Thu, 12 Dec 2024 12:15:23 -0700 Subject: [PATCH] DAS-2276: Use OPAQUE and TRANSPARENT. Reword comments. --- hybig/browse.py | 10 +++++----- tests/unit/test_browse.py | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hybig/browse.py b/hybig/browse.py index b84416c..bb152db 100644 --- a/hybig/browse.py +++ b/hybig/browse.py @@ -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. @@ -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) @@ -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') diff --git a/tests/unit/test_browse.py b/tests/unit/test_browse.py index 1d35725..d844fba 100644 --- a/tests/unit/test_browse.py +++ b/tests/unit/test_browse.py @@ -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')