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

Add BNDVI/NDRE spectral indices #386

Merged
merged 11 commits into from
Feb 14, 2022
14 changes: 13 additions & 1 deletion tests/transforms/test_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from torch import Tensor

from torchgeo.transforms import (
AppendBNDVI,
AppendGNDVI,
AppendNBR,
AppendNDBI,
AppendNDRE,
AppendNDSI,
AppendNDVI,
AppendNDWI,
Expand Down Expand Up @@ -64,7 +66,17 @@ def test_append_index_batch(batch: Dict[str, Tensor]) -> None:

@pytest.mark.parametrize(
"index",
[AppendNBR, AppendNDBI, AppendNDSI, AppendNDVI, AppendNDWI, AppendSWI, AppendGNDVI],
[
AppendBNDVI,
AppendNBR,
AppendNDBI,
AppendNDRE,
AppendNDSI,
AppendNDVI,
AppendNDWI,
AppendSWI,
AppendGNDVI,
],
)
def test_append_normalized_difference_indices(
sample: Dict[str, Tensor], index: AppendNormalizedDifferenceIndex
Expand Down
4 changes: 4 additions & 0 deletions torchgeo/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"""TorchGeo transforms."""

from .indices import (
AppendBNDVI,
AppendGNDVI,
AppendNBR,
AppendNDBI,
AppendNDRE,
AppendNDSI,
AppendNDVI,
AppendNDWI,
Expand All @@ -17,9 +19,11 @@

__all__ = (
"AppendNormalizedDifferenceIndex",
"AppendBNDVI",
"AppendGNDVI",
"AppendNBR",
"AppendNDBI",
"AppendNDRE",
"AppendNDSI",
"AppendNDVI",
"AppendNDWI",
Expand Down
40 changes: 40 additions & 0 deletions torchgeo/transforms/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,43 @@ def __init__(self, index_nir: int, index_green: int) -> None:
index_green: index of the Green band, e.g. B3 in Sentinel 2 imagery
"""
super().__init__(index_a=index_nir, index_b=index_green)


class AppendBNDVI(AppendNormalizedDifferenceIndex):
"""Blue Normalized Difference Vegetation Index (BNDVI).

If you use this index in your research, please cite the following paper:

* https://doi.org/10.1016/S1672-6308(07)60027-4
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 0.3
"""

def __init__(self, index_nir: int, index_blue: int) -> None:
"""Initialize a new transform instance.

Args:
index_nir: index of the NIR band, e.g. B8 in Sentinel 2 imagery
index_blue: index of the Blue band, e.g. B2 in Sentinel 2 imagery
"""
super().__init__(index_a=index_nir, index_b=index_blue)


class AppendNDRE(AppendNormalizedDifferenceIndex):
"""Normalized Difference Red Edge Vegetation Index (NDRE).

If you use this index in your research, please cite the following paper:

* https://agris.fao.org/agris-search/search.do?recordID=US201300795763

.. versionadded:: 0.3
"""

def __init__(self, index_nir: int, index_vre1: int) -> None:
"""Initialize a new transform instance.

Args:
index_nir: index of the NIR band, e.g. B8 in Sentinel 2 imagery
index_vre1: index of the Red Edge band, B5 in Sentinel 2 imagery
"""
super().__init__(index_a=index_nir, index_b=index_vre1)