Skip to content

Commit 645d6cc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f959ba3 commit 645d6cc

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

docs/config_ndvi_ls_median.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ cog_opts:
3030
# If you're making an RGBA image, compress better
3131
rgba:
3232
compress: JPEG
33-
jpeg_quality: 90
33+
jpeg_quality: 90

odc/stats/plugins/ls_ndvi_median.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Simple odc-stats plugin example, with excessive
33
documentation. Creates temporal mean NDVI
44
from DEA Landsat Collection 3
5-
5+
66
"""
77

88
from typing import Optional, Sequence, Tuple
@@ -17,11 +17,13 @@
1717
mask_cleanup,
1818
)
1919

20+
2021
class StatsNDVI(StatsPluginInterface):
2122
"""
22-
Define a class for summarising time
23+
Define a class for summarising time
2324
series of NDVI using the median.
2425
"""
26+
2527
NAME = "ndvi_median"
2628
SHORT_NAME = NAME
2729
VERSION = "1.0"
@@ -36,21 +38,19 @@ def __init__(
3638
group_by: str = "solar_day",
3739
**kwargs,
3840
):
39-
41+
4042
self.input_bands = input_bands
4143
self.output_bands = output_bands
4244
self.mask_band = mask_band
4345
self.contiguity_band = contiguity_band
4446
self.group_by = group_by
4547

46-
## These params get passed to the upstream
48+
## These params get passed to the upstream
4749
# base StatsPluginInterface class
4850
super().__init__(
49-
input_bands=tuple(input_bands)+(mask_band,)+(contiguity_band,),
50-
**kwargs
51+
input_bands=tuple(input_bands) + (mask_band,) + (contiguity_band,), **kwargs
5152
)
5253

53-
5454
@property
5555
def measurements(self) -> Tuple[str, ...]:
5656
"""
@@ -59,7 +59,7 @@ def measurements(self) -> Tuple[str, ...]:
5959
but equally we could define the outputs ames within this function.
6060
For example, by adding a suffix to the input bands.
6161
"""
62-
62+
6363
return (self.output_bands,)
6464

6565
def native_transform(self, xx):
@@ -70,21 +70,21 @@ def native_transform(self, xx):
7070
step of data and is usually used for things like
7171
masking clouds, nodata, and contiguity masking.
7272
"""
73-
#grab the QA band from the Landsat data
73+
# grab the QA band from the Landsat data
7474
mask = xx[self.mask_band]
7575

7676
# create boolean arrays from the mask for cloud
7777
# and cloud shadows, and nodata
7878
bad = enum_to_bool(mask, ("nodata",))
7979
non_contiguent = xx.get(self.contiguity_band, 1) == 0
8080
bad = bad | non_contiguent
81-
81+
8282
cloud_mask = enum_to_bool(mask, ("cloud", "shadow"))
83-
bad = cloud_mask | bad
83+
bad = cloud_mask | bad
8484

8585
# drop masking bands
8686
xx = xx.drop_vars([self.mask_band] + [self.contiguity_band])
87-
87+
8888
## Mask the bad data (clouds etc)
8989
xx = erase_bad(xx, bad)
9090

@@ -96,16 +96,17 @@ def reduce(self, xx: xr.Dataset) -> xr.Dataset:
9696
"""
9797
# convert to float by and convert nodata to NaN
9898
xx = mask_invalid_data(xx)
99-
100-
ndvi = (xx['nbart_nir'] - xx['nbart_red']) / (xx['nbart_nir'] + xx['nbart_red'])
10199

102-
# calculate temporal median NDVI.
103-
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!
100+
ndvi = (xx["nbart_nir"] - xx["nbart_red"]) / (xx["nbart_nir"] + xx["nbart_red"])
101+
102+
# calculate temporal median NDVI.
103+
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!
104104
# Note that we use 'spec' and not 'time', this is an odc-stats thing
105105
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!
106-
ndvi = ndvi.median('spec').rename(self.output_bands)
107-
106+
ndvi = ndvi.median("spec").rename(self.output_bands)
107+
108108
return ndvi.to_dataset()
109109

110+
110111
# now lets 'register' the function with odc-stats
111112
register("ndvi-median", StatsNDVI)

0 commit comments

Comments
 (0)