Skip to content

Commit

Permalink
Merge pull request #1015 from opendatacube/odc-env-cfg
Browse files Browse the repository at this point in the history
ODC environment configuration
  • Loading branch information
omad authored May 8, 2024
2 parents a846880 + 722bc6e commit c8214a7
Show file tree
Hide file tree
Showing 25 changed files with 821 additions and 932 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
push:
branches:
- 'master'
- 'develop-1.9'
paths:
- '**'
- '.github/workflows/lint.yml'
Expand Down Expand Up @@ -51,7 +52,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ["3.10"]
python-version: "3.10"
- run: python -m pip install flake8
- name: flake8 cleanup imported but unused
uses: liskin/gh-problem-matcher-wrap@v3
Expand Down
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
Expand Down
38 changes: 22 additions & 16 deletions datacube_ows/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import fsspec
from babel.messages import Catalog, Message
from datacube import Datacube
from datacube.model import Product
from datacube.utils.masking import make_mask
from flask_babel import gettext as _
Expand Down Expand Up @@ -157,6 +156,13 @@ class OWSConfigNotReady(ConfigException):
"""


class ODCInitException(ConfigException):
"""
Exception raised when a Datacube index could not be created
"""



class OWSConfigEntry:
"""
Base class for all configuration objects
Expand Down Expand Up @@ -228,7 +234,7 @@ def __setattr__(self, name: str, val: Any) -> None:
super().__setattr__(name, val)

# Validate against database and prepare for use.
def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
def make_ready(self, *args, **kwargs) -> None:
"""
Perform second phase initialisation with a database connection.
Expand Down Expand Up @@ -660,15 +666,15 @@ def __init__(self, cfg: CFG_DICT, product_cfg: "datacube_ows.ows_configuration.O
"""
super().__init__(cfg, **kwargs)
cfg = cast(CFG_DICT, self._raw_cfg)
self.product = product_cfg
pq_names = self.product.parse_pq_names(cfg)
self.layer = product_cfg
pq_names = self.layer.parse_pq_names(cfg)
self.pq_names = cast(list[str], pq_names["pq_names"])
self.pq_low_res_names = pq_names["pq_low_res_names"]
self.main_products = pq_names["main_products"]
self.pq_band = str(cfg["band"])
self.canonical_band_name = self.pq_band # Update for aliasing on make_ready
if "fuse_func" in cfg:
self.pq_fuse_func: Optional[FunctionWrapper] = FunctionWrapper(self.product, cast(CFG_DICT, cfg["fuse_func"]))
self.pq_fuse_func: Optional[FunctionWrapper] = FunctionWrapper(self.layer, cast(CFG_DICT, cfg["fuse_func"]))
else:
self.pq_fuse_func = None
self.pq_ignore_time = bool(cfg.get("ignore_time", False))
Expand All @@ -679,7 +685,7 @@ def __init__(self, cfg: CFG_DICT, product_cfg: "datacube_ows.ows_configuration.O
self.declare_unready("info_mask")

# pylint: disable=attribute-defined-outside-init
def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
def make_ready(self, *args: Any, **kwargs: Any) -> None:
"""
Second round (db-aware) intialisation.
Expand All @@ -691,21 +697,21 @@ def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
self.pq_low_res_products: list[Product] = []
for pqn in self.pq_names:
if pqn is not None:
pq_product = dc.index.products.get_by_name(pqn)
pq_product = self.layer.dc.index.products.get_by_name(pqn)
if pq_product is None:
raise ConfigException(f"Could not find flags product {pqn} for layer {self.product.name} in datacube")
raise ConfigException(f"Could not find flags product {pqn} for layer {self.layer.name} in datacube")
self.pq_products.append(pq_product)
for pqn in self.pq_low_res_names:
if pqn is not None:
pq_product = dc.index.products.get_by_name(pqn)
pq_product = self.layer.dc.index.products.get_by_name(pqn)
if pq_product is None:
raise ConfigException(f"Could not find flags low_res product {pqn} for layer {self.product.name} in datacube")
raise ConfigException(f"Could not find flags low_res product {pqn} for layer {self.layer.name} in datacube")
self.pq_low_res_products.append(pq_product)

# Resolve band alias if necessary.
if self.main_products:
try:
self.canonical_band_name = self.product.band_idx.band(self.pq_band)
self.canonical_band_name = self.layer.band_idx.band(self.pq_band)
except ConfigException:
pass

Expand All @@ -717,9 +723,9 @@ def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
meas = product.lookup_measurements([str(self.canonical_band_name)])[str(self.canonical_band_name)]
except KeyError:
raise ConfigException(
f"Band {self.pq_band} does not exist in product {product.name} - cannot be used as a flag band for layer {self.product.name}.")
f"Band {self.pq_band} does not exist in product {product.name} - cannot be used as a flag band for layer {self.layer.name}.")
if "flags_definition" not in meas:
raise ConfigException(f"Band {self.pq_band} in product {product.name} has no flags_definition in ODC - cannot be used as a flag band for layer {self.product.name}.")
raise ConfigException(f"Band {self.pq_band} in product {product.name} has no flags_definition in ODC - cannot be used as a flag band for layer {self.layer.name}.")
# pyre-ignore[16]
self.flags_def: dict[str, dict[str, RAW_CFG]] = meas["flags_definition"]
for bitname in self.ignore_info_flags:
Expand All @@ -728,7 +734,7 @@ def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
continue
flag = 1 << bit
self.info_mask &= ~flag
super().make_ready(dc, *args, **kwargs)
super().make_ready(*args, **kwargs)


FlagBand = OWSFlagBand | OWSFlagBandStandalone
Expand Down Expand Up @@ -789,7 +795,7 @@ def add_flag_band(self, fb: FlagBand) -> None:
self.declare_unready("low_res_products")

# pylint: disable=attribute-defined-outside-init
def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
def make_ready(self, *args, **kwargs) -> None:
"""
Second round (db-aware) intialisation.
Expand All @@ -804,7 +810,7 @@ def make_ready(self, dc: Datacube, *args, **kwargs) -> None:
break
if self.main_product:
self.bands = set(self.layer.band_idx.band(b) for b in self.bands)
super().make_ready(dc, *args, **kwargs)
super().make_ready(*args, **kwargs)

@classmethod
def build_list_from_masks(cls, masks: Iterable["datacube_ows.styles.base.StyleMask"],
Expand Down
109 changes: 0 additions & 109 deletions datacube_ows/cube_pool.py

This file was deleted.

Loading

0 comments on commit c8214a7

Please sign in to comment.