Skip to content

Commit b045f38

Browse files
committed
Add some tests about block_size argument
1 parent 95a1edd commit b045f38

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ dask.array<and_, shape=(3, 718, 791), dtype=uint8, chunksize=(1, 3, 791)>
5050
>>> write_raster('processed_image.tif', new_array, **prof)
5151
```
5252

53+
#### Chunk size
54+
55+
Both `read_raster` and `write_raster` accept a `block_size` argument that
56+
acts as a multiplier to the block size of rasters. The default value is 1,
57+
which means the dask array chunk size will be the same as the block size of
58+
the raster file. You will have to adjust this value depending on the
59+
specification of your machine (how much memory do you have, and the block
60+
size of the raster).
61+
62+
5363
## Install
5464

5565
Install with pip:

tests/test_dask_rasterio.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,25 @@ def test_cannot_write_raster_with_badly_shaped_array(some_raster_path):
183183

184184
with pytest.raises(TypeError):
185185
write_raster(dst_path, np.random.rand(10, 10, 10, 3), **prof)
186+
187+
188+
def multiply_chunks(chunks, multiplier):
189+
w_chunks = tuple(np.array([list(chunks[0])])) * multiplier
190+
h_chunks = tuple(np.array([list(chunks[1])])) * multiplier
191+
return (w_chunks, h_chunks)
192+
193+
194+
def test_read_raster_band_with_block_size(some_raster_path):
195+
array = read_raster_band(some_raster_path)
196+
array_4b = read_raster_band(some_raster_path, block_size=4)
197+
assert array.shape == array_4b.shape
198+
assert array.dtype == array_4b.dtype
199+
assert_array_equal(array, array_4b)
200+
201+
with rasterio.open(some_raster_path) as src:
202+
ch, cw = src.block_shapes[0]
203+
204+
assert array.chunks[0][0] == ch
205+
assert array.chunks[1][0] == cw
206+
assert array_4b.chunks[0][0] == ch * 4
207+
assert array_4b.chunks[1][0] == cw * 4

0 commit comments

Comments
 (0)