Skip to content

Commit

Permalink
refactor ERO into new SPC outlook logic #738
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Jul 11, 2023
1 parent 14e1af7 commit 76a4fd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/pyiem/nws/products/_outlook_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def compute_layers(prod):
"""Compute the differenced geomtries."""
# 1. Do polygons overlap for the same outlook
LOG.warning("==== Running Geometry differences")
for collect in prod.outlook_collections:
collect.difference_geometries()
for day in prod.outlook_collections:
prod.outlook_collections[day].difference_geometries()


def quality_control(prod):
Expand Down
36 changes: 6 additions & 30 deletions src/pyiem/nws/products/ero.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from shapely.geometry import MultiPolygon

from pyiem.nws.product import TextProduct
from pyiem.nws.products.spcpts import SPCOutlook as Outlook
from pyiem.nws.products.spcpts import SPCOutlookCollection as OutlookCollection

# Local
from pyiem.reference import txt2drct
Expand All @@ -20,6 +22,7 @@
from ._outlook_util import (
CONUS,
THRESHOLD2TEXT,
compute_layers,
condition_segment,
convert_segments,
load_conus_data,
Expand Down Expand Up @@ -120,34 +123,6 @@ def meat2segment(meat):
return pts


class OutlookCollection:
"""A collection of outlooks for a single 'day'"""

def __init__(self, issue, expire, day):
"""Constructor"""
self.issue = issue
self.expire = expire
self.day = day
self.outlooks = []


class Outlook:
"""A class holding what we store for a single outlook."""

def __init__(self, category, threshold, multipoly):
"""Constructor.
Args:
category (str): the label of this category
threshold (str): the threshold associated with the category
multipoly (MultiPolygon): the geometry
"""
self.category = category
self.threshold = threshold
self.geometry = multipoly
self.wfos = []


def jabber_messages(valid, outlook_collections) -> list:
"""Generate a list of Jabber messages to send.
Expand Down Expand Up @@ -262,7 +237,7 @@ def compute_wfos(outlook_collections):
geodf = load_geodf("cwa")
for day, collect in outlook_collections.items():
for outlook in collect.outlooks:
df2 = geodf[geodf["geom"].intersects(outlook.geometry)]
df2 = geodf[geodf["geom"].intersects(outlook.geometry_layers)]
outlook.wfos = df2.index.to_list()
LOG.info(
"Day: %s Category: %s Threshold: %s #WFOS: %s %s",
Expand Down Expand Up @@ -298,6 +273,7 @@ def __init__(
self.day, self.outlook_collections = init_days(self)
self.find_outlooks()
quality_control(self)
compute_layers(self)
compute_wfos(self.outlook_collections)
self.cycle = _compute_cycle(self)

Expand Down Expand Up @@ -330,7 +306,7 @@ def draw_outlooks(self):
color="b",
label="Conus",
)
for poly in outlook.geometry.geoms:
for poly in outlook.geometry_layers.geoms:
ax.plot(
poly.exterior.xy[0],
poly.exterior.xy[1],
Expand Down
8 changes: 4 additions & 4 deletions tests/nws/products/test_ero.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_211024_calif():
"""Test that we get the right geometries."""
prod = parser(get_test_file("ERO/RBG94E_calif.txt"))
outlook = prod.get_outlook("CATEGORICAL", "MDT", 1)
assert abs(outlook.geometry.area - 10.62) < 0.01
assert abs(outlook.geometry_layers.area - 10.62) < 0.01


@pytest.mark.parametrize("database", ["postgis"])
Expand All @@ -31,14 +31,14 @@ def test_210716_4f4():
"""Test our updated station table."""
prod = parser(get_test_file("ERO/RBG94E_4F4.txt"))
outlook = prod.get_outlook("CATEGORICAL", "MRGL", 1)
assert abs(outlook.geometry.area - 127.07999) < 0.01
assert abs(outlook.geometry_layers.area - 127.07999) < 0.01


def test_210714_duplicate():
"""Test that we do not have duplicate sfstns entries causing grief."""
prod = parser(get_test_file("ERO/RBG98E_dup.txt"))
outlook = prod.get_outlook("CATEGORICAL", "MRGL", 2)
assert abs(outlook.geometry.area - 96.5306) < 0.01
assert abs(outlook.geometry_layers.area - 96.5306) < 0.01


def test_get_jabbers():
Expand Down Expand Up @@ -102,4 +102,4 @@ def test_basic(dbcursor):
prod.get_jabbers("")
# prod.draw_outlooks()
outlook = prod.get_outlook("CATEGORICAL", "MRGL", 1)
assert abs(outlook.geometry.area - 188.754) < 0.01
assert abs(outlook.geometry_layers.area - 188.754) < 0.01

0 comments on commit 76a4fd5

Please sign in to comment.