def draw(self): ''' For debugging, draw the polygons!''' from descartes.patch import PolygonPatch from pyiem.plot import MapPlot for sig in self.sigmets: m = MapPlot(sector='conus') x, y = m.map(sig.geom.exterior.xy[0], sig.geom.exterior.xy[1]) patch = PolygonPatch(Polygon(zip(x, y)), fc='r', label='Outlook') m.ax.add_patch(patch) fn = '/tmp/%s.png' % (sig.label,) print ':: creating plot %s' % (fn,) m.postprocess(filename=fn) m.close()
def draw(self): ''' For debugging, draw the polygons!''' from descartes.patch import PolygonPatch from pyiem.plot import MapPlot for sig in self.sigmets: m = MapPlot(sector='conus') x, y = m.map(sig.geom.exterior.xy[0], sig.geom.exterior.xy[1]) patch = PolygonPatch(Polygon(zip(x, y)), fc='r', label='Outlook') m.ax.add_patch(patch) fn = '/tmp/%s.png' % (sig.label, ) print(':: creating plot %s' % (fn, )) m.postprocess(filename=fn) m.close()
def main(): """Go Main Go.""" pgconn = get_dbconn('iem') df = read_sql("""SELECT ST_x(geom) as x, ST_y(geom) as y, min(min_tmpf) as val, state, count(*) from summary s JOIN stations t on (t.iemid = s.iemid) WHERE s.day > '2018-09-01' and min_tmpf is not null and t.country = 'US' and t.network ~* 'COOP' and t.state in ('IA', 'MN', 'ND', 'SD', 'NE', 'KS', 'MO', 'WI', 'IL', 'IN', 'OH', 'MI', 'KY') GROUP by y, x, state ORDER by val ASC""", pgconn, index_col=None) df = df[(df['count'] > 110)] x3 = df[(df.val < 32) & (df.val >= 10)] x2 = df[(df.val < 10) & (df.val > -10)] x1 = df[(df.val < -10) & (df.val > -30)] x0 = df[df.val < -30] m = MapPlot(title='Fall 2016 Minimum Temperature Reports', axisbg='white', subtitle=('Based on NWS Cooperative Observer Data, ' 'thru 27 Dec 2016'), sector='midwest') x, y = m.map(tuple(x3.x), tuple(x3.y)) m.map.scatter(x, y, marker='o', color='g', s=50, zorder=1, label="10 to 32$^\circ$F") x, y = m.map(tuple(x2.x), tuple(x2.y)) m.map.scatter(x, y, marker='s', color='b', zorder=1, s=50, label="-10 to 10$^\circ$F") x, y = m.map(tuple(x1.x), tuple(x1.y)) m.map.scatter(x, y, marker='+', color='r', s=50, zorder=2, label="-30 to -10$^\circ$F") x, y = m.map(tuple(x0.x), tuple(x0.y)) m.map.scatter(x, y, marker='v', facecolor='w', edgecolor='k', s=50, zorder=2, label="Sub -30$^\circ$F") m.ax.legend(loc=4, scatterpoints=1, ncol=4) m.postprocess(filename='test.png')
for key in cnts.keys(): if key[2] == 'C' or key == 'IA0000': continue lons.append( nt.sts[key]['lon'] ) lats.append( nt.sts[key]['lat'] ) vals.append( cnts[key] ) m = MapPlot(sector='iowa', title='10 Sept 2013 US Drought Monitor', subtitle=r"Count of 30 / 60 / 90 / 120 Day Standardized Precip Index below -1.2 (D2+) $\sigma$") m.plot_values(lons, lats, vals, textsize=18) colors = ['#f6eb13', '#ffcc66', '#ff9900', '#ff3333', '#FF00FF'] classes = ['D0: Abnormal', 'D1: Moderate', 'D2: Severe'] m.map.readshapefile('dm_current', 'dm', ax=m.ax) for nshape, seg in enumerate(m.map.dm): cat = m.map.dm_info[nshape]['DM'] poly=Polygon(seg, fc=colors[cat], ec='k', lw=.4, zorder=3) m.ax.add_patch(poly) x,y = m.map(hole[:,0], hole[:,1]) poly=Polygon(zip(x,y), fc='w', ec='k', lw=.4, zorder=3) m.ax.add_patch(poly) for i in range(len(classes)): m.fig.text(0.9, 0.91 + ((i*2.5) /100.0), "%s" % (classes[i],), ha='right', color=colors[i], fontsize=14) m.postprocess(filename='test.ps') import iemplot iemplot.makefeature('test')
t.network ~* 'COOP' and t.state in ('IA', 'MN', 'ND', 'SD', 'NE', 'KS', 'MO', 'WI', 'IL', 'IN', 'OH', 'MI', 'KY') GROUP by st_y, st_x ORDER by min ASC""") res = [] for row in cursor: res.append(dict(val=row[2], x=row[0], y=row[1])) df = pd.DataFrame(res) x35 = df[(df.val < 36) & (df.val >= 32)] x32 = df[(df.val < 32) & (df.val > 28)] x29 = df[df.val < 29] m = MapPlot(title='Fall 2015 Minimum Temperature Reports', axisbg='white', subtitle='Based on NWS Cooperative Observer Data, thru 7 Oct 2015', sector='midwest') x, y = m.map(tuple(x35.x), tuple(x35.y)) m.map.scatter(x, y, marker='o', color='g', s=50, zorder=1, label="Sub 36$^\circ$F") x, y = m.map(tuple(x32.x), tuple(x32.y)) m.map.scatter(x, y, marker='s', zorder=1, s=50, label="Sub 32$^\circ$F") x, y = m.map(tuple(x29.x), tuple(x29.y)) m.map.scatter(x, y, marker='+', color='r', s=50, zorder=2, label="Sub 29$^\circ$F") m.ax.legend(loc=4, scatterpoints=1) m.postprocess(filename='test.png')
cursor.execute("""SELECT ST_x(geom), ST_y(geom), min(min_tmpf) from summary_2014 s JOIN stations t on (t.iemid = s.iemid) WHERE s.day > '2014-05-12' and min_tmpf > 0 and t.country = 'US' and t.network ~* 'COOP' GROUP by st_y, st_x ORDER by min ASC""") res = [] for row in cursor: res.append( dict(val=row[2], x=row[0], y=row[1]) ) df = pd.DataFrame(res) x32 = df[(df.val<32)&(df.val>28)] x29 = df[df.val<29] m = MapPlot(title='13-19 May 2014 Freezing Reports', subtitle='Based on NWS Cooperative Observer Data', sector='midwest') x,y = m.map(x32.x, x32.y) m.map.scatter(x,y, marker='s',zorder=1, label="Sub 32$^\circ$F") x,y = m.map(x29.x, x29.y) m.map.scatter(x,y, marker='+', color='r', s=40, zorder=2, label="Sub 29$^\circ$F") m.ax.legend(loc=4, scatterpoints=1) m.postprocess(filename='test.ps') import iemplot iemplot.makefeature('test')
res = [] for row in cursor: res.append(dict(val=row[2], x=row[0], y=row[1])) df = pd.DataFrame(res) x35 = df[(df.val < 36) & (df.val >= 32)] x32 = df[(df.val < 32) & (df.val > 28)] x29 = df[df.val < 29] m = MapPlot(title='Fall 2015 Minimum Temperature Reports', axisbg='white', subtitle='Based on NWS Cooperative Observer Data, thru 7 Oct 2015', sector='midwest') x, y = m.map(tuple(x35.x), tuple(x35.y)) m.map.scatter(x, y, marker='o', color='g', s=50, zorder=1, label="Sub 36$^\circ$F") x, y = m.map(tuple(x32.x), tuple(x32.y)) m.map.scatter(x, y, marker='s', zorder=1, s=50, label="Sub 32$^\circ$F") x, y = m.map(tuple(x29.x), tuple(x29.y)) m.map.scatter(x, y, marker='+', color='r', s=50,
clons = [] clats = [] for row in pcursor: clats.append( row['lat'] ) clons.append( row['lon'] ) cobs = nn(clons, clats) #cobs = griddata((lons, lats), soil_obs, (clons, clats)) m = MapPlot(sector='iowa', title="Iowa 4in Soil Temperatures %s" % (ts.strftime("%b %d %Y"), ), subtitle='Based on gridded analysis of ISUAG, ISUSM network observations' ) m.contourf(clons, clats, cobs, np.arange(10,101,5), cmap=cm.get_cmap('jet'), units=r'$^\circ$F') for lo, la, ob in zip(clons, clats, cobs): #for lo, la, ob in zip(lons, lats, soil_obs): xi, yi = m.map(lo, la) txt = m.ax.text(xi, yi, "%.0f" % (ob,)) m.drawcounties() m.postprocess(filename='highs.ps') os.system("convert -trim highs.ps obs.png") routes = "a" if day_ago < 4: routes = "ac" os.system("/home/ldm/bin/pqinsert -p 'plot %s %s0000 soilt_day%s.png isuag_county_4inch_soil.png png' obs.png" % ( routes, ts.strftime("%Y%m%d"), day_ago) ) os.unlink('highs.ps') os.unlink('obs.png')
if (m.map.roads_info[nshape]['US1'] in (69,30) or m.map.roads_info[nshape]['INT1'] == 35): data = np.array( seg ) m.ax.plot(data[:,0], data[:,1], lw=2, linestyle='--',color='k', zorder=3) m.map.readshapefile('cities', 'cities', ax=m.ax) for nshape, seg in enumerate(m.map.cities): if m.map.cities_info[nshape]['NAME10'] != 'Ames': continue poly=Polygon(seg, fc='None', ec='k', lw=1.5, zorder=3) m.ax.add_patch(poly) nc = netCDF4.Dataset('narr-a_221_20100626_0300_000.grb.nc') lats = nc.variables['lat'][:] lons = nc.variables['lon'][:] pcpn = nc.variables['Total_precipitation'][0,:,:] / 24.5 mask = lons > -100.0 n1p = [0,0.01,0.1,0.3,0.5,0.8,1.0,1.3,1.5,1.8,2.0,2.5,3.0,4.0,6.0,8.0] m.pcolormesh(lons, lats, pcpn, n1p, latlon=True) xx, yy = m.map(-93.62, 41.99) txt = m.ax.text(xx, yy, "%.2f" % (0.19,) , zorder=5, ha='center', va='center', fontsize=20) txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="w")]) m.postprocess(filename='test.png')
sector='iowa', title= 'Amount of additional June precipitation needed to break local record', subtitle='1-23 June 2014 totals shown') for row in data: #cursor.execute("""SELECT year, sum(precip) from alldata_ia where month =6 #and year < 2014 and station = %s #GROUP by year ORDER by sum DESC LIMIT 1""", (nt.sts[row[0]]['climate_site'],) ) #row2 = cursor.fetchone() #ratio = row[1] / row2[1] * 360. #print row[0], row[1], row2[1], ratio ratio = min(row[1] / row[2] * 360., 360.) xy = m.map(nt.sts[row[0]]['lon'], nt.sts[row[0]]['lat']) patches.append( Wedge(xy, 20000, 0, ratio, width=10000, fc='b', fill=True, zorder=2)) print "%.0f" % (ratio / 360. * 100., ), ratio / 360.0 remaining = max(0, row[2] - row[1]) txt = m.ax.text(xy[0], xy[1], "%.2f" % (remaining, ), fontsize=24, color='yellow', ha='center', va='center') txt.set_path_effects( [PathEffects.withStroke(linewidth=2, foreground="purple")]) txt = m.ax.text(xy[0],
X, Y = numpy.mgrid[reference.IA_WEST:reference.IA_EAST:100j, reference.IA_SOUTH:reference.IA_NORTH:100j] positions = numpy.vstack([X.ravel(), Y.ravel()]) values = numpy.vstack([lons, lats]) kernel = stats.gaussian_kde(values) Z = numpy.reshape(kernel(positions).T, X.shape) m = MapPlot(sector='iowa', title='NEXRAD Tornado Vortex Signature Reports', subtitle='%s - %s, (TVS storm attribute present)' % (minvalid.strftime("%d %b %Y"), maxvalid.strftime("%d %b %Y"))) #m.pcolormesh(X, Y, Z, numpy.arange(0,.11,.01), cmap=plt.cm.gist_earth_r, # latlon=True) xs, ys = m.map([-93.72,-96.37,-91.18,-90.57,-96.72], [41.72,41.32,43.82,41.6,43.58]) m.ax.scatter(xs, ys, marker='o', zorder=20, s=100, color='r') xs, ys = m.map(lons, lats) m.ax.scatter(xs, ys, marker='+', zorder=20, s=40, color='k') m.drawcounties() m.postprocess(filename='test.svg') import iemplot iemplot.makefeature('test') """ fig = plt.figure()
m = MapPlot(sector='iowa', title='Amount of additional June precipitation needed to break local record', subtitle='1-23 June 2014 totals shown') for row in data: #cursor.execute("""SELECT year, sum(precip) from alldata_ia where month =6 #and year < 2014 and station = %s #GROUP by year ORDER by sum DESC LIMIT 1""", (nt.sts[row[0]]['climate_site'],) ) #row2 = cursor.fetchone() #ratio = row[1] / row2[1] * 360. #print row[0], row[1], row2[1], ratio ratio = min(row[1] / row[2] * 360., 360.) xy = m.map(nt.sts[row[0]]['lon'], nt.sts[row[0]]['lat']) patches.append( Wedge(xy, 20000, 0, ratio, width=10000, fc='b', fill=True, zorder=2) ) print "%.0f" % (ratio/360. * 100.,), ratio / 360.0 remaining = max(0, row[2] - row[1]) txt = m.ax.text(xy[0], xy[1], "%.2f" % (remaining,), fontsize=24, color='yellow', ha='center', va='center') txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="purple")]) txt = m.ax.text(xy[0], xy[1]-12000, "%s" % (row[3],), fontsize=14, ha='center', va='center') txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="yellow")])
X, Y = numpy.mgrid[reference.IA_WEST:reference.IA_EAST:100j, reference.IA_SOUTH:reference.IA_NORTH:100j] positions = numpy.vstack([X.ravel(), Y.ravel()]) values = numpy.vstack([lons, lats]) kernel = stats.gaussian_kde(values) Z = numpy.reshape(kernel(positions).T, X.shape) m = MapPlot(sector='iowa', title='NEXRAD Tornado Vortex Signature Reports', subtitle='%s - %s, (TVS storm attribute present)' % (minvalid.strftime("%d %b %Y"), maxvalid.strftime("%d %b %Y"))) #m.pcolormesh(X, Y, Z, numpy.arange(0,.11,.01), cmap=plt.cm.gist_earth_r, # latlon=True) xs, ys = m.map([-93.72, -96.37, -91.18, -90.57, -96.72], [41.72, 41.32, 43.82, 41.6, 43.58]) m.ax.scatter(xs, ys, marker='o', zorder=20, s=100, color='r') xs, ys = m.map(lons, lats) m.ax.scatter(xs, ys, marker='+', zorder=20, s=40, color='k') m.drawcounties() m.postprocess(filename='test.svg') import iemplot iemplot.makefeature('test') """ fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(numpy.rot90(Z), cmap=plt.cm.gist_earth_r, extent=[reference.IA_WEST,reference.IA_EAST, reference.IA_SOUTH,
lons, lats = np.meshgrid( lons1x, lats1x) res = m.pcolormesh(lons, lats, data, n1p, latlon=True, units='inch') ys = np.digitize([41.965,42.085], lats1x) xs = np.digitize([-93.7,-93.55], lons1x) for x in range(xs[0], xs[1], 3): for y in range(ys[1], ys[0], 3): xx, yy = m.map(lons1x[x] + 0.0025, lats1x[y] - 0.0025) txt = m.ax.text(xx, yy, "%s" % (data[y,x],) , zorder=5, ha='center', va='center') txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="w")]) print np.average( data[ys[1]:ys[0],xs[0]:xs[1]] ) """ grbs = pygrib.open('ST4.2010062605.01h.grib') g = grbs.message(1) data = g['values'] / 25.4 lats, lons = g.latlons() n1p = [0,0.01,0.1,0.3,0.5,0.8,1.0,1.3,1.5,1.8,2.0,2.5,3.0,4.0,6.0,8.0] m.pcolormesh(lons, lats, data, n1p, latlon=True) for lo, la, val in zip(lons[np.logical_and(np.logical_and(np.logical_and(lats > 41.965, lats < 42.085),lons > -93.7), lons < -93.55)], lats[np.logical_and(np.logical_and(np.logical_and(lats > 41.965, lats < 42.085),lons > -93.7), lons < -93.55)], data[np.logical_and(np.logical_and(np.logical_and(lats > 41.965, lats < 42.085),lons > -93.7), lons < -93.55)]): xx, yy = m.map(lo + 0.02, la + 0.02) txt = m.ax.text(xx, yy, "%.2f" % (val,) , zorder=5, ha='center', va='center', fontsize=20) txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="w")]) m.postprocess(filename='test.png')
SELECT ST_Transform(simple_geom, 4326), (scenario_loss - baseline_loss) / 8.0 as val, i.huc_12 from huc12 i JOIN agg d on (d.huc_12 = i.huc_12) WHERE i.states ~* 'IA' ORDER by val DESC """, (scenario, )) # bins = np.arange(0, 101, 10) bins = [-25, -10, -5, -2, 0, 2, 5, 10, 25] cmap = plt.get_cmap("BrBG_r") cmap.set_under('purple') cmap.set_over('black') norm = mpcolors.BoundaryNorm(bins, cmap.N) patches = [] for row in cursor: # print "%s,%s" % (row[2], row[1]) polygon = loads(row[0].decode('hex')) a = np.asarray(polygon.exterior) x, y = m.map(a[:, 0], a[:, 1]) a = zip(x, y) c = cmap(norm([float(row[1]), ]))[0] p = Polygon(a, fc=c, ec='None', zorder=2, lw=.1) patches.append(p) m.ax.add_collection(PatchCollection(patches, match_original=True)) m.draw_colorbar(bins, cmap, norm, units='T/a') m.drawcounties() m.postprocess(filename='test.png')
""") bins = np.arange(0, 18, 2) # cmap = cm.get_cmap('BrBG') # cmap.set_under('orange') # cmap.set_over('black') cmap = james() cmap.set_under("white") cmap.set_over("black") norm = mpcolors.BoundaryNorm(bins, cmap.N) patches = [] for row in cursor: geom = loads(row[0].decode("hex")) for polygon in geom: a = np.asarray(polygon.exterior) x, y = m.map(a[:, 0], a[:, 1]) a = zip(x, y) # c = cmap( norm([float(row[1]),]) )[0] diff = data.get(row[1], 0) - data1.get(row[1], 0) diff = data.get(row[1], 0) c = cmap(norm([float(diff)]))[0] p = Polygon(a, fc=c, ec="None", zorder=2, lw=0.1) patches.append(p) m.ax.add_collection(PatchCollection(patches, match_original=True)) m.draw_colorbar(bins, cmap, norm, units="%") m.drawcounties() m.postprocess(filename="test.png")
m.map.readshapefile('cities', 'cities', ax=m.ax) for nshape, seg in enumerate(m.map.cities): if m.map.cities_info[nshape]['NAME10'] != 'Ames': continue poly=Polygon(seg, fc='None', ec='k', lw=1.5, zorder=3) m.ax.add_patch(poly) nc = netCDF4.Dataset('3B42.100626.6.6A.nc') lats = nc.variables['lat'][:] lons = nc.variables['lon'][:] lons, lats = np.meshgrid(lons, lats) pcpn = nc.variables['precipitation'][:,:] / 24.5 * 3 n1p = [0,0.01,0.1,0.3,0.5,0.8,1.0,1.3,1.5,1.8,2.0,2.5,3.0,4.0,6.0,8.0] m.pcolormesh(lons, lats, pcpn, n1p, latlon=True) xx, yy = m.map(-93.6, 42.02) txt = m.ax.text(xx, yy, "%.2f" % (0.65,) , zorder=5, ha='center', va='center', fontsize=20) txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="w")]) xx, yy = m.map(-93.64, 42.02) txt = m.ax.text(xx, yy, "%.2f" % (0.39,) , zorder=5, ha='center', va='center', fontsize=20) txt.set_path_effects([PathEffects.withStroke(linewidth=2, foreground="w")]) m.postprocess(filename='test.png')