@@ -132,6 +132,8 @@ def test_create_browse_imagery_with_single_band_raster(self):
132
132
)
133
133
message = HarmonyMessage ({'format' : {'mime' : 'JPEG' }})
134
134
135
+ mock_logger = MagicMock (spec = Logger )
136
+
135
137
with rasterio_test_file (
136
138
raster_data = two_dimensional_raster ,
137
139
height = two_dimensional_raster .shape [1 ],
@@ -142,7 +144,7 @@ def test_create_browse_imagery_with_single_band_raster(self):
142
144
HyBIGError , 'incorrect number of bands for image: 2'
143
145
):
144
146
create_browse_imagery (
145
- message , test_tif_filename , HarmonySource ({}), None , None
147
+ message , test_tif_filename , HarmonySource ({}), None , mock_logger
146
148
)
147
149
148
150
@patch ('hybig.browse.reproject' )
@@ -172,28 +174,10 @@ def test_create_browse_imagery_with_mocks(
172
174
expected_raster = np .array (
173
175
[
174
176
[
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 ],
197
181
],
198
182
],
199
183
dtype = 'uint8' ,
@@ -225,7 +209,8 @@ def test_create_browse_imagery_with_mocks(
225
209
target_transform = Affine (90.0 , 0.0 , - 180.0 , 0.0 , - 45.0 , 90.0 )
226
210
dest = np .zeros ((da_mock .rio .height , da_mock .rio .width ), dtype = 'uint8' )
227
211
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 )
229
214
230
215
expected_calls = [
231
216
call (
@@ -235,27 +220,7 @@ def test_create_browse_imagery_with_mocks(
235
220
src_crs = da_mock .rio .crs ,
236
221
dst_transform = target_transform ,
237
222
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
259
224
resampling = Resampling .nearest ,
260
225
),
261
226
]
@@ -306,41 +271,23 @@ def test_create_browse_imagery_with_mocks(
306
271
)
307
272
308
273
def test_convert_singleband_to_raster_without_colortable (self ):
309
- """Tests convert_gray_1band_to_raster ."""
274
+ """Tests scale_grey_1band ."""
310
275
return_data = np .copy (self .data ).astype ('float64' )
311
276
return_data [0 ][1 ] = np .nan
312
277
ds = DataArray (return_data ).expand_dims ('band' )
313
278
314
279
expected_raster = np .array (
315
280
[
316
281
[
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 ],
339
286
],
340
287
],
341
288
dtype = 'uint8' ,
342
289
)
343
- actual_raster = convert_singleband_to_raster (ds , None )
290
+ actual_raster , _ = convert_singleband_to_raster (ds , None )
344
291
assert_array_equal (expected_raster , actual_raster , strict = True )
345
292
346
293
def test_convert_singleband_to_raster_with_colormap (self ):
@@ -368,7 +315,7 @@ def test_convert_singleband_to_raster_with_colormap(self):
368
315
image_palette = convert_colormap_to_palette (self .colormap )
369
316
actual_raster , actual_palette = convert_singleband_to_raster (ds , image_palette )
370
317
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 )
372
319
373
320
374
321
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):
380
327
# Read the image down: red, yellow, green, blue
381
328
expected_raster = np .array (
382
329
[
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 ],
406
335
],
407
336
],
408
337
dtype = 'uint8' ,
409
338
)
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
+ }
410
346
411
347
colormap = {** self .colormap , 'nv' : nv_color }
412
348
413
349
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 )
415
351
assert_array_equal (expected_raster , actual_raster , strict = True )
352
+ assert_equal (expected_palette , actual_palette )
416
353
417
354
def test_convert_uint16_3_multiband_to_raster (self ):
418
355
"""Test that uint16 input scales the output."""
@@ -680,6 +617,7 @@ def test_get_color_map_from_image(self):
680
617
def test_get_color_palette_map_exists_source_does_not (self ):
681
618
ds = Mock (DatasetReader )
682
619
ds .colormap .return_value = self .colormap
620
+ ds .get_nodatavals .return_value = ()
683
621
684
622
lines = [
685
623
'100 255 0 0 255' ,
0 commit comments