Skip to content

Commit

Permalink
iterate on G-AIRMET processing #628
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Jul 1, 2022
1 parent 651ce25 commit baaa805
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ All notable changes to this library are documented in this file.

### New Features

- Enhance G-AIRMET processing to better define icing and not create airmet
entries for multiple-level freezing airmets (#628).

### Bug Fixes

- Correct decoding of 12 UTC timestamp in MND header.
Expand Down
2 changes: 2 additions & 0 deletions src/pyiem/models/gairmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class FreezingLevelRecord(BaseModel):
valid_at: datetime
geom: MultiLineString
level: int
lower_level: int
upper_level: int

class Config:
"""Pydantic config."""
Expand Down
30 changes: 24 additions & 6 deletions src/pyiem/nws/products/gairmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Break-up the XML G-AIRMET into atomic pieces.
"""
from datetime import timezone, datetime
import xml.etree.cElementTree as ET
import xml.etree.ElementTree as ET
from xml.dom import minidom

from shapely.geometry import Polygon, MultiLineString, LineString
Expand Down Expand Up @@ -53,9 +53,10 @@ def process_airmet(prod, airmet):
elem = airmet.find("hazardType", NS)
hazardtype = elem.attrib["{http://www.w3.org/1999/xlink}title"]
xy = [(float(x), float(y)) for x, y in zip(pts[1::2], pts[::2])]
if gml_id.startswith("FZLVL"):
if gml_id.startswith("FZLVL") or gml_id.startswith("M_FZLVL"):
ls = LineString(xy)
ul = int(airmet.find(".//aixm:upperLimit", NS).text)
ll = int(airmet.find(".//aixm:lowerLimit", NS).text)
# Need to search for previous records to see if we have
# a dupe
found = False
Expand All @@ -68,7 +69,9 @@ def process_airmet(prod, airmet):
prod.data.freezing_levels.append(
FreezingLevelRecord(
gml_id=gml_id,
level=ul,
level=None if ul != ll else ll,
lower_level=ll,
upper_level=ul,
valid_at=valid_at,
geom=MultiLineString([ls]),
)
Expand All @@ -94,6 +97,7 @@ def process_airmet(prod, airmet):
if elem is not None and elem.text == "true":
phenomena.append("Low Level Wind Shear")

# Turbulence
elem = airmet.find(".//turbulence", NS)
if elem is not None:
vol = elem.find(".//aixm:AirspaceVolume", NS)
Expand All @@ -105,6 +109,18 @@ def process_airmet(prod, airmet):
tt = tr.attrib["{http://www.w3.org/1999/xlink}title"]
phenomena.append(f"Turbulence {tt} from {ll} to {ul}")

# Icing
elem = airmet.find(".//icing", NS)
if elem is not None:
vol = elem.find(".//aixm:AirspaceVolume", NS)
if vol is not None:
ul = vol.find(".//aixm:upperLimit", NS).text
ll = vol.find(".//aixm:lowerLimit", NS).text
tr = elem.find(".//icingRangeStart", NS)
if tr is not None:
tt = tr.attrib["{http://www.w3.org/1999/xlink}title"]
phenomena.append(f"Icing {tt} from {ll} to {ul}")

prod.data.airmets.append(
AIRMETRecord(
gml_id=gml_id,
Expand Down Expand Up @@ -166,15 +182,17 @@ def sql(self, cursor):
for fzlvl in self.data.freezing_levels:
cursor.execute(
"""
INSERT into airmet_freezing_levels (
gml_id, product_id, valid_at, level, geom)
VALUES (%s, %s, %s, %s, ST_GeomFromText(%s, 4326))
INSERT into airmet_freezing_levels (gml_id, product_id,
valid_at, level, lower_level, upper_level, geom)
VALUES (%s, %s, %s, %s, %s, %s, ST_GeomFromText(%s, 4326))
""",
(
fzlvl.gml_id,
self.get_product_id(),
fzlvl.valid_at,
fzlvl.level,
fzlvl.lower_level,
fzlvl.upper_level,
fzlvl.geom.wkt,
),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/nws/products/test_gairmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_ice(dbcursor):
utcnow = utc(2022, 3, 17, 17, 0)
prod = parser(get_test_file("GAIRMET/LWIE00.txt"), utcnow=utcnow)
prod.sql(dbcursor)
assert len(prod.data.airmets) == 25
assert len(prod.data.airmets) == 20
assert len(prod.data.freezing_levels) == 25


Expand Down

0 comments on commit baaa805

Please sign in to comment.