|
| 1 | +import pickle |
| 2 | +from scipy.interpolate import griddata |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import numpy as np |
| 5 | +from glob import glob |
| 6 | + |
| 7 | +ro = 1.538461538 |
| 8 | +nx = 200 |
| 9 | +ny = 200 |
| 10 | + |
| 11 | +#f1 = open( "zonal_vphi_0000.pickle", "rb" ) |
| 12 | +#time1 = pickle.load(f1) |
| 13 | +#radius1 = pickle.load(f1)/ro |
| 14 | +#vphi1 = pickle.load(f1) |
| 15 | +#f1.close() |
| 16 | + |
| 17 | +#f2 = open( "zonal_vphi_2100.pickle", "rb" ) |
| 18 | +#time2 = pickle.load(f2) |
| 19 | +#radius2 = pickle.load(f2)/ro |
| 20 | +#vphi2 = pickle.load(f2) |
| 21 | +#f2.close() |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +#--------------------------- |
| 26 | +def grid_stuff(radius,data): |
| 27 | + #circular grid |
| 28 | + theta = np.linspace(np.pi/2, -np.pi/2, data.shape[0]) |
| 29 | + rr, ttheta = np.meshgrid(radius, theta) |
| 30 | + xx = rr * np.cos(ttheta) |
| 31 | + yy = rr * np.sin(ttheta) |
| 32 | + |
| 33 | + #regular grid |
| 34 | + rec_x = np.linspace(0, 1, nx) |
| 35 | + rec_y = np.linspace(-1, 1, ny) |
| 36 | + xx2, yy2 = np.meshgrid(rec_x, rec_y) |
| 37 | + |
| 38 | + # array with number of 0 elements |
| 39 | + zero_mask = np.ones(xx2.shape) |
| 40 | + for i in range(xx2.shape[0]): |
| 41 | + for j in range(xx2.shape[1]): |
| 42 | + radius = (xx2[i,j]**2 + yy2[i,j]**2)**0.5 |
| 43 | + #print radius |
| 44 | + if radius <0.35 or radius > 1.: |
| 45 | + zero_mask[i,j]=0. |
| 46 | + |
| 47 | + # count number of zero element |
| 48 | + num_zero = np.zeros(xx2.shape[1]) |
| 49 | + for i in range(xx2.shape[1]): |
| 50 | + num_zero[i] = np.count_nonzero(zero_mask[:,i]==0) |
| 51 | + |
| 52 | + return [xx, yy, xx2, yy2, num_zero] |
| 53 | +#---------------------------- |
| 54 | + |
| 55 | +#grid1 = grid_stuff(radius1,vphi1) |
| 56 | +#grid2 = grid_stuff(radius2,vphi2) |
| 57 | + |
| 58 | +#----------------------------------------------------------- |
| 59 | +N_temp_data = [0] * nx |
| 60 | +S_temp_data = [0] * nx |
| 61 | +time_arr = [] |
| 62 | +files = sorted(glob("zonal_vphi_*.pickle"))[:] |
| 63 | +for file in files: |
| 64 | + print 'Working on', file |
| 65 | + f = open( file, "rb" ) |
| 66 | + temp_time = pickle.load(f) |
| 67 | + radius = pickle.load(f)/ro |
| 68 | + vphi = pickle.load(f) |
| 69 | + f.close() |
| 70 | + #print temp_time |
| 71 | + [xx,yy,xx2,yy2,num_zero] = grid_stuff(radius,vphi) |
| 72 | + regular_vphi = griddata((xx.ravel(), yy.ravel()), vphi.ravel(), (xx2, yy2), method='nearest') |
| 73 | + #north |
| 74 | + N_z_sum = np.sum(regular_vphi[0:xx2.shape[0]/2,:], axis=0) |
| 75 | + N_vphi_z_avg = N_z_sum/(ny-num_zero)/2. |
| 76 | + #south |
| 77 | + S_z_sum = np.sum(regular_vphi[xx2.shape[0]/2:,:], axis=0) |
| 78 | + S_vphi_z_avg = S_z_sum/(ny-num_zero)/2. |
| 79 | + #print 'averaging done on grid2' |
| 80 | + |
| 81 | + N_temp_data = np.vstack((N_temp_data,N_vphi_z_avg)) |
| 82 | + S_temp_data = np.vstack((S_temp_data,S_vphi_z_avg)) |
| 83 | + print temp_time |
| 84 | + time_arr.append(temp_time) |
| 85 | + |
| 86 | +N_data = N_temp_data[1:,...] |
| 87 | +S_data = S_temp_data[1:,...] |
| 88 | + |
| 89 | +yy3 = np.linspace(0, 1, nx) |
| 90 | +xx3 = time_arr#np.linspace(0, 1, N_data.shape[0]) |
| 91 | + |
| 92 | + |
| 93 | +cut = 0.2 |
| 94 | +fig = plt.figure(figsize=(10,5)) |
| 95 | +ax = fig.add_axes([0.15, 0.07, 0.8, 0.9]) |
| 96 | +ax.set_ylim(-0.35,1) |
| 97 | +cs = np.linspace(-100,100, 60) |
| 98 | + |
| 99 | +out_TC_data = (N_data[:,np.int(nx*0.35):].T + S_data[:,np.int(nx*0.35):].T)/2.0 |
| 100 | +in_TC_N_data = N_data[:,0:np.int(nx*0.35)].T |
| 101 | +in_TC_S_data = S_data[:,0:np.int(nx*0.35)].T |
| 102 | + |
| 103 | +im = ax.contourf(xx3, yy3[np.int(nx*0.35):], out_TC_data, cs, cmap='seismic', extend='both') |
| 104 | +im2 = ax.contourf(xx3, yy3[0:np.int(nx*0.35)], in_TC_N_data, cs, cmap='seismic', extend='both') |
| 105 | +im3 = ax.contourf(xx3, -yy3[0:np.int(nx*0.35)], in_TC_S_data, cs, cmap='seismic', extend='both') |
| 106 | + |
| 107 | +ax.plot(xx3,np.zeros(len(time_arr))+0.35, '--k', lw=3) |
| 108 | +ax.plot(xx3,np.zeros(len(time_arr)), '--k', lw=3) |
| 109 | + |
| 110 | +#print vphi_z_avg |
| 111 | +#plt.plot(vphi_z_avg) |
| 112 | +plt.show() |
| 113 | + |
| 114 | + |
| 115 | +if False: |
| 116 | + cm = 'RdYlBu_r' |
| 117 | + lev = 100 |
| 118 | + to_plot = regular_vphi |
| 119 | + fig = plt.figure(figsize=(4,7)) |
| 120 | + ax = fig.add_axes([0.05, 0.05, 0.9, 0.9]) |
| 121 | + |
| 122 | + vmax = 2*np.std(to_plot) |
| 123 | + vmin = -vmax |
| 124 | + cs = np.linspace(vmin, vmax, lev) |
| 125 | + |
| 126 | + ax.contourf(xx2, yy2, to_plot, cs, cmap='seismic', extend='both'); ax.axis('off') |
| 127 | + #plt.imshow(to_plot, extent=(xx2.min(), xx2.max(), yy2.max(), yy2.min())) |
| 128 | + |
| 129 | + plt.show() |
| 130 | + |
| 131 | + #fig.savefig('e6_NSD_2e9.png', dpi=100) |
| 132 | + |
0 commit comments