зеркало из https://github.com/microsoft/torchgeo.git
Add plotting tests
This commit is contained in:
Родитель
25bc22d037
Коммит
d24c9a84ef
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -54,6 +54,11 @@ class TestCDL:
|
|||
def test_already_downloaded(self, dataset: CDL) -> None:
|
||||
CDL(root=dataset.root, download=True)
|
||||
|
||||
def test_plot(self, dataset: CDL) -> None:
|
||||
query = dataset.bounds
|
||||
x = dataset[query]
|
||||
dataset.plot(x["masks"], query)
|
||||
|
||||
def test_not_downloaded(self, tmp_path: Path) -> None:
|
||||
with pytest.raises(RuntimeError, match="Dataset not found or corrupted."):
|
||||
CDL(str(tmp_path))
|
||||
|
|
|
@ -28,6 +28,11 @@ class TestLandsat8:
|
|||
ds = dataset + dataset
|
||||
assert isinstance(ds, ZipDataset)
|
||||
|
||||
def test_plot(self, dataset: Landsat8) -> None:
|
||||
query = dataset.bounds
|
||||
x = dataset[query]
|
||||
dataset.plot(x["image"], query)
|
||||
|
||||
def test_no_data(self, tmp_path: Path) -> None:
|
||||
with pytest.raises(FileNotFoundError, match="No Landsat data was found in "):
|
||||
Landsat8(str(tmp_path))
|
||||
|
|
|
@ -5,6 +5,7 @@ import os
|
|||
from datetime import datetime
|
||||
from typing import Any, Callable, Dict, Optional
|
||||
|
||||
import cartopy.crs as ccrs
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import rasterio
|
||||
|
@ -19,7 +20,8 @@ from torchvision.datasets.utils import check_integrity, download_and_extract_arc
|
|||
from .geo import GeoDataset
|
||||
from .utils import BoundingBox
|
||||
|
||||
_crs = RCRS.from_wkt(
|
||||
_ccrs = ccrs.AlbersEqualArea(-96, 23, 0, 0, (29.5, 45.5))
|
||||
_rcrs = RCRS.from_wkt(
|
||||
"""
|
||||
PROJCS["Albers Conical Equal Area",
|
||||
GEOGCS["NAD83",
|
||||
|
@ -85,7 +87,7 @@ class CDL(GeoDataset):
|
|||
def __init__(
|
||||
self,
|
||||
root: str = "data",
|
||||
crs: RCRS = _crs,
|
||||
crs: RCRS = _rcrs,
|
||||
transforms: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
|
||||
download: bool = False,
|
||||
checksum: bool = False,
|
||||
|
@ -201,8 +203,8 @@ class CDL(GeoDataset):
|
|||
self,
|
||||
image: Tensor,
|
||||
bbox: BoundingBox,
|
||||
projection: CCRS,
|
||||
transform: CCRS,
|
||||
projection: CCRS = _ccrs,
|
||||
transform: CCRS = _ccrs,
|
||||
) -> None:
|
||||
"""Plot an image on a map.
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import os
|
|||
from datetime import datetime
|
||||
from typing import Any, Callable, Dict, Optional, Sequence
|
||||
|
||||
import cartopy.crs as ccrs
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import rasterio
|
||||
|
@ -20,6 +21,10 @@ from .geo import GeoDataset
|
|||
from .utils import BoundingBox
|
||||
|
||||
|
||||
_ccrs = ccrs.UTM(16)
|
||||
_rcrs = RCRS.from_epsg(32616)
|
||||
|
||||
|
||||
class Landsat(GeoDataset, abc.ABC):
|
||||
"""Abstract base class for all Landsat datasets.
|
||||
|
||||
|
@ -48,7 +53,7 @@ class Landsat(GeoDataset, abc.ABC):
|
|||
def __init__(
|
||||
self,
|
||||
root: str = "data",
|
||||
crs: RCRS = RCRS.from_epsg(32616),
|
||||
crs: RCRS = _rcrs,
|
||||
bands: Sequence[str] = [],
|
||||
transforms: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
|
||||
) -> None:
|
||||
|
@ -139,8 +144,8 @@ class Landsat(GeoDataset, abc.ABC):
|
|||
self,
|
||||
image: Tensor,
|
||||
bbox: BoundingBox,
|
||||
projection: CCRS,
|
||||
transform: CCRS,
|
||||
projection: CCRS = _ccrs,
|
||||
transform: CCRS = _ccrs,
|
||||
) -> None:
|
||||
"""Plot an image on a map.
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче