Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated ChesapeakeCVPR to use NLCD colormap #1690

Merged
merged 10 commits into from
Jan 20, 2024
16 changes: 9 additions & 7 deletions torchgeo/datasets/chesapeake.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from matplotlib.figure import Figure
from rasterio.crs import CRS
from torch import Tensor

from .nlcd import NLCD
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
from .geo import GeoDataset, RasterDataset
from .utils import BoundingBox, download_url, extract_archive

Expand Down Expand Up @@ -574,15 +574,15 @@ def __init__(
self.cache = cache
self.download = download
self.checksum = checksum

self.cmap = NLCD.cmap
self._verify()

super().__init__(transforms)

lc_colors = np.zeros((max(self.lc_cmap.keys()) + 1, 4))
lc_colors[list(self.lc_cmap.keys())] = list(self.lc_cmap.values())
lc_colors = lc_colors[:, :3] / 255
self._lc_cmap = ListedColormap(lc_colors)
nlcd_colors = np.zeros((max(self.nlcd_cmap.keys()) + 1, 4))
nlcd_colors[list(self.nlcd_cmap.keys())] = list(self.lc_cmap.values())
nlcd_colors = nlcd_colors[:, :3] / 255
self._nlcd_cmap = ListedColormap(nlcd_colors)

nlcd_colors = np.zeros((max(self.nlcd_cmap.keys()) + 1, 4))
nlcd_colors[list(self.nlcd_cmap.keys())] = list(self.nlcd_cmap.values())
Expand Down Expand Up @@ -618,7 +618,9 @@ def __init__(
"prior_from_cooccurrences_101_31_no_osm_no_buildings": prior_fn, # noqa: E501
},
)

@property
def _nlcd_cmap(self):
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
return self.cmap
def __getitem__(self, query: BoundingBox) -> dict[str, Any]:
"""Retrieve image/mask and metadata indexed by query.

Expand Down