Skip to content

Commit 2bea42e

Browse files
erialC-Probbibt
andauthored
Minor update to dea_tools with changes to band indices and plotting scripts (#1078)
* minor changes to band indices and plotting scripts * Update Tools/dea_tools/plotting.py Co-authored-by: Robbi Bishop-Taylor <Robbi.BishopTaylor@ga.gov.au> * Update Tools/dea_tools/plotting.py Co-authored-by: Robbi Bishop-Taylor <Robbi.BishopTaylor@ga.gov.au> --------- Co-authored-by: Robbi Bishop-Taylor <Robbi.BishopTaylor@ga.gov.au>
1 parent f5bddd8 commit 2bea42e

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Tools/dea_tools/bandindices.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
If you would like to report an issue with this script, you can file one
1616
on Github (https://github.com/GeoscienceAustralia/dea-notebooks/issues/new).
1717
18-
Last modified: March 2021
18+
Last modified: June 2023
1919
'''
2020

2121
# Import required packages
@@ -39,7 +39,7 @@ def calculate_indices(ds,
3939
in memory. This can be a memory-expensive operation, so to avoid
4040
this, set `inplace=True`.
4141
42-
Last modified: April 2023
42+
Last modified: June 2023
4343
4444
Parameters
4545
----------
@@ -76,6 +76,7 @@ def calculate_indices(ds,
7676
* ``'NDSI'`` (Normalised Difference Snow Index, Hall 1995)
7777
* ``'NDTI'`` (Normalise Difference Tillage Index,
7878
Van Deventeret et al. 1997)
79+
* ``'NDTI2'`` (Normalised Difference Turbidity Index, Lacaux et al., 2007)
7980
* ``'NDVI'`` (Normalised Difference Vegetation Index, Rouse 1973)
8081
* ``'NDWI'`` (Normalised Difference Water Index, McFeeters 1996)
8182
* ``'SAVI'`` (Soil Adjusted Vegetation Index, Huete 1988)
@@ -85,7 +86,6 @@ def calculate_indices(ds,
8586
* ``'TCB_GSO'`` (Tasseled Cap Brightness, Nedkov 2017)
8687
* ``'TCG_GSO'`` (Tasseled Cap Greeness, Nedkov 2017)
8788
* ``'TCW_GSO'`` (Tasseled Cap Wetness, Nedkov 2017)
88-
* ``'TI'`` (Normalised Difference Turbidity Index, Lacaux et al 2007)
8989
* ``'WI'`` (Water Index, Fisher 2016)
9090
* ``'kNDVI'`` (Non-linear Normalised Difference Vegation Index,
9191
Camps-Valls et al. 2021)
@@ -201,6 +201,11 @@ def calculate_indices(ds,
201201
# Van Deventer et al. 1997
202202
'NDTI': lambda ds: (ds.swir1 - ds.swir2) /
203203
(ds.swir1 + ds.swir2),
204+
205+
# Normalised Difference Turbidity Index,
206+
# Lacaux et al., 2007
207+
'NDTI2': lambda ds: (ds.red - ds.green) /
208+
(ds.red + ds.green),
204209

205210
# Normalised Difference Water Index, McFeeters 1996
206211
'NDWI': lambda ds: (ds.green - ds.nir) /
@@ -287,11 +292,7 @@ def calculate_indices(ds,
287292

288293
# Iron Oxide Ratio, Segal 1982
289294
'IOR': lambda ds: (ds.red / ds.blue),
290-
291-
# Normalised Difference Turbidity Index , Lacaux et al 2007
292-
#NB. 'NDTI' key already used. 'TI' used in lieu.
293-
'TI': lambda ds: (ds.red - ds.green) /
294-
(ds.red + ds.green)
295+
295296
}
296297

297298
# If index supplied is not a list, convert to list. This allows us to

Tools/dea_tools/plotting.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def rgb(ds,
5151
col_wrap=4,
5252
size=6,
5353
aspect=None,
54+
titles=None,
5455
savefig_path=None,
5556
savefig_kwargs={},
5657
**kwargs):
@@ -107,6 +108,10 @@ def rgb(ds,
107108
gives width of each facet in inches. Defaults to None, which
108109
will calculate the aspect based on the x and y dimensions of
109110
the input data.
111+
titles : string or list of strings, optional
112+
Replace the xarray 'time' dimension on plot titles with a string
113+
or list of string titles, when a list of index values are
114+
provided, of your choice. Defaults to None.
110115
savefig_path : string, optional
111116
Path to export image file for the RGB plot. Defaults to None,
112117
which does not export an image file.
@@ -182,6 +187,9 @@ def rgb(ds,
182187
col_wrap=col_wrap,
183188
**aspect_size_kwarg,
184189
**kwargs)
190+
if titles is not None:
191+
for ax, title in zip(img.axs.flat, titles):
192+
ax.set_title(title)
185193

186194
# If values provided for `index`, extract corresponding observations and
187195
# plot as either single image or facet plot
@@ -221,6 +229,9 @@ def rgb(ds,
221229
col_wrap=col_wrap,
222230
**aspect_size_kwarg,
223231
**kwargs)
232+
if titles is not None:
233+
for ax, title in zip(img.axs.flat, titles):
234+
ax.set_title(title)
224235

225236
# If only one index is supplied, squeeze out index_dim and plot as a
226237
# single panel
@@ -229,6 +240,9 @@ def rgb(ds,
229240
img = da.squeeze(dim=index_dim).plot.imshow(robust=robust,
230241
**aspect_size_kwarg,
231242
**kwargs)
243+
if titles is not None:
244+
for ax, title in zip(img.axs.flat, titles):
245+
ax.set_title(title)
232246

233247
# If an export path is provided, save image to file. Individual and
234248
# faceted plots have a different API (figure vs fig) so we get around this

0 commit comments

Comments
 (0)