Skip to content

Commit

Permalink
Merge pull request #449 from opendatacube/alos_rvi_bandutil
Browse files Browse the repository at this point in the history
New band util function to handle radar vegetation index.
  • Loading branch information
pindge authored Oct 23, 2020
2 parents bdebe62 + e3caf8c commit 20eace0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions datacube_ows/band_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,13 @@ def single_band_offset_log(data, band, scale=1.0, scale_from=None, scale_to=None
if scale_from:
return scale_data(unscaled, scale_from, scale_to)
return unscaled


def radar_vegetation_index(data, band_hv, band_hh, band_mapper=None):
if band_mapper:
band_hv = band_mapper(band_hv)
band_hh = band_mapper(band_hh)
hv_sq = data[band_hv]*data[band_hv]
hh_sq = data[band_hh]*data[band_hh]
return (hv_sq * 4.0) / (hh_sq + hv_sq)

54 changes: 54 additions & 0 deletions datacube_ows/cfg_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import click

from datacube_ows import __version__
from datacube_ows.ows_configuration import read_config, OWSConfig, ConfigException
from datacube import Datacube

@click.command()
@click.argument("paths", nargs=-1)
@click.option("--version", is_flag=True, default=False, help="Show OWS version number and exit")
@click.option("-p", "--parse-only", is_flag=True, default=False, help="Only parse the syntax of the config file - do not validate against database")
def main(version, parse_only, paths):
#layers, blocking,
# merge_only, summary,
# schema, views, role, version,
# product, multiproduct, calculate_extent):
"""Test configuration files
Valid invocations:
Uses the DATACUBE_OWS_CFG environment variable to find the OWS config file.
"""
# --version
if version:
print("Open Data Cube Open Web Services (datacube-ows) version",
__version__
)
return 0

if not paths:
if parse_path(None, parse_only):
return 0
else:
return 1
all_ok = True
for path in paths:
if not parse_path(path, parse_only):
all_ok = False


if all_ok:
return 1
return 0

def parse_path(path, parse_only):
try:
raw_cfg = read_config(path)
cfg = OWSConfig(refresh=True, cfg=raw_cfg)
if not parse_only:
with Datacube() as dc:
cfg.make_ready(dc)
except ConfigException as e:
print("Config exception for path", str(e))
6 changes: 6 additions & 0 deletions tests/test_band_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
multi_date_delta,
single_band_offset_log,
single_band_arcsec,
radar_vegetation_index
)
from datacube_ows.ows_configuration import BandIndex, OWSProductLayer

Expand Down Expand Up @@ -122,3 +123,8 @@ def test_single_band_arcsec(band_mapper):
assert not single_band_arcsec(TEST_XARR, "b1", scale_from=[0.0, 0.8]) is None
assert not single_band_arcsec(TEST_XARR, "b1", scale_from=[0.0, 0.8], scale_to=[0, 1024]) is None
assert not single_band_arcsec(TEST_XARR, "b1", band_mapper=band_mapper) is None


def test_rvi(band_mapper):
assert not radar_vegetation_index(TEST_XARR, "b1", "b2") is None
assert not radar_vegetation_index(TEST_XARR, "b1", "b2", band_mapper=band_mapper) is None

0 comments on commit 20eace0

Please sign in to comment.