Skip to content

Commit

Permalink
Merge pull request #1029 from akrherz/241213-2
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Dec 16, 2024
2 parents b170aea + 2858718 commit 5ef3993
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
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/pre-commit/mirrors-eslint
rev: 'v9.16.0'
rev: 'v9.17.0'
hooks:
- id: eslint
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand Down
10 changes: 6 additions & 4 deletions pylib/iemweb/autoplot/scripts200/p207.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import pandas as pd
from geopandas import GeoDataFrame, read_postgis
from pyiem.database import get_sqlalchemy_conn
from pyiem.exceptions import NoDataFound
from pyiem.plot import MapPlot, nwssnow
from pyiem.reference import EPSG
from pyiem.util import get_autoplot_context, logger
Expand Down Expand Up @@ -256,7 +257,7 @@ def load_data(ctx, basets, endts):
df2[USEME] = True
df2["plotme"] = True
df2["source"] = "COOP"
return pd.concat([df, df2], ignore_index=True, sort=False)
return pd.concat((df, df2), ignore_index=True, sort=False)


def compute_grid_bounds(ctx, csector):
Expand Down Expand Up @@ -328,7 +329,7 @@ def add_zeros(df, ctx):
if newrows:
if not df.empty:
df = pd.concat(
[df, GeoDataFrame(newrows, geometry="geo", crs=EPSG[2163])],
(df, GeoDataFrame(newrows, geometry="geo", crs=EPSG[2163])),
ignore_index=True,
sort=False,
)
Expand All @@ -350,7 +351,7 @@ def add_zeros(df, ctx):
return df


def do_analysis(df, ctx):
def do_analysis(df: pd.DataFrame, ctx: dict):
"""Do the analysis finally."""
# cull dups to prevent gridding badness
df2 = (
Expand All @@ -359,13 +360,14 @@ def do_analysis(df, ctx):
.first()
.reset_index()
)
if df2.empty:
raise NoDataFound("No Data Found.")
sz = ctx["sz"] * 1000.0
# Introduce some jitter
xi = np.arange(ctx["bnds2163"][0], ctx["bnds2163"][2] + sz, sz / 1.9)
yi = np.arange(ctx["bnds2163"][1], ctx["bnds2163"][3] + sz, sz / 1.9)
xi, yi = np.meshgrid(xi, yi)
lons, lats = T2163_4326.transform(xi, yi)

