Skip to content

Commit

Permalink
Tweak WMS query parameters and timeouts (#312)
Browse files Browse the repository at this point in the history
* Generate WMS legend values dynamically and expose API path for it

* Not providing static WMS legend information anymore

We now have the dynamic legend endpoint, which should be used instead

* Reverted previous implementation of dynamic WMS legend generation

This is not needed, as the underlying THREDDS WMS server does not perform dynamic contrast enhancement

* Set a default timeout of 30s to http client
  • Loading branch information
ricardogsilva authored Dec 5, 2024
1 parent 0e18040 commit 4f3a5a2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion arpav_ppcv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class ThreddsServerSettings(pydantic.BaseModel):
base_url: str = "http://localhost:8080/thredds"
wms_service_url_fragment: str = "wms"
netcdf_subset_service_url_fragment: str = "ncss/grid" # noqa
netcdf_subset_service_timeout_seconds: int = 30 # noqa
opendap_service_url_fragment: str = "dodsC" # noqa
uncertainty_visualization_scale_range: tuple[float, float] = pydantic.Field(
default=(0, 9)
Expand Down Expand Up @@ -132,6 +131,7 @@ class ArpavPpcvSettings(BaseSettings): # noqa
coverage_download_settings: CoverageDownloadSettings = CoverageDownloadSettings()
variable_stations_db_schema: str = "stations"
num_uvicorn_worker_processes: int = 1
http_client_timeout_seconds: float = 30.0

@pydantic.model_validator(mode="after")
def ensure_test_db_dsn(self):
Expand Down
4 changes: 4 additions & 0 deletions arpav_ppcv/thredds/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def tweak_wms_get_map_request(
num_color_bands = "2"
query_params["NUMCOLORBANDS"] = num_color_bands
else:
num_color_bands = "250"
if "uncertainty_group" in layer_name:
palette = ncwms_palette
else:
Expand All @@ -75,4 +76,7 @@ def tweak_wms_get_map_request(

query_params["styles"] = palette
query_params["colorscalerange"] = color_scale_range
query_params["NUMCOLORBANDS"] = num_color_bands
query_params["ABOVEMAXCOLOR"] = "extend"
query_params["BELOWMINCOLOR"] = "extend"
return query_params
3 changes: 0 additions & 3 deletions arpav_ppcv/webapp/api_v2/routers/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,6 @@ async def get_forecast_data(
fitted_bbox = None

cache_key = datadownloads.get_cache_key(coverage, fitted_bbox, temporal_range)
http_client.timeout = (
settings.thredds_server.netcdf_subset_service_timeout_seconds
)
response_to_stream = await datadownloads.retrieve_coverage_data(
settings, http_client, cache_key, coverage, fitted_bbox, temporal_range
)
Expand Down
12 changes: 8 additions & 4 deletions arpav_ppcv/webapp/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ def get_db_session(engine=Depends(get_db_engine)): # noqa: B008
yield session


def get_http_client() -> httpx.AsyncClient:
return httpx.AsyncClient()
def get_http_client(
settings: config.ArpavPpcvSettings = Depends(get_settings),
) -> httpx.AsyncClient:
return httpx.AsyncClient(timeout=settings.http_client_timeout_seconds)


def get_sync_http_client() -> httpx.Client:
return httpx.Client()
def get_sync_http_client(
settings: config.ArpavPpcvSettings = Depends(get_settings),
) -> httpx.Client:
return httpx.Client(timeout=settings.http_client_timeout_seconds)


class CommonListFilterParameters(pydantic.BaseModel): # noqa: D101
Expand Down

0 comments on commit 4f3a5a2

Please sign in to comment.