1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
import rasterio
from rasterio.rio.main import main_group
def test_stack(tmpdir, runner):
outputname = str(tmpdir.join('stacked.tif'))
result = runner.invoke(
main_group, ['stack', 'tests/data/RGB.byte.tif', outputname])
assert result.exit_code == 0
with rasterio.open(outputname) as out:
assert out.count == 3
assert out.read(1).max() > 0
def test_stack_2(tmpdir, runner):
outputname = str(tmpdir.join("stacked.tif"))
result = runner.invoke(
main_group,
["stack", "tests/data/RGB.byte.tif", "tests/data/RGB.byte.tif", outputname],
)
assert result.exit_code == 0
with rasterio.open(outputname) as out:
assert out.count == 6
assert out.read(1).max() > 0
def test_stack_disjoint(tmpdir, runner):
outputname = str(tmpdir.join("stacked.tif"))
result = runner.invoke(
main_group,
[
"stack",
"tests/data/rgb1.tif",
"tests/data/rgb2.tif",
"tests/data/rgb3.tif",
"tests/data/rgb4.tif",
outputname,
],
)
assert result.exit_code == 0
with rasterio.open(outputname) as out:
assert out.count == 12
assert out.shape == (718, 791)
def test_stack_list(tmpdir, runner):
outputname = str(tmpdir.join('stacked.tif'))
result = runner.invoke(
main_group, [
'stack', 'tests/data/RGB.byte.tif', '--bidx', '1,2,3', outputname])
assert result.exit_code == 0
with rasterio.open(outputname) as out:
assert out.count == 3
def test_stack_slice(tmpdir, runner):
outputname = str(tmpdir.join('stacked.tif'))
result = runner.invoke(
main_group, [
'stack',
'tests/data/RGB.byte.tif', '--bidx', '..2',
'tests/data/RGB.byte.tif', '--bidx', '3..',
outputname])
assert result.exit_code == 0
with rasterio.open(outputname) as out:
assert out.count == 3
def test_stack_single_slice(tmpdir, runner):
outputname = str(tmpdir.join('stacked.tif'))
result = runner.invoke(
main_group, [
'stack',
'tests/data/RGB.byte.tif', '--bidx', '1',
'tests/data/RGB.byte.tif', '--bidx', '2..',
'--rgb', outputname])
assert result.exit_code == 0
with rasterio.open(outputname) as out:
assert out.count == 3
def test_format_jpeg(tmpdir, runner):
outputname = str(tmpdir.join('stacked.jpg'))
result = runner.invoke(
main_group, [
'stack', 'tests/data/RGB.byte.tif', outputname,
'--format', 'JPEG'])
assert result.exit_code == 0
def test_error(tmpdir, runner):
outputname = str(tmpdir.join('stacked.tif'))
result = runner.invoke(
main_group, [
'stack', 'tests/data/RGB.byte.tif', outputname,
'--driver', 'BOGUS'])
assert result.exit_code == 1
|