Ejemplo n.º 1
0
def run(base, ceil, now, fn):
    """ Generate the plot """
    # Compute normal from the climate database
    sql = """SELECT station,
       sum(gddxx(%s, %s, high, low)) as gdd
       from alldata_ia WHERE year = %s and month in (5,6,7,8,9,10)
       and station != 'IA0000' and substr(station,2,1) != 'C'
       GROUP by station""" % (base, ceil, now.year)

    lats = []
    lons = []
    gdd50 = []
    ccursor.execute( sql )
    for row in ccursor:
        if not nt.sts.has_key(row[0]):
            continue
        lats.append( nt.sts[row[0]]['lat'] )
        lons.append( nt.sts[row[0]]['lon'] )
        gdd50.append( row[1] )

    cfg = {
 'wkColorMap': 'BlAqGrYeOrRe',
 'nglSpreadColorStart': 2,
 'nglSpreadColorEnd'  : -1,
 '_showvalues'        : True,
 '_format'            : '%.0f',
 '_title'             : "Iowa 1 May - %s GDD Accumulation" % (
                        now.strftime("%-d %B %Y"), ),
 'lbTitleString'      : "base %s" % (base,),
}
    # Generates tmp.ps
    tmpfp = iemplot.simple_contour(lons, lats, gdd50, cfg)

    pqstr = "plot c 000000000000 summary/%s.png bogus png" % (fn,)
    iemplot.postprocess(tmpfp, pqstr)
Ejemplo n.º 2
0
def do_month(ts, routes='m'):
    """
    Generate the plot for a given month, please
    """
    sql = """SELECT station, sum(precip) as total, max(day) as lastday
           from alldata_ia WHERE year = %s and month = %s
           and station != 'IA0000' and substr(station,2,1) != 'C'
           GROUP by station""" % (ts.year, ts.month)

    lats = []
    lons = []
    vals = []
    lastday = None
    ccursor.execute( sql )
    for row in ccursor:
        if not nt.sts.has_key(row['station']):
            continue
        if lastday is None:
            lastday = row['lastday']
        lats.append( nt.sts[row['station']]['lat'] )
        lons.append( nt.sts[row['station']]['lon'] )
        vals.append( row['total'] )
        
    cfg = {
     'wkColorMap': 'WhiteBlueGreenYellowRed',
     '_valid'    : '%s - %s' % (now.strftime("%d %B %Y"), lastday.strftime("%d %B %Y")),
     '_title'    : "%s Total Precipitation [inch]" % (now.strftime("%B %Y"),),
     'lbTitleString': 'inch',
     '_showvalues': True,
     '_format' : '%.2f',
     }

    tmpfp = iemplot.simple_contour(lons, lats, vals, cfg)
    pqstr = "plot %s %s summary/iemre_iowa_total_precip.png %s/summary/iemre_iowa_total_precip.png png" % (
                                    routes, ts.strftime("%Y%m%d%H%M"), 
                                                              ts.strftime("%Y/%m"),)
    iemplot.postprocess(tmpfp, pqstr)
Ejemplo n.º 3
0
valmask = []
labels = []
icursor.execute(sql)
for row in icursor:
  lats.append( row[2] )
  lons.append( row[1] )
  vals.append( row[3] )
  labels.append( row[0] )
  valmask.append( row[4] in ['AWOS', 'IA_ASOS'] )


cfg = {
 'wkColorMap': 'BlAqGrYeOrRe',
 '_showvalues'        : True,
 '_valuemask'         :   valmask,
 'lbTitleString'    : 'F',
 '_format'            : '%.0f',
 '_title'             : "Iowa Morning Low Temperature",
 '_valid'             : "%s" % (now.strftime("%d %b %Y"), ),
 '_labels'            : labels,
# '_midwest'		: True,
}
# Generates tmp.ps
tmpfp = iemplot.simple_contour(lons, lats, vals, cfg)

pqstr = "plot ac %s summary/iowa_asos_high.png iowa_asos_high.png png" % (
        now.strftime("%Y%m%d%H%M"), )
iemplot.postprocess(tmpfp, pqstr)
#iemplot.makefeature(tmpfp)

