Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnibus #965

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.8"
rev: "v0.6.9"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this library are documented in this file.

- Discontinue raw SPS product text within the database.
- Ensure raw text products into `WMOProduct` end with a line feed.
- Stop postprocessing the `MapPlot` figure into 8bit colorspace.

### New Features

Expand All @@ -21,6 +22,7 @@ generating plots of HRRR ptype.

- Accomodate ancient LSRs using `TRACE` as the magnitude field.
- Ensure geometries going into masking helper are CCW, to mask outside of.
- Properly check USDM service response prior to parsing it.

## **1.21.0** (6 Sep 2024)

Expand Down
35 changes: 12 additions & 23 deletions src/pyiem/plot/geoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ def draw_usdm(self, valid=None, filled=True, hatched=False, **kwargs):
valid = valid.strftime("%Y-%m-%d")
url = f"http://mesonet.agron.iastate.edu/geojson/usdm.py?date={valid}"
try:
req = requests.get(url, timeout=30)
df = gpd.GeoDataFrame().from_features(req.json())
resp = requests.get(url, timeout=30)
resp.raise_for_status()
df = gpd.GeoDataFrame().from_features(resp.json())
except Exception as exp:
warnings.warn(
f"draw_usdm IEM USDM Webservice failed: {exp}", stacklevel=1
Expand Down Expand Up @@ -1357,31 +1358,19 @@ def postprocess(self, **kwargs):
"""
with BytesIO() as ram:
self.fig.savefig(ram, format="png")
ram.seek(0)
im = Image.open(ram)
im2 = im.convert("RGB").convert(
"P", palette=Image.Palette.ADAPTIVE
imgdata = ram.getvalue()
if kwargs.get("memcache") and kwargs.get("memcachekey"):
kwargs["memcache"].set(
kwargs["memcachekey"],
imgdata,
time=kwargs.get("memcacheexpire", 300),
)
im.close()
if kwargs.get("memcache") and kwargs.get("memcachekey"):
ram = BytesIO()
im2.save(ram, format="png")
ram.seek(0)
r = ram.read()
kwargs["memcache"].set(
kwargs["memcachekey"],
r,
time=kwargs.get("memcacheexpire", 300),
)
if kwargs.get("web", False):
ssw("Content-Type: image/png\n\n")
im2.save(getattr(sys.stdout, "buffer", sys.stdout), format="png")
im2.close()
sys.stdout.buffer.write(imgdata)
return
tmpfd = tempfile.NamedTemporaryFile(delete=False)
im2.save(tmpfd, format="PNG")
im2.close()
tmpfd.close()
with tempfile.NamedTemporaryFile(delete=False) as tmpfd:
tmpfd.write(imgdata)
if kwargs.get("pqstr") is not None:
subprocess.call(["pqinsert", "-p", kwargs["pqstr"], tmpfd.name])
if kwargs.get("filename") is not None:
Expand Down
3 changes: 2 additions & 1 deletion tests/plot/test_geoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
def test_exercise_usdm():
"""Test the various checks in the usdm method."""
mp = MapPlot()
mp.draw_usdm()
with pytest.warns(UserWarning) as _:
mp.draw_usdm()
mp.draw_usdm(utc())
with pytest.warns(UserWarning) as _:
assert mp.draw_usdm("qqq") is None
Expand Down
Loading