# Generate A counting of rainfall events
# Daryl Herzmann 16 Mar 2005

import constants
import mx.DateTime
import numpy as np

# Data is generated by genMonthly.py

def write(monthly_rows, out, station):
    out.write("""# NUMBER OF SNOWY DAYS PER MONTH PER YEAR
# Days with a trace of snowfall reported are not included
YEAR   JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ANN   
""")

    db = {}
    monthly = [0]*13
    for i in range(13):
        monthly[i] = []
        
    for row in monthly_rows:
        ts = mx.DateTime.DateTime(row['year'], row['month'], 1)
        db[ts] = row["snow_days"]
        monthly[ts.month].append( row['snow_days'] )

    for yr in range(constants.startyear(station), constants._ENDYEAR):
        tot = 0
        out.write("%s   " % (yr,) )
        for mo in range(1, 13):
            cnt = db.get("%s-%02i-01" % (yr, mo), None)
            ts = mx.DateTime.DateTime(yr,mo,1)
            if ts >= constants._ARCHIVEENDTS or cnt is None:
                out.write("%3s " % ("M",) )
                continue
      
            out.write("%3i " % (cnt,))
            tot += cnt
        out.write("%3i\n" % (tot,))


    out.write("STDDEV ")
    for mo in range(1, 13):
        out.write("%3.0f " % (np.std(monthly[mo]),))
    out.write("%3.0f\n" % (0,) )
    out.write("AVG    ")
    for mo in range(1, 13):
        out.write("%3.0f " % (np.average(monthly[mo]),))
    out.write("%3.0f\n" % (0,))

@@ -88,24 +88,21 @@
 %0Aimport 
-mx.DateT
+datet
 ime%0Aimpo
@@ -121,45 +121,8 @@
 np%0A%0A
-# Data is generated by genMonthly.py%0A
 %0Adef
@@ -332,19 +332,16 @@
  DEC ANN
-   
 %0A%22%22%22)%0A%0A 
@@ -420,24 +420,16 @@
 i%5D = %5B%5D%0A
-        
 %0A    for
@@ -463,33 +463,30 @@
    ts = 
-mx.DateT
+datet
 ime.
-DateT
+datet
 ime(row%5B
@@ -578,17 +578,16 @@
 .append(
- 
 row%5B'sno
@@ -594,17 +594,16 @@
 w_days'%5D
- 
 )%0A%0A    f
@@ -717,17 +717,16 @@
  %25 (yr,)
- 
 )%0A      
@@ -767,50 +767,40 @@
     
-cn
 t
+s
  = d
-b.get(%22%25s-%2502i-01%22 %25 
+atetime.datetime
 (yr, mo
-)
 , 
-None
+1
 )%0A  
@@ -813,41 +813,29 @@
     
-ts = mx.DateTime.DateTime(yr,mo,1
+cnt = db.get(ts, None
 )%0A  
@@ -934,17 +934,16 @@
 %25 (%22M%22,)
- 
 )%0A      
@@ -961,22 +961,16 @@
 ontinue%0A
-      
 %0A       
@@ -1061,17 +1061,16 @@
 tot,))%0A%0A
-%0A
     out.
@@ -1197,17 +1197,16 @@
 %22 %25 (0,)
- 
 )%0A    ou

fix climodat bug with monthly snow days all appearing as missing