Skip to content

Commit

Permalink
Merge branch 'master' into 930-comparison-charts
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher authored Oct 24, 2023
2 parents 526eb1a + 9bc7b5f commit 7cd62d5
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 59 deletions.
4 changes: 1 addition & 3 deletions api/app/database/user_info_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""Alert database model."""
"""UserInfo database model."""
import datetime
import json
import logging

from sqlalchemy import JSON, TIMESTAMP, Column, DateTime, Identity, Integer, String
from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base
from sqlalchemy.sql.sqltypes import Boolean

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

Base = declarative_base()
Expand Down
6 changes: 5 additions & 1 deletion api/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
from .geotiff_from_stac_api import get_geotiff
from .models import AlertsModel, StatsModel, UserInfoPydanticModel

logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s",
level=logging.DEBUG,
datefmt="%Y-%m-%d %H:%M:%S",
)
logger = logging.getLogger(__name__)

# silence boto3 logging to avoid spamming the logs
Expand Down
26 changes: 26 additions & 0 deletions api/app/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import requests
from fastapi import HTTPException

Expand All @@ -12,3 +14,27 @@ def forward_http_error(resp: requests.Response, excluded_codes: list[int]) -> No
obj = resp.json()
detail = obj.get("detail", "Unknown error")
raise HTTPException(status_code=resp.status_code, detail=detail)


class WarningsFilter(logging.Filter):
"""Custom logging filter for warnings."""

def __init__(self):
super().__init__()
self.max_warnings = 1
self.warning_count = 0

def filter(self, record):
if (
self.warning_count >= self.max_warnings
and record.levelno == logging.WARNING
and "converting a masked element to nan" in record.getMessage()
):
return True
if (
record.levelno == logging.WARNING
and "converting a masked element to nan" in record.getMessage()
):
self.warning_count += 1

return False
5 changes: 5 additions & 0 deletions api/app/zonal_stats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Calulate zonal statistics and return a json or a geojson."""
import logging
import warnings
from collections import defaultdict
from datetime import datetime
from json import dump, load
Expand All @@ -20,6 +21,7 @@
)
from app.raster_utils import calculate_pixel_area, gdal_calc, reproj_match
from app.timer import timed
from app.utils import WarningsFilter
from app.validation import VALID_OPERATORS
from fastapi import HTTPException
from rasterio.warp import Resampling
Expand All @@ -29,6 +31,9 @@

logger = logging.getLogger(__name__)

# Add custom filter to silence 'converting a masked element to nan' warnings
logger.addFilter(WarningsFilter())


DEFAULT_STATS = ["min", "max", "mean", "median", "sum", "std", "nodata", "count"]

Expand Down
28 changes: 2 additions & 26 deletions frontend/src/config/srilanka/prism.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"country": "Sri Lanka",
"countryAdmin0Id": 231,
"alertFormActive": false,
"defaultLayer": "rainfall_dekad",
"defaultLayer": "precip_blended_dekad",
"icons": {
"rainfall": "icon_rain.png",
"vegetation": "icon_veg.png",
Expand All @@ -13,8 +13,7 @@
},
"serversUrls": {
"wms": [
"https://api.earthobservation.vam.wfp.org/ows/wms",
"https://sparc.wfp.org/geoserver/prism/wms"
"https://api.earthobservation.vam.wfp.org/ows/wms"
]
},
"map": {
Expand Down Expand Up @@ -231,29 +230,6 @@
}
]
},
"tropical_storms": {
"tropical_storms": [
{
"group_title": "Tropical Storms",
"activate_all": true,
"layers": [
{
"id": "adamts_buffers",
"label": "Wind buffers",
"main": true
},
{
"id": "adamts_nodes",
"label": "Nodes"
},
{
"id": "adamts_tracks",
"label": "Tracks"
}
]
}
]
},
"vegetation": {
"vegetation_conditions": [
"ndvi_dekad",
Expand Down
Loading

0 comments on commit 7cd62d5

Please sign in to comment.