Ejemplo n.º 4
0
   from alldata_ia WHERE year = %s and month = %s
   GROUP by station""" % (now.year, now.month)

lats = []
lons = []
sdd86 = []
valmask = []
ccursor.execute( sql )
for row in ccursor:
  lats.append( nt.sts[row[0]]['lat'] )
  lons.append( nt.sts[row[0]]['lon'] )
  sdd86.append( row[1] )
  valmask.append( True )

cfg = {
 'wkColorMap': 'BlAqGrYeOrRe',
 'nglSpreadColorStart': 2,
 'nglSpreadColorEnd'  : -1,
 '_showvalues'        : True,
 '_valueMask'         : valmask,
 '_format'            : '%.0f',
 '_title'             : "Iowa %s SDD Accumulation" % (
                        now.strftime("%B %Y"), ),
 'lbTitleString'      : "[base 86]",
}
# Generates tmp.ps
tmpfp = iemplot.simple_contour(lons, lats, sdd86, cfg)

pqstr = "plot c 000000000000 summary/sdd_mon.png bogus png"
iemplot.postprocess(tmpfp, pqstr)
Ejemplo n.º 5
0
icursor.execute(""" 
 WITH data as 
 (SELECT iemid,  min(wcht(tmpf::numeric, (sknt*1.15)::numeric)) from current_log WHERE tmpf > -50 and sknt >= 0 GROUP by iemid)

 SELECT ST_x(geom), ST_y(geom), d.min, t.network, t.id from data d JOIN stations t 
 ON (t.iemid = d.iemid)
 WHERE t.state in ('IA','MN','WI','ND','SD','NE','KS','MO','IL','IN','MI','OH','KY') and (t.network = 'AWOS' or t.network ~* 'ASOS')
 and t.id not in ('DKB', 'M30', 'CIR', 'EKQ', 'SME', 'P58')
 ORDER by d.min ASC
 """)
lats = []
lons = []
data = []
for row in icursor:
    print '%s %s %.1f' % (row[3], row[4], row[2])
    data.append( row[2] )
    lats.append( row[1] + (random.random()*0.001))
    lons.append( row[0] )
    
cfg = {
       '_midwest': True,
       'lbTitleString': '[F]',
       '_title': '5-6 January 2014 Minimum Wind Chill',
       #'_showvalues': True,
       #'_format': '%.0f',
       }

fp = iemplot.simple_contour(lons, lats, data, cfg)
#iemplot.postprocess(fp,'','')
iemplot.makefeature(fp)
Ejemplo n.º 6
0
            final_vals.append( 0.0 )
        else:
            final_vals.append( max(lvals) )
    else:
        final_vals.append( max(lvals) )
    final_lats.append( lat )
    final_lons.append( lon )
#"""
# Analysis and plot, please
cfg = {
 'wkColorMap': 'WhiteBlueGreenYellowRed',
 'nglSpreadColorStart': 2,
 'nglSpreadColorEnd'  : -1,
 '_title'             : "24 March 2013 - IEM Snowfall Total Analysis",
 '_valid'             : "Snowfall totals up until 8 AM 25 Mar 2013",
 #'_MaskZero'          : True,
 'lbTitleString'      : "[in]",
  '_showvalues'        : False,
 'cnLevelSelectionMode': "ExplicitLevels",
 'cnLevels' : [0.01,0.1,0.25,0.5,1,2,3,5,7,9,11,13,15,17],

 '_format'            : '%.0f',
 '_midwest'         : False,
}
# Generates tmp.ps
tmpfp = iemplot.simple_contour(final_lons, final_lats, final_vals, cfg)
pqstr = "plot c 000000000000 lsr_snowfall.png bogus png"
thumbpqstr = "plot c 000000000000 lsr_snowfall_thumb.png bogus png"
#iemplot.postprocess(tmpfp,pqstr, thumb=True, thumbpqstr=thumbpqstr)
iemplot.makefeature(tmpfp)
Ejemplo n.º 7
0
    #if row[5] != "IA":
    #    continue
    ccursor.execute("""
    SELECT max_high from climate where station = %s and valid = '2000-01-05'
    """, (row[0],))
    row2 = ccursor.fetchone()
    off = row[3] - row2[0]
    if row[4] == 'ABR':
        print row[4], row[3], row2[0], off
    diff.append( off )
    lats.append( row[2] )
    lons.append( row[1] )
    
import iemplot

cfg = {
       '_title': '5 Jan 2012 High Temperature Departure from Record High',
       '_valid': 'ASOS/AWOS Observations compared against long term climate',
      '_showvalues': True,
      '_format': '%.0f',
      'wkColorMap' : "BlWhRe",
      'cnLevelSelectionMode' : 'ManualLevels',
      'cnLevelSpacingF'      : 2,
     'cnMinLevelValF'       : -15,
     'cnMaxLevelValF'       : 15,
     'lbTitleString' : '[F]',
     '_midwest': True,
       }

