/
datasource.py
65 lines (51 loc) · 1.7 KB
/
datasource.py
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
# This file is part of the Open Data Cube, see https://opendatacube.org for more information
#
# Copyright (c) 2015-2023 ODC Contributors
# SPDX-License-Identifier: Apache-2.0
""" Defines abstract types for IO reader drivers.
"""
from abc import ABCMeta, abstractmethod
from contextlib import contextmanager
import numpy as np
from affine import Affine
from typing import Tuple, Iterator, Optional, Union
RasterShape = Tuple[int, int] # pylint: disable=invalid-name
RasterWindow = Union[ # pylint: disable=invalid-name
Tuple[Tuple[int, int], Tuple[int, int]],
Tuple[slice, slice]]
# pylint: disable=pointless-statement
class GeoRasterReader(object, metaclass=ABCMeta):
""" Abstract base class for dataset reader.
"""
@property
@abstractmethod
def crs(self):
... # pragma: no cover
@property
@abstractmethod
def transform(self) -> Optional[Affine]:
... # pragma: no cover
@property
@abstractmethod
def dtype(self) -> Union[str, np.dtype]:
... # pragma: no cover
@property
@abstractmethod
def shape(self) -> RasterShape:
... # pragma: no cover
@property
@abstractmethod
def nodata(self) -> Optional[Union[int, float]]:
... # pragma: no cover
@abstractmethod
def read(self,
window: Optional[RasterWindow] = None,
out_shape: Optional[RasterShape] = None) -> Optional[np.ndarray]:
... # pragma: no cover
class DataSource(object, metaclass=ABCMeta):
""" Abstract base class for dataset source.
"""
@abstractmethod
@contextmanager
def open(self) -> Iterator[GeoRasterReader]:
... # pragma: no cover