Skip to content

Commit

Permalink
Add BNDVI/NDRE spectral indices (microsoft#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX4284 authored Feb 14, 2022
1 parent b18efbf commit a70b075
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
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
.. 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)

0 comments on commit a70b075

Please sign in to comment.