Skip to content

Commit

Permalink
[vtec] add check for UGC uniqueness
Browse files Browse the repository at this point in the history
closes #540
  • Loading branch information
akrherz committed Feb 25, 2022
1 parent 6e090c0 commit d2019b1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

All notable changes to this library are documented in this file.

## Unreleased Version

### API Changes

### New Features

- Added VTEC product check for uniqueness of UGCs (#540).

### Bug Fixes

## **1.11.0** (25 Feb 2022)

### API Changes
Expand Down
29 changes: 29 additions & 0 deletions src/pyiem/nws/products/_vtec_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ def which_year(txn, prod, segment, vtec):
return prod.valid.year


def _check_unique_ugc(prod) -> bool:
"""Quality Control check that a given product uniquely uses UGCS.
Discussions with AWIPS developer expressed interesting in knowing that
this was being enforced. It adds a warning message and returns a bool
on if this was a problem.
Args:
prod: Product object to check.
Returns:
True if UGCS are unique, False if not.
"""
domain = []
for seg in prod.segments:
# HVTEC products are an exception to this rule.
if seg.hvtec:
continue
domain.extend([str(u) for u in seg.ugcs])
ugcs = pd.Series(domain, dtype=str)
if ugcs.duplicated().any():
vals = ugcs[ugcs.duplicated()].values
prod.warnings.append(
f"Duplicated UGCs Found (10.1701 3.9.1): {','.join(vals)}"
)
return False
return True


def _associate_vtec_year(prod, txn):
"""Figure out to which year each VTEC in the product belongs.
Expand Down
3 changes: 3 additions & 0 deletions src/pyiem/nws/products/vtec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyiem.reference import TWEET_CHARS
from pyiem.nws.products._vtec_util import (
_associate_vtec_year,
_check_unique_ugc,
_resent_match,
_do_sql_vtec_new,
_do_sql_vtec_cor,
Expand Down Expand Up @@ -49,6 +50,8 @@ def __init__(
and self.unixtext.find("$$") == -1
):
raise ValueError("Aborting processing of TSU without $$")
# Arb checks
_check_unique_ugc(self)

def sql(self, txn):
"""Persist to the database
Expand Down

0 comments on commit d2019b1

Please sign in to comment.