-
Notifications
You must be signed in to change notification settings - Fork 0
/
mothlymeans.py
108 lines (84 loc) · 3.29 KB
/
mothlymeans.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
#This program loads all of the data, splits it by pattern type and then prints pics for each
#Import a bunch of stuff
import numpy as np
import matplotlib as plt
from netCDF4 import Dataset
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import os
import datetime
import pickle
import csv
import scipy as sp
import scipy.ndimage as ndimage
import scipy.io as sio
from sklearn.metrics import mean_squared_error
from math import sqrt
#Check to see if out directory exists and if not, make it
outdir = "Allyear/pix"
if not os.path.exists(outdir):
os.makedirs(outdir)
missing = 1 * 10**15
#Load in the Matlab File
mat_contents = sio.loadmat('/home/mariofire/Documents/MATLAB/monthlydata.mat')
#Put Variables into an array (change the 3 letter month to the month you need)
h500 = mat_contents['seph500']
mslp = mat_contents['sepmslp']
u850 = mat_contents['sepu']
v850 = mat_contents['sepv']
#Place data into a new array (need to subtract 1 from the CI due to index differences)
dset1 = h500[:,:,:]
#open the lat lon files
latlon1 = Dataset("/home/mariofire/Downloads/19790101.nc4", mode='r')
#put the lat and lon data into arrays based on which grid type it is
lats = np.squeeze(latlon1.variables['YDim'][:])
lons = np.squeeze(latlon1.variables['XDim'][:])
# mesh the grids together for plotting purposes
LON,LAT = np.meshgrid(lons,lats)
#close the lat lon files
latlon1.close()
#Plot the images for each of the clusters
while i <= 1:
m = Basemap(projection='merc',
resolution='h',area_thresh = 1000.0,lat_0=0,lon_0=100., llcrnrlon=-90,
llcrnrlat=30,urcrnrlon=-60,urcrnrlat=50)
m.drawcoastlines()
m.drawcountries()
m.drawstates()
#Average the data based on the CI Value
H = np.zeros((lats.shape[0], lons.shape[0]))
S = np.zeros((lats.shape[0], lons.shape[0]))
U = np.zeros((lats.shape[0], lons.shape[0]))
V = np.zeros((lats.shape[0], lons.shape[0]))
count = 0
for q in range(dset1.shape[0]):
if(dset1[q] == i):
for mm in range (lats.shape[0]):
for nn in range( lons.shape[0]):
H[mm][nn] = H[mm][nn]+ h500[q][mm][nn]
S[mm][nn] = S[mm][nn] + mslp[q][mm][nn]
U[mm][nn] = U[mm][nn] + u850[q][mm][nn]
V[mm][nn] = V[mm][nn] + v850[q][mm][nn]
count = count + 1
for mm in range(lats.shape[0]):
for nn in range(lons.shape[0]):
H[mm][nn] = H[mm][nn] / (count*10)
S[mm][nn] = S[mm][nn] / (count*100)
U[mm][nn] = U[mm][nn] / count
V[mm][nn] = V[mm][nn] / count
x,y = m(LON,LAT)
Z_500 = ndimage.gaussian_filter(S[:][:], sigma=5, order=0)
cd = m.contour(x,y,H[:][:],colors='blue',)
plt.clabel(cd, inline=True, fmt='%1.0f', fontsize=10, colors='black')
m.quiver(x[:,:],y[:,:],U[:][:],V[:][:],scale=None, scale_units='inches')
cs = m.contour(x,y,Z_500, colors='black',)
plt.clabel(cs, inline=True, fmt='%1.0f', fontsize=12, colors='k')
m.drawparallels(np.arange(-80.,81.,10.), labels=[1,0,0,0],fontsize=10)
m.drawmeridians(np.arange(-180.,181.,10.), labels=[0,0,0,1], fontsize = 10)
#Change the title here tomatch the month we are doing this for
title = 'September Mean'
title1 = outdir + '/_' + 'Sep'
plt.title(title)
plt.savefig(title1, bbox_inches='tight')
plt.gcf().clear()
i = i + 1