|
13 | 13 | from numpy.testing import assert_array_equal, assert_equal |
14 | 14 | from osgeo_utils.auxiliary.color_palette import ColorPalette |
15 | 15 | from rasterio import Affine |
| 16 | +from rasterio.coords import BoundingBox |
16 | 17 | from rasterio.crs import CRS |
17 | 18 | from rasterio.io import DatasetReader, DatasetWriter |
18 | 19 | from rasterio.warp import Resampling |
@@ -161,7 +162,7 @@ def test_create_browse_imagery_with_mocks(self, rasterio_open_mock, reproject_mo |
161 | 162 | ds.crs = CRS.from_string('EPSG:4326') |
162 | 163 | ds.count = 1 |
163 | 164 | ds.colormap = Mock(side_effect=ValueError) |
164 | | - ds.bounds = (-180.0, -90.0, 180.0, 90.0) |
| 165 | + ds.bounds = BoundingBox(-180.0, -90.0, 180.0, 90.0) |
165 | 166 | ds.window_transform = Mock(return_value=file_transform) |
166 | 167 | ds.nodatavals = (255,) |
167 | 168 | ds.scales = (1,) |
@@ -313,7 +314,7 @@ def test_create_browse_imagery_excludes_all_nan_tiles(self, rasterio_open_mock): |
313 | 314 | ds.crs = CRS.from_string('EPSG:4326') |
314 | 315 | ds.count = 1 |
315 | 316 | ds.colormap = Mock(side_effect=ValueError) |
316 | | - ds.bounds = (-180.0, -90.0, 180.0, 90.0) |
| 317 | + ds.bounds = BoundingBox(-180.0, -90.0, 180.0, 90.0) |
317 | 318 | ds.window_transform = Mock(return_value=file_transform) |
318 | 319 | ds.nodatavals = (None,) |
319 | 320 | ds.scales = (1,) |
@@ -368,74 +369,6 @@ def test_read_window_with_mask_and_scale_without_out_shape(self): |
368 | 369 | ds.read.assert_called_once_with([1], window=window) |
369 | 370 | self.assertEqual(result.shape, (1, 4, 4)) |
370 | 371 |
|
371 | | - @patch('hybig.browse.reproject') |
372 | | - @patch('rasterio.open') |
373 | | - def test_process_tile_downsamples_read_for_coarser_output( |
374 | | - self, rasterio_open_mock, reproject_mock |
375 | | - ): |
376 | | - """Test process_tile reads at output resolution when output is coarser |
377 | | - than source. |
378 | | -
|
379 | | - This is the memory fix: a 36000x18000 source with a 1280x2560 output |
380 | | - should not load the full-resolution source into memory. |
381 | | - """ |
382 | | - # Source: 1° pixels, 10x10 |
383 | | - src_affine = Affine(1.0, 0.0, -5.0, 0.0, -1.0, 5.0) |
384 | | - ds = Mock(spec=DatasetReader) |
385 | | - ds.crs = CRS.from_string('EPSG:4326') |
386 | | - ds.transform = src_affine |
387 | | - ds.shape = (10, 10) |
388 | | - ds.count = 1 |
389 | | - ds.nodatavals = (None,) |
390 | | - ds.scales = (1,) |
391 | | - ds.offsets = (0,) |
392 | | - # Return data at the downsampled (2x2) size |
393 | | - ds.read.return_value = np.array([[[0, 100], [200, 255]]], dtype='float64') |
394 | | - ds.window_transform.return_value = src_affine |
395 | | - |
396 | | - dest_write_mock = Mock(spec=DatasetWriter) |
397 | | - rasterio_open_mock.return_value.__enter__.return_value = dest_write_mock |
398 | | - |
399 | | - # Output: 5° pixels, 2x2 — coarser than source |
400 | | - out_affine = Affine(5.0, 0.0, -5.0, 0.0, -5.0, 5.0) |
401 | | - grid_params = GridParams( |
402 | | - { |
403 | | - 'height': 2, |
404 | | - 'width': 2, |
405 | | - 'crs': CRS.from_string('EPSG:4326'), |
406 | | - 'transform': out_affine, |
407 | | - } |
408 | | - ) |
409 | | - |
410 | | - result = process_tile( |
411 | | - ds, |
412 | | - grid_params, |
413 | | - None, |
414 | | - 'PNG', |
415 | | - self.tmp_dir / 'output.png', |
416 | | - self.tmp_dir / 'output.pgw', |
417 | | - self.logger, |
418 | | - ) |
419 | | - |
420 | | - self.assertTrue(result) |
421 | | - |
422 | | - # Source window covers the full 10x10 source (with buffer, clamped). |
423 | | - # read_width = min(10, round(10 * 1.0 / 5.0)) = 2 |
424 | | - # read_height = min(10, round(10 * 1.0 / 5.0)) = 2 |
425 | | - ds.read.assert_called_once() |
426 | | - read_kwargs = ds.read.call_args.kwargs |
427 | | - self.assertIn('out_shape', read_kwargs) |
428 | | - _bands, read_height, read_width = read_kwargs['out_shape'] |
429 | | - self.assertEqual(read_width, 2) |
430 | | - self.assertEqual(read_height, 2) |
431 | | - |
432 | | - # src_transform passed to reproject must have 5° pixel size (scaled from 1°) |
433 | | - self.assertEqual(reproject_mock.call_count, 1) |
434 | | - actual_src_transform = reproject_mock.call_args.kwargs['src_transform'] |
435 | | - self.assertAlmostEqual(actual_src_transform.a, 5.0) |
436 | | - self.assertAlmostEqual(abs(actual_src_transform.e), 5.0) |
437 | | - self.assertAlmostEqual(actual_src_transform.c, -5.0) # origin unchanged |
438 | | - |
439 | 372 | @patch('hybig.browse.reproject') |
440 | 373 | @patch('rasterio.open') |
441 | 374 | def test_process_tile_full_res_when_resolutions_match( |
|
0 commit comments