本文整理汇总了Python中pyiem.plot.MapPlot.fill_cwas方法的典型用法代码示例。如果您正苦于以下问题:Python MapPlot.fill_cwas方法的具体用法?Python MapPlot.fill_cwas怎么用?Python MapPlot.fill_cwas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyiem.plot.MapPlot
的用法示例。
在下文中一共展示了MapPlot.fill_cwas方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def main():
"""Go Main"""
df = get_database_data()
print(df)
vals = {}
labels = {}
for wfo, row in df.iterrows():
if wfo == 'JSJ':
wfo = 'SJU'
vals[wfo] = row['percent']
labels[wfo] = '%.0f%%' % (row['percent'], )
#if row['count'] == 0:
# labels[wfo] = '-'
bins = np.arange(0, 101, 10)
#bins = [1, 25, 50, 75, 100, 125, 150, 200, 300]
#bins = [-50, -25, -10, -5, 0, 5, 10, 25, 50]
# bins[0] = 1
#clevlabels = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N']
cmap = plt.get_cmap('PuOr')
mp = MapPlot(sector='nws', continentalcolor='white', figsize=(12., 9.),
title=("2018 Percentage of Time with 1+ Flood Warning Active"),
subtitle=('1 January - 30 September 2018, based on IEM archives'))
mp.fill_cwas(vals, bins=bins, lblformat='%s', labels=labels,
cmap=cmap, ilabel=True, # clevlabels=clevlabels,
units='percent')
mp.postprocess(filename='test.png')
示例2: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def main():
"""Go MAin"""
df = pd.read_csv('flood_emergencies.csv')
df2 = df[['source', 'eventid', 'phenomena', 'significance', 'year']
].drop_duplicates()
gdf = df2.groupby('source').count()
vals = {}
labels = {}
for wfo, row in gdf.iterrows():
if wfo == 'TJSJ':
wfo = 'SJU'
else:
wfo = wfo[1:]
vals[wfo] = int(row['eventid'])
labels[wfo] = "%s" % (row['eventid'], )
bins = list(range(0, 31, 3))
bins[0] = 1.
cmap = plt.get_cmap('plasma_r')
cmap.set_over('black')
cmap.set_under('white')
mp = MapPlot(sector='nws', continentalcolor='white', figsize=(12., 9.),
title=("2003-2018 Flash Flood Emergency Events"),
subtitle=('based on unofficial IEM archives, searching '
'"FFS", "FLW", "FFS".'))
mp.fill_cwas(vals, bins=bins, lblformat='%s', labels=labels,
cmap=cmap, ilabel=True, # clevlabels=month_abbr[1:],
units='count')
mp.postprocess(filename='test.png')
示例3: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def plotter(fdict):
""" Go """
import matplotlib
matplotlib.use('agg')
from pyiem.plot import MapPlot
utc = datetime.datetime.utcnow()
bins = [0, 1, 14, 31, 91, 182, 273, 365, 730, 1460, 2920, 3800]
pgconn = psycopg2.connect(database='postgis', host='iemdb', user='nobody')
cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
phenomena = fdict.get('phenomena', 'TO')
significance = fdict.get('significance', 'W')
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))
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)
m = MapPlot(sector='nws', axisbg='white', nocaption=True,
title='Days since Last %s %s by NWS Office' % (
vtec._phenDict.get(phenomena, phenomena),
vtec._sigDict.get(significance, significance)),
subtitle='Valid %s' % (utc.strftime("%d %b %Y %H%M UTC"),))
m.fill_cwas(data, bins=bins, ilabel=True, units='Days',
lblformat='%.0f')
return m.fig, df
示例4: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def main():
"""Go Main Go"""
cursor = POSTGIS.cursor()
cursor2 = POSTGIS.cursor()
phenomena = 'WS'
cursor.execute("""
SELECT ugc, issue, init_expire, wfo from warnings where phenomena = %s and
significance = 'A' and issue > '2005-10-01' ORDER by issue ASC
""", (phenomena, ))
total = cursor.rowcount
print('Events is %s' % (total, ))
hits = {}
hits2 = {}
totals = {}
misses = 0
for row in tqdm(cursor, total=total):
wfo = row[3]
if wfo not in hits:
hits[wfo] = {}
if wfo not in totals:
totals[wfo] = 0
totals[wfo] += 1
cursor2.execute("""
SELECT distinct phenomena, significance from warnings
where ugc = %s and expire > %s and issue < %s and wfo = %s
""", (row[0], row[1], row[2], wfo))
for row2 in cursor2:
key = "%s.%s" % (row2[0], row2[1])
if key not in hits[wfo]:
hits[wfo][key] = 0
hits[wfo][key] += 1
if key not in hits2:
hits2[key] = 0
hits2[key] += 1
if cursor2.rowcount == 0:
misses += 1
data = {}
for wfo in hits:
data[wfo] = hits[wfo].get(
'%s.W' % (phenomena,), 0) / float(totals[wfo]) * 100.0
mp = MapPlot(sector='nws', axisbg='white',
title=("Conversion [%] of Winter Storm Watch "
"Counties/Parishes into Winter Storm Warnings"),
titlefontsize=14,
subtitle=('1 Oct 2005 - 29 Mar 2018, Overall %s/%s %.1f%%'
) % (hits2['%s.W' % (phenomena, )], total,
hits2['%s.W' % (phenomena, )] / float(total) * 100.))
mp.fill_cwas(data, ilabel=True, lblformat='%.0f')
mp.postprocess(filename='test.png')
print('Misses %s %.1f%%' % (misses, misses / float(total) * 100.0))
for key in hits2:
print('%s %s %.1f%%' % (key, hits2[key],
hits2[key] / float(total) * 100.0))
示例5: plot
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def plot():
"""Make a pretty plot"""
df = pd.read_csv('wfo.csv')
df.set_index('wfo', inplace=True)
m = MapPlot(sector='conus',
title="Percentage of Flash Flood Watches receiving 1+ FFW",
subtitle='PRELIMINARY PLOT! Please do not share :)')
cmap = plt.get_cmap('jet')
df2 = df[df['freq'].notnull()]
m.fill_cwas(df2['freq'].to_dict(), cmap=cmap, units='%',
lblformat='%.0f', ilabel=True)
m.postprocess(filename='test.png')
m.close()
示例6: make_map
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def make_map():
"""Generate a map plot"""
df = pd.read_csv('vertex_intersects.csv')
gdf = df.groupby('wfo').sum()
allvals = (gdf['allhits'] - gdf['cwahits']) / gdf['verticies'] * 100.
avgv = ((gdf['allhits'].sum() - gdf['cwahits'].sum()) /
gdf['verticies'].sum() * 100.)
mp = MapPlot(sector='nws', continentalcolor='white',
title=('Percent of SVR+TOR Warning Vertices within 2km '
'of County Border'),
subtitle=('1 Oct 2007 through 29 Mar 2018, '
'Overall Avg: %.1f%%, * CWA Borders Excluded'
) % (avgv,))
mp.fill_cwas(allvals.to_dict(), ilabel=True, lblformat='%.0f')
mp.postprocess(filename='test.png')
示例7: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def plotter(fdict):
""" Go """
import matplotlib
matplotlib.use('agg')
from pyiem.plot import MapPlot
bins = [0, 1, 14, 31, 91, 182, 273, 365, 730, 1460, 2920, 3800]
pgconn = psycopg2.connect(database='postgis', host='iemdb', user='nobody')
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 None:
edate = datetime.datetime.utcnow()
else:
edate = datetime.datetime(edate.year, edate.month,
edate.day, 0, 0)
edate = edate.replace(tzinfo=pytz.timezone("UTC"))
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))
if cursor.rowcount == 0:
return ("No Events Found for %s %s (%s.%s)"
) % (vtec._phenDict.get(phenomena, phenomena),
vtec._sigDict.get(significance, 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)
m = MapPlot(sector='nws', axisbg='white', nocaption=True,
title='Days since Last %s %s by NWS Office' % (
vtec._phenDict.get(phenomena, phenomena),
vtec._sigDict.get(significance, significance)),
subtitle='Valid %s' % (edate.strftime("%d %b %Y %H%M UTC"),))
m.fill_cwas(data, bins=bins, ilabel=True, units='Days',
lblformat='%.0f')
return m.fig, df
示例8: plotter
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def plotter(fdict):
""" Go """
import matplotlib
matplotlib.use('agg')
pgconn = psycopg2.connect(database='postgis', host='iemdb', user='nobody')
ctx = get_autoplot_context(fdict, get_description())
sts = ctx['sdate']
sts = sts.replace(tzinfo=pytz.utc)
ets = ctx['edate']
ets = ets.replace(tzinfo=pytz.utc)
myfilter = ctx['filter']
if myfilter == 'NONE':
tlimiter = ''
elif myfilter == 'NRS':
tlimiter = " and typetext not in ('HEAVY RAIN', 'SNOW') "
else:
tlimiter = " and typetext = '%s' " % (myfilter,)
df = read_sql("""
SELECT wfo, count(*) from lsrs
WHERE valid >= %s and valid < %s """ + tlimiter + """
GROUP by wfo ORDER by wfo ASC
""", pgconn, params=(sts, ets), index_col='wfo')
data = {}
for wfo, row in df.iterrows():
data[wfo] = row['count']
maxv = df['count'].max()
bins = np.linspace(0, maxv, 12, dtype='i')
bins[-1] += 1
p = MapPlot(sector='nws', axisbg='white',
title='Local Storm Report Counts by NWS Office',
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)))
p.fill_cwas(data, bins=bins, ilabel=True)
return p.fig, df
示例9: main
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def main():
"""Go Main"""
vals = {}
for line in data.split("\n"):
wfo, valid = line.strip().split("|")
wfo = wfo.strip()
year = valid.strip()[:4]
wfo = wfo[1:]
if wfo == 'JSJ':
wfo = 'SJU'
vals[wfo] = int(year)
print(vals)
#bins = [1, 25, 50, 75, 100, 125, 150, 200, 300]
bins = np.arange(2002, 2019, 2)
cmap = plt.get_cmap('PuOr')
mp = MapPlot(sector='nws', continentalcolor='white', figsize=(12., 9.),
title=("Year of Last RWS Text Product Issuance"),
subtitle=('based on IEM archives'))
mp.fill_cwas(vals, bins=bins, lblformat='%s', # , labels=labels,
cmap=cmap, ilabel=True, # clevlabels=clevlabels,
units='Year')
mp.postprocess(filename='test.png')
示例10: float
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
from pyiem.plot import MapPlot
import pandas as pd
df = pd.read_csv('vertex.csv', index_col='WFO', na_values=['None'])
df['r'] = (df['CNTY_HITS'] - df['CWA_HITS']) / df['ALL'] * 100.
avgv = (df['CNTY_HITS'] - df['CWA_HITS']).sum() / float(df['ALL'].sum()) * 100.
m = MapPlot(sector='nws', axisbg='white',
title='Percent of SVR+TOR Warning Vertices within 2km of County Border',
subtitle='1 Oct 2007 through 23 May 2016, Overall Avg: %.1f%%, * CWA Borders Excluded' % (avgv,))
m.fill_cwas(df['r'], ilabel=True, lblformat='%.0f')
m.postprocess(filename='test.png')
示例11: test_plot
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def test_plot():
""" Exercise the API """
mp = MapPlot(sector='midwest', nocaption=True)
mp.fill_cwas({'DMX': 80, 'MKX': 5, 'SJU': 30, 'AJK': 40},
units='no units')
return mp.fig
示例12: len
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
data = {}
labels = {}
uniq = []
for line in text.split("\n"):
tokens = line.replace(" ", "").split("|")
wfo = tokens[0][1:]
if tokens[0][0] == 'P':
wfo = tokens[0]
key = "%s" % (tokens[1], )
if not nt.sts.has_key(wfo):
continue
# P
wfo = tokens[0][1:]
if not key in uniq:
uniq.append( key )
data[ wfo ] = len(uniq) -1
labels[ wfo ] = key
if wfo == 'JSJ':
labels['SJU'] = labels['JSJ']
bins = range(len(uniq)+1)
uniq.append('')
p = MapPlot(sector='nws', axisbg='white',
title="2009-2013 Most Frequently issued non-SHEF 3char AWIPS ID",
subtitle='RR* products were excluded from this analysis')
p.fill_cwas(data, bins=bins, labels=labels, lblformat='%s', clevlabels=uniq)
p.postprocess(filename='test.png')
#import iemplot
#iemplot.makefeature('test')
示例13: float
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
cursor2.execute("""
SELECT distinct phenomena, significance from warnings_temp
where ugc = %s and expire > %s and issue < %s and wfo = %s
""", (row[0], row[1], row[2], wfo))
for row2 in cursor2:
key = "%s.%s" % (row2[0], row2[1])
if key not in hits[wfo]:
hits[wfo][key] = 0
hits[wfo][key] += 1
if key not in hits2:
hits2[key] = 0
hits2[key] += 1
if cursor2.rowcount == 0:
misses += 1
data = {}
for wfo in hits.keys():
data[wfo] = hits[wfo].get(
'%s.W' % (phenomena,), 0) / float(totals[wfo]) * 100.0
m = MapPlot(sector='nws', axisbg='white',
title=("Conversion [%] of Severe T'Storm Watch Counties/Parishes into "
"SVR Warnings"), titlefontsize=14,
subtitle='1 Oct 2005 - 19 May 2016')
m.fill_cwas(data, ilabel=True, lblformat='%.0f')
m.postprocess(filename='test.png')
print 'Misses %s %.1f%%' % (misses, misses / float(total) * 100.0)
for key in hits2.keys():
print '%s %s %.1f%%' % (key, hits2[key], hits2[key] / float(total) * 100.0)
示例14: test_plot2
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def test_plot2():
""" Exercise NWS plot API """
mp = MapPlot(sector='nws', continentalcolor='white', nocaption=True)
mp.fill_cwas({'DMX': 80, 'MKX': 5, 'SJU': 30, 'AJK': 40, 'HFO': 50},
units='NWS Something or Another', ilabel=True)
return mp.fig
示例15: test_plot22
# 需要导入模块: from pyiem.plot import MapPlot [as 别名]
# 或者: from pyiem.plot.MapPlot import fill_cwas [as 别名]
def test_plot22():
"""plot cwas that are filled"""
mp = MapPlot(sector='iowa', continentalcolor='white', nocaption=True)
mp.fill_cwas({'DMX': 80, 'MKX': 5, 'SJU': 30, 'AJK': 40, 'HFO': 50},
units='NWS Something or Another')
return mp.fig