コード例 #1
0
ファイル: genDailyRecords.py プロジェクト: KayneWest/iem
def write(mydb, out, station):
    r = {}
    out.write("""# DAILY RECORD HIGHS AND LOWS OCCURRING DURING %s-%s FOR STATION NUMBER  %s
     JAN     FEB     MAR     APR     MAY     JUN     JUL     AUG     SEP     OCT     NOV     DEC
 DY  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN
""" % (constants.startyear(station), constants._ENDYEAR, station) )
  
    rs = mydb.query("SELECT * from %s WHERE station = '%s'" % (
            constants.climatetable(station), station) ).dictresult()
    for i in range(len(rs)):
        day = mx.DateTime.strptime(rs[i]["valid"], "%Y-%m-%d")
        r[day] = rs[i]

    for day in range(1,32):
        out.write("%3i" % (day,) )
        for mo in range(1,13):
            try:
                ts = mx.DateTime.DateTime(2000, mo, day)
                if not r.has_key(ts):
                    print ("Records missing for table: %s station: %s "
                           +"date: %s") % (constants.climatetable(station),
                                           station, ts.strftime("%b %d"))
                    out.write(" *** ***")
                    continue
            except:
                out.write(" *** ***")
                continue
            if (r[ts]['max_high'] is None or
                r[ts]['min_low'] is None):
                out.write(" *** ***")
                continue
            out.write("%4i%4i" % (r[ts]["max_high"], r[ts]["min_low"]) )
        out.write("\n")
コード例 #2
0
ファイル: genDailyMeans.py プロジェクト: KayneWest/iem
def write(mydb, out, station):
    r = {}
    out.write("""#DAILY MEAN HIGHS AND LOWS FOR STATION NUMBER  %s
    JAN     FEB     MAR     APR     MAY     JUN     JUL     AUG     SEP     OCT     NOV     DEC
DY  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN  MX  MN
""" % (station,) )
  
    rs = mydb.query("SELECT * from %s WHERE station = '%s'" % (
        constants.climatetable(station), station) ).dictresult()
    for i in range(len(rs)):
        day = mx.DateTime.strptime(rs[i]["valid"], "%Y-%m-%d")
        r[day] = rs[i]

    for day in range(1,32):
        out.write("%2i" % (day,) )
        for mo in range(1,13):
            try:
                ts = mx.DateTime.DateTime(2000, mo, day)
            except:
                out.write(" *** ***")
                continue
            if not r.has_key(ts) or r[ts]['high'] is None:
                out.write(" *** ***")
                continue
            out.write("%4i%4i" % (r[ts]["high"], r[ts]["low"]) )
        out.write("\n")
コード例 #3
0
ファイル: genDailyRecordsRain.py プロジェクト: KayneWest/iem
def write(mydb, out, station):
    r = {}
    out.write("""# DAILY MAXIMUM PRECIPITATION FOR STATION NUMBER %s 
     JAN   FEB   MAR   APR   MAY   JUN   JUL   AUG   SEP   OCT   NOV   DEC
""" % (station,) )
  
    rs = mydb.query("SELECT * from %s WHERE station = '%s'" % (
            constants.climatetable(station), station) ).dictresult()
    for i in range(len(rs)):
        day = mx.DateTime.strptime(rs[i]["valid"], "%Y-%m-%d")
        r[day] = rs[i]

    for day in range(1,32):
        out.write("%3i" % (day,) )
        for mo in range(1,13):
            try:
                ts = mx.DateTime.DateTime(2000, mo, day)
            except:
                out.write("  ****")
                continue
            if not r.has_key(ts) or r[ts]['max_precip'] is None:
                out.write("  ****")
                continue
            out.write("%6.2f" % (r[ts]["max_precip"]) )
        out.write("\n")
