I was able to print out daily values and aggregate the final annual result but I am lost and dont know where to start on how to sum the daily values to monthly and print it out. I need your help badely.

Here is part of the code

import os.path

# Open files to read
ifh = open("D:/ArcView/pcp_avg.txt", "r")
ifh2 = open("D:/ArcView/parameters_31Oct.txt", "r")

# Open files to write output 

ofh1 = open("D:/ArcView/rye1.txt", "w")
ofh2 = open("D:/ArcView/rye2.txt", "w")

# Read the files
rainF = ifh.readline()
cropP = ifh2.readline()

# print heading on the annual output

print >>ofh2, 'X_CORD', 'Y_CORD', 'ID', 'ETct', 'ETat'

while rainF and cropP:

    rfields = rainF.split()
    cfields = cropP.split()

    X_Grid = cfields[0]     # X-grid (latitude) in degree
    Y_Grid = cfields[1]     # Y-grid (longitude)
    ID = int(float(cfields[2]))

    # parameters initialization

    KS = 1

    Dri = TAWC*Zrmin_rf*Pstd                                          

    Total = 0
    ETat = 0       
    ETct = 0       

    print >>ofh1, X_Grid, Y_Grid, ID,
    print >>ofh2, X_Grid, Y_Grid, ID,

    #for loop over the grawing period - from planting to harvest

    for J in range (1, 365, 1):

        # Daily calculation of different parameters
        PR = float(rfields[J])                 
        ETo = float(efields[J])
        ETc = ETo * KC                                                  

        # do some more here ........

        # calculation of soil water balance
        if Dri > RAW:
            KS = max(0,((St)/((1-Pi)*TAW)))
            KS = 1

        # and some more ......

        ETa = ETc * KS                                                 

        # aggregation over the growing period         
        ETct += ETc
        ETat += ETa

        # print daily values
        print >>ofh1, '%7.2f'   %ETc, 

        # how to print monthly values ??????       

    # print annual values
    print >> ofh2, '%.2f %.2f'%(ETct, ETat), 

    print >>ofh1
    print >>ofh2

    # running over the files
    rainF = ifh.readline()
    cropP = ifh2.readline()

# closing the files


6 Years
Discussion Span
Last Post by woooee

If you want to print one month and not keep the info, then use a list to store all of the values, monthly[0] += rainfall, etc. On the first day of a new month, print the results, zero the list, and start adding again. If you want to retain the data then consider using a dictionary with each month as the key, pointing to a list of the values you want to keep.


Thanks woooee!

I am beginner and dont know how to create list or dictionary. Can you give me some idea?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.