Exemplo n.º 1
0
def plotter(fdict):
    """ Go """
    ctx = get_autoplot_context(fdict, get_description())
    if ctx["sz"] < 5:
        ctx["sz"] = 5
    if ctx["hours"] > 300:
        ctx["hours"] = 300
    endts = ctx["endts"]
    basets = endts - datetime.timedelta(hours=ctx["hours"])
    # Retrieve available obs
    df = load_data(ctx, basets, endts)
    # figure out our grid bounds
    ctx["bnds2163"] = compute_grid_bounds(ctx)
    # add zeros and QC
    df = add_zeros(df, ctx)
    # do gridding
    df2 = df[df[USEME]]
    lons, lats, vals = do_analysis(df2, ctx)

    rng = [0.01, 1, 2, 3, 4, 6, 8, 12, 18, 24, 30, 36]
    cmap = nwssnow()
    if ctx["t"] == "cwa":
        sector = "cwa"
    else:
        sector = "state" if len(ctx["csector"]) == 2 else ctx["csector"]

    mp = MapPlot(
        sector=sector,
        state=ctx["csector"],
        cwa=(ctx["wfo"] if len(ctx["wfo"]) == 3 else ctx["wfo"][1:]),
        axisbg="white",
        title=("NWS Local Storm Report%s Snowfall Total Analysis") %
        (" & COOP" if ctx["coop"] == "yes" else "", ),
        subtitle=("%.0f reports over past %.0f hours till %s, "
                  "grid size: %.0fkm, Rbf: %s"
                  "" % (
                      len(df2.index),
                      ctx["hours"],
                      endts.strftime("%d %b %Y %I:%M %p"),
                      ctx["sz"],
                      ctx["f"],
                  )),
    )
    if df2["val"].max() > 0 and ctx["p"] in ["both", "contour"]:
        mp.contourf(lons,
                    lats,
                    vals,
                    rng,
                    cmap=cmap,
                    clip_on=(ctx["t"] != "cwa"))
        # Allow analysis to bleed outside the CWA per request.
        if ctx["t"] == "cwa":
            mp.draw_mask(sector="conus")
            mp.draw_cwas(linewidth=2)
    mp.drawcounties()
    if not df.empty and ctx["p"] in ["both", "plot"]:
        df2 = df[df["plotme"]]
        mp.plot_values(
            df2["lon"].values,
            df2["lat"].values,
            df2["val"].values,
            fmt="%.1f",
            labelbuffer=2,
        )
    if ctx["z"] == "plot":
        df2 = df[df["state"] == "Z"]
        if not df2.empty:
            mp.plot_values(
                df2["lon"].values,
                df2["lat"].values,
                df2["state"].values,
                fmt="%s",
                color="#FF0000",
                labelbuffer=0,
            )
    mp.drawcities()
    return mp.fig, df.drop(["geo", "plotme"], axis=1)