def get2(station): acursor.execute(""" SELECT date(valid), max(tmpf), max(dwpf) from t2012 where station = '%s' and extract(hour from valid + '10 minutes'::interval) = 16 and extract(minute from valid) > 50 and valid > '2012-07-01' GROUP by date ORDER by date ASC """ % (station,)) tmpf = [] dwpf = [] feel = [] for row in acursor: tmpf.append( row[1]) dwpf.append( row[2]) feel.append( mesonet.heatidx(row[1], mesonet.relh(row[1], row[2]))) return tmpf, dwpf, feel
def computeOthers(d): r = {} # Need something to compute other values needed for output for sid in d.keys(): ob = d[sid].data ob["ticks"] = int(ob["ts"]) ob["sped"] = ob["sknt"] * 1.17 if ob.get('tmpf') is not None and ob.get('dwpf') is not None: ob["relh"] = mesonet.relh(ob["tmpf"], ob["dwpf"]) else: ob['relh'] = None if ob['relh'] == 'M': ob['relh'] = None if (ob.get('tmpf') is not None and ob.get('dwpf') is not None and ob.get('sped') is not None): ob["feel"] = mesonet.feelslike(ob["tmpf"], ob["relh"], ob["sped"]) else: ob['feel'] = None if ob['feel'] == 'M': ob['feel'] = None ob["altiTend"] = altiTxt(ob["alti_15m"]) ob["drctTxt"] = mesonet.drct2dirTxt(ob["drct"]) if ob["max_drct"] is None: ob["max_drct"] = 0 ob["max_drctTxt"] = mesonet.drct2dirTxt(ob["max_drct"]) ob["20gu"] = 0 ob["gmph"] = ob["gust"] * 1.17 ob["max_sped"] = ob["max_gust"] * 1.17 ob["gtim"] = "0000" ob["gtim2"] = "12:00 AM" if ob["max_gust_ts"] is not None and ob["max_gust_ts"] != "null": ob["gtim"] = ob["max_gust_ts"].strftime("%H%M") ob["gtim2"] = ob["max_gust_ts"].strftime("%-I:%M %p") r[sid] = ob return r
if val.mask: return 'M' except: pass return "%5.1f" % (val,) for sid in indices: idx = indices[sid]['idx'] name = nc.variables["stationName"][idx].tostring().replace('\x00','') latitude = nc.variables['latitude'][idx] longitude = nc.variables['longitude'][idx] tmpf = s( nc.variables['temperature'][idx] ) dwpf = s( nc.variables['dewpoint'][idx] ) heat = "M" if tmpf != "M" and dwpf != "M": relh = mesonet.relh(mesonet.k2f(nc.variables['temperature'][idx]), mesonet.k2f(nc.variables['dewpoint'][idx])) heat = "%5.1f" % (mesonet.heatidx(mesonet.k2f(nc.variables['temperature'][idx]), relh),) drct = s2( nc.variables['windDir'][idx]) smps = s2( nc.variables['windSpeed'][idx]) sped = "M" if smps != "M": sped = "%5.1f" % (nc.variables['windSpeed'][idx] * 2.23694,) wcht = "M" if tmpf != "M" and sped != "M": wcht = "%5.1f" % (mesonet.wchtidx(mesonet.k2f(nc.variables['temperature'][idx]), nc.variables['windSpeed'][idx] * 2.23694),) ts = indices[sid]['ts'] out.write("%5.5s %25.25s %8.4f %10.4f %02i %02i %5s %5s %5s %5s %5s %5s\n" % (sid, name, latitude,
snow = row[1] day = row[0] acursor.execute(""" SELECT valid, tmpf, dwpf, p01i from alldata WHERE station = 'DSM' and valid BETWEEN '%s'::timestamp - '2 days'::interval and '%s 23:49'::timestamp + '2 days'::interval ORDER by valid ASC """ % (day, day)) valid = [] relh = [] tmpf = [] dwpf = [] t0 = None for row in acursor: tmpf.append( row[1]) dwpf.append( row[2]) relh.append( mesonet.relh(row[1], row[2]) ) valid.append( row[0] ) if (t0 is None and row[3] >= 0.01 and row[1] <= 34 and row[0].day != valid[0].day): t0 = row[0] print day, t0, snow if t0 is None: continue x = [] for v in valid: diff = (v - t0).days * 86400 + (v - t0).seconds x.append(diff) ax.plot( x, tmpf) for i in range(len(x)): if x[i] > -100600:
import iemdb ASOS = iemdb.connect('iem', bypass=True) acursor = ASOS.cursor() import mx.DateTime import numpy import network nt = network.Table(("IA_ASOS", 'AWOS')) acursor.execute("""SELECT t.id, valid, tmpf, dwpf from current_log c JOIN stations t on (t.iemid = c.iemid) WHERE t.network in ('IA_ASOS','AWOS') and valid BETWEEN '2012-09-04' and '2012-09-05' and tmpf > 0 and dwpf > 0 """) maxes = {} for row in acursor: h = mesonet.heatidx(row[2], mesonet.relh(row[2], row[3])) maxes[row[0]] = max(h, maxes.get(row[0], 0)) vals = [] lons = [] lats = [] for sid in maxes.keys(): vals.append( maxes[sid]) lons.append( nt.sts[sid]['lon'] ) lats.append( nt.sts[sid]['lat'] ) cfg = {'wkColorMap': 'WhiteYellowOrangeRed', '_title': '4 Sep 2012 ASOS/AWOS Maximum Heat Index', 'lbTitleString': 'F', '_showvalues': True, '_format': '%.0f'
def main(): print "Content-type: text/plain \n\n", form = cgi.FormContent() metadata = {} mcursor.execute("""SELECT id, x(geom) as lon, y(geom) as lat from stations WHERE network ~* 'ASOS' or network = 'AWOS' and country = 'US' """) for row in mcursor: metadata[row[0]] = {'lon': "%.4f" % (row[1],), 'lat': "%.4f" % (row[2],)} year = int(form["year"][0]) month = int(form["month"][0]) day = int(form["day"][0]) hour = int(form["hour"][0]) ts = mx.DateTime.DateTime(year, month, day, hour) queryCols = "tmpf, dwpf, relh, drct, sknt, p01i, alti, mslp, vsby, gust, skyc1, skyc2, skyc3, skyc4, skyl1, skyl2, skyl3, skyl4, metar" outCols = ['tmpf','dwpf','relh', 'drct','sknt','p01i','alti','mslp', 'vsby', 'gust', 'skyc1', 'skyc2', 'skyc3', 'skyc4', 'skyl1', 'skyl2', 'skyl3', 'skyl4', 'metar'] queryStr = """SELECT * from t%s WHERE valid >= '%s' and valid < '%s' ORDER by station ASC""" % (ts.year, (ts - mx.DateTime.RelativeDateTime(minutes=10)).strftime("%Y-%m-%d %H:%M"), (ts + mx.DateTime.RelativeDateTime(minutes=1)).strftime("%Y-%m-%d %H:%M")) rD = "," acursor.execute("SET TIME ZONE 'GMT' ") #print queryStr acursor.execute( queryStr ) print "station"+rD+"valid (UTC timezone)"+rD+"lon"+rD+"lat"+rD, print queryCols for row in acursor: if not metadata.has_key(row['station']): continue sys.stdout.write( row["station"] + rD ) sys.stdout.write( row["valid"].strftime("%Y-%m-%d %H:%M") + rD ) sys.stdout.write( metadata[row['station']]['lon'] + rD ) sys.stdout.write( metadata[row['station']]['lat'] + rD ) for data1 in outCols: if data1 == 'relh': val = mesonet.relh( row['tmpf'], row['dwpf'] ) if val != "M": sys.stdout.write("%.2f%s" % (val, rD)) else: sys.stdout.write("M%s" % (rD,)) elif data1 == 'p01m': if row['p01i'] >= 0: sys.stdout.write("%.2f%s" % (row['p01i'] * 25.4, rD)) else: sys.stdout.write("M%s" % (rD,)) elif data1 == 'tmpc': if row['tmpf'] is not None: val = mesonet.f2c( row['tmpf'] ) sys.stdout.write("%.2f%s" % (val, rD)) else: sys.stdout.write("M%s" % (rD,)) elif data1 == 'dwpc': if row['dwpf'] is not None: val = mesonet.f2c( row['dwpf'] ) sys.stdout.write("%.2f%s" % (val, rD)) else: sys.stdout.write("M%s" % (rD,)) elif data1 in ["metar","skyc1","skyc2","skyc3","skyc4"]: sys.stdout.write("%s%s" % (row[data1], rD)) elif row[ data1 ] is None or row[ data1 ] <= -99.0 or row[ data1 ] == "M": sys.stdout.write("M%s" % (rD,)) else: sys.stdout.write("%2.2f%s" % (row[ data1 ], rD)) print