Skip to content

Commit e70e505

Browse files
committed
read output (python file)
1 parent 940f146 commit e70e505

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

python/read_qgcm.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python
2+
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
import scipy.io.netcdf as netcdf
6+
plt.ion()
7+
8+
9+
# x,y subsampling (1: no sub sampling, 2: every two points, etc)
10+
sp_xy = 1
11+
# select layer (0: upper layer)
12+
ilayer = 0
13+
14+
dir0 = '../examples/double_gyre_ocean_only/outdata/'
15+
file0 = 'ocpo.nc'
16+
file1 = 'ocpo.dat'
17+
file2 = 'mean.dat'
18+
19+
fid1 = open(dir0 + file1,'wb')
20+
21+
# get sizes
22+
f = netcdf.netcdf_file(dir0 + file0,'r')
23+
psi = f.variables['p'][0,0,:,:].copy()
24+
xp = f.variables['xp'][:].copy()
25+
yp = f.variables['yp'][:].copy()
26+
zi = f.variables['zi'][:].copy()
27+
28+
time = f.variables['time'][:].copy()
29+
si_t, = time.shape
30+
newt = f.variables['p'][:,0,1,1].copy()
31+
newt = newt[newt<1e5]
32+
si_t2 = newt.size
33+
34+
si_y,si_x = psi.shape
35+
36+
# compute mean
37+
psi_me = 0.0*np.zeros((si_y,si_x))
38+
n_me = 0
39+
for nt in range(0,si_t2):
40+
psi = f.variables['p'][nt,ilayer,:,:].copy()
41+
psi_me = psi_me + psi
42+
n_me = n_me + 1
43+
psi_sav = psi[0:-1:sp_xy,0:-1:sp_xy].reshape(-1)
44+
np.savetxt(fid1, psi_sav[None],fmt='%10.5e')
45+
46+
# save mean
47+
psi_me = psi_me/n_me
48+
np.savetxt(dir0 + file2, psi_me[0:-1:sp_xy,0:-1:sp_xy])
49+
50+
# close files
51+
f.close()
52+
fid1.close()
53+
54+
# plot
55+
plt.figure()
56+
plt.contour(psi_me)

0 commit comments

Comments
 (0)