gridder = Rbf(
df2["level_0"].values,
df2["level_1"].values,
Expand Down
15 changes: 8 additions & 7 deletions pylib/iemweb/autoplot/scripts200/p227.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from zoneinfo import ZoneInfo

# third party
import requests
import httpx
from geopandas import read_postgis
from pyiem.database import get_sqlalchemy_conn
from pyiem.exceptions import NoDataFound
from pyiem.network import Table as NetworkTable
from pyiem.plot.geoplot import MapPlot
from pyiem.reference import LATLON, Z_OVERLAY2, prodDefinitions
from pyiem.util import LOG, get_autoplot_context, get_sqlalchemy_conn
from pyiem.util import LOG, get_autoplot_context
from sqlalchemy import text

TFORMAT = "%b %-d %Y %-I:%M %p %Z"
Expand Down Expand Up @@ -40,15 +41,15 @@ def get_description():
return desc


def get_text(product_id):
def get_text(product_id: str) -> str:
"""get the raw text."""
res = "Text Unavailable, Sorry."
uri = f"https://mesonet.agron.iastate.edu/api/1/nwstext/{product_id}"
try:
req = requests.get(uri, timeout=5)
if req.status_code == 200:
res = req.content.decode("ascii", "ignore").replace("\001", "")
res = "\n".join(text.replace("\r", "").split("\n")[5:])
resp = httpx.get(uri, timeout=5)
resp.raise_for_status()
res = resp.content.decode("ascii", "ignore").replace("\001", "")
res = "\n".join(text.replace("\r", "").split("\n")[5:])
except Exception as exp:
LOG.info(exp)

Expand Down
7 changes: 4 additions & 3 deletions pylib/iemweb/autoplot/scripts200/p229.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
to the derecho power outage.</p>
"""

import datetime
from datetime import timedelta
from zoneinfo import ZoneInfo

import geopandas as gpd
import matplotlib.colors as mpcolors
import numpy as np
from pyiem.database import get_sqlalchemy_conn
from pyiem.exceptions import NoDataFound
from pyiem.plot import MapPlot, get_cmap, pretty_bins
from pyiem.reference import EPSG, Z_CLIP2, state_bounds
from pyiem.util import get_autoplot_context, get_sqlalchemy_conn, utc
from pyiem.util import get_autoplot_context, utc

LL = (
"https://www.vaisala.com/en/products/"
Expand All @@ -30,7 +31,7 @@

def get_description():
"""Return a dict describing how to call this plotter"""
t24 = utc() - datetime.timedelta(hours=24)
t24 = utc() - timedelta(hours=24)
return {
"data": False,
"description": __doc__.replace("{LL}", LL),
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/c/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def application(environ, start_response):
"""),
{
"addr": environ.get(
"X-Forwarded-For", environ.get("REMOTE_ADDR")
"HTTP_X_FORWARDED_FOR", environ.get("REMOTE_ADDR")
)
.split(",")[0]
.strip(),
"uri": environ.get("PATH_INFO"),
"ref": environ.get("HTTP_REFERER"),
"status": 404,
"for": environ.get("X-Forwarded-For"),
"for": environ.get("HTTP_X_FORWARDED_FOR"),
},
)
conn.commit()
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/cache/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def application(environ, start_response):
"""),
{
"addr": environ.get(
"X-Forwarded-For", environ.get("REMOTE_ADDR")
"HTTP_X_FORWARDED_FOR", environ.get("REMOTE_ADDR")
)
.split(",")[0]
.strip(),
"uri": environ.get("PATH_INFO"),
"ref": environ.get("HTTP_REFERER"),
"status": 404,
"for": environ.get("X-Forwarded-For"),
"for": environ.get("HTTP_X_FORWARDED_FOR"),
},
)
conn.commit()
Expand Down
1 change: 1 addition & 0 deletions pylib/iemweb/json/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Schema(CGIModel):
default="KDSM",
description="The station identifier to query for",
max_length=4,
pattern="^[A-Z]{4}$",
)
year: int = Field(default=2019, description="The year to query for")

Expand Down
5 changes: 2 additions & 3 deletions scripts/iemre/grid_rsds.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ def do_hrrr(ts: datetime) -> Optional[np.ndarray]:
ppath = (utcnow - timedelta(hours=1)).strftime(
"%Y/%m/%d/model/hrrr/%H/hrrr.t%Hz.3kmf01.grib2"
)
grbname = "Time-mean surface downward short-wave radiation flux"
with archive_fetch(ppath) as fn:
if fn is not None:
try:
grbs = pygrib.open(fn)
selgrbs = grbs.select(
name="Mean surface downward short-wave radiation flux"
)
selgrbs = grbs.select(name=grbname)
except Exception:
LOG.warning("Read of %s failed", fn)
continue
Expand Down
1 change: 1 addition & 0 deletions tests/iemweb/autoplot/urllist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
/plotting/auto/plot/220/which:7C::cat:categorical::t:fema::network:WFO::wfo:DMX::fema:4::csector:southeast::valid:2001-09-10%201943::_r:t::dpi:100.png
/plotting/auto/plot/220/which:2C::cat:categorical::t:fema::network:WFO::wfo:DMX::fema:4::csector:southeast::valid:2024-08-08%200352::_r:t::dpi:100.png
/plotting/auto/plot/220/which:2C::cat:hail::t:cwa::network:WFO::wfo:GSP::fema:4::csector:southeast::valid:2024-08-08%200352::_r:t::dpi:100.png
/plotting/auto/plot/227/pid:202410012036-KDTX-FZUS73-MWSDTX::segnum:0::_r:t::dpi:100.png
/plotting/auto/plot/228/mode:normal::state:IA::date:2024-01-10::d1:30::d2:60::d3:90::_r:t::dpi:100::_cb:1.png
/plotting/auto/plot/228/mode:iadrought::state:IA::date:2024-01-10::d1:30::d2:60::d3:90::_r:t::dpi:100.png
/plotting/auto/plot/230/outlook_type:E::day:4::w:ugc::network:WFO::wfo:ABR::mystate:IA::ugc:NCC001::month:all::_r:t::dpi:100.png
Expand Down

0 comments on commit 5ef3993

Please sign in to comment.