-
Notifications
You must be signed in to change notification settings - Fork 1
/
acfd_find.py
113 lines (98 loc) · 3.05 KB
/
acfd_find.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
import os, sys
import tempfile
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
import matplotlib
import pydarn
import datetime as dt
import datetime
#Defining radars I've already done. So we can skip these ones
completes = [ 'san' ]
def acfd_find_loop(sDate,radar):
missing=0
records=0
eDate = sDate + datetime.timedelta(days=1)
remote_fnamefmt = ['{date}.{hour}......{radar}.{ftype}','{date}.{hour}......{radar}...{ftype}']
try: myPtr = pydarn.sdio.radDataOpen(sDate,radar,eDate,fileType='rawacf',local_fnamefmt=remote_fnamefmt,remote_fnamefmt=remote_fnamefmt)
except Exception, e:
print "problem with radDataOpen"
print "sDate: %s radar: %s eDate: %s " % (str(sDate), radar, str(eDate))
print e
sys.exit(-2)
if(myPtr.dType == None):
print "No data found."
return (-1, -1)
print "Reading data..."
myData = pydarn.sdio.radDataReadRec(myPtr)
if(myData == None):
print "Not able to read data."
return (-2, -2)
#for key in myData.prm.__dict__.keys():
# print 'myData.rawacf.'+key
print "Searching through files for missing acfd arrays..."
while (myData != None):
try: array=myData.rawacf.acfd[0]
except IndexError:
missing += 1
records += 1
# Read in the next record
myData = pydarn.sdio.radDataReadRec(myPtr)
return (missing, records)
if __name__ == '__main__':
radars = pydarn.radar.network()
for iRad in xrange( radars.nradar ):
sYear=2014
eYear=2014
if (radars.radars[iRad].status != 1):
continue
rad = radars.radars[iRad].code[0]
# rad = 'sas'
# Marking radars that we've completed for this month
if rad in completes:
continue
while sYear >= eYear:
sMonth=1
eMonth=1
while sMonth >= eMonth:
# Reset missing and records for each new month
missing=0
records=0
yrmnrad = str(sYear)+str(sMonth).zfill(2)+"."+rad
sDay=31
eDay=1
while sDay >= eDay:
fDate = str(sYear)+str(sMonth).zfill(2)+str(sDay).zfill(2)+"."+rad
# sDate = dt.datetime(sYear,sMonth,sDay, 18, 00)
sDate = dt.datetime(sYear,sMonth,sDay)
miss, reco = acfd_find_loop(sDate, str(rad));
if ( (miss < 0) or (reco < 0)):
print "Did not find any data for "+str(rad)+" "+str(sDate)
sDay -= 1
continue
if miss >= 0:
missing+=miss
if reco >= 0:
records+=reco
percentage = (float(missing)/float(records)) * 100
print "missing: "+str(missing)
print "records: "+str(records)
print "percentage: %.3f percent" % (percentage)
sDay -= 1
print "Making: "+yrmnrad
try: f = open(yrmnrad, 'w')
except Exception, e:
print e
print "problem opening the file %s" % yrmnrad
sys.exit(-1)
# Case where no data was found for the month
if ( records <= 0 ):
percentage = 0
f.write('Date: '+str(sYear)+str(sMonth).zfill(2)+str(sDay).zfill(2)+'\n')
f.write('Total Number of Records: '+str(records)+'\n')
f.write('Missing: '+str(missing)+'\n')
f.write('Percentage: {:.3f}\n'.format(float(percentage)))
sMonth -= 1
f.close()
sYear -= 1
# Exit after just one radar
# sys.exit(1)