def test_fillstates(): """Can we fill states""" data = {'AK': 10, 'HI': 30, 'IA': 40, 'NY': 80} mp = MapPlot(sector='nws', title='Fill AK, HI, IA, NY States', subtitle='test_fillstates', nocaption=True) mp.fill_states(data, ilabel=True) return mp.fig
def plotter(fdict): """ Go """ pgconn = get_dbconn("postgis") ctx = get_autoplot_context(fdict, get_description()) sts = ctx["sdate"] sts = sts.replace(tzinfo=pytz.utc) ets = ctx["edate"] by = ctx["by"] ets = ets.replace(tzinfo=pytz.utc) myfilter = ctx["filter"] if myfilter == "NONE": tlimiter = "" elif myfilter == "NRS": tlimiter = " and typetext not in ('HEAVY RAIN', 'SNOW', 'HEAVY SNOW') " elif myfilter == "CON": tlimiter = (" and typetext in ('TORNADO', 'HAIL', 'TSTM WND GST', " "'TSTM WND DMG') ") else: tlimiter = " and typetext = '%s' " % (myfilter, ) df = read_sql( """ WITH data as ( SELECT distinct wfo, state, valid, type, magnitude, geom from lsrs where valid >= %s and valid < %s """ + tlimiter + """ ) SELECT """ + by + """, count(*) from data GROUP by """ + by + """ """, pgconn, params=(sts, ets), index_col=by, ) data = {} for idx, row in df.iterrows(): if idx == "JSJ": idx = "SJU" data[idx] = row["count"] maxv = df["count"].max() bins = np.linspace(1, maxv, 12, dtype="i") bins[-1] += 1 mp = MapPlot( sector="nws", axisbg="white", title=("Preliminary/Unfiltered Local Storm Report Counts %s") % (PDICT[by], ), subtitlefontsize=10, subtitle=("Valid %s - %s UTC, type limiter: %s") % ( sts.strftime("%d %b %Y %H:%M"), ets.strftime("%d %b %Y %H:%M"), MDICT.get(myfilter), ), ) cmap = plt.get_cmap(ctx["cmap"]) if by == "wfo": mp.fill_cwas(data, bins=bins, cmap=cmap, ilabel=True) else: mp.fill_states(data, bins=bins, cmap=cmap, ilabel=True) return mp.fig, df
def plotter(fdict): """ Go """ pgconn = get_dbconn('postgis') ctx = get_autoplot_context(fdict, get_description()) sts = ctx['sdate'] sts = sts.replace(tzinfo=pytz.utc) ets = ctx['edate'] by = ctx['by'] ets = ets.replace(tzinfo=pytz.utc) myfilter = ctx['filter'] if myfilter == 'NONE': tlimiter = '' elif myfilter == 'NRS': tlimiter = " and typetext not in ('HEAVY RAIN', 'SNOW', 'HEAVY SNOW') " elif myfilter == 'CON': tlimiter = (" and typetext in ('TORNADO', 'HAIL', 'TSTM WND GST', " "'TSTM WND DMG') ") else: tlimiter = " and typetext = '%s' " % (myfilter, ) df = read_sql(""" WITH data as ( SELECT distinct wfo, state, valid, type, magnitude, geom from lsrs where valid >= %s and valid < %s """ + tlimiter + """ ) SELECT """ + by + """, count(*) from data GROUP by """ + by + """ """, pgconn, params=(sts, ets), index_col=by) data = {} for idx, row in df.iterrows(): if idx == 'JSJ': idx = 'SJU' data[idx] = row['count'] maxv = df['count'].max() bins = np.linspace(1, maxv, 12, dtype='i') bins[-1] += 1 mp = MapPlot( sector='nws', axisbg='white', title=('Preliminary/Unfiltered Local Storm Report Counts %s') % (PDICT[by], ), subtitlefontsize=10, subtitle=('Valid %s - %s UTC, type limiter: %s') % (sts.strftime("%d %b %Y %H:%M"), ets.strftime("%d %b %Y %H:%M"), MDICT.get(myfilter))) cmap = plt.get_cmap(ctx['cmap']) if by == 'wfo': mp.fill_cwas(data, bins=bins, cmap=cmap, ilabel=True) else: mp.fill_states(data, bins=bins, cmap=cmap, ilabel=True) return mp.fig, df
from pyiem.plot import MapPlot import pandas as pd import StringIO import matplotlib.pyplot as plt df = pd.read_csv(StringIO.StringIO(txt.replace(" ", "")), sep='|') df.columns = ['states', 'date'] df2 = df.groupby('states').count() data = {} for i, row in df2.iterrows(): data[i] = row['date'] print data m = MapPlot( sector='conus', title='Days with Tornado *Watch* & Winter Storm or Blizzard Warning', subtitle= '1 Oct 2005 - 24 Mar 2016 :: # of Dates with both alerts active within the same state at the same time', axisbg='white') cmap = plt.get_cmap('jet') cmap.set_over('black') cmap.set_under('white') m.fill_states(data, bins=[0, 1, 2, 3, 4, 5, 6, 7, 10, 15, 20], units='count', ilabel=True, cmap=cmap) m.postprocess(filename='states.png')
CO | 2015-11-16 NM | 2015-11-16 TX | 2015-12-26 OK | 2015-12-26 TX | 2015-12-27 GA | 2016-01-22 NE | 2016-03-23 IA | 2016-03-23 KS | 2016-03-23""" from pyiem.plot import MapPlot import pandas as pd import StringIO import matplotlib.pyplot as plt df = pd.read_csv(StringIO.StringIO(txt.replace(" ", "")), sep='|') df.columns = ['states', 'date'] df2 = df.groupby('states').count() data = {} for i, row in df2.iterrows(): data[i] = row['date'] print data m = MapPlot(sector='conus', title='Days with Tornado *Watch* & Winter Storm or Blizzard Warning', subtitle='1 Oct 2005 - 24 Mar 2016 :: # of Dates with both alerts active within the same state at the same time', axisbg='white') cmap = plt.get_cmap('jet') cmap.set_over('black') cmap.set_under('white') m.fill_states(data, bins=[0, 1, 2, 3, 4, 5, 6, 7, 10, 15, 20], units='count', ilabel=True, cmap=cmap) m.postprocess(filename='states.png')