@@ -132,6 +132,8 @@ def test_create_browse_imagery_with_single_band_raster(self):
132132 )
133133 message = HarmonyMessage ({'format' : {'mime' : 'JPEG' }})
134134
135+ mock_logger = MagicMock (spec = Logger )
136+
135137 with rasterio_test_file (
136138 raster_data = two_dimensional_raster ,
137139 height = two_dimensional_raster .shape [1 ],
@@ -142,7 +144,7 @@ def test_create_browse_imagery_with_single_band_raster(self):
142144 HyBIGError , 'incorrect number of bands for image: 2'
143145 ):
144146 create_browse_imagery (
145- message , test_tif_filename , HarmonySource ({}), None , None
147+ message , test_tif_filename , HarmonySource ({}), None , mock_logger
146148 )
147149
148150 @patch ('hybig.browse.reproject' )
@@ -172,28 +174,10 @@ def test_create_browse_imagery_with_mocks(
172174 expected_raster = np .array (
173175 [
174176 [
175- [0 , 104 , 198 , 255 ],
176- [0 , 104 , 198 , 255 ],
177- [0 , 104 , 198 , 255 ],
178- [0 , 104 , 198 , 255 ],
179- ],
180- [
181- [0 , 104 , 198 , 255 ],
182- [0 , 104 , 198 , 255 ],
183- [0 , 104 , 198 , 255 ],
184- [0 , 104 , 198 , 255 ],
185- ],
186- [
187- [0 , 104 , 198 , 255 ],
188- [0 , 104 , 198 , 255 ],
189- [0 , 104 , 198 , 255 ],
190- [0 , 104 , 198 , 255 ],
191- ],
192- [
193- [255 , 255 , 255 , 255 ],
194- [255 , 255 , 255 , 255 ],
195- [255 , 255 , 255 , 255 ],
196- [255 , 255 , 255 , 255 ],
177+ [0 , 85 , 169 , 254 ],
178+ [0 , 85 , 169 , 254 ],
179+ [0 , 85 , 169 , 254 ],
180+ [0 , 85 , 169 , 254 ],
197181 ],
198182 ],
199183 dtype = 'uint8' ,
@@ -225,7 +209,8 @@ def test_create_browse_imagery_with_mocks(
225209 target_transform = Affine (90.0 , 0.0 , - 180.0 , 0.0 , - 45.0 , 90.0 )
226210 dest = np .zeros ((da_mock .rio .height , da_mock .rio .width ), dtype = 'uint8' )
227211
228- self .assertEqual (reproject_mock .call_count , 3 )
212+ # since we are no longer de-palettizing, we only have to reproject a single band
213+ self .assertEqual (reproject_mock .call_count , 1 )
229214
230215 expected_calls = [
231216 call (
@@ -235,27 +220,7 @@ def test_create_browse_imagery_with_mocks(
235220 src_crs = da_mock .rio .crs ,
236221 dst_transform = target_transform ,
237222 dst_crs = CRS .from_string ('EPSG:4326' ),
238- dst_nodata = 0 ,
239- resampling = Resampling .nearest ,
240- ),
241- call (
242- source = expected_raster [1 , :, :],
243- destination = dest ,
244- src_transform = file_transform ,
245- src_crs = da_mock .rio .crs ,
246- dst_transform = target_transform ,
247- dst_crs = CRS .from_string ('EPSG:4326' ),
248- dst_nodata = 0 ,
249- resampling = Resampling .nearest ,
250- ),
251- call (
252- source = expected_raster [2 , :, :],
253- destination = dest ,
254- src_transform = file_transform ,
255- src_crs = da_mock .rio .crs ,
256- dst_transform = target_transform ,
257- dst_crs = CRS .from_string ('EPSG:4326' ),
258- dst_nodata = 0 ,
223+ dst_nodata = 255 , # NODATA_IDX
259224 resampling = Resampling .nearest ,
260225 ),
261226 ]
@@ -306,41 +271,23 @@ def test_create_browse_imagery_with_mocks(
306271 )
307272
308273 def test_convert_singleband_to_raster_without_colortable (self ):
309- """Tests convert_gray_1band_to_raster ."""
274+ """Tests scale_grey_1band ."""
310275 return_data = np .copy (self .data ).astype ('float64' )
311276 return_data [0 ][1 ] = np .nan
312277 ds = DataArray (return_data ).expand_dims ('band' )
313278
314279 expected_raster = np .array (
315280 [
316281 [
317- [0 , 0 , 198 , 255 ],
318- [0 , 104 , 198 , 255 ],
319- [0 , 104 , 198 , 255 ],
320- [0 , 104 , 198 , 255 ],
321- ],
322- [
323- [0 , 0 , 198 , 255 ],
324- [0 , 104 , 198 , 255 ],
325- [0 , 104 , 198 , 255 ],
326- [0 , 104 , 198 , 255 ],
327- ],
328- [
329- [0 , 0 , 198 , 255 ],
330- [0 , 104 , 198 , 255 ],
331- [0 , 104 , 198 , 255 ],
332- [0 , 104 , 198 , 255 ],
333- ],
334- [
335- [255 , 0 , 255 , 255 ],
336- [255 , 255 , 255 , 255 ],
337- [255 , 255 , 255 , 255 ],
338- [255 , 255 , 255 , 255 ],
282+ [0 , 255 , 169 , 254 ],
283+ [0 , 85 , 169 , 254 ],
284+ [0 , 85 , 169 , 254 ],
285+ [0 , 85 , 169 , 254 ],
339286 ],
340287 ],
341288 dtype = 'uint8' ,
342289 )
343- actual_raster = convert_singleband_to_raster (ds , None )
290+ actual_raster , _ = convert_singleband_to_raster (ds , None )
344291 assert_array_equal (expected_raster , actual_raster , strict = True )
345292
346293 def test_convert_singleband_to_raster_with_colormap (self ):
@@ -368,7 +315,7 @@ def test_convert_singleband_to_raster_with_colormap(self):
368315 image_palette = convert_colormap_to_palette (self .colormap )
369316 actual_raster , actual_palette = convert_singleband_to_raster (ds , image_palette )
370317 assert_array_equal (expected_raster , actual_raster , strict = True )
371- assert_equal (expected_palette , actual_palette , strict = True )
318+ assert_equal (expected_palette , actual_palette )
372319
373320
374321 def test_convert_singleband_to_raster_with_colormap_and_bad_data (self ):
@@ -380,39 +327,29 @@ def test_convert_singleband_to_raster_with_colormap_and_bad_data(self):
380327 # Read the image down: red, yellow, green, blue
381328 expected_raster = np .array (
382329 [
383- [ # red
384- [nv_color [0 ], 255 , 0 , 0 ],
385- [255 , 255 , 0 , 0 ],
386- [255 , 255 , 0 , 0 ],
387- [255 , 255 , 0 , 0 ],
388- ],
389- [ # green
390- [nv_color [1 ], 255 , 255 , 0 ],
391- [0 , 255 , 255 , 0 ],
392- [0 , 255 , 255 , 0 ],
393- [0 , 255 , 255 , 0 ],
394- ],
395- [ # blue
396- [nv_color [2 ], 0 , 0 , 255 ],
397- [0 , 0 , 0 , 255 ],
398- [0 , 0 , 0 , 255 ],
399- [0 , 0 , 0 , 255 ],
400- ],
401- [ # alpha
402- [nv_color [3 ], 255 , 255 , 255 ],
403- [255 , 255 , 255 , 255 ],
404- [255 , 255 , 255 , 255 ],
405- [255 , 255 , 255 , 255 ],
330+ [ # singleband paletted
331+ [4 , 1 , 2 , 3 ],
332+ [0 , 1 , 2 , 3 ],
333+ [0 , 1 , 2 , 3 ],
334+ [0 , 1 , 2 , 3 ],
406335 ],
407336 ],
408337 dtype = 'uint8' ,
409338 )
339+ expected_palette = {
340+ 0 : (255 , 0 , 0 , 255 ), # red
341+ 1 : (255 , 255 , 0 , 255 ), # yellow
342+ 2 : (0 , 255 , 0 , 255 ), # green
343+ 3 : (0 , 0 , 255 , 255 ), # blue
344+ 4 : (10 , 20 , 30 , 40 ), # nv
345+ }
410346
411347 colormap = {** self .colormap , 'nv' : nv_color }
412348
413349 image_palette = convert_colormap_to_palette (colormap )
414- actual_raster = convert_singleband_to_raster (ds , image_palette )
350+ actual_raster , actual_palette = convert_singleband_to_raster (ds , image_palette )
415351 assert_array_equal (expected_raster , actual_raster , strict = True )
352+ assert_equal (expected_palette , actual_palette )
416353
417354 def test_convert_uint16_3_multiband_to_raster (self ):
418355 """Test that uint16 input scales the output."""
@@ -680,6 +617,7 @@ def test_get_color_map_from_image(self):
680617 def test_get_color_palette_map_exists_source_does_not (self ):
681618 ds = Mock (DatasetReader )
682619 ds .colormap .return_value = self .colormap
620+ ds .get_nodatavals .return_value = ()
683621
684622 lines = [
685623 '100 255 0 0 255' ,
0 commit comments