File: test_convert.py

package info (click to toggle)
stactools 0.5.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,796 kB
  • sloc: python: 4,498; xml: 554; sh: 395; makefile: 34
file content (44 lines) | stat: -rw-r--r-- 1,438 bytes parent folder | download | duplicates (2)
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
from pathlib import Path

import rasterio
from stactools.core import utils
from stactools.core.utils.convert import cogify, cogify_subdatasets

from tests import test_data


def test_default(tmp_path: Path):
    infile = test_data.get_path("data-files/core/byte.tif")
    outfile = tmp_path / "byte.tif"
    cogify(infile, str(outfile))

    assert outfile.exists()
    with rasterio.open(outfile) as dataset:
        assert dataset.compression == rasterio.enums.Compression.deflate


def test_profile(tmp_path: Path):
    infile = test_data.get_path("data-files/core/byte.tif")
    outfile = tmp_path / "byte.tif"

    cogify(infile, str(outfile), profile={"compress": "lzw"})

    assert outfile.exists()
    with rasterio.open(outfile) as dataset:
        assert dataset.compression == rasterio.enums.Compression.lzw


def test_subdataset(tmp_path: Path):
    infile = test_data.get_path("data-files/hdf/AMSR_E_L3_RainGrid_B05_200707.h5")
    with utils.ignore_not_georeferenced():
        paths, names = cogify_subdatasets(infile, str(tmp_path))

    assert set(names) == {
        "MonthlyRainTotal_GeoGrid_Data_Fields_RrLandRain",
        "MonthlyRainTotal_GeoGrid_Data_Fields_TbOceanRain",
    }
    for path in paths:
        assert Path(path).exists()
        with utils.ignore_not_georeferenced():
            with rasterio.open(path) as dataset:
                assert dataset.compression == rasterio.enums.Compression.deflate