Skip to content

Commit

Permalink
DAS-2276: prepare_raster_for_writing -> standardize_raster_for_writing
Browse files Browse the repository at this point in the history
  • Loading branch information
flamingbear committed Dec 17, 2024
1 parent 41bad90 commit b6aadd0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions hybig/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def create_browse_imagery(
f'incorrect number of bands for image: {rio_in_array.rio.count}'
)

raster, color_map = prepare_raster_for_writing(
raster, color_map = standardize_raster_for_writing(
raster, output_driver, rio_in_array.rio.count
)

Expand Down Expand Up @@ -357,7 +357,7 @@ def image_driver(mime: str) -> str:
return 'PNG'


def prepare_raster_for_writing(
def standardize_raster_for_writing(
raster: ndarray,
driver: str,
band_count: int,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_service/test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from harmony_service.exceptions import HyBIGServiceError
from hybig.browse import (
convert_mulitband_to_raster,
prepare_raster_for_writing,
standardize_raster_for_writing,
)
from tests.utilities import Granule, create_stac

Expand Down Expand Up @@ -460,7 +460,7 @@ def move_tif(*args, **kwargs):
'count': 3,
}
raster = convert_mulitband_to_raster(rio_data_array)
raster, color_map = prepare_raster_for_writing(raster, 'PNG', 3)
raster, color_map = standardize_raster_for_writing(raster, 'PNG', 3)

dest = np.full(
(expected_params['height'], expected_params['width']),
Expand Down
20 changes: 10 additions & 10 deletions tests/unit/test_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
output_image_file,
output_world_file,
palettize_raster,
prepare_raster_for_writing,
standardize_raster_for_writing,
validate_file_crs,
validate_file_type,
)
Expand Down Expand Up @@ -653,48 +653,48 @@ def test_convert_5_multiband_to_raster(self):
'Cannot create image from 5 band image. Expecting 3 or 4 bands.',
)

def test_prepare_raster_for_writing_jpeg_3band(self):
def test_standardize_raster_for_writing_jpeg_3band(self):
raster = self.random.integers(255, size=(3, 5, 6))
count = 'irrelevant'
driver = 'JPEG'
expected_raster = np.copy(raster)
expected_color_map = None

actual_raster, actual_color_map = prepare_raster_for_writing(
actual_raster, actual_color_map = standardize_raster_for_writing(
raster, driver, count
)
self.assertEqual(expected_color_map, actual_color_map)
np.testing.assert_array_equal(expected_raster, actual_raster, strict=True)

def test_prepare_raster_for_writing_jpeg_4band(self):
def test_standardize_raster_for_writing_jpeg_4band(self):
raster = self.random.integers(255, size=(4, 7, 8))
driver = 'JPEG'
count = 'irrelevant'
expected_raster = np.copy(raster[0:3, :, :])
expected_color_map = None
actual_raster, actual_color_map = prepare_raster_for_writing(
actual_raster, actual_color_map = standardize_raster_for_writing(
raster, driver, count
)
self.assertEqual(expected_color_map, actual_color_map)
np.testing.assert_array_equal(expected_raster, actual_raster, strict=True)

@patch('hybig.browse.palettize_raster')
def test_prepare_raster_for_writing_png_4band(self, palettize_mock):
def test_standardize_raster_for_writing_png_4band(self, palettize_mock):
raster = self.random.integers(255, size=(4, 7, 8))
driver = 'PNG'
count = 'not 1'

expected, _ = prepare_raster_for_writing(raster, driver, count)
expected, _ = standardize_raster_for_writing(raster, driver, count)
np.testing.assert_array_equal(raster, expected, strict=True)
palettize_mock.assert_not_called()

@patch('hybig.browse.palettize_raster')
def test_prepare_raster_for_writing_png_3band(self, palettize_mock):
def test_standardize_raster_for_writing_png_3band(self, palettize_mock):
raster = self.random.integers(255, size=(3, 7, 8))
driver = 'PNG'
count = 'not 1'

expected, _ = prepare_raster_for_writing(raster, driver, count)
expected, _ = standardize_raster_for_writing(raster, driver, count)
np.testing.assert_array_equal(raster, expected, strict=True)
palettize_mock.assert_not_called()

Expand All @@ -704,7 +704,7 @@ def test_prepare_1band_raster_for_writing_png(self, palettize_mock):
driver = 'PNG'
count = 1
palettize_mock.return_value = (None, None)
expected, _ = prepare_raster_for_writing(raster, driver, count)
expected, _ = standardize_raster_for_writing(raster, driver, count)
palettize_mock.assert_called_with(raster)

@patch('hybig.browse.Image')
Expand Down

0 comments on commit b6aadd0

Please sign in to comment.