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 #1066

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Omnibus #1066

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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v9.17.0'
rev: 'v9.18.0'
hooks:
- id: eslint
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.9.0"
rev: "v0.9.1"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p76.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
to the same value.</p>
"""

import datetime
from datetime import datetime

import metpy.calc as mcalc
import numpy as np
Expand Down Expand Up @@ -179,7 +179,7 @@ def run_calcs(df, ctx):

def get_data(ctx, startyear):
"""Get data"""
today = datetime.datetime.now()
today = datetime.now()
lastyear = today.year
deltadays = 0
months = month2months(ctx["season"])
Expand Down
17 changes: 9 additions & 8 deletions pylib/iemweb/autoplot/scripts/p77.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"""

import calendar
import datetime
from datetime import datetime

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
from sqlalchemy import text

from iemweb.autoplot import ARG_STATION

Expand All @@ -28,24 +29,24 @@ def plotter(ctx: dict):
"""Go"""
station = ctx["station"]

today = datetime.datetime.now()
today = datetime.now()
thisyear = today.year

with get_sqlalchemy_conn("coop") as conn:
df = pd.read_sql(
"""
text("""
with data as (
select year, month, extract(doy from day) as doy,
generate_series(32, high) as t from alldata
where station = %s and year < %s),
where station = :station and year < :thisyear),
agger as (
SELECT year, t, min(doy), max(doy) from data GROUP by year, t)
SELECT t as tmpf, avg(min) as min_jday,
avg(max) as max_jday from agger GROUP by t ORDER by t ASC
""",
"""),
conn,
params=(station, thisyear),
params={"station": station, "thisyear": thisyear},
index_col="tmpf",
)
if df.empty:
Expand All @@ -55,8 +56,8 @@ def plotter(ctx: dict):
"Average Last and First High Temperature of Year"
)
fig = figure(title=title, apctx=ctx)
ax = fig.add_axes([0.1, 0.1, 0.7, 0.8])
ax2 = fig.add_axes([0.81, 0.1, 0.15, 0.8])
ax = fig.add_axes((0.1, 0.1, 0.7, 0.8))
ax2 = fig.add_axes((0.81, 0.1, 0.15, 0.8))
height = df["min_jday"][:] + 365.0 - df["max_jday"]
ax2.plot(height, df.index.values)
ax2.set_xticks([30, 90, 180, 365])
Expand Down
6 changes: 3 additions & 3 deletions pylib/iemweb/autoplot/scripts/p78.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
relative humidity value is computed.
"""

import datetime
from datetime import date, datetime

import metpy.calc as mcalc
import pandas as pd
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_description():
name="date",
optional=True,
label="Plot Obs for A Single Calendar Date (optional)",
default=datetime.date.today().strftime("%Y/%m/%d"),
default=date.today().strftime("%Y/%m/%d"),
),
]
return desc
Expand Down Expand Up @@ -149,7 +149,7 @@ def plotter(ctx: dict):
raise NoDataFound("Unknown station metadata.")
title = (
f"{ctx['_sname']}:: Dew Point Distribution by Air Temp "
f"(month={month.upper()}) ({ab.year}-{datetime.datetime.now().year}), "
f"(month={month.upper()}) ({ab.year}-{datetime.now().year}), "
f"n={len(df.index):.0f}"
)
subtitle = "(must have 6+ hourly observations at the given temperature)"
Expand Down
6 changes: 3 additions & 3 deletions pylib/iemweb/autoplot/scripts100/p111.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Top 30 24-Hour Precipitation Events."""

import datetime
from datetime import date

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand Down Expand Up @@ -41,9 +41,9 @@ def plotter(ctx: dict):

