Skip to content

Commit

Permalink
Merge pull request #1096 from akrherz/250203-2
Browse files Browse the repository at this point in the history
📝 Sundry updates per review
  • Loading branch information
akrherz authored Feb 4, 2025
2 parents afab059 + 21b47cb commit 1e12076
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 38 deletions.
5 changes: 4 additions & 1 deletion cgi-bin/afos/retrieve.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at pylib/iemweb/afos/retrieve.py"""

from iemweb.afos.retrieve import application # noqa: F401
from iemweb.afos.retrieve import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion cgi-bin/climate/orc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at pylib/iemweb/climate/orc.py"""

from iemweb.climate.orc import application # noqa
from iemweb.climate.orc import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion cgi-bin/onsite/birthday/getweather.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at pylib/iemweb/getweather.py"""

from iemweb.getweather import application # noqa: F401
from iemweb.getweather import application

# Appease the linter
_ = application
5 changes: 4 additions & 1 deletion cgi-bin/precip/catAZOS.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at pylib/iemweb/precip/catAZOS.py"""

from iemweb.precip.catAZOS import application # noqa: F401
from iemweb.precip.catAZOS import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion cgi-bin/precip/catSNET.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at pylib/iemweb/precip/catSNET.py"""

from iemweb.precip.catSNET import application # noqa: F401
from iemweb.precip.catSNET import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion cgi-bin/precip/snetRates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at pylib/iemweb/precip/snetRates.py"""

from iemweb.precip.snetRates import application # noqa: F401
from iemweb.precip.snetRates import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion cgi-bin/request/asos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""implemented in /pylib/iemweb/request/asos.py"""

from iemweb.request.asos import application # noqa: F401
from iemweb.request.asos import application

# Appease the linter
_ = application
5 changes: 4 additions & 1 deletion htdocs/plotting/auto/autoplot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at /pylib/iemweb/autoplot/autoplot.py"""

from iemweb.autoplot.autoplot import application # noqa: F401
from iemweb.autoplot.autoplot import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion htdocs/plotting/auto/gen_qrcode.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at /pylib/iemweb/autoplot/gen_qrcode.py"""

from iemweb.autoplot.gen_qrcode import application # noqa: F401
from iemweb.autoplot.gen_qrcode import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion htdocs/plotting/auto/index.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at /pylib/iemweb/autoplot/index.py"""

from iemweb.autoplot.index import application # noqa: F401
from iemweb.autoplot.index import application

# Appease linter
_ = application
5 changes: 4 additions & 1 deletion htdocs/plotting/auto/meta.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""Implementation at /pylib/iemweb/autoplot/meta.py"""

from iemweb.autoplot.meta import application # noqa: F401
from iemweb.autoplot.meta import application

# Appease linter
_ = application
5 changes: 2 additions & 3 deletions pylib/iemweb/autoplot/scripts/p21.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
from datetime import date, timedelta

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
from pyiem.database import get_sqlalchemy_conn, sql_helper
from pyiem.exceptions import NoDataFound
from pyiem.plot import centered_bins, get_cmap
from pyiem.plot.geoplot import MapPlot
from sqlalchemy import text

PDICT = {
"high": "High temperature",
Expand Down Expand Up @@ -74,7 +73,7 @@ def plotter(ctx: dict):
varname = ctx["varname"]
with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
text("""
sql_helper("""
WITH t2 as (
SELECT station, high, low, precip from ncei_climate91 WHERE
valid = :date2
Expand Down
12 changes: 7 additions & 5 deletions pylib/iemweb/autoplot/scripts/p25.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import numpy as np
import pandas as pd
from pyiem import reference
from pyiem.database import get_sqlalchemy_conn
from pyiem.database import get_sqlalchemy_conn, sql_helper
from pyiem.exceptions import NoDataFound
from pyiem.plot import figure_axes
from scipy.stats import norm
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION

Expand Down Expand Up @@ -53,7 +52,7 @@ def plotter(ctx: dict):
title = f"{ctx['_sname']} {ts:%d %B} Temperature Distribution"
with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
text("""SELECT high, low from alldata
sql_helper("""SELECT high, low from alldata
where station = :station and sday = :sday and high is not null
and low is not null
"""),
Expand All @@ -71,11 +70,14 @@ def plotter(ctx: dict):
)
with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
text(f"""SELECT high, low from alldata_{state}
sql_helper(
"""SELECT high, low from {table}
where sday = :sday and high is not null and low is not null and
substr(station, 3, 1) != 'T' and
substr(station, 3, 4) != '0000'
"""),
""",
table=f"alldata_{state.lower()}",
),
conn,
params={"sday": f"{month:02.0f}{day:02.0f}"},
)
Expand Down
11 changes: 6 additions & 5 deletions pylib/iemweb/autoplot/scripts/p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@

import numpy as np
import pandas as pd
from pyiem.database import get_sqlalchemy_conn
from pyiem.database import get_sqlalchemy_conn, sql_helper
from pyiem.exceptions import NoDataFound
from pyiem.plot import figure_axes
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION

