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
12 changes: 3 additions & 9 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 @@ -121,7 +121,6 @@ def __init__(
self.paths = paths
self.download = download
self.checksum = checksum

adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
self._verify()

colors = []
Expand Down Expand Up @@ -574,7 +573,7 @@ def __init__(
self.cache = cache
self.download = download
self.checksum = checksum

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

super().__init__(transforms)
Expand All @@ -584,11 +583,6 @@ def __init__(
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.nlcd_cmap.values())
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
nlcd_colors = nlcd_colors[:, :3] / 255
self._nlcd_cmap = ListedColormap(nlcd_colors)

# Add all tiles into the index in epsg:3857 based on the included geojson
mint: float = 0
maxt: float = sys.maxsize
Expand Down Expand Up @@ -793,7 +787,7 @@ def plot(
img = mask[:, :, 0]
mask = mask[:, :, 1:]
axs[i].imshow(
img, vmin=0, vmax=95, cmap=self._nlcd_cmap, interpolation="none"
img, vmin=0, vmax=95, cmap=self.cmap, interpolation="none"
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
)
axs[i].axis("off")
elif layer == "lc":
Expand Down