コード例 #4
0
def process(id, csv):
  # Fetch Yearly Totals
    sql = """SELECT year, round(avg(high)::numeric,1) as avg_high, 
    round(avg(low)::numeric,1) as avg_low, 
    round(sum(precip)::numeric,2) as rain from %s 
    WHERE station = '%s' and year >= %s 
    GROUP by year ORDER by year ASC""" % (constants.get_table(id), 
                                        id, constants.startyear(id) )
    rs = constants.mydb.query(sql).dictresult()
    data = {}
    for i in range(len(rs)):
        year = int(rs[i]["year"])
        data[year] = {'oHigh': rs[i]["avg_high"], 'oLow': rs[i]["avg_low"], 
                  'oRain': rs[i]["rain"]}

    for i in range(1893, constants._ENDYEAR):
        if (not data.has_key(i)):
            data[i] = {'oHigh': "M", 'oLow': "M", 'oRain': "M"}
        csv.write("%s,%s,%s,"%(data[i]['oLow'],data[i]['oHigh'],data[i]['oRain']))

  # Need to do climate stuff
  # Then climate
    sql = """SELECT round(avg(high)::numeric,1) as avg_high,
    round(avg(low)::numeric,1) as avg_low, 
    round(sum(precip)::numeric,2) as rain from %s WHERE station = '%s' """ % (
        constants.climatetable(id), id)
    rs = constants.mydb.query(sql).dictresult()
    aHigh = rs[0]["avg_high"]
    aLow = rs[0]["avg_low"]
    aRain = rs[0]["rain"]
    csv.write("%s,%s,%s," % (aLow,aHigh,aRain) )

    csv.write("\n")
    csv.flush()
コード例 #5
0
ファイル: genDailyRange.py プロジェクト: KayneWest/iem
def go(mydb, rs, stationID):
  s = mx.DateTime.DateTime(2000, 1, 1)
  e = mx.DateTime.DateTime(2001, 1, 1)
  interval = mx.DateTime.RelativeDateTime(days=+1)
  r = {}
  now = s
  while (now < e):
   r[now] = {'max': 0, 'min': 100}
   now += interval

  for i in range(len(rs)):
    valid = mx.DateTime.strptime(rs[i]["day"], "%Y-%m-%d")
    valid += mx.DateTime.RelativeDateTime(year=2000)
    try:
      high = int(rs[i]["high"])
      low = int(rs[i]["low"])
      tr = high - low
    except:
      continue
    if (tr > r[valid]["max"]):
      r[valid]["max"] = tr
    if (tr < r[valid]["min"]):
      r[valid]["min"] = tr

  for day in r.keys():
    sql = "UPDATE %s SET max_range = %s, min_range = %s \
      WHERE station = '%s' and valid = '%s' " % (constants.climatetable(stationID), r[day]["max"], \
      r[day]["min"], stationID, day.strftime("%Y-%m-%d") )
    mydb.query(sql)
コード例 #6
0
def process(id, csv,yr):
    for i in range(1,13):
    # Compute Climate
        sql = """SELECT round(avg(high)::numeric,1) as avg_high,
      round(avg(low)::numeric,1) as avg_low, 
      round(sum(precip)::numeric,2) as rain from %s WHERE station = '%s' and 
      extract(month from valid) = %s""" % (constants.climatetable(id), id, i)
        rs = constants.mydb.query(sql).dictresult()
        aHigh = rs[0]["avg_high"]
        aLow = rs[0]["avg_low"]
        aRain = rs[0]["rain"]

    # Fetch Obs
        sql = """SELECT round(avg_high::numeric,1) as avg_high, 
      round(avg_low::numeric,1) as avg_low, 
      round(rain::numeric,2) as rain from r_monthly WHERE station = '%s' 
      and monthdate = '%s-%02i-01'""" % (id, yr, i)
        rs = constants.mydb.query(sql).dictresult()
        oHigh = rs[0]["avg_high"]
        oLow = rs[0]["avg_low"]
        oRain = rs[0]["rain"]

        csv.write("%s,%s,%s,%s,%s,%s," % (oLow,aLow,oHigh,aHigh,oRain,aRain) )

  # Need to do yearly stuff
  # First, get our obs
    sql = """SELECT round(avg(high)::numeric,1) as avg_high,
      round(avg(low)::numeric,1) as avg_low, 
      round(sum(precip)::numeric,2) as rain from %s WHERE 
      station = '%s' and year = %s """ % (constants.get_table(id), id, yr)
    rs = constants.mydb.query(sql).dictresult()
    oHigh = rs[0]["avg_high"]
    oLow = rs[0]["avg_low"]
    oRain = rs[0]["rain"]
  # Then climate
    sql = """SELECT round(avg(high)::numeric,1) as avg_high,
    round(avg(low)::numeric,1) as avg_low, 
    round(sum(precip)::numeric,2) as rain from %s WHERE station = '%s' """ % (
                            constants.climatetable(id.lower()), id,)
    rs = constants.mydb.query(sql).dictresult()
    aHigh = rs[0]["avg_high"]
    aLow = rs[0]["avg_low"]
    aRain = rs[0]["rain"]
    csv.write("%s,%s,%s,%s,%s,%s," % (oLow,aLow,oHigh,aHigh,oRain,aRain) )

    csv.write("\n")
    csv.flush()