Expand Down Expand Up @@ -225,8 +224,8 @@ def add_ctx(ctx):
decagg = 10 if ctx["decadal"] else 1
with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
text(
f"""
sql_helper(
"""
WITH climo as (
SELECT to_char(valid, 'mmdd') as sday,
high, low from ncei_climate91 WHERE station = :ncei),
Expand Down Expand Up @@ -284,7 +283,9 @@ def add_ctx(ctx):
on (a.myyear = b.myyear) WHERE b.myyear * {decagg} >= :syear
and b.myyear * {decagg} <= :eyear
ORDER by b.myyear ASC
"""
""",
lag=str(lag), # ugly
decagg=str(decagg),
),
conn,
params={
Expand Down
19 changes: 11 additions & 8 deletions pylib/iemweb/autoplot/scripts/p31.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
from datetime import date, datetime

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
from pyiem.database import get_sqlalchemy_conn, sql_helper
from pyiem.exceptions import NoDataFound
from pyiem.plot import figure_axes
from scipy import stats
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION

Expand Down Expand Up @@ -192,20 +191,24 @@ def plotter(ctx: dict):
months = [int(month)]
with get_sqlalchemy_conn("coop") as conn:
obs = pd.read_sql(
text(
f"""WITH data as (
sql_helper(
"""WITH data as (
select day, extract(week from day) - 1 as week, year, month, sday,
{ctx["fstat"]}({ctx["var"]}) OVER
{fstat}({varname}) OVER
(ORDER by day ASC rows between :f1 FOLLOWING and :f2 FOLLOWING)
as forward_stat, {ctx["mstat"]}({ctx["var"]}) OVER
as forward_stat, {mstat}({varname}) OVER
(ORDER by day ASC rows between CURRENT ROW and :f3 FOLLOWING)
as middle_stat, {ctx["stat"]}({ctx["var"]}) OVER
as middle_stat, {stat}({varname}) OVER
(ORDER by day ASC rows between :days PRECEDING and 1 PRECEDING)
as trailing_stat
from alldata where station = :station)
SELECT * from data WHERE month = ANY(:months) and year >= :syear
and year <= :eyear ORDER by day ASC
"""
""",
fstat=ctx["fstat"],
mstat=ctx["mstat"],
stat=ctx["stat"],
varname=ctx["var"],
),
conn,
params={
Expand Down
8 changes: 4 additions & 4 deletions pylib/iemweb/autoplot/scripts200/p210.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
issuance counts for a single Weather Forecast Offices.</p>
"""

from datetime import timedelta
from zoneinfo import ZoneInfo
from datetime import timedelta, timezone

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -100,10 +99,11 @@ def get_description():

def plotter(ctx: dict):
"""Go"""
ctx["sts"] = ctx["sts"].replace(tzinfo=timezone.utc)
ctx["ets"] = ctx["ets"].replace(tzinfo=timezone.utc)
fix()
pil = ctx["pil"][:3]
if ctx["ets"].astimezone(ZoneInfo("UTC")) > utc():
ctx["ets"] = utc()
ctx["ets"] = min(ctx["ets"], utc())

with get_sqlalchemy_conn("afos") as conn:
df = pd.read_sql(
Expand Down
2 changes: 1 addition & 1 deletion pylib/iemweb/autoplot/scripts200/p241.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
def get_description():
"""Return a dict describing how to call this plotter"""
desc = {"description": __doc__}
sts = utc() - timedelta(hours=26)
sts = utc() - timedelta(hours=6) # Save some CI time
ets = utc() - timedelta(hours=2)
desc["arguments"] = [
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/hads/compute_hads_pday.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def workflow(dt: date):
sql_helper(
"""
SELECT distinct station, valid at time zone 'UTC' as utc_valid, value
from raw{dt:%Y} WHERE valid between :sts and :ets and
from {table} WHERE valid between :sts and :ets and
substr(key, 1, 3) = 'PPH' and value >= 0
""",
table=f"raw{dt:%Y}",
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 @@ -304,6 +304,7 @@
/plotting/auto/plot/207/v:snow::t:cwa::network:WFO::wfo:RIW::csector:TN::p:contour::endts:2025-01-20%201549::hours:12::sz:50::f:linear::z:plot::coop:yes::c:yes::ct:yes::lw:1::_r:t::dpi:100.png
/plotting/auto/plot/208/network:WFO::wfo:DMX::year:2024::phenomenav:TO::significancev:W::etn:47::opt:single::n:auto::_r:43::dpi:100.png
/plotting/auto/plot/208/valid:2024-08-27%201717::network:WFO::wfo:DMX::year:2024::phenomenav:TO::significancev:W::etn:47::opt:single::n:off::_r:43::dpi:100.png
/plotting/auto/plot/210/pil:AFD::var:count::w:cwa::sts:2024-01-01%200000::ets:2025-02-05%200000::cmap:jet::_r:t::dpi:100.png
/plotting/auto/plot/211/ptype:precip::network:IA_ASOS::zstation:AMW::sts:2024-07-10%200000::ets:2024-07-12%202359::_r:t::dpi:100.png
/plotting/auto/plot/211/ptype:meteo::network:IA_ASOS::zstation:AMW::sts:2024-07-10%200000::ets:2024-07-12%202359::_r:t::dpi:100.png
/plotting/auto/plot/211/ptype:wind::network:IA_ASOS::zstation:AMW::sts:2024-07-10%200000::ets:2024-07-12%202359::_r:t::dpi:100.png
Expand Down

0 comments on commit 1e12076

Please sign in to comment.