Skip to content

Commit

Permalink
📝 Autoplot updates
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Jan 10, 2025
1 parent 0c9232d commit 9109294
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 110 deletions.
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p63.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
expect to set 365 records the first year, 183 the second, and so on...
"""

import datetime
from datetime import datetime

import pandas as pd
from pyiem.database import get_dbconnc
Expand Down Expand Up @@ -37,7 +37,7 @@ def plotter(ctx: dict):
pgconn, cursor = get_dbconnc("coop")
syear = sts.year if sts.month == 1 and sts.day == 1 else (sts.year + 1)
syear = max(syear, 1893)
eyear = datetime.datetime.now().year
eyear = datetime.now().year

cursor.execute(
"""
Expand Down
12 changes: 5 additions & 7 deletions pylib/iemweb/autoplot/scripts/p64.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

import calendar
import datetime
from datetime import date, datetime, timedelta

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_data(ctx):
if ab is None:
raise NoDataFound("No Data Found.")
syear = max(1893, ab.year)
eyear = datetime.datetime.now().year
eyear = datetime.now().year

snow = np.zeros((eyear - syear + 1, 366))
snowd = np.zeros((eyear - syear + 1, 366))
Expand Down Expand Up @@ -112,9 +112,7 @@ def get_data(ctx):
color = "b"
else:
color = "r"
dt = datetime.date(year, 1, 1) + datetime.timedelta(
days=(int(idx) + 183 - 1)
)
dt = date(year, 1, 1) + timedelta(days=(int(idx) + 183 - 1))
rows.append(
dict(
year=year,
Expand Down Expand Up @@ -184,7 +182,7 @@ def plotter(ctx: dict):
)
fig = figure(title=title, apctx=ctx)
plot_yearly_trend(fig, df)
ax = fig.add_axes([0.08, 0.11, 0.36, 0.79])
ax = fig.add_axes((0.08, 0.11, 0.36, 0.79))

ax.scatter(
df["snow_doy"],
Expand Down Expand Up @@ -212,7 +210,7 @@ def plotter(ctx: dict):
ax.grid(True)
ax.set_ylim(bottom=0)
ax2 = ax.twinx()
ptile = np.percentile(df["snow_doy"].values, np.arange(100))
ptile = np.percentile(df["snow_doy"].to_numpy(), np.arange(100))
ax2.plot(ptile, np.arange(100), lw=2, color="k")
ax2.set_ylabel(
("Frequency of %s Date (CDF) [%%] (black line)")
Expand Down
8 changes: 4 additions & 4 deletions pylib/iemweb/autoplot/scripts/p65.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import calendar
import datetime
from datetime import date, datetime, timedelta

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand All @@ -19,7 +19,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()
desc["arguments"] = [
ARG_STATION,
dict(
Expand All @@ -44,8 +44,8 @@ def plotter(ctx: dict):
station = ctx["station"]
month = ctx["month"]
mydir = ctx["dir"]
ts = datetime.datetime(2000, month, 1)
ets = ts + datetime.timedelta(days=35)
ts = datetime(2000, month, 1)
ets = ts + timedelta(days=35)
ets = ets.replace(day=1)
days = int((ets - ts).days)

Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p67.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import calendar
import datetime
from datetime import datetime

import matplotlib.patheffects as PathEffects
import pandas as pd
Expand Down Expand Up @@ -88,7 +88,7 @@ def plotter(ctx: dict):
f"{ctx['_sname']}\n"
f"Frequency of {threshold}+ knot Wind Speeds by Temperature "
f"for {calendar.month_name[month]} "
f"({ab.year}-{datetime.datetime.now().year})\n"
f"({ab.year}-{datetime.now().year})\n"
"(must have 3+ hourly observations at the given temperature)"
)
(fig, ax) = figure_axes(title=title, apctx=ctx)
Expand Down
8 changes: 4 additions & 4 deletions pylib/iemweb/autoplot/scripts/p71.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
is computed by vector averaging of the wind speed and direction reports.
"""

import datetime
from datetime import date, datetime

import matplotlib.patheffects as PathEffects
import numpy as np
Expand Down Expand Up @@ -46,13 +46,13 @@ def get_description():
dict(
type="year",
name="year",
default=datetime.datetime.now().year,
default=datetime.now().year,
label="Select Year:",
),
dict(
type="month",
name="month",
default=datetime.datetime.now().month,
default=datetime.now().month,
label="Select Month:",
),
dict(
Expand Down Expand Up @@ -88,7 +88,7 @@ def plotter(ctx: dict):
plot_units = ctx["units"]
year = ctx["year"]
month = ctx["month"]
sts = datetime.date(year, month, 1)
sts = date(year, month, 1)
with get_sqlalchemy_conn("iem") as conn:
df = pd.read_sql(
"""
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p72.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plots for a single county/zone/parish at a time.
"""

import datetime
from datetime import datetime

import pandas as pd
from pyiem.database import get_sqlalchemy_conn
Expand Down Expand Up @@ -142,7 +142,7 @@ def plotter(ctx: dict):
elif ctx["season"] == "winter":
months = [12, 1, 2]
else:
ts = datetime.datetime.strptime(f"2000-{ctx['season']}-01", "%Y-%b-%d")
ts = datetime.strptime(f"2000-{ctx['season']}-01", "%Y-%b-%d")
months = [ts.month]

tzname = ctx["_nt"].sts[wfo]["tzname"]
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p75.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Simple plot of seasonal/yearly precipitation totals.
"""

import datetime
from datetime import datetime

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -76,7 +76,7 @@ def plotter(ctx: dict):
pgconn.close()
raise NoDataFound("No Data Found.")

today = datetime.datetime.now()
today = datetime.now()
thisyear = today.year
if season == "spring" and today.month > 5:
thisyear += 1
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p79.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
relative humidity value is computed.
"""

import datetime
from datetime import datetime

import matplotlib.ticker as mticker
import metpy.calc as mcalc
Expand Down Expand Up @@ -170,7 +170,7 @@ def plotter(ctx: dict):
titles = [
f"{ctx['_sname']}:: ",
f"Average Dew Point by Wind Direction (month={month.upper()}) "
f"({max([1973, ab.year])}-{datetime.datetime.now().year})",
f"({max([1973, ab.year])}-{datetime.now().year})",
"(must have 3+ hourly obs >= 3 knots at given direction)",
]
ax.set_title("\n".join(titles), size=10)
Expand Down
16 changes: 8 additions & 8 deletions pylib/iemweb/autoplot/scripts/p87.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

import calendar
import datetime
from datetime import date

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -64,7 +64,7 @@ def get_description():
dict(
type="year",
name="eyear",
default=datetime.date.today().year,
default=date.today().year,
label="End Year of Analysis (inclusive):",
),
]
Expand All @@ -77,8 +77,8 @@ def plotter(ctx: dict):
syear = ctx["syear"]
eyear = ctx["eyear"]
groupby = ctx["groupby"]
sts = datetime.date(syear, 1, 1)
ets = datetime.date(eyear + 1, 1, 1)
sts = date(syear, 1, 1)
ets = date(eyear + 1, 1, 1)
code = ctx["code"]
if code == "PSN":
code = "+SN"
Expand Down Expand Up @@ -148,8 +148,8 @@ def plotter(ctx: dict):
f"{PDICT2[groupby].replace('group ', '')}"
)
fig = figure(apctx=ctx, title=title)
ax = fig.add_axes([0.11, 0.25, 0.7, 0.65])
cax = fig.add_axes([0.82, 0.04, 0.02, 0.15])
ax = fig.add_axes((0.11, 0.25, 0.7, 0.65))
cax = fig.add_axes((0.82, 0.04, 0.02, 0.15))

res = ax.imshow(
data, aspect="auto", rasterized=True, interpolation="nearest"
Expand All @@ -163,7 +163,7 @@ def plotter(ctx: dict):
ax.set_ylabel(f"Local Time, {ctx['_nt'].sts[station]['tzname']}")
ax.set_yticklabels(("Mid", "4 AM", "8 AM", "Noon", "4 PM", "8 PM"))
ax.grid(True)
lax = fig.add_axes([0.11, 0.1, 0.7, 0.15])
lax = fig.add_axes((0.11, 0.1, 0.7, 0.15))
if groupby == "week":
ax.set_xticks(np.arange(0, 55, 7))
lax.bar(np.arange(0, 52), np.ma.sum(data, 0), facecolor="tan")
Expand Down Expand Up @@ -198,7 +198,7 @@ def plotter(ctx: dict):
lax.yaxis.get_major_ticks()[-1].label1.set_visible(False)

# Right grid
rax = fig.add_axes([0.81, 0.25, 0.15, 0.65])
rax = fig.add_axes((0.81, 0.25, 0.15, 0.65))
rax.barh(np.arange(0, 24) - 0.4, np.ma.sum(data, 1), facecolor="tan")
rax.set_ylim(-0.5, 23.5)
rax.set_yticks([])
Expand Down
4 changes: 2 additions & 2 deletions pylib/iemweb/autoplot/scripts/p88.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
reliable/comparable.
"""

import datetime
from datetime import date

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -92,7 +92,7 @@ def plotter(ctx: dict):
raise NoDataFound("Unknown station metadata.")
title = (
f"{ctx['_sname']} "
f"({max([ab.year, 1973])}-{datetime.date.today().year})\n"
f"({max([ab.year, 1973])}-{date.today().year})\n"
f"Hourly Temp Departure (skies were {PDICT[ctx['which']]} vs all)"
)
(fig, ax) = figure_axes(title=title, apctx=ctx)
Expand Down
Loading

0 comments on commit 9109294

Please sign in to comment.