コード例 #7
0
def process(sid, csv):
    # Fetch Yearly Totals
    cursor.execute("""
        SELECT year, round(avg(high)::numeric,1) as avg_high,
        round(avg(low)::numeric,1) as avg_low,
        round(sum(precip)::numeric,2) as rain from %s
        WHERE station = '%s' and year >= %s GROUP by year ORDER by year ASC
    """ % (constants.get_table(sid), sid, constants.startyear(sid)))

    data = {}
    for row in cursor:
        year = row["year"]
        data[year] = {
            'oHigh': row["avg_high"],
            'oLow': row["avg_low"],
            'oRain': row["rain"]
        }

    for i in range(1893, constants._ENDYEAR):
        if i not in data:
            data[i] = {'oHigh': "M", 'oLow': "M", 'oRain': "M"}
        csv.write("%s,%s,%s," %
                  (data[i]['oLow'], data[i]['oHigh'], data[i]['oRain']))

    # Need to do climate stuff
    # Then climate
    cursor.execute("""
        SELECT round(avg(high)::numeric,1) as avg_high,
        round(avg(low)::numeric,1) as avg_low,
        round(sum(precip)::numeric,2) as rain from %s WHERE station = '%s'
    """ % (constants.climatetable(sid), sid))
    row = cursor.fetchone()
    aHigh = row["avg_high"]
    aLow = row["avg_low"]
    aRain = row["rain"]
    csv.write("%s,%s,%s," % (aLow, aHigh, aRain))

    csv.write("\n")
    csv.flush()
コード例 #8
0
ファイル: ksYearly.py プロジェクト: muthulatha/iem
def process(sid, csv):
    # Fetch Yearly Totals
    cursor.execute("""
        SELECT year, round(avg(high)::numeric,1) as avg_high,
        round(avg(low)::numeric,1) as avg_low,
        round(sum(precip)::numeric,2) as rain from %s
        WHERE station = '%s' and year >= %s GROUP by year ORDER by year ASC
    """ % (constants.get_table(sid), sid, constants.startyear(sid)))

    data = {}
    for row in cursor:
        year = row["year"]
        data[year] = {'oHigh': row["avg_high"], 'oLow': row["avg_low"],
                      'oRain': row["rain"]}

    for i in range(1893, constants._ENDYEAR):
        if i not in data:
            data[i] = {'oHigh': "M", 'oLow': "M", 'oRain': "M"}
        csv.write("%s,%s,%s," % (data[i]['oLow'], data[i]['oHigh'],
                                 data[i]['oRain']))

    # Need to do climate stuff
    # Then climate
    cursor.execute("""
        SELECT round(avg(high)::numeric,1) as avg_high,
        round(avg(low)::numeric,1) as avg_low,
        round(sum(precip)::numeric,2) as rain from %s WHERE station = '%s'
    """ % (constants.climatetable(sid), sid))
    row = cursor.fetchone()
    aHigh = row["avg_high"]
    aLow = row["avg_low"]
    aRain = row["rain"]
    csv.write("%s,%s,%s," % (aLow, aHigh, aRain))

    csv.write("\n")
    csv.flush()