Ejemplo n.º 1
0
def plotter(fdict):
    """ Go """
    bins = [0, 1, 14, 31, 91, 182, 273, 365, 730, 1460, 2920, 3800]
    pgconn = get_dbconn("postgis")
    cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    ctx = get_autoplot_context(fdict, get_description())
    phenomena = ctx["phenomena"]
    significance = ctx["significance"]
    edate = ctx.get("edate")
    if edate is not None:
        edate = utc(edate.year, edate.month, edate.day, 0, 0)
        cursor.execute(
            """
         select wfo,  extract(days from (%s::date - max(issue))) as m
         from warnings where significance = %s and phenomena = %s
         and issue < %s
         GROUP by wfo ORDER by m ASC
        """,
            (edate, significance, phenomena, edate),
        )
    else:
        cursor.execute(
            """
         select wfo,  extract(days from ('TODAY'::date - max(issue))) as m
         from warnings where significance = %s and phenomena = %s
         GROUP by wfo ORDER by m ASC
        """,
            (significance, phenomena),
        )
        edate = datetime.datetime.utcnow()

    if cursor.rowcount == 0:
        raise NoDataFound(("No Events Found for %s (%s.%s)") % (
            vtec.get_ps_string(phenomena, significance),
            phenomena,
            significance,
        ))
    data = {}
    rows = []
    for row in cursor:
        wfo = row[0] if row[0] != "JSJ" else "SJU"
        rows.append(dict(wfo=wfo, days=row[1]))
        data[wfo] = max([row[1], 0])
    df = pd.DataFrame(rows)
    df.set_index("wfo", inplace=True)

    mp = MapPlot(
        sector="nws",
        axisbg="white",
        nocaption=True,
        title="Days since Last %s by NWS Office" %
        (vtec.get_ps_string(phenomena, significance), ),
        subtitle="Valid %s" % (edate.strftime("%d %b %Y %H%M UTC"), ),
    )
    mp.fill_cwas(data, bins=bins, ilabel=True, units="Days", lblformat="%.0f")

    return mp.fig, df
Ejemplo n.º 2
0
def main():
    """Go Main Go."""
    dbconn = get_dbconn("postgis")
    df = read_sql("""
    WITH data as (
        SELECT wfo, eventid, extract(year from issue) as year,
        max(case when svs is not null then 1 else 0 end) as hit from
        warnings where product_issue > '2014-04-01' and
        product_issue < '2019-02-22' and phenomena = 'SV'
        and date(issue) not in ('2017-08-25', '2017-08-26', '2017-08-27',
        '2017-08-28', '2017-08-29', '2017-08-30')
        and significance = 'W' GROUP by wfo, eventid, year
    )
    SELECT wfo, sum(hit) as got_update, count(*) as total_events from data
    GROUP by wfo ORDER by total_events DESC
    """, dbconn, index_col='wfo')
    if 'JSJ' in df.index and 'SJU' not in df.index:
        df.loc['SJU'] = df.loc['JSJ']

    df['no_update_percent'] = (
        100. - df['got_update'] / df['total_events'] * 100.
    )
    df.to_csv("140401_190221_svr_nofls.csv")

    # NOTE: FFW followup is FFS
    mp = MapPlot(
        sector='nws',
        title='Percentage of Severe TStorm Warnings without a SVS Update Issued',
        subtitle=('1 April 2014 - 21 February 2019 (exclude Harvey 26-30 Aug '
                  '2017), based on unofficial data')
    )
    cmap = plt.get_cmap("copper_r")
    cmap.set_under('white')
    cmap.set_over('black')
    ramp = range(0, 101, 5)
    mp.fill_cwas(
        df['no_update_percent'], bins=ramp, cmap=cmap, units='%', ilabel=True,
        lblformat='%.1f'
    )
    mp.postprocess(filename='140401_190221_svr_nosvs.png')
Ejemplo n.º 3
0
def plotter(fdict):
    """ Go """
    fix()
    pgconn = get_dbconn("afos")
    ctx = get_autoplot_context(fdict, get_description())
    pil = ctx["pil"][:3]
    if ctx["ets"].astimezone(pytz.UTC) > utc():
        ctx["ets"] = utc()

    df = read_sql(
        ("SELECT source, pil, min(entered at time zone 'UTC') as first, "
         "max(entered at time zone 'UTC') as last, count(*) from products "
         "WHERE substr(pil, 1, 3) = %s and entered >= %s and entered < %s "
         "GROUP by source, pil ORDER by source, pil ASC"),
        pgconn,
        params=(pil, ctx["sts"], ctx["ets"]),
        index_col=None,
    )
    if df.empty:
        raise NoDataFound("No text products found for query, sorry.")

    data = {}
    if ctx["var"] == "count":
        gdf = df.groupby("source").sum()
    elif ctx["var"] == "last":
        gdf = df.groupby("source").max()
    elif ctx["var"] == "first":
        gdf = df.groupby("source").min()
    minval = 1
    maxval = gdf["count"].max()
    if ctx["var"] in ["last", "first"]:
        minval = gdf[ctx["var"]].min().year
        maxval = gdf[ctx["var"]].max().year
    if (maxval - minval) < 10:
        bins = range(minval - 1, maxval + 2)
    else:
        bins = np.linspace(minval, maxval + 2, 10, dtype="i")
    for source, row in gdf.iterrows():
        if source == "PABR":
            continue
        key = source[1:]
        if key == "JSJ":
            key = "SJU"
        if ctx["var"] == "count":
            data[key] = row["count"]
        else:
            data[key] = row[ctx["var"]].year

    mp = MapPlot(
        title="NWS %s of %s" % (PDICT[ctx["var"]], prodDefinitions[pil]),
        subtitle=("Plot valid between %s UTC and %s UTC, "
                  "based on unofficial IEM Archives") % (
                      ctx["sts"].strftime("%d %b %Y %H:%M"),
                      ctx["ets"].strftime("%d %b %Y %H:%M"),
                  ),
        sector="nws",
        nocaption=True,
    )
    mp.fill_cwas(
        data,
        ilabel=True,
        lblformat="%.0f",
        cmap=ctx["cmap"],
        extend="neither",
        bins=bins,
        units="count" if ctx["var"] == "count" else "year",
    )
    return mp.fig, df