res = (
"# IEM Climodat https://mesonet.agron.iastate.edu/climodat/\n"
f"# Report Generated: {datetime.date.today():%d %b %Y}\n"
f"# Report Generated: {date.today():%d %b %Y}\n"
f"# Climate Record: {ctx['_nt'].sts[station]['archive_begin']} "
f"-> {datetime.date.today()}\n"
f"-> {date.today()}\n"
f"# Site Information: {ctx['_sname']}\n"
"# Contact Information: Daryl Herzmann "
"akrherz@iastate.edu 515.294.5978\n"
Expand Down
8 changes: 4 additions & 4 deletions pylib/iemweb/autoplot/scripts100/p114.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Days per year"""

import datetime
from datetime import date

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand Down Expand Up @@ -33,7 +33,7 @@ def plotter(ctx: dict):
"WHERE station = %s and low >= 32 and year < %s "
"GROUP by year ORDER by year ASC",
conn,
params=(station, datetime.date.today().year),
params=(station, date.today().year),
index_col=None,
)
if df.empty:
Expand All @@ -47,9 +47,9 @@ def plotter(ctx: dict):
# Contact Information: Daryl Herzmann akrherz@iastate.edu 515.294.5978
# OF DAYS EACH YEAR WHERE MIN >=32 F
""" % (
datetime.date.today().strftime("%d %b %Y"),
date.today().strftime("%d %b %Y"),
ctx["_nt"].sts[station]["archive_begin"],
datetime.date.today(),
date.today(),
station,
ctx["_nt"].sts[station]["name"],
)
Expand Down
6 changes: 3 additions & 3 deletions pylib/iemweb/autoplot/scripts100/p115.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import calendar
import datetime
from datetime import date

import pandas as pd
import seaborn as sns
Expand Down Expand Up @@ -44,7 +44,7 @@
def get_description():
"""Return a dict describing how to call this plotter"""
desc = {"description": __doc__, "data": True, "report": True}
y20 = datetime.date.today().year - 19
y20 = date.today().year - 19
desc["arguments"] = [
ARG_STATION,
dict(
Expand Down Expand Up @@ -113,7 +113,7 @@ def plotter(ctx: dict):

res = (
"# IEM Climodat https://mesonet.agron.iastate.edu/climodat/\n"
f"# Report Generated: {datetime.date.today():%d %b %Y}\n"
f"# Report Generated: {date.today():%d %b %Y}\n"
f"# Climate Record: {ctx['_nt'].sts[station]['archive_begin']} "
f"-> {df['max_day'].max()}, "
"WYEAR column is Water Year Oct 1 - Sep 30\n"
Expand Down
12 changes: 6 additions & 6 deletions pylib/iemweb/autoplot/scripts100/p116.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
years contained.
"""

import datetime
from datetime import date

import pandas as pd
import seaborn as sns
Expand All @@ -21,7 +21,7 @@
def get_description():
"""Return a dict describing how to call this plotter"""
desc = {"description": __doc__, "data": True, "report": True}
y20 = datetime.date.today().year - 19
y20 = date.today().year - 19
desc["arguments"] = [
ARG_STATION,
dict(
Expand Down Expand Up @@ -66,15 +66,15 @@ def plotter(ctx: dict):
if df.empty:
raise NoDataFound("No Data Found.")
df["monthdate"] = df[["year", "month"]].apply(
lambda x: datetime.date(x.iloc[0], x.iloc[1], 1), axis=1
lambda x: date(x.iloc[0], x.iloc[1], 1), axis=1
)
df = df.set_index("monthdate")

res = (
"# IEM Climodat https://mesonet.agron.iastate.edu/climodat/\n"
f"# Report Generated: {datetime.date.today():%d %b %Y}\n"
f"# Report Generated: {date.today():%d %b %Y}\n"
f"# Climate Record: {ctx['_nt'].sts[station]['archive_begin']} "
f"-> {datetime.date.today()}\n"
f"-> {date.today()}\n"
f"# Site Information: {ctx['_sname']}\n"
"# Contact Information: Daryl Herzmann "
"akrherz@iastate.edu 515.294.5978\n"
Expand All @@ -96,7 +96,7 @@ def plotter(ctx: dict):
res += f"{yr:4.0f}"
second += f"{yr:4.0f}"
for mo in range(1, 13):
ts = datetime.date(yr, mo, 1)
ts = date(yr, mo, 1)
if ts not in df.index:
res += f"{'M':>7s}"
second += f"{'M':>7s}"
Expand Down
8 changes: 4 additions & 4 deletions pylib/iemweb/autoplot/scripts100/p117.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""To be written."""
"""Stress Degree Days."""

import datetime
from datetime import date

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -39,9 +39,9 @@ def plotter(ctx: dict):
"# Contact Information: Daryl Herzmann "
"akrherz@iastate.edu 515.294.5978\n"
) % (
datetime.date.today().strftime("%d %b %Y"),
date.today().strftime("%d %b %Y"),
bs,
datetime.date.today(),
date.today(),
station,
ctx["_nt"].sts[station]["name"],
)
Expand Down
6 changes: 3 additions & 3 deletions pylib/iemweb/autoplot/scripts100/p118.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""precip days per month"""

import datetime
from datetime import date

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand Down Expand Up @@ -63,9 +63,9 @@ def plotter(ctx: dict):
# Days with a trace accumulation are not included
YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANN
""" % (
datetime.date.today().strftime("%d %b %Y"),
date.today().strftime("%d %b %Y"),
ctx["_nt"].sts[station]["archive_begin"],
datetime.date.today(),
date.today(),
station,
ctx["_nt"].sts[station]["name"],
"PRECIPITATION" if varname == "precip_days" else "SNOW FALL",
Expand Down
16 changes: 8 additions & 8 deletions pylib/iemweb/autoplot/scripts100/p119.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
autoplot and presents the spring season values.</p>
"""

import datetime
from datetime import date, datetime, timedelta

import matplotlib.dates as mdates
import numpy as np
Expand Down Expand Up @@ -130,7 +130,7 @@ def plotter(ctx: dict):
for idx, row in df2.iterrows():
if row["date"].year in [2099, 1800]:
continue
jan1 = datetime.date(row["winter"] - 1, 1, 1)
jan1 = date(row["winter"] - 1, 1, 1)
doy = (row["date"] - jan1).days
df2.at[idx, "doy"] = doy
df.loc[doy:sz, f"{base}cnts"] += 1
Expand All @@ -155,8 +155,8 @@ def plotter(ctx: dict):
)
res = (
"# IEM Climodat https://mesonet.agron.iastate.edu/climodat/\n"
f"# Report Generated: {datetime.date.today():%d %b %Y}\n"
f"# Climate Record: {bs} -> {datetime.date.today()}\n"
f"# Report Generated: {date.today():%d %b %Y}\n"
f"# Climate Record: {bs} -> {date.today()}\n"
f"# Site Information: {ctx['_sname']}\n"
"# Contact: Daryl Herzmann akrherz@iastate.edu 515.294.5978\n"
f"# {PDICT[ctx['var']]} exceedence probabilities\n"
Expand All @@ -172,10 +172,10 @@ def plotter(ctx: dict):
continue
if row[fcols[3]] >= 100:
if maxdate is None:
maxdate = row["dates"] + datetime.timedelta(days=5)
maxdate = row["dates"] + timedelta(days=5)
continue
if row[fcols[0]] > 0 and mindate is None:
mindate = row["dates"] - datetime.timedelta(days=5)
mindate = row["dates"] - timedelta(days=5)
res += (" %3s %s %3i %3i %3i %3i\n") % (
row["dates"].strftime("%-j"),
row["dates"].strftime("%b %d"),
Expand All @@ -187,7 +187,7 @@ def plotter(ctx: dict):
if mindate is None:
raise NoDataFound("Error found, try different thresholds.")
if maxdate is None:
maxdate = datetime.datetime(2001, 6, 1)
maxdate = datetime(2001, 6, 1)

byear = bs.year
if ctx["var"] == "era5land_soilt4_avg":
Expand All @@ -197,7 +197,7 @@ def plotter(ctx: dict):
station,
ctx["_nt"].sts[station]["name"],
byear,
datetime.date.today().year,
date.today().year,
)
(fig, ax) = figure_axes(title=title, apctx=ctx)
# shrink the plot to make room for the table
Expand Down
16 changes: 7 additions & 9 deletions pylib/iemweb/autoplot/scripts100/p172.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
missing data for the year to be considered in the plot.</p>
"""

import datetime
from datetime import date, timedelta

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand All @@ -35,7 +35,7 @@
def get_description():
"""Return a dict describing how to call this plotter"""
desc = {"description": __doc__, "data": True}
today = datetime.date.today()
today = date.today()
thisyear = today.year
desc["arguments"] = [
ARG_STATION,
Expand Down Expand Up @@ -148,7 +148,7 @@ def plotter(ctx: dict):
raise NoDataFound("No data found!")
# Truncate plot
doy_trunc = 365
today = ctx.get("edate", datetime.date.today())
today = ctx.get("edate", date.today())
if ctx.get("edate") is not None:
today_doy = int(today.strftime("%j"))
sdate_doy = int(sdate.strftime("%j"))
Expand All @@ -164,9 +164,7 @@ def plotter(ctx: dict):

extra = "" if doy_trunc == 365 else f" through {today.strftime('%-d %B')}"
title = f"Accumulated {PDICT[ctx['var']]}{extra} after {sdate:%-d %B}"
subtitle = (
f"{ctx['_sname']} ({df['binyear'].min()}-{datetime.date.today().year})"
)
subtitle = f"{ctx['_sname']} ({df['binyear'].min()}-{date.today().year})"
if cullyears:
subtitle += (
f", {len(cullyears)} years excluded due to "
Expand Down Expand Up @@ -254,11 +252,11 @@ def plotter(ctx: dict):
xticks = []
xticklabels = []
for i in range(doy_trunc + 1):
date = sdate + datetime.timedelta(days=i)
if date.day != 1:
dt = sdate + timedelta(days=i)
if dt.day != 1:
continue
xticks.append(i)
xticklabels.append(date.strftime("%b"))
xticklabels.append(dt.strftime("%b"))
ax.set_xlim(0, doy_trunc + 1)
ax.set_ylim(bottom=-0.1)
ax.set_xticks(xticks)
Expand Down
Loading
Loading