Skip to content

Commit

Permalink
Merge pull request #1025 from akrherz/241210-2
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Dec 11, 2024
2 parents fcf115a + 26dac12 commit 2bc0a5d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
48 changes: 39 additions & 9 deletions pylib/iemweb/autoplot/scripts100/p151.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""
This map produces an analysis yearly averages. You
can either plot the difference between two period of years or simply the
years between the first period. This app is meant to address the question
about changes in climate or just to produce a simple plot of yearly
averages over some period of years.
This autoplot can either produce a plot of averages for a given period or
annual over a period of years; or a difference between a second set of years.
<a href="/plotting/auto/?q=97">Autoplot 97</a> is a similar plot and perhaps
more useful for some users than this one.
"""

from datetime import date

import numpy as np
import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand Down Expand Up @@ -70,6 +71,7 @@
PRECISION = {"total_precip": 2}
MDICT = {
"all": "Annual",
"custom": "Custom Period (select below)",
"spring": "Spring (MAM)",
"fall": "Fall (SON)",
"winter": "Winter (DJF)",
Expand Down Expand Up @@ -100,8 +102,20 @@ def get_description():
name="month",
default="all",
options=MDICT,
label="Show Monthly or Annual Averages",
label="Show Monthly, Annual or Custom Defined Period Averages",
),
{
"type": "sday",
"default": "0101",
"name": "sday",
"label": "Inclusive Start Day (select custom period above)",
},
{
"type": "sday",
"default": "1231",
"name": "eday",
"label": "Inclusive End Day (select custom period above)",
},
dict(
type="select",
name="sector",
Expand Down Expand Up @@ -186,15 +200,23 @@ def get_data(ctx):
sector = ctx["sector"]
threshold = ctx["threshold"]
month = ctx["month"]
sday: date = ctx["sday"]
eday: date = ctx["eday"]
p1syear = ctx["p1syear"]
p1eyear = ctx["p1eyear"]
p1years = p1eyear - p1syear + 1
p2syear = ctx["p2syear"]
p2eyear = ctx["p2eyear"]
p2years = p2eyear - p2syear + 1

mlimiter = "and month = ANY(:months)" if month != "all" else ""
months = month2months(month)
if month != "custom":
mlimiter = "and month = ANY(:months)" if month != "all" else ""
months = month2months(month)
else:
mlimiter = "and sday >= :sday and sday <= :eday"
if sday > eday:
mlimiter = "and (sday >= :sday or sday <= :eday)"
months = None
table = "alldata"
if sector == "state":
# optimization
Expand Down Expand Up @@ -270,6 +292,8 @@ def get_data(ctx):
"syear1": p1syear,
"eyear1": p1eyear,
"months": months,
"sday": f"{sday:%m%d}",
"eday": f"{eday:%m%d}",
"syear2": p2syear,
"eyear2": p2eyear,
"p1years": p1years,
Expand Down Expand Up @@ -306,7 +330,13 @@ def plotter(fdict):
opt1 = ctx["opt1"]

column = varname
title = f"{MDICT[month]} {PDICT3[varname]}"
if month == "custom":
title = (
f"({ctx['sday']:%-d %b} thru {ctx['eday']:%-d %b}) "
f"{PDICT3[varname]}"
)
else:
title = f"{MDICT[month]} {PDICT3[varname]}"
title = title.replace("[Threshold]", f"{threshold:.1f}")
if opt1 == "p1":
column = f"p1_{varname}"
Expand Down
10 changes: 6 additions & 4 deletions pylib/iemweb/autoplot/scripts200/p208.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_description():
default="DMX",
label="Select WFO:",
),
dict(type="year", min=1986, default=2019, name="year", label="Year"),
dict(type="year", min=1986, default=2024, name="year", label="Year"),
dict(
type="vtec_ps",
name="v",
Expand Down Expand Up @@ -262,7 +262,7 @@ def m(valid):
df["color"] = vtec.NWS_COLORS.get(f"{p1}.{s1}", "#FF0000") + "D0"
if not sbwdf.empty:
df["color"] = "#D2B48CD0"
if len(df["wfo"].unique()) == 1:
if len(df.wfo.unique()) == 1:
bounds = df["simple_geom"].total_bounds
if not sbwdf.empty:
bounds = sbwdf["geom"].total_bounds
Expand Down Expand Up @@ -296,12 +296,14 @@ def m(valid):
north=bounds[3] + buffer,
nocaption=True,
)
if len(df["wfo"].unique()) == 1 and wfo not in ["PHEB", "PAAQ"]:
if len(df.wfo.unique()) == 1 and wfo not in ["PHEB", "PAAQ"]:
mp.sector = "cwa"
mp.cwa = wfo[-3:]
# CAN statements come here with time == expire :/
if ctx["opt"] == "single":
df2 = df[(df["issue"] <= utcvalid) & (df["expire"] > utcvalid)]
df2: gpd.GeoDataFrame = df[
(df["issue"] <= utcvalid) & (df["expire"] > utcvalid)
]
else:
df2 = df
if df2.empty:
Expand Down
6 changes: 3 additions & 3 deletions pylib/iemweb/autoplot/scripts200/p216.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
the long term climate sites is <a href="/request/coop/fe.phtml">here</a>.
"""