tmpfp = iemplot.simple_contour(lons, lats, diff, cfg)
iemplot.makefeature(tmpfp)
Ejemplo n.º 8
0
    station = row[0]
    if not st.sts.has_key(station):
        continue
    lats.append( st.sts[station]['lat'] )
    lons.append( st.sts[station]['lon'] )
    gdd50.append( row[1] )
    valmask.append( True )

cfg = {
 'wkColorMap': 'BlAqGrYeOrRe',
 'nglSpreadColorStart': 2,
 'nglSpreadColorEnd'  : -1,
 '_showvalues'        : True,
 '_valueMask'         : valmask,
 '_format'            : '%.0f',
 '_title'             : "Iowa %s GDD (base=%s) Accumulation" % (
                        now.strftime("%Y"), gbase),
 '_valid'          : "1 Jan - %s" % (
                        now.strftime("%d %b %Y"), ),
 'lbTitleString'      : "[base %s] " % (gbase,),
}
# Generates tmp.ps
tmpfp = iemplot.simple_contour(lons, lats, gdd50, cfg)

pqstr = "plot c 000000000000 summary/gdd_jan1.png bogus png"
if gbase == 52:
  pqstr = "plot c 000000000000 summary/gdd52_jan1.png bogus png"
elif gbase == 48:
  pqstr = "plot c 000000000000 summary/gdd48_jan1.png bogus png"
iemplot.postprocess(tmpfp, pqstr)
Ejemplo n.º 9
0
                flons.append( lon )
                flats.append( lat )
                fvals.append( 0.0 )
                fmask.append( False )



cfg = {
 'wkColorMap': 'WhiteBlueGreenYellowRed',
 'nglSpreadColorStart': 2,
 'nglSpreadColorEnd'  : -1,
 '_valuemask'         : fmask,
 '_title'             : "Local Storm Report Snowfall Total Analysis",
 '_valid'             : "Reports past 12 hours: "+ now.strftime("%d %b %Y %I:%M %p"),
 '_showvalues'        : True,
 '_format'            : '%.1f',
 '_MaskZero'          : True,
 'lbTitleString'      : "[in]",
}
# Generates tmp.ps
tmpfp = iemplot.simple_contour(flons, flats, fvals, cfg)
pqstr = "plot c 000000000000 lsr_snowfall.png bogus png"
thumbpqstr = "plot c 000000000000 lsr_snowfall_thumb.png bogus png"
iemplot.postprocess(tmpfp,pqstr, thumb=True, thumbpqstr=thumbpqstr)

cfg['_midwest'] = True
cfg['_showvalues'] = False
tmpfp = iemplot.simple_contour(flons, flats, fvals, cfg)
pqstr = "plot c 000000000000 mw_lsr_snowfall.png bogus png"
iemplot.postprocess(tmpfp,pqstr)
Ejemplo n.º 10
0
def doit(now):
  """
  Generate some plots for the COOP data!
  """
  # We'll assume all COOP data is 12z, sigh for now
  sql = """SELECT id, pday, network
           from summary_%s s JOIN stations t ON (t.iemid = s.iemid) WHERE day = '%s' and
           t.network ~* 'COOP' and pday >= 0""" % (now.year,
           now.strftime("%Y-%m-%d") )

  lats = []
  lons = []
  vals = []
  #labels = []
  icursor.execute( sql )
  iamax = 0.
  for row in icursor:
    id = row[0]
    if not st.sts.has_key(id):
      continue
    #labels.append( id[2:] )
    lats.append( st.sts[id]['lat'] )
    lons.append( st.sts[id]['lon'] )
    vals.append( row[1] )
    if row[2] == 'IA_COOP' and row[1] > iamax:
        iamax = row[1]


  if iamax == 0:
      # Dummy in some bad data to prevent the contouring from going mad
      lats.append( 42. )
      lons.append( -96.0 )
      vals.append( 1. )
    
  # Plot Iowa
  cfg = {
     'wkColorMap': 'BlAqGrYeOrRe',
     'nglSpreadColorStart': -1,
     'nglSpreadColorEnd'  : 2,
     '_MaskZero'          : True,
     'lbTitleString'      : "[inch]",
     '_valid'    : 'Ending %s at roughly 12Z' % (now.strftime("%d %B %Y"),),
     '_title'    : "24 Hour NWS COOP Precipitation [inch]",
  }

  tmpfp = iemplot.simple_contour(lons, lats, vals, cfg)
  pqstr = "plot ac %s0000 iowa_coop_12z_precip.png iowa_coop_12z_precip.png png" % (ts.strftime("%Y%m%d"),)
  iemplot.postprocess(tmpfp, pqstr)

  # Plot Midwest
  cfg = {
     'wkColorMap': 'BlAqGrYeOrRe',
     'nglSpreadColorStart': -1,
     'nglSpreadColorEnd'  : 2,
     '_MaskZero'          : True,
     '_midwest'           : True,
     'lbTitleString'      : "[inch]",
     '_valid'    : 'Ending %s at roughly 12Z' % (now.strftime("%d %B %Y"),),
     '_title'    : "24 Hour NWS COOP Precipitation [inch]",
  }

  tmpfp = iemplot.simple_contour(lons, lats, vals, cfg)
  pqstr = "plot ac %s0000 midwest_coop_12z_precip.png midwest_coop_12z_precip.png png" % (ts.strftime("%Y%m%d"),)
  iemplot.postprocess(tmpfp, pqstr)
