From 1b66b1122ab987f535f299b9b35df48d1a463b19 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 15 Feb 2022 15:30:25 -0600 Subject: [PATCH 1/2] Add formulas to indices docs --- docs/conf.py | 1 + torchgeo/transforms/indices.py | 80 +++++++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 43138d673f5..b4d68d41c98 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,6 +38,7 @@ extensions = [ "sphinx.ext.autodoc", "sphinx.ext.intersphinx", + "sphinx.ext.mathjax", "sphinx.ext.napoleon", "sphinx.ext.todo", "sphinx.ext.viewcode", diff --git a/torchgeo/transforms/indices.py b/torchgeo/transforms/indices.py index 40aab4bbd95..db9e6bc96bc 100644 --- a/torchgeo/transforms/indices.py +++ b/torchgeo/transforms/indices.py @@ -23,7 +23,13 @@ class AppendNormalizedDifferenceIndex(Module): - """Append normalized difference index as channel to image tensor. + r"""Append normalized difference index as channel to image tensor. + + Computes the following index: + + .. math:: + + NDI = \frac{A - B}{A + B} .. versionadded:: 0.2 """ @@ -76,7 +82,13 @@ def forward(self, sample: Dict[str, Tensor]) -> Dict[str, Tensor]: class AppendNBR(AppendNormalizedDifferenceIndex): - """Normalized Burn Ratio (NBR). + r"""Normalized Burn Ratio (NBR). + + Computes the following index: + + .. math:: + + NBR = \frac{NIR - SWIR}{NIR + SWIR} If you use this index in your research, please cite the following paper: @@ -96,7 +108,13 @@ def __init__(self, index_nir: int, index_swir: int) -> None: class AppendNDBI(AppendNormalizedDifferenceIndex): - """Normalized Difference Built-up Index (NDBI). + r"""Normalized Difference Built-up Index (NDBI). + + Computes the following index: + + .. math:: + + NDBI = \frac{SWIR - NIR}{SWIR + NIR} If you use this index in your research, please cite the following paper: @@ -114,7 +132,13 @@ def __init__(self, index_swir: int, index_nir: int) -> None: class AppendNDSI(AppendNormalizedDifferenceIndex): - """Normalized Difference Snow Index (NDSI). + r"""Normalized Difference Snow Index (NDSI). + + Computes the following index: + + .. math:: + + NDSI = \frac{G - SWIR}{G + SWIR} If you use this index in your research, please cite the following paper: @@ -132,7 +156,13 @@ def __init__(self, index_green: int, index_swir: int) -> None: class AppendNDVI(AppendNormalizedDifferenceIndex): - """Normalized Difference Vegetation Index (NDVI). + r"""Normalized Difference Vegetation Index (NDVI). + + Computes the following index: + + .. math:: + + NDVI = \frac{R - NIR}{R + NIR} If you use this index in your research, please cite the following paper: @@ -150,7 +180,13 @@ def __init__(self, index_red: int, index_nir: int) -> None: class AppendNDWI(AppendNormalizedDifferenceIndex): - """Normalized Difference Water Index (NDWI). + r"""Normalized Difference Water Index (NDWI). + + Computes the following index: + + .. math:: + + NDWI = \frac{G - NIR}{G + NIR} If you use this index in your research, please cite the following paper: @@ -168,7 +204,13 @@ def __init__(self, index_green: int, index_nir: int) -> None: class AppendSWI(AppendNormalizedDifferenceIndex): - """Standardized Water-Level Index (SWI). + r"""Standardized Water-Level Index (SWI). + + Computes the following index: + + .. math:: + + SWI = \frac{R - SWIR}{R + SWIR} If you use this index in your research, please cite the following paper: @@ -186,7 +228,13 @@ def __init__(self, index_red: int, index_swir: int) -> None: class AppendGNDVI(AppendNormalizedDifferenceIndex): - """Green Normalized Difference Vegetation Index (GNDVI). + r"""Green Normalized Difference Vegetation Index (GNDVI). + + Computes the following index: + + .. math:: + + GNDVI = \frac{NIR - G}{NIR + G} If you use this index in your research, please cite the following paper: @@ -204,7 +252,13 @@ def __init__(self, index_nir: int, index_green: int) -> None: class AppendBNDVI(AppendNormalizedDifferenceIndex): - """Blue Normalized Difference Vegetation Index (BNDVI). + r"""Blue Normalized Difference Vegetation Index (BNDVI). + + Computes the following index: + + .. math:: + + BNDVI = \frac{NIR - B}{NIR + B} If you use this index in your research, please cite the following paper: @@ -224,7 +278,13 @@ def __init__(self, index_nir: int, index_blue: int) -> None: class AppendNDRE(AppendNormalizedDifferenceIndex): - """Normalized Difference Red Edge Vegetation Index (NDRE). + r"""Normalized Difference Red Edge Vegetation Index (NDRE). + + Computes the following index: + + .. math:: + + NDRE = \frac{NIR - VRE1}{NIR + VRE1} If you use this index in your research, please cite the following paper: From 2bcdb2642115bf52b2317e2a197b9d18b6a672d9 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Tue, 15 Feb 2022 15:41:19 -0600 Subject: [PATCH 2/2] Use math text mode --- torchgeo/transforms/indices.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/torchgeo/transforms/indices.py b/torchgeo/transforms/indices.py index db9e6bc96bc..63a45ae517f 100644 --- a/torchgeo/transforms/indices.py +++ b/torchgeo/transforms/indices.py @@ -29,7 +29,7 @@ class AppendNormalizedDifferenceIndex(Module): .. math:: - NDI = \frac{A - B}{A + B} + \text{NDI} = \frac{A - B}{A + B} .. versionadded:: 0.2 """ @@ -88,7 +88,7 @@ class AppendNBR(AppendNormalizedDifferenceIndex): .. math:: - NBR = \frac{NIR - SWIR}{NIR + SWIR} + \text{NBR} = \frac{\text{NIR} - \text{SWIR}}{\text{NIR} + \text{SWIR}} If you use this index in your research, please cite the following paper: @@ -114,7 +114,7 @@ class AppendNDBI(AppendNormalizedDifferenceIndex): .. math:: - NDBI = \frac{SWIR - NIR}{SWIR + NIR} + \text{NDBI} = \frac{\text{SWIR} - \text{NIR}}{\text{SWIR} + \text{NIR}} If you use this index in your research, please cite the following paper: @@ -138,7 +138,7 @@ class AppendNDSI(AppendNormalizedDifferenceIndex): .. math:: - NDSI = \frac{G - SWIR}{G + SWIR} + \text{NDSI} = \frac{\text{G} - \text{SWIR}}{\text{G} + \text{SWIR}} If you use this index in your research, please cite the following paper: @@ -162,7 +162,7 @@ class AppendNDVI(AppendNormalizedDifferenceIndex): .. math:: - NDVI = \frac{R - NIR}{R + NIR} + \text{NDVI} = \frac{\text{R} - \text{NIR}}{\text{R} + \text{NIR}} If you use this index in your research, please cite the following paper: @@ -186,7 +186,7 @@ class AppendNDWI(AppendNormalizedDifferenceIndex): .. math:: - NDWI = \frac{G - NIR}{G + NIR} + \text{NDWI} = \frac{\text{G} - \text{NIR}}{\text{G} + \text{NIR}} If you use this index in your research, please cite the following paper: @@ -210,7 +210,7 @@ class AppendSWI(AppendNormalizedDifferenceIndex): .. math:: - SWI = \frac{R - SWIR}{R + SWIR} + \text{SWI} = \frac{\text{R} - \text{SWIR}}{\text{R} + \text{SWIR}} If you use this index in your research, please cite the following paper: @@ -234,7 +234,7 @@ class AppendGNDVI(AppendNormalizedDifferenceIndex): .. math:: - GNDVI = \frac{NIR - G}{NIR + G} + \text{GNDVI} = \frac{\text{NIR} - \text{G}}{\text{NIR} + \text{G}} If you use this index in your research, please cite the following paper: @@ -258,7 +258,7 @@ class AppendBNDVI(AppendNormalizedDifferenceIndex): .. math:: - BNDVI = \frac{NIR - B}{NIR + B} + \text{BNDVI} = \frac{\text{NIR} - \text{B}}{\text{NIR} + \text{B}} If you use this index in your research, please cite the following paper: @@ -284,7 +284,7 @@ class AppendNDRE(AppendNormalizedDifferenceIndex): .. math:: - NDRE = \frac{NIR - VRE1}{NIR + VRE1} + \text{NDRE} = \frac{\text{NIR} - \text{VRE1}}{\text{NIR} + \text{VRE1}} If you use this index in your research, please cite the following paper: