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

NLCD2016 Tree Canopy #1243

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions torchgeo/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from .millionaid import MillionAID
from .naip import NAIP
from .nasa_marine_debris import NASAMarineDebris
from .nlcd import NLCD2016TreeCanopy
from .openbuildings import OpenBuildings
from .oscd import OSCD
from .patternnet import PatternNet
Expand Down Expand Up @@ -184,6 +185,7 @@
"LoveDA",
"MillionAID",
"NASAMarineDebris",
"NLCD2016TreeCanopy",
"OSCD",
"PatternNet",
"Potsdam2D",
Expand Down
86 changes: 86 additions & 0 deletions torchgeo/datasets/nlcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

"""National Agriculture Imagery Program (NAIP) dataset."""

from typing import Any, Dict, Optional

import matplotlib.pyplot as plt

from .geo import RasterDataset


class NLCD2016TreeCanopy(RasterDataset):
"""National Land Cover Database 2016 (NLCD2016) - Tree Canopy dataset.

The `National Land Cover Database <https://www.mrlc.gov/>`_ provides 30m tree
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would link to the tree canopy page, not the NLCD page

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `National Land Cover Database <https://www.mrlc.gov/>`_ provides 30m tree
The `Multi-Resolution Land Characteristics (MRLC) Consortium <https://www.mrlc.gov/>`_ provides 30m tree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canopy cover raster datasets generated by the United States Forest
Service (USFS). The data covers the conterminous United States, coastal Alaska,
Hawaii, and Puerto Rico and consists of continuous percent tree canopy estimates
for each pixel across all land covers. The data is derived from multi-spectral
Landsat imagery and other available ground and ancillary information.

If you use this dataset in your research, please cite it using the following format:

* https://doi.org/10.14358/PERS.78.7.715

.. note::

This dataset can be automatically downloaded and converted to geotiffs from the
ERDAS IMAGINE .img format using the following bash script:
calebrob6 marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: bash

wget "https://s3-us-west-2.amazonaws.com/mrlc/nlcd_2016_treecanopy_2019_08_31.zip"
wget "https://s3-us-west-2.amazonaws.com/mrlc/nlcd_tcc_hi_2016.zip"
wget "https://s3-us-west-2.amazonaws.com/mrlc/nlcd_tcc_coastalAK_2016.zip"
wget "https://s3-us-west-2.amazonaws.com/mrlc/nlcd_tcc_prusvi_2016.zip"
unzip nlcd_2016_treecanopy_2019_08_31.zip
unzip nlcd_tcc_hi_2016.zip
unzip nlcd_tcc_coastalAK_2016.zip
unzip nlcd_tcc_prusvi_2016.zip
gdal_translate -co COMPRESS=LZW -of GTiff nlcd_2016_treecanopy_2019_08_31.img nlcd_2016_treecanopy_2019_08_31.tif
gdal_translate -co COMPRESS=LZW -of GTiff nlcd_2016_hi_treecanopy_20191018.img nlcd_2016_hi_treecanopy_20191018.tif
gdal_translate -co COMPRESS=LZW -of GTiff nlcd_2016_coastal_alaska_treecanopy.img nlcd_2016_coastal_alaska_treecanopy.tif
gdal_translate -co COMPRESS=LZW -of GTiff nlcd_2016_prusvi_treecanopy_20191017.img nlcd_2016_prusvi_treecanopy_20191017.tif

or manually downloaded from https://www.mrlc.gov/data

.. versionadded:: 0.5
""" # noqa: E501

is_image = False
filename_glob = "nlcd_2016*.tif"
filename_regex = r"""
(?P<name>[nlcd_2016]{9})*
"""

def plot(
self,
sample: Dict[str, Any],
show_titles: bool = True,
suptitle: Optional[str] = None,
) -> plt.Figure:
"""Plot a sample from the dataset.

Args:
sample: a sample returned by :meth:`RasterDataset.__getitem__`
show_titles: flag indicating whether to show titles above each panel
suptitle: optional string to use as a suptitle

Returns:
a matplotlib Figure with the rendered sample
"""
image = sample["mask"][0, :, :]

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(4, 4))

ax.imshow(image, cmap="Greens")
ax.axis("off")
if show_titles:
ax.set_title("Mask")

if suptitle is not None:
plt.suptitle(suptitle)

return fig