Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FlagBands aware of band aliases on the main product(s). #887

Merged
merged 8 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion datacube_ows/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ def __init__(self, cfg: CFG_DICT, product_cfg: "datacube_ows.ows_configuration.O
pq_names = self.product.parse_pq_names(cfg)
self.pq_names = pq_names["pq_names"]
self.pq_low_res_names = pq_names["pq_low_res_names"]
self.pq_band = cfg["band"]
self.main_products = pq_names["main_products"]
self.pq_band = cfg["band"] # N.B. May be an alias if on main_products
if "fuse_func" in cfg:
self.pq_fuse_func: Optional[FunctionWrapper] = FunctionWrapper(self.product, cast(Mapping[str, Any], cfg["fuse_func"]))
else:
Expand Down Expand Up @@ -685,6 +686,12 @@ def make_ready(self, dc: "datacube.Datacube", *args, **kwargs) -> None:
raise ConfigException(f"Could not find flags low_res product {pqn} for layer {self.product.name} in datacube")
self.pq_low_res_products.append(pq_product)

# Resolve band alias if necessary.
if self.main_products:
canonical_band = self.product.band_idx.band(self.pq_band)
if canonical_band and canonical_band != self.pq_band:
self.pq_band = canonical_band

# pyre-ignore[16]
self.info_mask: int = ~0
# A (hopefully) representative product
Expand Down
12 changes: 11 additions & 1 deletion datacube_ows/ows_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,24 +921,30 @@ def parse_product_names(self, cfg):
raise ConfigException(f"'low_res_product_names' entry in non-multi-product layer {self.name} - use 'low_res_product_name' only")

def parse_pq_names(self, cfg):
main_product = False
if "dataset" in cfg:
raise ConfigException(f"The 'dataset' entry in the flags section is no longer supported. Please refer to the documentation for the correct format (layer {self.name})")
if "product" in cfg:
pq_names = (cfg["product"],)
else:
pq_names = (self.product_name,)
main_product = (pq_names[0] == self.product_name)

if "low_res_product" in cfg:
pq_low_res_names = (cfg.get("low_res_product"),)
else:
elif main_product:
pq_low_res_names = self.low_res_product_names
else:
pq_low_res_names = pq_names

if "products" in cfg:
raise ConfigException(f"'products' entry in flags section of non-multi-product layer {self.name} - use 'product' only")
if "low_res_products" in cfg:
raise ConfigException(f"'low_res_products' entry in flags section of non-multi-product layer {self.name}- use 'low_res_product' only")
return {
"pq_names": pq_names,
"pq_low_res_names": pq_low_res_names,
"main_products": main_product
}


Expand All @@ -959,11 +965,14 @@ def parse_product_names(self, cfg):
raise ConfigException(f"'low_res_product_name' entry in multi-product layer {self.name} - use 'low_res_product_names' only")

def parse_pq_names(self, cfg):
main_products = False
if "datasets" in cfg:
raise ConfigException(f"The 'datasets' entry in the flags section is no longer supported. Please refer to the documentation for the correct format (layer {self.name})")
if "products" in cfg:
pq_names = tuple(cfg["products"])
main_products = pq_names == self.product_names
else:
main_products = True
pq_names = self.product_names

if "low_res_products" in cfg:
Expand All @@ -977,6 +986,7 @@ def parse_pq_names(self, cfg):
return {
"pq_names": pq_names,
"pq_low_res_names": pq_low_res_names,
"main_products": main_products,
}

def dataset_groupby(self):
Expand Down