From fc78baf1d3c3f26591d1cb4372dfc5efa35d4881 Mon Sep 17 00:00:00 2001 From: phaesler Date: Fri, 23 Oct 2020 14:08:41 +1100 Subject: [PATCH 1/2] New band util function to handle radar vegetation index. --- datacube_ows/band_utils.py | 10 ++++++++++ tests/test_band_utils.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/datacube_ows/band_utils.py b/datacube_ows/band_utils.py index eb4546c35..60d41a436 100644 --- a/datacube_ows/band_utils.py +++ b/datacube_ows/band_utils.py @@ -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) + diff --git a/tests/test_band_utils.py b/tests/test_band_utils.py index fe2f8a5f7..bc427e38e 100644 --- a/tests/test_band_utils.py +++ b/tests/test_band_utils.py @@ -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 @@ -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 From e3caf8caad208f542df71e2b31927cd2917cdd8e Mon Sep 17 00:00:00 2001 From: phaesler Date: Fri, 23 Oct 2020 14:28:57 +1100 Subject: [PATCH 2/2] Oops - missing file from last PR. --- datacube_ows/cfg_parser.py | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 datacube_ows/cfg_parser.py diff --git a/datacube_ows/cfg_parser.py b/datacube_ows/cfg_parser.py new file mode 100755 index 000000000..9c8687a13 --- /dev/null +++ b/datacube_ows/cfg_parser.py @@ -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))