-
Notifications
You must be signed in to change notification settings - Fork 62
/
monthly_cors.py
50 lines (44 loc) · 1.31 KB
/
monthly_cors.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
import iemdb
import numpy
import numpy.ma
import scipy.stats
import network
nt = network.Table("IACLIMATE")
nt.sts['IA0200']['lon'] += 0.2
COOP = iemdb.connect('coop', bypass=True)
ccursor = COOP.cursor()
statewide = []
ccursor.execute("""
SELECT year, month, sum(precip) from alldata_ia
where station = 'IA0000' and year > 1950 and month in (9,10,11) GROUP by year, month
ORDER by year ASC, month ASC
""")
for row in ccursor:
statewide.append( row[2] )
cors = []
lats = []
lons = []
for stid in nt.sts.keys():
if stid == 'IA0000' or stid[2] == 'C' or stid == 'IA0149':
continue
ccursor.execute("""
SELECT year, month, sum(precip) from alldata_ia
where station = '%s' and year > 1950 and month in (9,10,11) GROUP by year, month
ORDER by year ASC, month ASC
""" % (stid,))
data = []
for row in ccursor:
data.append( row[2] )
R = numpy.corrcoef(data, statewide)
print stid, R[0,1], nt.sts[stid]['name']
lats.append( nt.sts[stid]['lat'] )
lons.append( nt.sts[stid]['lon'] )
cors.append( R[0,1] )
cfg = {'lbTitleString': ' ',
'_title': '1951-2012 SON Monthly Precip Correlation Coefficient',
'_valid': 'Local Station Against IEM Computed Statewide Areal Average',
'_showvalues': True,
'_format': '%.2f'}
import iemplot
tmpfp = iemplot.simple_contour(lons, lats, cors, cfg)
iemplot.makefeature(tmpfp)