Skip to content

Commit

Permalink
Misc cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacemanPaul committed Nov 7, 2024
1 parent a365058 commit ddd420e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
6 changes: 4 additions & 2 deletions datacube_ows/feature_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ def _make_band_dict(prod_cfg: OWSNamedLayer, pixel_dataset: xarray.Dataset) -> d


@log_call
def _make_derived_band_dict(pixel_dataset: xarray.Dataset, style_index: dict[str, StyleDef]) -> dict[str, int | float]:
def _make_derived_band_dict(
pixel_dataset: xarray.Dataset, style_index: dict[str, StyleDef]
) -> dict[str, str | int | float]:
"""Creates a dict of values for bands derived by styles.
This only works for styles with an `index_function` defined.
:param xarray.Dataset pixel_dataset: A 1x1 pixel dataset containing band arrays
:param dict(str, StyleCfg) style_index: dict of style configuration dicts
:return: dict of style names to derived value
"""
derived_band_dict = {}
derived_band_dict: dict[str, int | float | str] = {}
for style_name, style in style_index.items():
if not style.include_in_feature_info:
continue
Expand Down
9 changes: 4 additions & 5 deletions datacube_ows/index/postgis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import click
import datetime
import logging

from threading import Lock
from typing import Any, Iterable, Type
Expand All @@ -23,8 +22,6 @@
from .product_ranges import create_range_entry as create_range_entry_impl, get_ranges as get_ranges_impl
from ...utils import default_to_utc

_LOG: logging.Logger = logging.getLogger(__name__)


class OWSPostgisIndex(OWSAbstractIndex):
name: str = "postgis"
Expand Down Expand Up @@ -65,11 +62,13 @@ def _query(self,
) -> dict[str, Any]:
query: dict[str, Any] = {}
if geom:
if geom.crs in layer.dc.index.spatial_indexes():
if geom.crs and geom.crs in layer.dc.index.spatial_indexes():
query["geopolygon"] = geom
else:
# Default to 4326 and take a long hard look at yourself.
geopoly = self._prep_geom(layer, geom).to_crs("epsg:4326")
prepared_geom = self._prep_geom(layer, geom)
assert prepared_geom is not None
geopoly = prepared_geom.to_crs("epsg:4326")
geopoly = Geometry(fix_shape(geopoly.geom), crs="epsg:4326")
query["geopolygon"] = geopoly
if products is not None:
Expand Down
5 changes: 0 additions & 5 deletions datacube_ows/index/postgis/product_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ def create_range_entry(layer: OWSNamedLayer, cache: dict[LayerSignature, list[st
# Get extent polygon from materialised views

base_crs = CRS(layer.native_CRS)
# if base_crs not in layer.dc.index.spatial_indexes():
# click.echo(f"Native CRS for layer {layer.name} ({layer.native_CRS}) does not have a spatial index. "
# "Using epsg:4326 for extent calculations.")
# base_crs = CRS("EPSG:4326")

base_extent = None
for product in layer.products:
prod_extent = layer.dc.index.products.spatial_extent(product, base_crs)
Expand Down
4 changes: 0 additions & 4 deletions datacube_ows/wms_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Copyright (c) 2017-2024 OWS Contributors
# SPDX-License-Identifier: Apache-2.0

import logging
import math
from datetime import datetime, date

Expand All @@ -27,7 +26,6 @@
from datacube_ows.styles.expression import ExpressionException
from datacube_ows.utils import default_to_utc, find_matching_date

_LOG = logging.getLogger(__name__)

RESAMPLING_METHODS = {
'nearest': Resampling.nearest,
Expand Down Expand Up @@ -317,12 +315,10 @@ def __init__(self, args):
self.geometry = _get_polygon(args, self.crs)
# BBox, height and width parameters
self.geobox = _get_geobox(args, self.crs)
_LOG.warning("geobox bbox = %s", repr(self.geobox.boundingbox))
# Web-merc antimeridian hack:
if self.geobox.crs != self.crs:
self.crs = self.geobox.crs
self.geometry = self.geometry.to_crs(self.crs)
_LOG.warning("geometry = %s", repr(self.geometry))

# Time parameter
self.times = get_times(args, self.layer)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_wms_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_get_geobox():
"height": "256",
"bbox": "-43.28507087113431,146.18504300790977,-43.07072582535469,146.64289867785524",
},
src_crs=CRS("EPSG:4326")
crs=CRS("EPSG:4326")
)
assert gbox.affine
assert str(gbox.crs) == "EPSG:4326"
Expand All @@ -274,7 +274,7 @@ def test_get_geobox():
"height": "256",
"bbox": "-43.28507087113431,146.18504300790977,-43.28507087113431,146.64289867785524",
},
src_crs = CRS("EPSG:4326")
crs = CRS("EPSG:4326")
)
assert "Bounding box must enclose a non-zero area" in str(e.value)
OWSConfig._instance = None
Expand Down

0 comments on commit ddd420e

Please sign in to comment.