Skip to content

Commit

Permalink
Merge pull request #1021 from akrherz/241205
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Dec 6, 2024
2 parents f62d682 + 356f41a commit b9c3d86
Show file tree
Hide file tree
Showing 31 changed files with 215 additions and 502 deletions.
28 changes: 27 additions & 1 deletion htdocs/nws/cf6table.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
<th>Avg Speed</th><th>Max Speed</th><th>Avg Drct</th>
<th>Max Gust</th><th>Gust Drct</th>
<th>Minutes Sunshine</th><th>Poss Sunshine</th>
<th>Cloud SS</th><th>Weather Codes</th>
<th>Cloud SS</th>
<th>Weather Codes [<a href="#wxcodes">1</a>]</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -192,6 +193,31 @@ function trace($val)
{$table}
<p><a name="wxcodes">1. Weather Codes</a>:
<br />The numeric weather codes shown above are just concatenated values. For
instance, a value of 12 implies a <code>1</code> and a <code>2</code> weather
code.
<br />
<table class="table table-condensed table-striped table-bordered table-hover">
<thead>
<tr><th>Code</th><th>Meaning</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>Fog or Mist</td></tr>
<tr><td>2</td><td>Fog or Vis 0.25 mile or less</td></tr>
<tr><td>3</td><td>Thunder</td></tr>
<tr><td>4</td><td>Ice pellets</td></tr>
<tr><td>5</td><td>Hail</td></tr>
<tr><td>6</td><td>Freezing Rain or Drizzle</td></tr>
<tr><td>7</td><td>Duststorm or Sandstorm vis 0.25 mile or less</td></tr>
<tr><td>8</td><td>Smoke or Haze</td></tr>
<tr><td>9</td><td>Blowing Snow</td></tr>
<tr><td>X</td><td>Tornado</td></tr>
</tbody>
</table></p>
EOF;
$t->headextra = <<<EOF
<link rel="stylesheet" type="text/css" href="/vendor/select2/4.0.3/select2.min.css"/ >
Expand Down
14 changes: 7 additions & 7 deletions pylib/iemweb/autoplot/scripts/p15.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"""

import calendar
import datetime

import matplotlib.patheffects as PathEffects
import numpy as np
import pandas as pd
from pyiem.database import get_sqlalchemy_conn
from pyiem.exceptions import NoDataFound
from pyiem.plot import figure_axes
from pyiem.util import get_autoplot_context
from pyiem.util import get_autoplot_context, utc
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION

Expand All @@ -34,7 +34,7 @@ def get_description():
dict(
type="year",
name="year",
default=datetime.date.today().year,
default=utc().year,
label="Year to Highlight",
min=1893,
),
Expand All @@ -51,11 +51,11 @@ def plotter(fdict):

with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
"""
text("""
with obs as
(select month, year, high, lag(high) OVER (ORDER by day ASC) as lhigh,
low, lag(low) OVER (ORDER by day ASC) as llow
from alldata where station = %s)
from alldata where station = :station)
SELECT year, month,
sum(case when high > lhigh then 1 else 0 end)::numeric as high_greater,
Expand All @@ -65,9 +65,9 @@ def plotter(fdict):
sum(case when low = llow then 1 else 0 end)::numeric as low_unch,
sum(case when low < llow then 1 else 0 end)::numeric as low_lower
from obs GROUP by year, month ORDER by year, month
""",
"""),
conn,
params=(station,),
params={"station": station},
index_col=None,
)
gdf = df.groupby("month").sum()
Expand Down
22 changes: 3 additions & 19 deletions pylib/iemweb/autoplot/scripts/p16.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
wind speed and direction.
"""

import datetime

import numpy as np
import pandas as pd
from metpy.units import units
Expand All @@ -15,6 +13,8 @@
from pyiem.util import drct2text, get_autoplot_context
from sqlalchemy import text

from iemweb.util import month2months

PDICT = {
"ts": "Thunderstorm (TS) Reported",
"tmpf_above": "Temperature At or Above Threshold (F)",
Expand Down Expand Up @@ -215,23 +215,7 @@ def get_highcharts(ctx: dict) -> str:
def add_ctx(ctx):
"""Do the agnostic stuff"""
ctx["station"] = ctx["zstation"]

if ctx["month"] == "all":
months = list(range(1, 13))
elif ctx["month"] == "fall":
months = [9, 10, 11]
elif ctx["month"] == "winter":
months = [12, 1, 2]
elif ctx["month"] == "spring":
months = [3, 4, 5]
elif ctx["month"] == "summer":
months = [6, 7, 8]
else:
ts = datetime.datetime.strptime(
"2000-" + ctx["month"] + "-01", "%Y-%b-%d"
)
# make sure it is length two for the trick below in SQL
months = [ts.month, 999]
months = month2months(ctx["month"])

limiter = "array_to_string(wxcodes, '') ~* 'TS'"
title = "Thunderstorm (TS) contained in METAR"
Expand Down
23 changes: 5 additions & 18 deletions pylib/iemweb/autoplot/scripts/p19.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION, get_monofont
from iemweb.util import month2months

MDICT = {
"all": "No Month/Time Limit",
Expand Down Expand Up @@ -91,20 +92,6 @@ def plotter(fdict):
binsize = ctx["binsize"]
month = ctx["month"]
year = ctx.get("year")
if month == "all":
months = list(range(1, 13))
elif month == "fall":
months = [9, 10, 11]
elif month == "winter":
months = [12, 1, 2]
elif month == "spring":
months = [3, 4, 5]
elif month == "summer":
months = [6, 7, 8]
else:
ts = datetime.datetime.strptime(f"2000-{month}-01", "%Y-%b-%d")
# make sure it is length two for the trick below in SQL
months = [ts.month, 999]
with get_sqlalchemy_conn("coop") as conn:
ddf = pd.read_sql(
text(
Expand All @@ -113,7 +100,7 @@ def plotter(fdict):
"and high >= low and month = ANY(:months) "
),
conn,
params={"station": station, "months": months},
params={"station": station, "months": month2months(month)},
index_col=None,
)
if ddf.empty:
Expand Down Expand Up @@ -146,7 +133,7 @@ def plotter(fdict):
f"{ctx['_sname']} ({ddf['year'].min():.0f}-{ddf['year'].max():.0f})"
)
fig = figure(title=title, subtitle=subtitle, apctx=ctx)
kax = fig.add_axes([0.65, 0.5, 0.3, 0.36])
kax = fig.add_axes((0.65, 0.5, 0.3, 0.36))
kax.grid(True)
kax.text(
0.02,
Expand Down Expand Up @@ -194,9 +181,9 @@ def plotter(fdict):
label = f"{q * 100:-6g} {val:-6.0f}"
fig.text(xpos, ypos, label, fontproperties=monofont)

ax = fig.add_axes([0.07, 0.17, 0.5, 0.73])
ax = fig.add_axes((0.07, 0.17, 0.5, 0.73))
res = ax.pcolormesh(xedges, yedges, hist.T, cmap=get_cmap(ctx["cmap"]))
cax = fig.add_axes([0.07, 0.08, 0.5, 0.01])
cax = fig.add_axes((0.07, 0.08, 0.5, 0.01))
fig.colorbar(res, label="Days per Year", orientation="horizontal", cax=cax)
ax.grid(True)
ax.set_ylabel(r"High Temperature $^{\circ}\mathrm{F}$")
Expand Down
78 changes: 30 additions & 48 deletions pylib/iemweb/autoplot/scripts/p41.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
and duration of stretches of hot or cold weather.
"""

from datetime import timedelta

import numpy as np
import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand All @@ -30,8 +32,10 @@
from pyiem.plot.use_agg import plt
from pyiem.util import get_autoplot_context
from scipy import stats
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION, get_monofont
from iemweb.util import month2months

ODICT = {"max": "Maximum", "min": "Minimum", "avg": "Average"}
PDICT = {
Expand Down Expand Up @@ -125,40 +129,35 @@ def get_description():

def get_data(station, month, period, varname, days, opt):
"""Get Data please"""
doffset = "0 days"
if len(month) < 3:
mlimiter = f" and month = {int(month)} "
elif month == "all":
mlimiter = ""
elif month == "fall":
mlimiter = " and month in (9, 10, 11) "
elif month == "winter":
mlimiter = " and month in (12, 1, 2) "
doffset = "31 days"
elif month == "spring":
mlimiter = " and month in (3, 4, 5) "
else: # summer
mlimiter = " and month in (6, 7, 8) "

params = {
"station": station,
"months": month2months(month),
"doffset": timedelta(days=0),
}
mlimiter = "and month = ANY(:months)"
if month == "winter":
params["doffset"] = timedelta(days=31)
ylimiter = ""
if period is not None:
(y1, y2) = [int(x) for x in period.split("-")]
ylimiter = f"WHERE myyear >= {y1} and myyear <= {y2}"
params["y1"] = y1
params["y2"] = y2
ylimiter = "WHERE myyear >= :y1 and myyear <= :y2"
if days == 1:
with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
f"""
text(f"""
WITH data as (
SELECT
extract(year from day + '{doffset}'::interval)::int
extract(year from day + :doffset)::int
as myyear,
high, low, (high+low)/2. as avg from alldata
WHERE station = %s and high is not null
WHERE station = :station and high is not null
and low is not null {mlimiter})
SELECT * from data {ylimiter}
""",
"""),
conn,
params=(station,),
params=params,
index_col=None,
)
else:
Expand All @@ -168,20 +167,21 @@ def get_data(station, month, period, varname, days, opt):
)
with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
f"""
text(f"""
WITH data as (
SELECT
extract(year from day + '{doffset}'::interval)::int
extract(year from day + :doffset)::int
as myyear,
high, low, (high+low)/2. as avg, day, month from alldata
WHERE station = %s and high is not null and low is not null),
WHERE station = :station
and high is not null and low is not null),
agg1 as (
SELECT myyear, month, {res} as {varname}
from data WHERE 1 = 1 {mlimiter})
SELECT * from agg1 {ylimiter}
""",
"""),
conn,
params=(station,),
params=params,
index_col=None,
)
if df.empty:
Expand Down Expand Up @@ -221,7 +221,7 @@ def plotter(fdict):
s_slp, s_int, s_r, _, _ = stats.linregress(pc1, pc2)

fig = figure(apctx=ctx)
ax = fig.add_axes([0.1, 0.11, 0.4, 0.76])
ax = fig.add_axes((0.1, 0.11, 0.4, 0.76))
ax.scatter(pc1[::5], pc2[::5], s=40, marker="s", color="b", zorder=3)
ax.plot(
pc1,
Expand Down Expand Up @@ -273,7 +273,7 @@ def plotter(fdict):
ax.legend(loc=2)

# Second
ax = fig.add_axes([0.56, 0.18, 0.26, 0.68])
ax = fig.add_axes((0.56, 0.18, 0.26, 0.68))
ax.set_title("Distribution")
v1 = ax.violinplot(m1data, positions=[0], showextrema=True, showmeans=True)
b = v1["bodies"][0]
Expand Down Expand Up @@ -320,26 +320,8 @@ def plotter(fdict):
col1 = f"{MDICT[month1]}_{varname}_{y1}_{y2}"
col2 = f"{MDICT[month2]}_{varname}_{y3}_{y4}"
fig.text(x, y + 0.04, "Percentile Data Diff")
for percentile in [
100,
99,
98,
97,
96,
95,
92,
90,
75,
50,
25,
10,
8,
5,
4,
3,
2,
1,
]:
pt = [100, 99, 98, 97, 96, 95, 92, 90, 75, 50, 25, 10, 8, 5, 4, 3, 2, 1]
for percentile in pt:
row = df.loc[percentile]
fig.text(x, y, f"{percentile:3.0f}", fontproperties=monofont)
fig.text(
Expand Down
20 changes: 4 additions & 16 deletions pylib/iemweb/autoplot/scripts/p42.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from pyiem.plot import figure
from pyiem.util import get_autoplot_context

from iemweb.util import month2months

PDICT = {
"above": "At or Above Threshold...",
"below": "Below Threshold...",
Expand Down Expand Up @@ -221,21 +223,7 @@ def plotter(fdict):
f" and valid >= '{int(y1)}-01-01' and "
f"valid < '{int(y2) + 1}-01-01' "
)
if month == "all":
months = list(range(1, 13))
elif month == "fall":
months = [9, 10, 11]
elif month == "winter":
months = [12, 1, 2]
elif month == "octmar":
months = [10, 11, 12, 1, 2, 3]
elif month == "spring":
months = [3, 4, 5]
elif month == "summer":
months = [6, 7, 8]
else:
ts = datetime.datetime.strptime(f"2000-{month}-01", "%Y-%b-%d")
months = [ts.month]
months = month2months(month)

ab = ctx["_nt"].sts[station]["archive_begin"]
if ab is None:
Expand Down Expand Up @@ -288,7 +276,7 @@ def plotter(fdict):
f"{MDICT.get(month)} :: Streaks {PDICT2[varname]} {label} {units}"
)
fig = figure(title=title, subtitle=subtitle, apctx=ctx)
ax = fig.add_axes([0.07, 0.25, 0.6, 0.65])
ax = fig.add_axes((0.07, 0.25, 0.6, 0.65))

threshold = datetime.timedelta(hours=3)
reset_valid = datetime.datetime(1910, 1, 1, tzinfo=tzinfo)
Expand Down
Loading

0 comments on commit b9c3d86

Please sign in to comment.