import datetime
from datetime import timedelta

import matplotlib.ticker as mticker
import numpy as np
Expand Down Expand Up @@ -154,7 +154,7 @@ def plotter(fdict):
"days": running,
"season": day.year if mydir == "above" else row["season"],
"startdate": startdate,
"enddate": day - datetime.timedelta(days=1),
"enddate": day - timedelta(days=1),
}
)
running = 0
Expand All @@ -180,7 +180,7 @@ def plotter(fdict):
)
subtitle = f"{PDICT2[varname]} {label} {threshold} {UNITS[varname]}"
fig = figure(title=title, subtitle=subtitle, apctx=ctx)
ax = fig.add_axes([0.1, 0.1, 0.5, 0.8])
ax = fig.add_axes((0.1, 0.1, 0.5, 0.8))
ax.set_ylabel(f"Max Streak by {label2} [days]")
ax.grid(True)
gdf = df.groupby("season").max()
Expand Down
2 changes: 1 addition & 1 deletion pylib/iemweb/iemre/multiday.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""".. title:: IEMRE Multi-Day Data
Return to `JSON Services </json/>`_
Return to `API Services </api/>`_
Documentation for /iemre/multiday.py
------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions pylib/iemweb/json/cf6.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""".. title:: NWS CF6 JSON Service
Return to `API Services </json/#json>`_
Return to `API Services </api/#json>`_
Documentation for /json/cf6.py
------------------------------
Expand All @@ -21,7 +21,7 @@
"""

import datetime
from datetime import date

import simplejson as json
from pydantic import Field
Expand Down Expand Up @@ -98,7 +98,7 @@ def get_data(cursor, station, year, fmt):
and c.valid >= %s and c.valid <= %s
ORDER by c.valid ASC
""",
(station, datetime.date(year, 1, 1), datetime.date(year, 12, 31)),
(station, date(year, 1, 1), date(year, 12, 31)),
)
for row in cursor:
data["results"].append(
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 @@ -169,6 +169,7 @@
/plotting/auto/plot/149/network:IACLIMATE::station:IATAME::days:91::days2:13::days3:0::year2:2015::year3:2023::sdate:2024-03-03::edate:2024-08-30::_r:43::dpi:100.png
/plotting/auto/plot/150/network:RAOB::station:_OAX::date:2024-07-19::hour:12::which:none::h:same::var:tmpc::_r:t::dpi:100.png
/plotting/auto/plot/151/month:all::sector:state::state:IA::opt:both::var:total_precip::r:english::threshold:-99::opt1:diff::p1syear:2000::p1eyear:2010::p2syear:2011::p2eyear:2021::cmap:seismic_r::_r:t::dpi:100.png
/plotting/auto/plot/151/month:custom::sday:0814::eday:0901::sector:state::state:IA::opt:both::var:total_precip::r:english::threshold:-99::opt1:diff::p1syear:1951::p1eyear:1980::p2syear:1981::p2eyear:2010::cmap:seismic_r::_r:t::dpi:100::_cb:1.png
/plotting/auto/plot/153/network:IA_ASOS::zstation:DSM::month:all::var:min_relh::_r:t::dpi:100.png
/plotting/auto/plot/155/network:IA_ASOS::zstation:AMW::var:max_gust::w:all::threshold:100::month:nov::_r:t::dpi:100.png
/plotting/auto/plot/155/network:IA_ASOS::zstation:AMW::var:above_dwpf::w:one::threshold:10::hour:12::month:nov::_r:t::dpi:100.png
Expand Down

0 comments on commit 2bc0a5d

Please sign in to comment.