Skip to content

Commit

Permalink
Deprecate old path to rolling_windows_ndays function - redirect to ti…
Browse files Browse the repository at this point in the history
…me_utils
  • Loading branch information
SpacemanPaul committed Apr 24, 2024
1 parent 2b585f1 commit 2421fef
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
18 changes: 12 additions & 6 deletions datacube_ows/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
# Copyright (c) 2017-2024 OWS Contributors
# SPDX-License-Identifier: Apache-2.0
import json
from typing import Optional
from urllib.parse import urlparse

from flask import Request, request, render_template

from datacube_ows.config_utils import CFG_DICT
from datacube_ows.ows_configuration import OWSConfig, get_config

TYPE_CHECKING = False
if TYPE_CHECKING:
from datacube_ows.ows_configuration import OWSConfig

FlaskResponse = tuple[str | bytes, int, dict[str, str]]



def resp_headers(d: dict[str, str]) -> dict[str, str]:
"""
Take a dictionary of http response headers and all required response headers from the configuration.
Expand Down Expand Up @@ -100,22 +103,25 @@ def lower_get_args() -> dict[str, str]:
return d


def json_response(result: CFG_DICT, cfg: OWSConfig | None = None) -> FlaskResponse:
def json_response(result: CFG_DICT, cfg: Optional["OWSConfig"] = None) -> FlaskResponse:
from datacube_ows.ows_configuration import get_config
if not cfg:
cfg = get_config()
assert cfg is not None # for type checker
return json.dumps(result), 200, cfg.response_headers({"Content-Type": "application/json"})


def html_json_response(result: CFG_DICT, cfg: OWSConfig | None = None) -> FlaskResponse:
def html_json_response(result: CFG_DICT, cfg: Optional["OWSConfig"] = None) -> FlaskResponse:
from datacube_ows.ows_configuration import get_config
if not cfg:
cfg = get_config()
assert cfg is not None # for type checker
html_content = render_template("html_feature_info.html", result=result)
return html_content, 200, cfg.response_headers({"Content-Type": "text/html"})


def png_response(body: bytes, cfg: OWSConfig | None = None, extra_headers: dict[str, str] | None = None) -> FlaskResponse:
def png_response(body: bytes, cfg: Optional["OWSConfig"] = None, extra_headers: dict[str, str] | None = None) -> FlaskResponse:
from datacube_ows.ows_configuration import get_config
if not cfg:
cfg = get_config()
assert cfg is not None # For type checker
Expand Down
23 changes: 21 additions & 2 deletions datacube_ows/ogc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,38 @@
# Copyright (c) 2017-2023 OWS Contributors
# SPDX-License-Identifier: Apache-2.0
import logging
import datetime
from io import BytesIO
from typing import Any, cast

from deprecat import deprecat
import numpy
import xarray
from affine import Affine
from odc.geo.geobox import GeoBox
from odc.geo.geom import CRS
from PIL import Image
TYPE_CHECKING = False
if TYPE_CHECKING:
from datacube_ows.config_utils import OWSExtensibleConfigEntry


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

# Extent Mask Functions

@deprecat(
reason="The 'rolling_windows_ndays' mosaicing function has moved to 'datacube.time_utils' - "
"please import it from there.",
version="1.9.0"
)
def rolling_window_ndays(
available_dates: list[datetime.datetime],
layer_cfg: "OWSExtensibleConfigEntry",
ndays: int = 6) -> tuple[datetime.datetime, datetime.datetime]:
from datacube_ows.time_utils import rolling_window_ndays
return rolling_window_ndays(available_dates=available_dates,
layer_cfg=layer_cfg,
ndays=ndays)


def mask_by_val(data: xarray.Dataset, band: str, val: Any = None) -> xarray.DataArray:
"""
Expand Down
2 changes: 1 addition & 1 deletion datacube_ows/time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def tz_for_geometry(geom: Geometry) -> datetime.tzinfo:


def rolling_window_ndays(
available_dates: Sequence[datetime.datetime],
available_dates: list[datetime.datetime],
layer_cfg: OWSExtensibleConfigEntry,
ndays: int = 6) -> tuple[datetime.datetime, datetime.datetime]:
idx = -ndays
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/cfg/ows_test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@
Latest imagery mosaic with no time dimension.
""",
"mosaic_date_func": {
"function": "datacube_ows.ogc_utils.rolling_window_ndays",
"function": "datacube_ows.time_utils.rolling_window_ndays",
"pass_layer_cfg": True,
"kwargs": {
"ndays": 6,
Expand Down

0 comments on commit 2421fef

Please sign in to comment.