-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoldPlots.py
65 lines (43 loc) · 1.81 KB
/
goldPlots.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
import numpy as np
import os
from scipy.io import netcdf as scipy_netcdf
from matplotlib import pyplot as plt
from scipy.signal import firwin, filtfilt, lfilter
from scipy.fftpack import fft, fftfreq, fftshift, ifft, fft2, ifft2
def FilterField2D(inputField,cutoffFreqX,cutoffFreqY,samplingIntervalX,samplingIntervalY):
[nY,nX] = inputField.shape
kernalLength = 20.0
nyquistFrequencyX = 0.5/samplingIntervalX
nyquistFrequencyY = 0.5/samplingIntervalY
tapWeightsX = firwin(kernalLength,cutoffFreqX,window='blackman',nyq=nyquistFrequencyX)
tapWeightsY = firwin(kernalLength,cutoffFreqY,window='blackman',nyq=nyquistFrequencyY)
filteredField = np.zeros([nY,nX],dtype='float64')
for iY in range(0,nY):
filteredField[iY,:] = filtfilt(tapWeightsX,[1.0],inputField[iY,:])
for iX in range(0,nX):
filteredField[:,iX] = filtfilt(tapWeightsY,[1.0],inputField[:,iX])
return filteredField
#Get Data
modelDataFileName = '/home/chris/GOLD/postprocessedOut.nc'
topoFileName = '/home/chris/ETOPO1/randTopo_01.nc'
dataFile = scipy_netcdf.netcdf_file(modelDataFileName,'r')
topoFile = scipy_netcdf.netcdf_file(topoFileName,'r')
#Get variables
x = dataFile.variables['x'][:]
y = dataFile.variables['y'][:]
zl = dataFile.variables['zl'][:]
zi = dataFile.variables['zi'][:]
uTimeMean = dataFile.variables['u_time_mean'][:,:,:]
vTimeMean = dataFile.variables['v_time_mean'][:,:,:]
ekeTimeMean = dataFile.variables['eke'][:,:,:]
topo = topoFile.variables['topo'][:,:]
dataFile.close()
topoFile.close()
cutoffPeriodX = 100.0 * (x[1]-x[0])
cutoffPeriodY = 50.0 * (y[1]-y[0])
LPFilteredTopo = FilterField2D(topo,1.0/cutoffPeriodX,1.0/cutoffPeriodY,x[1]-x[0],y[1]-y[0])
fig = plt.figure(1)
ax = fig.add_subplot(1,1,1)
ax.contourf(x,y,uTimeMean[0,:,:],15,cmap=plt.cm.jet)
ax.contour(x,y,LPFilteredTopo[1::,:],10,colors='k')
plt.show()