Ejemplo n.º 11
0
def doit(now, model):
    # Figure out the model runtime we care about
    mcursor.execute("""
    SELECT max(runtime) from alldata where station = 'KDSM'
    and ftime = %s and model = %s
    """, (now.strftime("%Y-%m-%d %H:00"), model))
    row = mcursor.fetchone()
    runtime = row[0]
    if runtime is None:
        sys.exit()
    #print "Model Runtime used: %s" % (runtime,)

    # Load up the mos forecast for our given 
    mcursor.execute("""
      SELECT station, tmp FROM alldata
    WHERE model = %s and runtime = %s and ftime = %s and tmp < 999
    """, (model, runtime, now.strftime("%Y-%m-%d %H:00") ))
    forecast = {}
    for row in mcursor:
        if row[0][0] == 'K':
            forecast[ row[0][1:] ] = row[1]

    # Load up the currents!
    icursor.execute("""
SELECT 
  s.id, s.network, tmpf, x(s.geom) as lon, y(s.geom) as lat
FROM 
  current c, stations s
WHERE
  c.iemid = s.iemid and
  (s.network ~* 'ASOS' or s.network = 'AWOS') and 
  valid + '60 minutes'::interval > now() and
  tmpf > -50
    """)

    lats = []
    lons = []
    vals = []
    valmask = []
    for row in icursor:
        if not forecast.has_key( row[0] ):
            continue

        diff = forecast[row[0]] - row[2]
        if diff > 20 or diff < -20:
            mcursor2.execute("""
            INSERT into large_difference(model, valid, station, ob, mos)
            VALUES (%s, %s, %s, %s, %s)
            """, (model, now.strftime("%Y-%m-%d %H:00"), row[0], row[2],
                    forecast[row[0]]))
            continue
        lats.append( row[4] )
        lons.append( row[3] )
        vals.append( diff )
        valmask.append(  (row[1] in ['AWOS','IA_AWOS']) )

    cfg = {
 'wkColorMap': 'BlAqGrYeOrRe',
 'nglSpreadColorStart': 2,
 'nglSpreadColorEnd'  : -1,
 '_title'             : "%s MOS Temperature Bias " % (model,),
 '_midwest'     : True,
 '_valid'             : 'Model Run: %s Forecast Time: %s' % (
                                runtime.strftime("%d %b %Y %-I %p"), 
                                now.strftime("%d %b %Y %-I %p")),
# '_showvalues'        : True,
 '_format'            : '%.0f',
# '_valuemask'         : valmask,
 'lbTitleString'      : "[F]",
}
    # Generates tmp.ps
    fp = iemplot.simple_contour(lons, lats, vals, cfg)
    pqstr = "plot ac %s00 %s_mos_T_bias.png %s_mos_T_bias_%s.png png" % (
                now.gmtime().strftime("%Y%m%d%H"), model.lower(),
                model.lower(), now.gmtime().strftime("%H"))
    iemplot.postprocess(fp,pqstr)
    
    del(cfg['_midwest'])
    cfg['_conus'] = True
    fp = iemplot.simple_contour(lons, lats, vals, cfg)
    pqstr = "plot ac %s00 conus_%s_mos_T_bias.png conus_%s_mos_T_bias_%s.png png" % (
                now.gmtime().strftime("%Y%m%d%H"), model.lower(),
                model.lower(), now.gmtime().strftime("%H"))
    iemplot.postprocess(fp,pqstr)