<commit_before>from scipy import stats
import psycopg2
import numpy
from pyiem import reference
from pyiem.plot import MapPlot
import matplotlib.pyplot as plt

POSTGIS = psycopg2.connect(database='postgis', user='nobody', host='iemdb')
cursor = POSTGIS.cursor()

lons = []
lats = []
cursor.execute(""" 
  SELECT x(geom), y(geom) from nexrad_attributes_2013
  where nexrad = 'DMX' and tvs != 'NONE'
""")
for row in cursor:
    lons.append( row[0] )
    lats.append( row[1] )
    
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='DMX NEXRAD Tornado Vortex Signature Kernel Density Estimate',
            subtitle='Jan 2013- May 2013')

m.pcolormesh(X, Y, Z, numpy.arange(0,1,.1), cmap=plt.cm.gist_earth_r,
            latlon=True)

xs, ys = m.map(-93.72, 41.72)
m.ax.scatter(xs, ys, marker='o', zorder=20, s=50, color='k')

#xs, ys = m.map(lons, lats)
#m.ax.scatter(xs, ys, marker='+', zorder=20, s=100, color='k')

m.drawcounties()
m.postprocess(filename='test.png')

"""

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,
                  reference.IA_NORTH])
ax.plot(lons, lats, 'k.', markersize=2)
ax.set_title("2013 Des Moines NEXRAD MESO Kernel Density Estimate")
fig.savefig('test.png')<commit_msg>26 jun feature<commit_after>from scipy import stats
import psycopg2
import numpy
from pyiem import reference
from pyiem.plot import MapPlot
import matplotlib.pyplot as plt

POSTGIS = psycopg2.connect(database='postgis', user='nobody', host='iemdb')
cursor = POSTGIS.cursor()

lons = []
lats = []
cursor.execute(""" 
  SELECT x(geom), y(geom), valid from nexrad_attributes_log
  where nexrad in ('DMX','ARX','DVN','OAX','FSD','EAX','MPX') and tvs != 'NONE'
""")
minvalid = None
maxvalid = None
for row in cursor:
    if minvalid is None or row[2] < minvalid:
        minvalid = row[2]
    if maxvalid is None or row[2] > maxvalid:
        maxvalid = row[2]
    lons.append( row[0] )
    lats.append( row[1] )
    
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,
                  reference.IA_NORTH])
ax.plot(lons, lats, 'k.', markersize=2)
ax.set_title("2013 Des Moines NEXRAD MESO Kernel Density Estimate")
fig.savefig('test.png')
{'fraction_non_alphanumeric': 0.16530054644808742, 'fraction_numerical': 0.03579234972677595, 'mean_word_length': 3.9339622641509435, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5989251', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1427, 'n_words': 287}