#!/usr/bin/python # program gives rate of CG strikes over a latitude/longitude box. # written by K. Kuhlman import cPickle, math, getopt, sys #read in NLDN data nldn = 'cgdata_040530.pickle' cgfile = open(nldn, 'r') cgdata = cPickle.load(cgfile) cgfile.close() print "\nhere are the keys and types in cgdata:" for key in cgdata.keys(): print key,type(cgdata[key]) print "\nthe README:\n", cgdata['Readme'] cg = cgdata.get('cgs') p = len(cg) print p header = 0 ### determine start and end times flash rate counting, input must be string ### time_start = input("What time to start counting? (format- 'hh:mm') ") time_end = input("What time to end counting? (format- 'hh:mm') ") header = input("Do you want to start a new text file or add onto flashes.txt? (1 = new, 2 = add) ") #interval = input("How long of period for each count in minutes? (integer < 10) (format: 1) ") #k = interval #print k #set the bounds for the box: (input not string?) # ######### use below for input for storms other than 29 June 2004 ############ #lonmax = input("What is the westernmost longitude you want? (format: -103.0) ") #lonmin = input("What is the easternmost longitude you want? (format: -94.5) ") #latmin = input("What is the southernmost latitude you want? (format: 33.0) ") #latmax = input("What is the northernmost latitude you want? (format: 37.0) ") ### below lat/lon box works for 29 June 2004 from 2300 - 0100 UTC #### lonmax = -99.2 lonmin = -97.2 latmin = 35.5 latmax = 36.2 # focuses on time selected # n = 0 m = 0 while m < p: time = cg[m][1] if time.startswith(time_start): n = m break else: m += 1 q = 0 while q < p: time = cg[q][1] if time.startswith(time_end): l = q break else: q += 1 ## counts cgs in given area (lat-long box) ## if header == 1: f = open('flashes.txt','w') headerline = 'time \t total_all CGflashes \t total_neg \t <10 kA neg \t total_pos \t <10 kA pos\n' f.write(headerline) else: f = open('flashes.txt','a') total_cgs = 0 neg_cgs = 0 lowamp_neg = 0 pos_cgs = 0 lowamp_pos = 0 print n print l #j = n #print j #r = n #print r #t = 0 #for k < l0: # print 'j = ' + `j` # time_s=list(time_start) # time_s[4] = str(k) # time_hold = ''.join(time_s) # k += interval # time = cg[j][1] # print time_hold # if time.startswith(time_hold): # t = j # print t # else: # j += 1 r = n while r < l: lon = float(cg[r][3]) lat = float(cg[r][2]) kA = float(cg[r][5]) if lonmax <= lon <= lonmin: if latmin <= lat <= latmax: total_cgs += 1 #print n, cg[n][2], lon if cg[r][4].startswith('-'): neg_cgs += 1 if kA > -10.0: lowamp_neg += 1 else: pos_cgs +=1 if kA < 10.0: lowamp_pos += 1 r += 1 #j += 1 f.write(time_start + '\t' + `total_cgs` + '\t' + `neg_cgs` + '\t' + `lowamp_neg` + '\t' + `pos_cgs` + '\t' + `lowamp_pos` + '\n') #print 'r = ' + `r` #print 't = ' + `t` f.close print "total CG flashes for time period = " + `total_cgs` print "total negative cg flashes = " + `neg_cgs` print "total negative cg flashes < 10 kA = (" + `lowamp_neg` + ")" print "total positive cg flashes = " + `pos_cgs` print "total positive cg flashes < 10 kA = (" + `lowamp_pos` + ")"