+
+ elif USE_BINNING:
+ sortedlist = []
+ # Iterate over dictionary and write (key, value) pairs
+ ind = 0
+ first = 0
+ last = 0
+ for key in sorted(dictionary):
+ sortedlist.append(key)
+ print "Key: ", key, " - Value: ", dictionary[key], " - Ind: ", ind
+ ind += 1
+ first = hms_to_seconds(sortedlist[0])
+ #print "First: ", key
+ last = hms_to_seconds(sortedlist[ind-1])
+ #print "Last: ", key
+ resultdict = dict()
+ # Put new binning keys
+ time_ind = first
+ ind = 0
+ while time_ind < last:
+ # Initialize with the first key in the list
+ curr_key = sortedlist[ind]
+ curr_key_secs = hms_to_seconds(curr_key)
+ # Initialize with 0 first
+ resultdict[time_ind] = 0
+ # Check if this is still within RANGE - bin the value if it is
+ while time_ind - RANGE <= curr_key_secs and curr_key_secs <= time_ind + RANGE:
+ resultdict[time_ind] += dictionary[curr_key]
+ print "Time index: ", seconds_to_hms(time_ind), " Value: ", resultdict[time_ind]
+ ind += 1
+ if ind > len(dictionary)-1:
+ break
+ # Initialize with the key in the list
+ curr_key = sortedlist[ind]
+ curr_key_secs = hms_to_seconds(curr_key)
+ # Increment time index
+ time_ind += TOTAL_RANGE
+ # Now write to file after binning
+ for key in sorted(resultdict):
+ # Space separated
+ f.write(seconds_to_hms(key) + " " + str(resultdict[key]) + "\n")
+ #print seconds_to_hms(key) + " " + str(resultdict[key])
+