Advertisement
Guest User

main.py

a guest
Dec 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.91 KB | None | 0 0
  1. import numpy
  2. import matplotlib.pyplot as plt
  3. from mpl_toolkits.mplot3d import Axes3D
  4. from mpl_toolkits.basemap import Basemap
  5.  
  6. from parameters import *
  7. from variables import *
  8. from initial import *
  9. from advectionx import*
  10. from advectiony import*
  11. from advectionz import*
  12. from dispersionx import *
  13. from dispersiony import *
  14. from dispersionz import *
  15. from degree_conversion import *
  16. from settling import *
  17. from landed import *
  18.  
  19. #[height,lat,lon]; [z,y,x]
  20. Rold = initial(sigma_lat,sigma_lon)
  21.  
  22. lon1 = 65.
  23. lon2 = 155.
  24. lat1 = -25.
  25. lat2 = 25.
  26.  
  27. fig = plt.figure(1,facecolor = 'white')
  28. ax = fig.add_subplot(111, projection='3d')
  29. ax.set_xlabel('longitude [decimal degees]')
  30. ax.set_ylabel('latitude [decimal degees]')
  31. ax.set_zlabel('altitude [meters]')
  32. ax.set_zlim(0,20000)
  33. ax.set_ylim(lat1,lat2)
  34. ax.set_xlim(lon1,lon2)
  35. ax.scatter(Rold[:,2],Rold[:,1],Rold[:,0],c='r',s=10)
  36. ax.set_title('Particle Trajectory')
  37.  
  38.  
  39. plt.figure(2)
  40. m = Basemap(llcrnrlon=lon1,llcrnrlat=lat1,urcrnrlon=lon2,urcrnrlat=lat2,
  41.             projection='lcc',lon_0=start_lon,lat_0=start_lat,
  42.             resolution ='l',area_thresh=1000.)
  43. m.drawcoastlines(linewidth=0.25)
  44. m.drawcountries(linewidth=0.25)
  45. m.drawparallels(np.arange(lat1,lat2,10),labels=[1,1,0,0])
  46. m.drawmeridians(np.arange(lon1,lon2,10),labels=[0,0,0,1])
  47. x, y = m(Rold[:,2],Rold[:,1])
  48. m.scatter(x,y,s=20,marker='o',color='r',zorder=10)
  49. plt.title('Particle Trajectory')
  50.  
  51. j=3
  52. for t in xrange(1,time_steps):
  53.     t_index = int(float(t)/float(time_steps)*20.)
  54.     t_time_1 = float(t)/float(time_steps)*20.
  55.     t_time_2 = (float(t)+0.5)/float(time_steps)*20.
  56.     t_time_3 = (float(t)+0.5)/float(time_steps)*20.
  57.     t_time_4 = (float(t)+1.0)/float(time_steps)*20.  
  58.      
  59.     dx_lat, dx_lon = degree_to_dx(R)
  60.      
  61.     #RUNGA KUTTA
  62.     R_step1[:,:] = 0.0
  63.     R_step2[:,:] = 0.0
  64.     R_step3[:,:] = 0.0
  65.     R_step4[:,:] = 0.0
  66.     #dispersion
  67.     dispz_temp = dispersionz(Active) * dt
  68.     dispy_temp = dispersiony(Active) * dt / dx_lat
  69.     dispx_temp = dispersionx(Active) * dt / dx_lon
  70.     R_step1[:,0] += dispz_temp
  71.     R_step2[:,0] += dispz_temp
  72.     R_step3[:,0] += dispz_temp
  73.     R_step4[:,0] += dispz_temp
  74.     R_step1[:,1] += dispy_temp
  75.     R_step2[:,1] += dispy_temp
  76.     R_step3[:,1] += dispy_temp
  77.     R_step4[:,1] += dispy_temp
  78.     R_step1[:,2] += dispx_temp
  79.     R_step2[:,2] += dispx_temp
  80.     R_step3[:,2] += dispx_temp
  81.     R_step4[:,2] += dispx_temp
  82.      
  83.     #settling
  84.     R_step1[:,0] -= settling(D,Active) * dt
  85.     R_step2[:,0] -= settling(D,Active) * dt
  86.     R_step3[:,0] -= settling(D,Active) * dt
  87.     R_step4[:,0] -= settling(D,Active) * dt
  88.      
  89.     R_step1[:,0] += advectionz(Rold,Active,t_index,t_time_1) * dt
  90.     R_step1[:,1] += advectiony(Rold,Active,t_index,t_time_1) * dt / dx_lat
  91.     R_step1[:,2] += advectionx(Rold,Active,t_index,t_time_1) * dt / dx_lon
  92.     R_step2[:,0] += advectionz(Rold+R_step1/2.0,Active,t_index,t_time_2) * dt
  93.     R_step2[:,1] += advectiony(Rold+R_step1/2.0,Active,t_index,t_time_2) * dt / dx_lat
  94.     R_step2[:,2] += advectionx(Rold+R_step1/2.0,Active,t_index,t_time_2) * dt / dx_lon
  95.     R_step3[:,0] += advectionz(Rold+R_step2/2.0,Active,t_index,t_time_3) * dt
  96.     R_step3[:,1] += advectiony(Rold+R_step2/2.0,Active,t_index,t_time_3) * dt / dx_lat
  97.     R_step3[:,2] += advectionx(Rold+R_step2/2.0,Active,t_index,t_time_3) * dt / dx_lon
  98.     R_step4[:,0] += advectionz(Rold+R_step3,Active,t_index,t_time_4) * dt
  99.     R_step4[:,1] += advectiony(Rold+R_step3,Active,t_index,t_time_4) * dt / dx_lat
  100.     R_step4[:,2] += advectionx(Rold+R_step3,Active,t_index,t_time_4) * dt / dx_lon
  101.  
  102.     Rnew =  Rold + R_step1/6.0 + R_step2/3.0 + R_step3/3.0 + R_step4/6.0  
  103.     Active, Rnew[:,0] = landed(Rnew[:,0],Active)
  104.      
  105.     if t%(time_steps/50)==0:
  106.         ax.scatter(Rnew[:,2],Rnew[:,1],Rnew[:,0],c='k',s=1,alpha=float(t)/float(time_steps-1)*0.5)
  107.         plt.figure(2,facecolor='white')
  108.         x, y = m(Rnew[:,2],Rnew[:,1])
  109.         m.scatter(x,y,s=1,marker='o',color='k',alpha=float(t)/float(time_steps-1)*0.5,zorder=10)
  110. #        print str(int(100.*float(t)/float(time_steps-1))) + '% done'
  111.     if t%(time_steps/10)==0:
  112.         plt.figure(j)
  113.         m = Basemap(llcrnrlon=lon1,llcrnrlat=lat1,urcrnrlon=lon2,urcrnrlat=lat2,
  114.             projection='lcc',lon_0=start_lon,lat_0=start_lat,
  115.             resolution ='l',area_thresh=1000.)
  116.         m.drawcoastlines(linewidth=0.25)
  117.         m.drawcountries(linewidth=0.25)
  118.         m.drawparallels(np.arange(lat1,lat2,10),labels=[1,1,0,0])
  119.         m.drawmeridians(np.arange(lon1,lon2,10),labels=[0,0,0,1])
  120.         x, y = m(start_lon,start_lat)
  121.         m.scatter(x,y,s=20,marker='o',color='r',zorder=10)
  122.         x, y = m(Rnew[:,2],Rnew[:,1])
  123.         m.scatter(x,y,s=2,marker='o',color='k',zorder=10,alpha=0.5)
  124.         plt.title('Plume after ' + str((j-2)*12) + ' hrs')
  125.  
  126.         fig = plt.figure(j+10,facecolor = 'white')
  127.         axx = fig.add_subplot(111, projection='3d')
  128.         axx.set_xlabel('longitude [decimal degees]')
  129.         axx.set_ylabel('latitude [decimal degees]')
  130.         axx.set_zlabel('altitude [meters]')
  131.         axx.set_zlim(0,20000)
  132.         axx.set_ylim(lat1,lat2)
  133.         axx.set_xlim(lon1,lon2)
  134.         axx.scatter(Rnew[:,2],Rnew[:,1],Rnew[:,0],c='k',s=1)
  135.         axx.set_title('Plume after ' + str((j-2)*12) + ' hrs')
  136.         j+=1
  137.          
  138.     Rold = Rnew
  139.  
  140. for i in xrange(0,num_particles):
  141.     if Active[i] == 0:
  142.         ax.scatter(Rnew[i,2],Rnew[i,1],Rnew[i,0],c='g',s=10)
  143.         plt.figure(2,facecolor='white')
  144.         x, y = m(Rnew[i,2],Rnew[i,1])
  145.         m.scatter(x,y,s=2,marker='o',color='g',zorder=10)
  146.     else:
  147.         ax.scatter(Rnew[i,2],Rnew[i,1],Rnew[i,0],c='b',s=10)
  148.         plt.figure(2,facecolor='white')
  149.         x, y = m(Rnew[i,2],Rnew[i,1])
  150.         m.scatter(x,y,s=10,marker='o',color='b',zorder=10)
  151. plt.figure(1,facecolor='white')
  152. plt.savefig('3D-final.png')
  153. plt.figure(2,facecolor='white')
  154. plt.savefig('2D-final.png')
  155. plt.figure(3,facecolor='white')
  156. plt.savefig('2D-12hr.png')
  157. plt.figure(4,facecolor='white')
  158. plt.savefig('2D-24hr.png')
  159. plt.figure(5,facecolor='white')
  160. plt.savefig('2D-36hr.png')
  161. plt.figure(6,facecolor='white')
  162. plt.savefig('2D-48hr.png')
  163. plt.figure(7,facecolor='white')
  164. plt.savefig('2D-60hr.png')
  165. plt.figure(8,facecolor='white')
  166. plt.savefig('2D-72hr.png')
  167. plt.figure(9,facecolor='white')
  168. plt.savefig('2D-84hr.png')
  169. plt.figure(10,facecolor='white')
  170. plt.savefig('2D-96hr.png')
  171. plt.figure(11,facecolor='white')
  172. plt.savefig('2D-108hr.png')
  173. plt.figure(12,facecolor='white')
  174. plt.savefig('2D-120hr.png')
  175. plt.figure(13,facecolor='white')
  176. plt.savefig('3D-12hr.png')
  177. plt.figure(14,facecolor='white')
  178. plt.savefig('3D-24hr.png')
  179. plt.figure(15,facecolor='white')
  180. plt.savefig('3D-36hr.png')
  181. plt.figure(16,facecolor='white')
  182. plt.savefig('3D-48hr.png')
  183. plt.figure(17,facecolor='white')
  184. plt.savefig('3D-60hr.png')
  185. plt.figure(18,facecolor='white')
  186. plt.savefig('3D-72hr.png')
  187. plt.figure(19,facecolor='white')
  188. plt.savefig('3D-84hr.png')
  189. plt.figure(20,facecolor='white')
  190. plt.savefig('3D-96hr.png')
  191. plt.figure(21,facecolor='white')
  192. plt.savefig('3D-108hr.png')
  193. plt.figure(22,facecolor='white')
  194. plt.savefig('3D-120hr.png')
  195.      
  196. #plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement