def save_moving_window_coordinates(path, frame): s = "%2.2i" % frame # conversion to 2-character-long-string file_name = "Bdenout" + s + ".bin" matrix, x, y, z = read_ALaDyn_bin(path, file_name, "grid") # --- axis coordinates of the moving window ---# print "saving moving window axes" np.savetxt(os.path.join(path, "data", "axes", ("x_" + ("%2.2i" % frame) + ".dat")), x, fmt="%15.14e") np.savetxt(os.path.join(path, "data", "axes", ("y_" + ("%2.2i" % frame) + ".dat")), y, fmt="%15.14e") np.savetxt(os.path.join(path, "data", "axes", ("z_" + ("%2.2i" % frame) + ".dat")), z, fmt="%15.14e")
def save_moving_window_coordinates(path,frame): s='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Bdenout'+s+'.bin' matrix, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #--- axis coordinates of the moving window ---# print 'saving moving window axes' np.savetxt( os.path.join(path,'data','Moving_window_axes',('moving_window_x_axis_'+('%2.2i'%frame)+'.dat')) ,x,fmt='%15.14e') np.savetxt( os.path.join(path,'data','Moving_window_axes',('moving_window_y_axis_'+('%2.2i'%frame)+'.dat')) ,y,fmt='%15.14e') np.savetxt( os.path.join(path,'data','Moving_window_axes',('moving_window_z_axis_'+('%2.2i'%frame)+'.dat')) ,z,fmt='%15.14e')
def save_moving_window_coordinates(path, frame): s = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Bdenout' + s + '.bin' matrix, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #--- axis coordinates of the moving window ---# print('saving moving window axes') np.savetxt(os.path.join(path, 'data', 'axes', ('x_' + ('%2.2i' % frame) + '.dat')), x, fmt='%15.14e') np.savetxt(os.path.join(path, 'data', 'axes', ('y_' + ('%2.2i' % frame) + '.dat')), y, fmt='%15.14e') np.savetxt(os.path.join(path, 'data', 'axes', ('z_' + ('%2.2i' % frame) + '.dat')), z, fmt='%15.14e')
def write_vts(path,frame,X,Y,Z,cell_cut): # for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # write_VTS(path,i) sf='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Bdenout'+sf+'.bin' rhobunch, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rhobunch = np.abs( rhobunch ) file_name = 'Edenout'+sf+'.bin' rhobck, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rhobck = np.abs( rhobck ) #- matrix shaving if cell_cut > 0: rhobunch = rhobunch[:,cell_cut:-cell_cut,cell_cut:-cell_cut] rhobck = rhobck[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = rhobunch.shape #- #- writing vts header f = open(os.path.join(path,'VTS_files','ALaDyn_output_'+sf+'.vts'),'w+') f.write('<?xml version="1.0"?>' + '\n') f.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #--- ---# #- generating vector-MESH mesh=[] for i in range(0,size[0]): for j in range(0,size[1]): for k in range(0,size[2]): mesh.append( Y[j] ) mesh.append( Z[k] ) mesh.append( X[i] ) #- Writing MESH -# f.write('<Points> \n') f.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f.write( s ) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') # f.write('<CellData> \n') #- -# #- Writing BUNCH Density -# f.write('<DataArray type="Float32" Name="rho_bunch" format="binary"> \n') mesh = matrix2vector( rhobunch ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Writing Tot-Density -# f.write('<DataArray type="Float32" Name="rho" format="binary"> \n') mesh = matrix2vector( rhobunch+rhobck ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory rhobunch = [0.]; rhobck = [0.] #- Writing E-field -# #- background -# file_name = 'Exfout'+sf+'.bin' Ex, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eyfout'+sf+'.bin' Ey, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezfout'+sf+'.bin' Ez, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- bunch(es) -# file_name = 'Exbout'+sf+'.bin' Exb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+sf+'.bin' Eyb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezbout'+sf+'.bin' Ezb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Ex = Ex[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Ey = Ey[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Ez = Ez[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Exb = Exb[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Eyb = Eyb[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Ezb = Ezb[:,cell_cut:-cell_cut,cell_cut:-cell_cut] #- #- E-field bunch f.write('<DataArray type="Float32" Name="E_bunch" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Exb,Eyb,Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- E-field total f.write('<DataArray type="Float32" Name="E" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Ex+Exb,Ey+Eyb,Ez+Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Ex=[0.];Ey=[0.];Ez=[0.];Exb=[0.];Eyb=[0.];Ezb=[0.]; #- Writing B-field -# #- background -# file_name = 'Bxfout'+sf+'.bin' Bx, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Byfout'+sf+'.bin' By, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Bzfout'+sf+'.bin' Bz, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # #- bunch(es) -# # file_name = 'Bxbout'+sf+'.bin' # Bxb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bybout'+sf+'.bin' # Byb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bzbout'+sf+'.bin' # Bzb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Bx = Bx[:,cell_cut:-cell_cut,cell_cut:-cell_cut] By = By[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Bz = Bz[:,cell_cut:-cell_cut,cell_cut:-cell_cut] #- #- B-field bunch # f.write('<DataArray type="Float32" Name="B_bunch" NumberOfComponents="3" format="binary"> \n') # mesh = matrix2vectorField(Bxb,Byb,Bzb) # s = base64.b64encode(np.array(mesh,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # f.write('</DataArray> \n') #- B-field total f.write('<DataArray type="Float32" Name="B" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Bx,By,Bz) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Bx=[0.];By=[0.];Bz=[0.];#Bxb=[0.];Byb=[0.];Bzb=[0.]; #- Point Data End-# f.write('</PointData> \n') # f.write('</CellData> \n') #- -# # frame = 0 # s='%2.2i'%frame #conversion to 2-character-long-string # file_name = 'Bdenout'+s+'.bin' # matrix, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # # file_name = 'Edenout'+s+'.bin' # # matrix2, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # #- cut & sign # matrix = np.abs( matrix ) # # matrix2 = np.abs( matrix2 ) # size = matrix.shape #- writing vts header # f = open('test.vts','w+') # f.write('<?xml version="1.0"?>' + '\n') # f.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') # f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1],0,size[0],0,size[2]) ) # f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1],0,size[0],0,size[2]) ) # f.write('<Points> \n') # f.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') # buffer=[] # for i in range(1,NI+2): # for j in range(1,NJ+2): # for k in range(1,NK+2): # buffer.append(1./float(NJ)*(float(j)-1.)) # buffer.append(1./float(NI)*(float(i)-1.)) # buffer.append(1./float(NK)*(float(k)-1.)) # # s = base64.b64encode(np.array(buffer,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # f.write('</DataArray> \n') # f.write('</Points> \n') # f.write('<PointData>\n') # f.write('<DataArray type="Float32" Name="rhoEdge" format="binary"> \n') # buffer=[] # n=0 # for i in range(0,NI+1): # for j in range(0,NJ+1): # for k in range(0,NK+1): # buffer.append(n*1.) # n+=1 # # s = base64.b64encode(np.array(buffer,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # # for item in buffer: # # f.write(str(item)+'\n') # f.write('</DataArray> \n') # f.write('</PointData> \n') # f.write('<CellData> \n') # f.write('<DataArray type="Float32" Name="rho" format="ascii"> \n') # # buffer=[] # n=0 # for i in range(0,NI): # for j in range(0,NJ): # for k in range(0,NK): # buffer.append(str(n*1.)) # n+=1 # # for item in buffer: # f.write(str(item)+'\n') # # f.write('</DataArray> \n') # f.write('</CellData> \n') f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>')
def write_density_vts(path,frame,X,Y,Z,cell_cut): sf='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Bdenout'+sf+'.bin' rhobunch, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rhobunch = np.abs( rhobunch ) file_name = 'Edenout'+sf+'.bin' rhobck, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rhobck = np.abs( rhobck ) #- matrix shaving if cell_cut > 0: rhobunch = rhobunch[:,cell_cut:-cell_cut,cell_cut:-cell_cut] rhobck = rhobck[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = rhobunch.shape #- #- writing vts header #total f_total = open(os.path.join(path,'VTS_files','ALaDyn_rho_'+sf+'.vts'),'w+') f_total.write('<?xml version="1.0"?>' + '\n') f_total.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f_total.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) f_total.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #bunch(es) f_bunch = open(os.path.join(path,'VTS_files','ALaDyn_rho_bunch_'+sf+'.vts'),'w+') f_bunch.write('<?xml version="1.0"?>' + '\n') f_bunch.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f_bunch.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) f_bunch.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #background f_bck = open(os.path.join(path,'VTS_files','ALaDyn_rho_bck_'+sf+'.vts'),'w+') f_bck.write('<?xml version="1.0"?>' + '\n') f_bck.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f_bck.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) f_bck.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #--- ---# #- generating vector-MESH mesh=[] for i in range(0,size[0]): for j in range(0,size[1]): for k in range(0,size[2]): mesh.append( Y[j] ) mesh.append( Z[k] ) mesh.append( X[i] ) #- Writing MESH -# #it's the same for the whole 3 cases #total f_total.write('<Points> \n') f_total.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f_total.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f_total.write( s ) f_total.write('</DataArray> \n') f_total.write('</Points> \n') #bunch(es) f_bunch.write('<Points> \n') f_bunch.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f_bunch.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f_bunch.write( s ) f_bunch.write('</DataArray> \n') f_bunch.write('</Points> \n') #background f_bck.write('<Points> \n') f_bck.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f_bck.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f_bck.write( s ) f_bck.write('</DataArray> \n') f_bck.write('</Points> \n') #- -# #- Point Data Begin-# f_total.write('<PointData>\n') f_bunch.write('<PointData>\n') f_bck.write('<PointData>\n') #- -# #- Writing DensitIES -# #total f_total.write('<DataArray type="Float32" Name="rho" format="binary"> \n') mesh = matrix2vector( rhobunch+rhobck ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f_total.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f_total.write(s) f_total.write('</DataArray> \n') #bunch(es) f_bunch.write('<DataArray type="Float32" Name="rho_bunch" format="binary"> \n') mesh = matrix2vector( rhobunch ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f_bunch.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f_bunch.write(s) f_bunch.write('</DataArray> \n') #background f_bck.write('<DataArray type="Float32" Name="rho_bck" format="binary"> \n') mesh = matrix2vector( rhobck ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f_bck.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f_bck.write(s) f_bck.write('</DataArray> \n') #-Deallocate memory rhobunch = [0.]; rhobck = [0.] #- Point Data End-# f_total.write('</PointData> \n') f_bunch.write('</PointData> \n') f_bck.write('</PointData> \n') #- -# # --- # f_total.write('</Piece> \n') f_bunch.write('</Piece> \n') f_bck.write('</Piece> \n') f_total.write('</StructuredGrid> \n') f_bunch.write('</StructuredGrid> \n') f_bck.write('</StructuredGrid> \n') f_total.write('</VTKFile>') f_bunch.write('</VTKFile>') f_bck.write('</VTKFile>')
def write_E_vts(path,frame,X,Y,Z,cell_cut): # for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # write_VTS(path,i) sf='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Exfout'+sf+'.bin' Ex, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eyfout'+sf+'.bin' Ey, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezfout'+sf+'.bin' Ez, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- bunch(es) -# file_name = 'Exbout'+sf+'.bin' Exb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+sf+'.bin' Eyb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezbout'+sf+'.bin' Ezb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Ex = Ex[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Ey = Ey[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Ez = Ez[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Exb = Exb[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Eyb = Eyb[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Ezb = Ezb[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = Ex.shape #- #- writing vts header f = open(os.path.join(path,'VTS_files','ALaDyn_E_'+sf+'.vts'),'w+') f.write('<?xml version="1.0"?>' + '\n') f.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #--- ---# #- writing Ex-vts header fEx = open(os.path.join(path,'VTS_files','ALaDyn_Ex_'+sf+'.vts'),'w+') fEx.write('<?xml version="1.0"?>' + '\n') fEx.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') fEx.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) fEx.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #- writing Ey-vts header fEy = open(os.path.join(path,'VTS_files','ALaDyn_Ey_'+sf+'.vts'),'w+') fEy.write('<?xml version="1.0"?>' + '\n') fEy.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') fEy.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) fEy.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #- writing Ex-vts header fEz = open(os.path.join(path,'VTS_files','ALaDyn_Ez_'+sf+'.vts'),'w+') fEz.write('<?xml version="1.0"?>' + '\n') fEz.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') fEz.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) fEz.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #--- ---# #- generating vector-MESH mesh=[] for i in range(0,size[0]): for j in range(0,size[1]): for k in range(0,size[2]): mesh.append( Y[j] ) mesh.append( Z[k] ) mesh.append( X[i] ) #- Writing MESH -# f.write('<Points> \n') f.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f.write( s ) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Writing ExMESH -# fEx.write('<Points> \n') fEx.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) fEx.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) fEx.write( s ) fEx.write('</DataArray> \n') fEx.write('</Points> \n') #- Writing ExMESH -# fEy.write('<Points> \n') fEy.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) fEy.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) fEy.write( s ) fEy.write('</DataArray> \n') fEy.write('</Points> \n') #- Writing ExMESH -# fEz.write('<Points> \n') fEz.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) fEz.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) fEz.write( s ) fEz.write('</DataArray> \n') fEz.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') fEx.write('<PointData>\n') fEy.write('<PointData>\n') fEz.write('<PointData>\n') #- -# #- Writing E-field -# #- E-field total f.write('<DataArray type="Float32" Name="E" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Ex+Exb,Ey+Eyb,Ez+Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Writing Ex-field -# fEx.write('<DataArray type="Float32" Name="Ex" NumberOfComponents="1" format="binary"> \n') mesh = matrix2vector(Ex+Exb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) fEx.write(base64.b64encode(np.array(len(s),dtype=np.int32))) fEx.write(s) fEx.write('</DataArray> \n') #- Writing Ex-field -# fEy.write('<DataArray type="Float32" Name="Ey" NumberOfComponents="1" format="binary"> \n') mesh = matrix2vector(Ey+Eyb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) fEy.write(base64.b64encode(np.array(len(s),dtype=np.int32))) fEy.write(s) fEy.write('</DataArray> \n') #- Writing Ex-field -# fEz.write('<DataArray type="Float32" Name="Ez" NumberOfComponents="1" format="binary"> \n') mesh = matrix2vector(Ez+Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) fEz.write(base64.b64encode(np.array(len(s),dtype=np.int32))) fEz.write(s) fEz.write('</DataArray> \n') #-Deallocate memory Ex=[0.];Ey=[0.];Ez=[0.];Exb=[0.];Eyb=[0.];Ezb=[0.]; #- Point Data End-# f.write('</PointData> \n') fEx.write('</PointData> \n') fEy.write('</PointData> \n') fEz.write('</PointData> \n') #- -# f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>') fEx.write('</Piece> \n') fEx.write('</StructuredGrid> \n') fEx.write('</VTKFile>') fEy.write('</Piece> \n') fEy.write('</StructuredGrid> \n') fEy.write('</VTKFile>') fEz.write('</Piece> \n') fEz.write('</StructuredGrid> \n') fEz.write('</VTKFile>')
# FRAME NUMBER frame = 6 # --- # magnification_fig = 3.0 rho_min = 10 rho_max = 0.001 #--- *** ---# file_name = 'Bdenout'+('%2.2i'%frame)+'.bin' matrix, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Edenout'+('%2.2i'%frame)+'.bin' matrix2, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #--- *** ---# file_name = 'Exbout'+('%2.2i'%frame)+'.bin' Ex_b, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+('%2.2i'%frame)+'.bin' Ey_b, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezbout'+('%2.2i'%frame)+'.bin' Ez_b, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Exfout'+('%2.2i'%frame)+'.bin' Ex_w, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eyfout'+('%2.2i'%frame)+'.bin'
def write_vts_section_longitudinal(path, frame, X, Y, Z, cell_cut, sliceposition_y): sf = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Bdenout' + sf + '.bin' rhobunch, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') rhobunch = np.abs(rhobunch) file_name = 'Edenout' + sf + '.bin' rhobck, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') rhobck = np.abs(rhobck) #-original size sizeO = rhobunch.shape #- matrix shaving if cell_cut > 0: rhobunch = rhobunch[:, sizeO[1] / 2 + sliceposition_y, cell_cut:-cell_cut] rhobck = rhobck[:, sizeO[1] / 2 + sliceposition_y, cell_cut:-cell_cut] Y = Y[sizeO[1] / 2 + sliceposition_y] Z = Z[cell_cut:-cell_cut] else: rhobunch = rhobunch[:, sizeO[1] / 2 + sliceposition_y, :] rhobck = rhobck[:, sizeO[1] / 2 + sliceposition_y, :] Y = Y[sizeO[1] / 2 + sliceposition_y] Z = Z[:] #- size = rhobunch.shape #- #- writing vts header f = open( os.path.join(path, 'VTS_files', 'ALaDyn_section_longitudinal_output_' + sf + '.vts'), 'w+') f.write('<?xml version="1.0"?>' + '\n') f.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, 0, 0, size[1] - 1, 0, size[0] - 1)) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, 0, 0, size[1] - 1, 0, size[0] - 1)) #--- ---# #- generating vector-MESH mesh = [] for i in range(0, size[0]): for k in range(0, size[1]): mesh.append(Y) mesh.append(Z[k]) mesh.append(X[i]) #- Writing MESH -# f.write('<Points> \n') f.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') # f.write('<CellData> \n') #- -# #- Writing BUNCH Density -# f.write('<DataArray type="Float32" Name="rho_bunch" format="binary"> \n') mesh = matrix2vector(rhobunch) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Writing Tot-Density -# f.write('<DataArray type="Float32" Name="rho" format="binary"> \n') mesh = matrix2vector(rhobunch + rhobck) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory rhobunch = [0.] rhobck = [0.] #- Writing E-field -# #- background -# file_name = 'Exfout' + sf + '.bin' Ex, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Eyfout' + sf + '.bin' Ey, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Ezfout' + sf + '.bin' Ez, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- bunch(es) -# file_name = 'Exbout' + sf + '.bin' Exb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Eybout' + sf + '.bin' Eyb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Ezbout' + sf + '.bin' Ezb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- matrix shaving if cell_cut > 0: Ex = Ex[:, sizeO[1] / 2, cell_cut:-cell_cut] Ey = Ey[:, sizeO[1] / 2, cell_cut:-cell_cut] Ez = Ez[:, sizeO[1] / 2, cell_cut:-cell_cut] Exb = Exb[:, sizeO[1] / 2, cell_cut:-cell_cut] Eyb = Eyb[:, sizeO[1] / 2, cell_cut:-cell_cut] Ezb = Ezb[:, sizeO[1] / 2, cell_cut:-cell_cut] else: Ex = Ex[:, sizeO[1] / 2, :] Ey = Ey[:, sizeO[1] / 2, :] Ez = Ez[:, sizeO[1] / 2, :] Exb = Exb[:, sizeO[1] / 2, :] Eyb = Eyb[:, sizeO[1] / 2, :] Ezb = Ezb[:, sizeO[1] / 2, :] #- #- E-field bunch f.write( '<DataArray type="Float32" Name="E_bunch" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Exb, Eyb, Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- E-field total f.write( '<DataArray type="Float32" Name="E" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Ex + Exb, Ey + Eyb, Ez + Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Ex-total f.write( '<DataArray type="Float32" Name="Ex" NumberOfComponents="1" format="binary"> \n' ) mesh = matrix2vector(Ex + Exb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Ey-total f.write( '<DataArray type="Float32" Name="Ey" NumberOfComponents="1" format="binary"> \n' ) mesh = matrix2vector(Ey + Eyb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Ez-total f.write( '<DataArray type="Float32" Name="Ez" NumberOfComponents="1" format="binary"> \n' ) mesh = matrix2vector(Ez + Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Ex = [0.] Ey = [0.] Ez = [0.] Exb = [0.] Eyb = [0.] Ezb = [0.] #- Writing B-field -# #- background -# file_name = 'Bxfout' + sf + '.bin' Bx, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Byfout' + sf + '.bin' By, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Bzfout' + sf + '.bin' Bz, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') # #- bunch(es) -# # file_name = 'Bxbout'+sf+'.bin' # Bxb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bybout'+sf+'.bin' # Byb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bzbout'+sf+'.bin' # Bzb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Bx = Bx[:, sizeO[1] / 2, cell_cut:-cell_cut] By = By[:, sizeO[1] / 2, cell_cut:-cell_cut] Bz = Bz[:, sizeO[1] / 2, cell_cut:-cell_cut] else: Bx = Bx[:, sizeO[1] / 2, :] By = By[:, sizeO[1] / 2, :] Bz = Bz[:, sizeO[1] / 2, :] #- #- B-field bunch # f.write('<DataArray type="Float32" Name="B_bunch" NumberOfComponents="3" format="binary"> \n') # mesh = matrix2vectorField(Bxb,Byb,Bzb) # s = base64.b64encode(np.array(mesh,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # f.write('</DataArray> \n') #- B-field total f.write( '<DataArray type="Float32" Name="B" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Bx, By, Bz) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Bx = [0.] By = [0.] Bz = [0.] #Bxb=[0.];Byb=[0.];Bzb=[0.]; #- Point Data End-# f.write('</PointData> \n') # f.write('</CellData> \n') #- -# f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>')
### --- ### #--- *** ---# path = os.getcwd() # --- # # FRAME NUMBER frame = 2 # --- # magnification_fig = 3.0 #--- *** ---# file_name = 'Bdenout'+('%2.2i'%frame)+'.bin' rho_b, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Edenout'+('%2.2i'%frame)+'.bin' rho_w, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rho_b=np.abs( rho_b ) rho_w=np.abs( rho_w ) rho = rho_b+rho_w p = rho.shape x2=p[0]/2; y2=p[1]/2; z2=p[2]/2; #--- *** ---# file_name = 'Exbout'+('%2.2i'%frame)+'.bin' Ex_b, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+('%2.2i'%frame)+'.bin'
path = os.getcwd() #-folder output structure generate_folder_output_structure(path,'True') for i in range(frame_begin,frame_end+1): print '-------------------' s='%2.2i'%i path_read = os.path.join(path,'%4.4i'%i) path_write = path print path_read if output_exists(path_read,'rho',i) == True: print 'n_bunch --- frame >>> ',i n_bunch,ax1,ax2,ax3 = read_ALaDyn_bin(path_read,'Bdenout'+s+'.bin','grid') print 'n_bck --- frame >>> ',i n_bck,ax4,ax5,ax6 = read_ALaDyn_bin(path_read,'Edenout'+s+'.bin','grid') print 'jx_bunch --- frame >>> ',i jx_bunch,ax7,ax8,ax9= read_ALaDyn_bin(path_read,'Jxbout'+s+'.bin','grid') print 'jx_bck --- frame >>> ',i jx_bck,ax7,ax8,ax9 = read_ALaDyn_bin(path_read,'Jxfout'+s+'.bin','grid') n = n_bunch + n_bck jx = jx_bunch + jx_bck #variable declaration [nx,ny,nz]=n_bck.shape xmin = min(ax1)
def plot_Bfield_sections(path,frame,scale_factor,sliceposition_x,sliceposition_y,sliceposition_z,savedata): s='%2.2i'%frame #conversion to 2-character-long-string #- background -# file_name = 'Bxfout'+s+'.bin' Bx, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Byfout'+s+'.bin' By, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Bzfout'+s+'.bin' Bz, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- bunch(es) -# file_name = 'Bxbout'+s+'.bin' Bxb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Bybout'+s+'.bin' Byb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Bzbout'+s+'.bin' Bzb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #-sum-# Bx = Bx+Bxb By = By+Byb Bz = Bz+Bzb p = Bx.shape x2=p[0]/2; y2=p[1]/2; z2=p[2]/2; sizeX, sizeZ = figure_dimension_inch(x,y,z,scale_factor) #- Bx_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Bx[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Bx_XY_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- By_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,By[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'By_XY_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- Bz_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Bz[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Bz_XY_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- Bx_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Bx[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Bx_XZ_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- By_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,By[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'By_XZ_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- Bz_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Bz[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Bz_XZ_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) # #- Bx_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Bx[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Bx_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','B_field',name_output) ) # close(fig) # #- By_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,By[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'By_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','B_field',name_output) ) # close(fig) # #- Bz_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Bz[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Bz_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','B_field',name_output) ) # close(fig) #- norm(B) -# norm_B = np.power( np.power(Bx,2)+np.power(By,2)+np.power(Bz,2) , 0.5 ) #- norm_E_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,norm_B[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'B_XY_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- norm_E_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,norm_B[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'B_XZ_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) #- norm_E_YZ -# fig = figure(1, figsize=(sizeZ, sizeZ)) contourf(y,z,norm_B[x2,:,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'B_YZ_'+s+'.png' savefig( os.path.join(path,'plots','B_field',name_output) ) close(fig) if (savedata == 'True'): print 'saving E field data' #--- saves E-sections data---# np.savetxt( os.path.join(path,'plots','B_field',('Bx_z0_section_'+('%2.2i'%frame)+'.dat')) ,Bx[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'plots','B_field',('By_z0_section_'+('%2.2i'%frame)+'.dat')) ,By[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'plots','B_field',('Bz_z0_section_'+('%2.2i'%frame)+'.dat')) ,Bz[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'plots','B_field',('B_z0_section_'+('%2.2i'%frame)+'.dat')) ,norm_B[:,:,z2].T,fmt='%15.14e')
def plot_ionization_profile(path,frame,min_ionization_rate,max_ionzation_rate,isolines,celltocut,sliceposition_x,sliceposition_y,sliceposition_z,magnification_fig,savedata): s='%2.2i'%frame #conversion to 2-character-long-string # file_name = 'Elpout'+s+'.bin' file_name = 'H1dnout'+s+'.bin' matrix, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- cut & sign matrix = np.abs( matrix ) #---cut edges---# if celltocut > 0: matrix = matrix[:,celltocut:-celltocut,celltocut:-celltocut] y = y[celltocut:-celltocut] z = z[celltocut:-celltocut] p = matrix.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; sizeX, sizeZ = figure_dimension_inch(x,y,z,magnification_fig) # levs_lin = np.linspace( rho_min , rho_max ,isolines) # levs_lin = np.insert(levs_lin,0,np.min([np.min(matrix),np.min(matrix2)])) # levs_lin = np.insert(levs_lin,len(levs_lin),np.min([np.max(matrix),np.max(matrix2)])) # levs_log = np.logspace(log10(rho_min),log10(rho_max),isolines) #--------------------# #--- Linear plots ---# #--------------------# #- Plot Bdenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_XY_lin_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_XZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix2[:,:,z2].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_XY_lin_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix2[:,y2,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_XZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T + matrix2[:,:,z2].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_XY_lin_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T + matrix2[:,y2,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_XZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T - matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #--------------------# #--- Log plots ---# #--------------------# #- Plot Bdenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_XY_log_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T,levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_XZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix2[:,:,z2].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_XY_log_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix2[:,y2,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_XZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T + matrix2[:,:,z2].T,levs_log , norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_XY_log_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T + matrix2[:,y2,:].T,levs_log , norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_XZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T + matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #----- Save density sections data -----# if (savedata == 'True'): print('saving ionization data') ionization_map = matrix ionization_map=np.abs( ionization_map ) p = ionization_map.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; np.savetxt( os.path.join(path,'data','ionization',('ionization_profile_'+('%2.2i'%frame)+'.dat')),ionization_map[:,:,z2].T,fmt='%15.14e')
### --- ### sys.path.append( os.path.join(os.path.expanduser('~'), 'Codes', 'Code_ALaDyn', 'tools-ALaDyn', 'pythons')) from read_ALaDyn_bin import * ### --- ### #FLAGS plotDensitySlice = 0 plotDephasingMap = 0 plotInterferogram = 1 # - # #LOAD FILE bin_path = 'C:/Users/Fil/Codes/synthetic_diagnostics' n, x, y, z = read_ALaDyn_bin(bin_path, 'Edenout10.bin', 'grid') n_0 = 1E19 #CHIEDI ALBERTO NOME IN ALADYN n = n * n_0 #FUNDAMENTAL CONSTANTS c = 299792458 #[m/s] e = 1.60219E-19 # elementary charge [C] me = 9.1091E-31 # electron rest mass [kg] eps0 = 8.854187817e-12 #[F/m] #CCD #CCD_x=659 #CCD_z=494 recording_bit = 16
def write_B_vts(path,frame,X,Y,Z,cell_cut): # for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # write_VTS(path,i) sf='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Bxfout'+sf+'.bin' Bx, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Byfout'+sf+'.bin' By, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Bzfout'+sf+'.bin' Bz, x,y,z = read_ALaDyn_bin(path,file_name,'grid') size = Bx.shape #- matrix shaving if cell_cut > 0: Bx = Bx[:,cell_cut:-cell_cut,cell_cut:-cell_cut] By = By[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Bz = Bz[:,cell_cut:-cell_cut,cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = Bx.shape #- #- writing vts header f = open(os.path.join(path,'VTS_files','ALaDyn_B_'+sf+'.vts'),'w+') f.write('<?xml version="1.0"?>' + '\n') f.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1]-1,0,size[2]-1,0,size[0]-1) ) #--- ---# #- generating vector-MESH mesh=[] for i in range(0,size[0]): for j in range(0,size[1]): for k in range(0,size[2]): mesh.append( Y[j] ) mesh.append( Z[k] ) mesh.append( X[i] ) #- Writing MESH -# f.write('<Points> \n') f.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f.write( s ) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') #- -# #- Writing B-field -# f.write('<DataArray type="Float32" Name="B" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Bx,By,Bz) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Bx=[0.];By=[0.];Bz=[0.];#Bxb=[0.];Byb=[0.];Bzb=[0.]; #- Point Data End-# f.write('</PointData> \n') #- -# f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>')
#--- *** ---# if __name__ == '__main__': #-path path = os.getcwd() #-folder output structure generate_folder_vts(path) # write_vts(path,2) frame =0; s='%2.2i'%frame rhobunch, X,Y,Z = read_ALaDyn_bin(path,'Bdenout'+s+'.bin','grid') print '--- Generating VTS ---' for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # print '--- COMPLETE vts: frame >',i # write_vts(path,i,X,Y,Z,cell_cut) print '--- write vts-section longitudinal: frame >',i write_vts_section_longitudinal(path,i,X,Y,Z,cell_cut,sliceposition_y) #- in such a way it is much longer, but it is neater to write #- plus: it has to be done only once print '--- density only vts: frame >',i write_density_vts(path,i,X,Y,Z,cell_cut) print '--- E-field only vts: frame >',i
def plot_Efield_sections(path,frame,scale_factor,sliceposition_x,sliceposition_y,sliceposition_z,savedata): s='%2.2i'%frame #conversion to 2-character-long-string #- background -# file_name = 'Exfout'+s+'.bin' Ex, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eyfout'+s+'.bin' Ey, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezfout'+s+'.bin' Ez, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- bunch(es) -# file_name = 'Exbout'+s+'.bin' Exb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+s+'.bin' Eyb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezbout'+s+'.bin' Ezb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #-sum-# Ex = Ex+Exb Ey = Ey+Eyb Ez = Ez+Ezb p = Ex.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; sizeX, sizeZ = figure_dimension_inch(x,y,z,scale_factor) #- Ex_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Ex[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ex_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ey_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Ey[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ey_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ez_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Ez[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ez_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ex_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Ex[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ex_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ey_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Ey[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ey_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ez_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Ez[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ez_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) # #- Ex_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Ex[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Ex_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','E_field',name_output) ) # close(fig) # #- Ey_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Ey[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Ey_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','E_field',name_output) ) # close(fig) # #- Ez_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Ez[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Ez_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','E_field',name_output) ) # close(fig) #- norm(E) -# norm_E = np.power( np.power(Ex,2)+np.power(Ey,2)+np.power(Ez,2) , 0.5 ) #- norm_E_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,norm_E[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'E_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- norm_E_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,norm_E[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'E_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- norm_E_YZ -# fig = figure(1, figsize=(sizeZ, sizeZ)) contourf(y,z,norm_E[x2,:,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'E_YZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) if (savedata == 'True'): print 'saving E field data' #--- saves E-sections ---# np.savetxt( os.path.join(path,'data','E_field',('Ex_z0_section_'+('%2.2i'%frame)+'.dat' )),Ex[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','E_field',('Ey_z0_section_'+('%2.2i'%frame)+'.dat' )),Ey[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','E_field',('Ez_z0_section_'+('%2.2i'%frame)+'.dat' )),Ez[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','E_field',('E_z0_section_'+('%2.2i'%frame)+'.dat' )),norm_E[:,:,z2].T,fmt='%15.14e')
def plot_energy_density_sections(path,frame,Energy_density_min,Energy_density_max,isolines,celltocut,sliceposition_x,sliceposition_y,sliceposition_z,magnification_fig,savedata): s='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Elenout'+s+'.bin' matrix3, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- cut & sign matrix3 = np.abs( matrix3 ) print 'Energy_density_max >>', np.max([np.max(matrix3)]) print 'Energy_density_min >>', np.min([np.min(matrix3)]) #---cut edges---# if celltocut > 0: matrix3 = matrix3[:,celltocut:-celltocut,celltocut:-celltocut] y = y[celltocut:-celltocut] z = z[celltocut:-celltocut] p = matrix3.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; sizeX, sizeZ = figure_dimension_inch(x,y,z,magnification_fig) levs_lin = np.linspace( Energy_density_min , Energy_density_max ,isolines) levs_log = np.logspace(log10(Energy_density_min),log10(Energy_density_max),isolines) #--------------------# #--- Linear plots ---# #--------------------# #- Plot Elenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix3[:,:,z2].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'Energy_density_XY_lin_'+s+'.png' savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix3[:,y2,:].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'Energy_density_XZ_lin_'+s+'.png' fig.savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) #--------------------# #--- Log plots ---# #--------------------# #- Plot Elenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix3[:,:,z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'Energy_density_XY_log_'+s+'.png' savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix3[:,y2,:].T,levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'Energy_density_XZ_log_'+s+'.png' fig.savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #----- Save density sections data -----# if (savedata == 'True'): print 'saving Energy_density data' Energy_density = matrix3 p = Energy_density.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; np.savetxt( os.path.join(path,'data','Energy_density',('Energy_Density'+('%2.2i'%frame)+'.dat')),Energy_density[:,:,z2].T,fmt='%15.14e')
def plot_Efield_sections(path,frame,scale_factor,sliceposition_x,sliceposition_y,sliceposition_z,savedata): s='%2.2i'%frame #conversion to 2-character-long-string #- background -# file_name = 'Exfout'+s+'.bin' Ex, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eyfout'+s+'.bin' Ey, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezfout'+s+'.bin' Ez, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- bunch(es) -# file_name = 'Exbout'+s+'.bin' Exb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+s+'.bin' Eyb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezbout'+s+'.bin' Ezb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #-sum-# Ex = Ex+Exb Ey = Ey+Eyb Ez = Ez+Ezb p = Ex.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; sizeX, sizeZ = figure_dimension_inch(x,y,z,scale_factor) #- Ex_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Ex[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ex_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ey_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Ey[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ey_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ez_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,Ez[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ez_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ex_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Ex[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ex_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ey_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Ey[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ey_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- Ez_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,Ez[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'Ez_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) # #- Ex_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Ex[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Ex_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','E_field',name_output) ) # close(fig) # #- Ey_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Ey[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Ey_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','E_field',name_output) ) # close(fig) # #- Ez_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Ez[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Ez_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','E_field',name_output) ) # close(fig) #- norm(E) -# norm_E = np.power( np.power(Ex,2)+np.power(Ey,2)+np.power(Ez,2) , 0.5 ) #- norm_E_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,norm_E[:,:,z2].T,100, linewidths = 0.00001) axis('tight') name_output = 'E_XY_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- norm_E_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,norm_E[:,y2,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'E_XZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) #- norm_E_YZ -# fig = figure(1, figsize=(sizeZ, sizeZ)) contourf(y,z,norm_E[x2,:,:].T,100, linewidths = 0.00001) axis('tight') name_output = 'E_YZ_'+s+'.png' savefig( os.path.join(path,'plots','E_field',name_output) ) close(fig) if (savedata == 'True'): print('saving E field data') #--- saves E-sections ---# np.savetxt( os.path.join(path,'data','E_field',('Ex_z0_section_'+('%2.2i'%frame)+'.dat' )),Ex[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','E_field',('Ey_z0_section_'+('%2.2i'%frame)+'.dat' )),Ey[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','E_field',('Ez_z0_section_'+('%2.2i'%frame)+'.dat' )),Ez[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','E_field',('E_z0_section_'+('%2.2i'%frame)+'.dat' )),norm_E[:,:,z2].T,fmt='%15.14e')
path = os.getcwd() #-folder output structure generate_folder_output_structure(path, 'True') for i in range(frame_begin, frame_end + 1): print '-------------------' s = '%2.2i' % i path_read = os.path.join(path, '%4.4i' % i) path_write = path print path_read if output_exists(path_read, 'rho', i) == True: print 'n_bunch --- frame >>> ', i n_bunch, ax1, ax2, ax3 = read_ALaDyn_bin(path_read, 'Bdenout' + s + '.bin', 'grid') print 'n_bck --- frame >>> ', i n_bck, ax4, ax5, ax6 = read_ALaDyn_bin(path_read, 'Edenout' + s + '.bin', 'grid') print 'jx_bunch --- frame >>> ', i jx_bunch, ax7, ax8, ax9 = read_ALaDyn_bin(path_read, 'Jxbout' + s + '.bin', 'grid') print 'jx_bck --- frame >>> ', i jx_bck, ax7, ax8, ax9 = read_ALaDyn_bin(path_read, 'Jxfout' + s + '.bin', 'grid') n = n_bunch + n_bck jx = jx_bunch + jx_bck
def write_vts_section_longitudinal(path,frame,X,Y,Z,cell_cut,sliceposition_y): sf='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Bdenout'+sf+'.bin' rhobunch, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rhobunch = np.abs( rhobunch ) file_name = 'Edenout'+sf+'.bin' rhobck, x,y,z = read_ALaDyn_bin(path,file_name,'grid') rhobck = np.abs( rhobck ) #-original size sizeO = rhobunch.shape #- matrix shaving if cell_cut > 0: rhobunch = rhobunch[:, sizeO[1]/2+sliceposition_y, cell_cut:-cell_cut] rhobck = rhobck[:, sizeO[1]/2+sliceposition_y, cell_cut:-cell_cut] Y = Y[ sizeO[1]/2+sliceposition_y ] Z = Z[cell_cut:-cell_cut] else: rhobunch = rhobunch[:, sizeO[1]/2+sliceposition_y,:] rhobck = rhobck[:, sizeO[1]/2+sliceposition_y,:] Y = Y[ sizeO[1]/2+sliceposition_y ] Z = Z[:] #- size = rhobunch.shape #- #- writing vts header f = open(os.path.join(path,'VTS_files','ALaDyn_section_longitudinal_output_'+sf+'.vts'),'w+') f.write('<?xml version="1.0"?>' + '\n') f.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,0,0,size[1]-1,0,size[0]-1) ) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,0,0,size[1]-1,0,size[0]-1) ) #--- ---# #- generating vector-MESH mesh=[] for i in range(0,size[0]): for k in range(0,size[1]): mesh.append( Y ) mesh.append( Z[k] ) mesh.append( X[i] ) #- Writing MESH -# f.write('<Points> \n') f.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write( base64.b64encode(np.array(len(s),dtype=np.int32)) ) f.write( s ) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') # f.write('<CellData> \n') #- -# #- Writing BUNCH Density -# f.write('<DataArray type="Float32" Name="rho_bunch" format="binary"> \n') mesh = matrix2vector( rhobunch ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Writing Tot-Density -# f.write('<DataArray type="Float32" Name="rho" format="binary"> \n') mesh = matrix2vector( rhobunch+rhobck ) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory rhobunch = [0.]; rhobck = [0.] #- Writing E-field -# #- background -# file_name = 'Exfout'+sf+'.bin' Ex, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eyfout'+sf+'.bin' Ey, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezfout'+sf+'.bin' Ez, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- bunch(es) -# file_name = 'Exbout'+sf+'.bin' Exb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Eybout'+sf+'.bin' Eyb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Ezbout'+sf+'.bin' Ezb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Ex = Ex[:,sizeO[1]/2,cell_cut:-cell_cut] Ey = Ey[:,sizeO[1]/2,cell_cut:-cell_cut] Ez = Ez[:,sizeO[1]/2,cell_cut:-cell_cut] Exb = Exb[:,sizeO[1]/2,cell_cut:-cell_cut] Eyb = Eyb[:,sizeO[1]/2,cell_cut:-cell_cut] Ezb = Ezb[:,sizeO[1]/2,cell_cut:-cell_cut] else: Ex = Ex[:,sizeO[1]/2,:] Ey = Ey[:,sizeO[1]/2,:] Ez = Ez[:,sizeO[1]/2,:] Exb = Exb[:,sizeO[1]/2,:] Eyb = Eyb[:,sizeO[1]/2,:] Ezb = Ezb[:,sizeO[1]/2,:] #- #- E-field bunch f.write('<DataArray type="Float32" Name="E_bunch" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Exb,Eyb,Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- E-field total f.write('<DataArray type="Float32" Name="E" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Ex+Exb,Ey+Eyb,Ez+Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Ex-total f.write('<DataArray type="Float32" Name="Ex" NumberOfComponents="1" format="binary"> \n') mesh = matrix2vector(Ex+Exb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Ey-total f.write('<DataArray type="Float32" Name="Ey" NumberOfComponents="1" format="binary"> \n') mesh = matrix2vector(Ey+Eyb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Ez-total f.write('<DataArray type="Float32" Name="Ez" NumberOfComponents="1" format="binary"> \n') mesh = matrix2vector(Ez+Ezb) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Ex=[0.];Ey=[0.];Ez=[0.];Exb=[0.];Eyb=[0.];Ezb=[0.]; #- Writing B-field -# #- background -# file_name = 'Bxfout'+sf+'.bin' Bx, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Byfout'+sf+'.bin' By, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Bzfout'+sf+'.bin' Bz, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # #- bunch(es) -# # file_name = 'Bxbout'+sf+'.bin' # Bxb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bybout'+sf+'.bin' # Byb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bzbout'+sf+'.bin' # Bzb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Bx = Bx[:,sizeO[1]/2,cell_cut:-cell_cut] By = By[:,sizeO[1]/2,cell_cut:-cell_cut] Bz = Bz[:,sizeO[1]/2,cell_cut:-cell_cut] else: Bx = Bx[:,sizeO[1]/2,:] By = By[:,sizeO[1]/2,:] Bz = Bz[:,sizeO[1]/2,:] #- #- B-field bunch # f.write('<DataArray type="Float32" Name="B_bunch" NumberOfComponents="3" format="binary"> \n') # mesh = matrix2vectorField(Bxb,Byb,Bzb) # s = base64.b64encode(np.array(mesh,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # f.write('</DataArray> \n') #- B-field total f.write('<DataArray type="Float32" Name="B" NumberOfComponents="3" format="binary"> \n') mesh = matrix2vectorField(Bx,By,Bz) s = base64.b64encode(np.array(mesh,dtype=np.float32)) f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Bx=[0.];By=[0.];Bz=[0.];#Bxb=[0.];Byb=[0.];Bzb=[0.]; #- Point Data End-# f.write('</PointData> \n') # f.write('</CellData> \n') #- -# f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>')
def plot_Bfield_sections(path, frame, scale_factor, sliceposition_x, sliceposition_y, sliceposition_z, savedata): s = '%2.2i' % frame #conversion to 2-character-long-string #- background -# file_name = 'Bxfout' + s + '.bin' Bx, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Byfout' + s + '.bin' By, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Bzfout' + s + '.bin' Bz, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- bunch(es) -# file_name = 'Bxbout' + s + '.bin' Bxb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Bybout' + s + '.bin' Byb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Bzbout' + s + '.bin' Bzb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #-sum-# Bx = Bx + Bxb By = By + Byb Bz = Bz + Bzb p = Bx.shape x2 = p[0] / 2 y2 = p[1] / 2 z2 = p[2] / 2 sizeX, sizeZ = figure_dimension_inch(x, y, z, scale_factor) #- Bx_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, Bx[:, :, z2].T, 100, linewidths=0.00001) axis('tight') name_output = 'Bx_XY_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- By_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, By[:, :, z2].T, 100, linewidths=0.00001) axis('tight') name_output = 'By_XY_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- Bz_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, Bz[:, :, z2].T, 100, linewidths=0.00001) axis('tight') name_output = 'Bz_XY_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- Bx_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, Bx[:, y2, :].T, 100, linewidths=0.00001) axis('tight') name_output = 'Bx_XZ_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- By_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, By[:, y2, :].T, 100, linewidths=0.00001) axis('tight') name_output = 'By_XZ_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- Bz_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, Bz[:, y2, :].T, 100, linewidths=0.00001) axis('tight') name_output = 'Bz_XZ_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) # #- Bx_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Bx[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Bx_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','B_field',name_output) ) # close(fig) # #- By_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,By[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'By_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','B_field',name_output) ) # close(fig) # #- Bz_YZ -# # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,Bz[x2,:,:].T,100, linewidths = 0.00001) # axis('tight') # name_output = 'Bz_YZ_'+s+'.png' # savefig( os.path.join(path,'plots','B_field',name_output) ) # close(fig) #- norm(B) -# norm_B = np.power(np.power(Bx, 2) + np.power(By, 2) + np.power(Bz, 2), 0.5) #- norm_E_XY -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, norm_B[:, :, z2].T, 100, linewidths=0.00001) axis('tight') name_output = 'B_XY_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- norm_E_XZ -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, norm_B[:, y2, :].T, 100, linewidths=0.00001) axis('tight') name_output = 'B_XZ_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) #- norm_E_YZ -# fig = figure(1, figsize=(sizeZ, sizeZ)) contourf(y, z, norm_B[x2, :, :].T, 100, linewidths=0.00001) axis('tight') name_output = 'B_YZ_' + s + '.png' savefig(os.path.join(path, 'plots', 'B_field', name_output)) close(fig) if (savedata == 'True'): print('saving E field data') #--- saves E-sections data---# np.savetxt(os.path.join(path, 'plots', 'B_field', ('Bx_z0_section_' + ('%2.2i' % frame) + '.dat')), Bx[:, :, z2].T, fmt='%15.14e') np.savetxt(os.path.join(path, 'plots', 'B_field', ('By_z0_section_' + ('%2.2i' % frame) + '.dat')), By[:, :, z2].T, fmt='%15.14e') np.savetxt(os.path.join(path, 'plots', 'B_field', ('Bz_z0_section_' + ('%2.2i' % frame) + '.dat')), Bz[:, :, z2].T, fmt='%15.14e') np.savetxt(os.path.join(path, 'plots', 'B_field', ('B_z0_section_' + ('%2.2i' % frame) + '.dat')), norm_B[:, :, z2].T, fmt='%15.14e')
def plot_density_sections(path,frame,rho_min,rho_max,isolines,celltocut,sliceposition_x,sliceposition_y,sliceposition_z,magnification_fig,savedata): s='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Bdenout'+s+'.bin' matrix, x,y,z = read_ALaDyn_bin(path,file_name,'grid') file_name = 'Edenout'+s+'.bin' matrix2, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- cut & sign matrix = np.abs( matrix ) matrix2 = np.abs( matrix2 ) print 'rho-max >>', np.max([np.max(matrix),np.max(matrix2)]) print 'rho-min >>', np.min([np.min(matrix),np.min(matrix2)]) # matrix[ (matrix<rho_min) ] = rho_min # matrix[ (matrix>rho_max) ] = rho_max # matrix2[ (matrix2<rho_min) ] = rho_min # matrix2[ (matrix2>rho_max) ] = rho_max #---cut edges---# if celltocut > 0: matrix = matrix[:,celltocut:-celltocut,celltocut:-celltocut] matrix2 = matrix2[:,celltocut:-celltocut,celltocut:-celltocut] y = y[celltocut:-celltocut] z = z[celltocut:-celltocut] p = matrix.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; sizeX, sizeZ = figure_dimension_inch(x,y,z,magnification_fig) levs_lin = np.linspace( rho_min , rho_max ,isolines) # levs_lin = np.insert(levs_lin,0,np.min([np.min(matrix),np.min(matrix2)])) # levs_lin = np.insert(levs_lin,len(levs_lin),np.min([np.max(matrix),np.max(matrix2)])) levs_log = np.logspace(log10(rho_min),log10(rho_max),isolines) #--------------------# #--- Linear plots ---# #--------------------# #- Plot Bdenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix[:,:,z2].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'rho_Bunch_XY_lin_'+s+'.png' savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix[:,y2,:].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'rho_Bunch_XZ_lin_'+s+'.png' fig.savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix2[:,:,z2].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'rho_Background_XY_lin_'+s+'.png' savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix2[:,y2,:].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'rho_Background_XZ_lin_'+s+'.png' fig.savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix[:,:,z2].T + matrix2[:,:,z2].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'rho_tot_XY_lin_'+s+'.png' savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix[:,y2,:].T + matrix2[:,y2,:].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'rho_tot_XZ_lin_'+s+'.png' fig.savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T - matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #--------------------# #--- Log plots ---# #--------------------# #- Plot Bdenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix[:,:,z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Bunch_XY_log_'+s+'.png' savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix[:,y2,:].T,levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Bunch_XZ_log_'+s+'.png' fig.savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix2[:,:,z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Background_XY_log_'+s+'.png' savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix2[:,y2,:].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Background_XZ_log_'+s+'.png' fig.savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix[:,:,z2].T + matrix2[:,:,z2].T,levs_log , norm=colors.LogNorm()) axis('tight') name_output = 'rho_tot_XY_log_'+s+'.png' savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix[:,y2,:].T + matrix2[:,y2,:].T,levs_log , norm=colors.LogNorm()) axis('tight') name_output = 'rho_tot_XZ_log_'+s+'.png' fig.savefig( os.path.join(path,'plots','rho',name_output) ) close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T + matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #----- Save density sections data -----# if (savedata == 'True'): print 'saving rho data' rho_b = matrix rho_w = matrix2 rho_b=np.abs( rho_b ) rho_w=np.abs( rho_w ) rho = rho_b+rho_w p = rho.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; np.savetxt( os.path.join(path,'data','rho',('rho_section_'+('%2.2i'%frame)+'.dat')),rho[:,:,z2].T,fmt='%15.14e') np.savetxt( os.path.join(path,'data','rho',('rho_bunch_section_'+('%2.2i'%frame)+'.dat')),rho_b[:,:,z2].T,fmt='%15.14e')
def write_density_vts(path, frame, X, Y, Z, cell_cut): sf = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Bdenout' + sf + '.bin' rhobunch, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') rhobunch = np.abs(rhobunch) file_name = 'Edenout' + sf + '.bin' rhobck, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') rhobck = np.abs(rhobck) #- matrix shaving if cell_cut > 0: rhobunch = rhobunch[:, cell_cut:-cell_cut, cell_cut:-cell_cut] rhobck = rhobck[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = rhobunch.shape #- #- writing vts header #total f_total = open( os.path.join(path, 'VTS_files', 'ALaDyn_rho_' + sf + '.vts'), 'w+') f_total.write('<?xml version="1.0"?>' + '\n') f_total.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f_total.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) f_total.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #bunch(es) f_bunch = open( os.path.join(path, 'VTS_files', 'ALaDyn_rho_bunch_' + sf + '.vts'), 'w+') f_bunch.write('<?xml version="1.0"?>' + '\n') f_bunch.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f_bunch.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) f_bunch.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #background f_bck = open( os.path.join(path, 'VTS_files', 'ALaDyn_rho_bck_' + sf + '.vts'), 'w+') f_bck.write('<?xml version="1.0"?>' + '\n') f_bck.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f_bck.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) f_bck.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #--- ---# #- generating vector-MESH mesh = [] for i in range(0, size[0]): for j in range(0, size[1]): for k in range(0, size[2]): mesh.append(Y[j]) mesh.append(Z[k]) mesh.append(X[i]) #- Writing MESH -# #it's the same for the whole 3 cases #total f_total.write('<Points> \n') f_total.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f_total.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f_total.write(s) f_total.write('</DataArray> \n') f_total.write('</Points> \n') #bunch(es) f_bunch.write('<Points> \n') f_bunch.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f_bunch.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f_bunch.write(s) f_bunch.write('</DataArray> \n') f_bunch.write('</Points> \n') #background f_bck.write('<Points> \n') f_bck.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f_bck.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f_bck.write(s) f_bck.write('</DataArray> \n') f_bck.write('</Points> \n') #- -# #- Point Data Begin-# f_total.write('<PointData>\n') f_bunch.write('<PointData>\n') f_bck.write('<PointData>\n') #- -# #- Writing DensitIES -# #total f_total.write('<DataArray type="Float32" Name="rho" format="binary"> \n') mesh = matrix2vector(rhobunch + rhobck) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f_total.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f_total.write(s) f_total.write('</DataArray> \n') #bunch(es) f_bunch.write( '<DataArray type="Float32" Name="rho_bunch" format="binary"> \n') mesh = matrix2vector(rhobunch) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f_bunch.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f_bunch.write(s) f_bunch.write('</DataArray> \n') #background f_bck.write('<DataArray type="Float32" Name="rho_bck" format="binary"> \n') mesh = matrix2vector(rhobck) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f_bck.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f_bck.write(s) f_bck.write('</DataArray> \n') #-Deallocate memory rhobunch = [0.] rhobck = [0.] #- Point Data End-# f_total.write('</PointData> \n') f_bunch.write('</PointData> \n') f_bck.write('</PointData> \n') #- -# # --- # f_total.write('</Piece> \n') f_bunch.write('</Piece> \n') f_bck.write('</Piece> \n') f_total.write('</StructuredGrid> \n') f_bunch.write('</StructuredGrid> \n') f_bck.write('</StructuredGrid> \n') f_total.write('</VTKFile>') f_bunch.write('</VTKFile>') f_bck.write('</VTKFile>')
def plot_density_sections(path, frame, rho_min, rho_max, isolines, celltocut, sliceposition_x, sliceposition_y, sliceposition_z, magnification_fig, savedata): s = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Bdenout' + s + '.bin' matrix, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Edenout' + s + '.bin' matrix2, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- cut & sign matrix = np.abs(matrix) matrix2 = np.abs(matrix2) print('rho-max >>', np.max([np.max(matrix), np.max(matrix2)])) print('rho-min >>', np.min([np.min(matrix), np.min(matrix2)])) # matrix[ (matrix<rho_min) ] = rho_min # matrix[ (matrix>rho_max) ] = rho_max # matrix2[ (matrix2<rho_min) ] = rho_min # matrix2[ (matrix2>rho_max) ] = rho_max #---cut edges---# if celltocut > 0: matrix = matrix[:, celltocut:-celltocut, celltocut:-celltocut] matrix2 = matrix2[:, celltocut:-celltocut, celltocut:-celltocut] y = y[celltocut:-celltocut] z = z[celltocut:-celltocut] p = matrix.shape x2 = p[0] / 2 + sliceposition_x y2 = p[1] / 2 + sliceposition_y z2 = p[2] / 2 + sliceposition_z sizeX, sizeZ = figure_dimension_inch(x, y, z, magnification_fig) levs_lin = np.linspace(rho_min, rho_max, isolines) # levs_lin = np.insert(levs_lin,0,np.min([np.min(matrix),np.min(matrix2)])) # levs_lin = np.insert(levs_lin,len(levs_lin),np.min([np.max(matrix),np.max(matrix2)])) levs_log = np.logspace(log10(rho_min), log10(rho_max), isolines) #--------------------# #--- Linear plots ---# #--------------------# #- Plot Bdenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, matrix[:, :, z2].T, levs_lin, linewidths=0.00001) axis('tight') name_output = 'rho_Bunch_XY_lin_' + s + '.png' savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, matrix[:, y2, :].T, levs_lin, linewidths=0.00001) axis('tight') name_output = 'rho_Bunch_XZ_lin_' + s + '.png' fig.savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, matrix2[:, :, z2].T, levs_lin, linewidths=0.00001) axis('tight') name_output = 'rho_Background_XY_lin_' + s + '.png' savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, matrix2[:, y2, :].T, levs_lin, linewidths=0.00001) axis('tight') name_output = 'rho_Background_XZ_lin_' + s + '.png' fig.savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, matrix[:, :, z2].T + matrix2[:, :, z2].T, levs_lin, linewidths=0.00001) axis('tight') name_output = 'rho_tot_XY_lin_' + s + '.png' savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, matrix[:, y2, :].T + matrix2[:, y2, :].T, levs_lin, linewidths=0.00001) axis('tight') name_output = 'rho_tot_XZ_lin_' + s + '.png' fig.savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T - matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #--------------------# #--- Log plots ---# #--------------------# #- Plot Bdenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, matrix[:, :, z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Bunch_XY_log_' + s + '.png' savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, matrix[:, y2, :].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Bunch_XZ_log_' + s + '.png' fig.savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, matrix2[:, :, z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Background_XY_log_' + s + '.png' savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, matrix2[:, y2, :].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_Background_XZ_log_' + s + '.png' fig.savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, y, matrix[:, :, z2].T + matrix2[:, :, z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_tot_XY_log_' + s + '.png' savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x, z, matrix[:, y2, :].T + matrix2[:, y2, :].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'rho_tot_XZ_log_' + s + '.png' fig.savefig(os.path.join(path, 'plots', 'rho', name_output)) close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T + matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #----- Save density sections data -----# if (savedata == 'True'): print('saving rho data') rho_b = matrix rho_w = matrix2 rho_b = np.abs(rho_b) rho_w = np.abs(rho_w) rho = rho_b + rho_w p = rho.shape x2 = p[0] / 2 + sliceposition_x y2 = p[1] / 2 + sliceposition_y z2 = p[2] / 2 + sliceposition_z np.savetxt(os.path.join(path, 'data', 'rho', ('rho_section_' + ('%2.2i' % frame) + '.dat')), rho[:, :, z2].T, fmt='%15.14e') np.savetxt(os.path.join(path, 'data', 'rho', ('rho_bunch_section_' + ('%2.2i' % frame) + '.dat')), rho_b[:, :, z2].T, fmt='%15.14e')
def write_E_vts(path, frame, X, Y, Z, cell_cut): # for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # write_VTS(path,i) sf = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Exfout' + sf + '.bin' Ex, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Eyfout' + sf + '.bin' Ey, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Ezfout' + sf + '.bin' Ez, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- bunch(es) -# file_name = 'Exbout' + sf + '.bin' Exb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Eybout' + sf + '.bin' Eyb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Ezbout' + sf + '.bin' Ezb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- matrix shaving if cell_cut > 0: Ex = Ex[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Ey = Ey[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Ez = Ez[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Exb = Exb[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Eyb = Eyb[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Ezb = Ezb[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = Ex.shape #- #- writing vts header f = open(os.path.join(path, 'VTS_files', 'ALaDyn_E_' + sf + '.vts'), 'w+') f.write('<?xml version="1.0"?>' + '\n') f.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #--- ---# #- writing Ex-vts header fEx = open(os.path.join(path, 'VTS_files', 'ALaDyn_Ex_' + sf + '.vts'), 'w+') fEx.write('<?xml version="1.0"?>' + '\n') fEx.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') fEx.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) fEx.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #- writing Ey-vts header fEy = open(os.path.join(path, 'VTS_files', 'ALaDyn_Ey_' + sf + '.vts'), 'w+') fEy.write('<?xml version="1.0"?>' + '\n') fEy.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') fEy.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) fEy.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #- writing Ex-vts header fEz = open(os.path.join(path, 'VTS_files', 'ALaDyn_Ez_' + sf + '.vts'), 'w+') fEz.write('<?xml version="1.0"?>' + '\n') fEz.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') fEz.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) fEz.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #--- ---# #- generating vector-MESH mesh = [] for i in range(0, size[0]): for j in range(0, size[1]): for k in range(0, size[2]): mesh.append(Y[j]) mesh.append(Z[k]) mesh.append(X[i]) #- Writing MESH -# f.write('<Points> \n') f.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Writing ExMESH -# fEx.write('<Points> \n') fEx.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) fEx.write(base64.b64encode(np.array(len(s), dtype=np.int32))) fEx.write(s) fEx.write('</DataArray> \n') fEx.write('</Points> \n') #- Writing ExMESH -# fEy.write('<Points> \n') fEy.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) fEy.write(base64.b64encode(np.array(len(s), dtype=np.int32))) fEy.write(s) fEy.write('</DataArray> \n') fEy.write('</Points> \n') #- Writing ExMESH -# fEz.write('<Points> \n') fEz.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) fEz.write(base64.b64encode(np.array(len(s), dtype=np.int32))) fEz.write(s) fEz.write('</DataArray> \n') fEz.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') fEx.write('<PointData>\n') fEy.write('<PointData>\n') fEz.write('<PointData>\n') #- -# #- Writing E-field -# #- E-field total f.write( '<DataArray type="Float32" Name="E" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Ex + Exb, Ey + Eyb, Ez + Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Writing Ex-field -# fEx.write( '<DataArray type="Float32" Name="Ex" NumberOfComponents="1" format="binary"> \n' ) mesh = matrix2vector(Ex + Exb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) fEx.write(base64.b64encode(np.array(len(s), dtype=np.int32))) fEx.write(s) fEx.write('</DataArray> \n') #- Writing Ex-field -# fEy.write( '<DataArray type="Float32" Name="Ey" NumberOfComponents="1" format="binary"> \n' ) mesh = matrix2vector(Ey + Eyb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) fEy.write(base64.b64encode(np.array(len(s), dtype=np.int32))) fEy.write(s) fEy.write('</DataArray> \n') #- Writing Ex-field -# fEz.write( '<DataArray type="Float32" Name="Ez" NumberOfComponents="1" format="binary"> \n' ) mesh = matrix2vector(Ez + Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) fEz.write(base64.b64encode(np.array(len(s), dtype=np.int32))) fEz.write(s) fEz.write('</DataArray> \n') #-Deallocate memory Ex = [0.] Ey = [0.] Ez = [0.] Exb = [0.] Eyb = [0.] Ezb = [0.] #- Point Data End-# f.write('</PointData> \n') fEx.write('</PointData> \n') fEy.write('</PointData> \n') fEz.write('</PointData> \n') #- -# f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>') fEx.write('</Piece> \n') fEx.write('</StructuredGrid> \n') fEx.write('</VTKFile>') fEy.write('</Piece> \n') fEy.write('</StructuredGrid> \n') fEy.write('</VTKFile>') fEz.write('</Piece> \n') fEz.write('</StructuredGrid> \n') fEz.write('</VTKFile>')
def plot_ionization_profile(path, frame, min_ionization_rate, max_ionzation_rate, isolines, celltocut, sliceposition_x, sliceposition_y, sliceposition_z, magnification_fig, savedata): s = '%2.2i' % frame #conversion to 2-character-long-string # file_name = 'Elpout'+s+'.bin' file_name = 'H1dnout' + s + '.bin' matrix, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- cut & sign matrix = np.abs(matrix) #---cut edges---# if celltocut > 0: matrix = matrix[:, celltocut:-celltocut, celltocut:-celltocut] y = y[celltocut:-celltocut] z = z[celltocut:-celltocut] p = matrix.shape x2 = p[0] / 2 + sliceposition_x y2 = p[1] / 2 + sliceposition_y z2 = p[2] / 2 + sliceposition_z sizeX, sizeZ = figure_dimension_inch(x, y, z, magnification_fig) # levs_lin = np.linspace( rho_min , rho_max ,isolines) # levs_lin = np.insert(levs_lin,0,np.min([np.min(matrix),np.min(matrix2)])) # levs_lin = np.insert(levs_lin,len(levs_lin),np.min([np.max(matrix),np.max(matrix2)])) # levs_log = np.logspace(log10(rho_min),log10(rho_max),isolines) #--------------------# #--- Linear plots ---# #--------------------# #- Plot Bdenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_XY_lin_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_XZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Bunch_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix2[:,:,z2].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_XY_lin_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix2[:,y2,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_XZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_Background_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T + matrix2[:,:,z2].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_XY_lin_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T + matrix2[:,y2,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_XZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T - matrix2[x2,:,:].T,levs_lin, linewidths = 0.00001) # axis('tight') # name_output = 'rho_tot_YZ_lin_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #--------------------# #--- Log plots ---# #--------------------# #- Plot Bdenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_XY_log_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T,levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_XZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix2[:,:,z2].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_XY_log_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix2[:,y2,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_XZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Background_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #- Plot Bdenout+Edenout -# # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,y,matrix[:,:,z2].T + matrix2[:,:,z2].T,levs_log , norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_XY_log_'+s+'.png' # savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeZ)) # contourf(x,z,matrix[:,y2,:].T + matrix2[:,y2,:].T,levs_log , norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_XZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) # fig = figure(1, figsize=(sizeX, sizeX)) # contourf(y,z,matrix[x2,:,:].T + matrix2[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_tot_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #----- Save density sections data -----# if (savedata == 'True'): print('saving ionization data') ionization_map = matrix ionization_map = np.abs(ionization_map) p = ionization_map.shape x2 = p[0] / 2 + sliceposition_x y2 = p[1] / 2 + sliceposition_y z2 = p[2] / 2 + sliceposition_z np.savetxt(os.path.join(path, 'data', 'ionization', ('ionization_profile_' + ('%2.2i' % frame) + '.dat')), ionization_map[:, :, z2].T, fmt='%15.14e')
def write_vts(path, frame, X, Y, Z, cell_cut): # for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # write_VTS(path,i) sf = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Bdenout' + sf + '.bin' rhobunch, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') rhobunch = np.abs(rhobunch) file_name = 'Edenout' + sf + '.bin' rhobck, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') rhobck = np.abs(rhobck) #- matrix shaving if cell_cut > 0: rhobunch = rhobunch[:, cell_cut:-cell_cut, cell_cut:-cell_cut] rhobck = rhobck[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = rhobunch.shape #- #- writing vts header f = open(os.path.join(path, 'VTS_files', 'ALaDyn_output_' + sf + '.vts'), 'w+') f.write('<?xml version="1.0"?>' + '\n') f.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #--- ---# #- generating vector-MESH mesh = [] for i in range(0, size[0]): for j in range(0, size[1]): for k in range(0, size[2]): mesh.append(Y[j]) mesh.append(Z[k]) mesh.append(X[i]) #- Writing MESH -# f.write('<Points> \n') f.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') # f.write('<CellData> \n') #- -# #- Writing BUNCH Density -# f.write('<DataArray type="Float32" Name="rho_bunch" format="binary"> \n') mesh = matrix2vector(rhobunch) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- Writing Tot-Density -# f.write('<DataArray type="Float32" Name="rho" format="binary"> \n') mesh = matrix2vector(rhobunch + rhobck) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory rhobunch = [0.] rhobck = [0.] #- Writing E-field -# #- background -# file_name = 'Exfout' + sf + '.bin' Ex, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Eyfout' + sf + '.bin' Ey, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Ezfout' + sf + '.bin' Ez, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- bunch(es) -# file_name = 'Exbout' + sf + '.bin' Exb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Eybout' + sf + '.bin' Eyb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Ezbout' + sf + '.bin' Ezb, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') #- matrix shaving if cell_cut > 0: Ex = Ex[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Ey = Ey[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Ez = Ez[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Exb = Exb[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Eyb = Eyb[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Ezb = Ezb[:, cell_cut:-cell_cut, cell_cut:-cell_cut] #- #- E-field bunch f.write( '<DataArray type="Float32" Name="E_bunch" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Exb, Eyb, Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #- E-field total f.write( '<DataArray type="Float32" Name="E" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Ex + Exb, Ey + Eyb, Ez + Ezb) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Ex = [0.] Ey = [0.] Ez = [0.] Exb = [0.] Eyb = [0.] Ezb = [0.] #- Writing B-field -# #- background -# file_name = 'Bxfout' + sf + '.bin' Bx, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Byfout' + sf + '.bin' By, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Bzfout' + sf + '.bin' Bz, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') # #- bunch(es) -# # file_name = 'Bxbout'+sf+'.bin' # Bxb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bybout'+sf+'.bin' # Byb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # file_name = 'Bzbout'+sf+'.bin' # Bzb, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- matrix shaving if cell_cut > 0: Bx = Bx[:, cell_cut:-cell_cut, cell_cut:-cell_cut] By = By[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Bz = Bz[:, cell_cut:-cell_cut, cell_cut:-cell_cut] #- #- B-field bunch # f.write('<DataArray type="Float32" Name="B_bunch" NumberOfComponents="3" format="binary"> \n') # mesh = matrix2vectorField(Bxb,Byb,Bzb) # s = base64.b64encode(np.array(mesh,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # f.write('</DataArray> \n') #- B-field total f.write( '<DataArray type="Float32" Name="B" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Bx, By, Bz) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Bx = [0.] By = [0.] Bz = [0.] #Bxb=[0.];Byb=[0.];Bzb=[0.]; #- Point Data End-# f.write('</PointData> \n') # f.write('</CellData> \n') #- -# # frame = 0 # s='%2.2i'%frame #conversion to 2-character-long-string # file_name = 'Bdenout'+s+'.bin' # matrix, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # # file_name = 'Edenout'+s+'.bin' # # matrix2, x,y,z = read_ALaDyn_bin(path,file_name,'grid') # #- cut & sign # matrix = np.abs( matrix ) # # matrix2 = np.abs( matrix2 ) # size = matrix.shape #- writing vts header # f = open('test.vts','w+') # f.write('<?xml version="1.0"?>' + '\n') # f.write('<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') # f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0,size[1],0,size[0],0,size[2]) ) # f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0,size[1],0,size[0],0,size[2]) ) # f.write('<Points> \n') # f.write('<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n') # buffer=[] # for i in range(1,NI+2): # for j in range(1,NJ+2): # for k in range(1,NK+2): # buffer.append(1./float(NJ)*(float(j)-1.)) # buffer.append(1./float(NI)*(float(i)-1.)) # buffer.append(1./float(NK)*(float(k)-1.)) # # s = base64.b64encode(np.array(buffer,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # f.write('</DataArray> \n') # f.write('</Points> \n') # f.write('<PointData>\n') # f.write('<DataArray type="Float32" Name="rhoEdge" format="binary"> \n') # buffer=[] # n=0 # for i in range(0,NI+1): # for j in range(0,NJ+1): # for k in range(0,NK+1): # buffer.append(n*1.) # n+=1 # # s = base64.b64encode(np.array(buffer,dtype=np.float32)) # f.write(base64.b64encode(np.array(len(s),dtype=np.int32))) # f.write(s) # # for item in buffer: # # f.write(str(item)+'\n') # f.write('</DataArray> \n') # f.write('</PointData> \n') # f.write('<CellData> \n') # f.write('<DataArray type="Float32" Name="rho" format="ascii"> \n') # # buffer=[] # n=0 # for i in range(0,NI): # for j in range(0,NJ): # for k in range(0,NK): # buffer.append(str(n*1.)) # n+=1 # # for item in buffer: # f.write(str(item)+'\n') # # f.write('</DataArray> \n') # f.write('</CellData> \n') f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>')
def write_B_vts(path, frame, X, Y, Z, cell_cut): # for i in range(frame_begin, min(frame_end,last_output(os.getcwd())) + 1 ): # write_VTS(path,i) sf = '%2.2i' % frame #conversion to 2-character-long-string file_name = 'Bxfout' + sf + '.bin' Bx, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Byfout' + sf + '.bin' By, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') file_name = 'Bzfout' + sf + '.bin' Bz, x, y, z = read_ALaDyn_bin(path, file_name, 'grid') size = Bx.shape #- matrix shaving if cell_cut > 0: Bx = Bx[:, cell_cut:-cell_cut, cell_cut:-cell_cut] By = By[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Bz = Bz[:, cell_cut:-cell_cut, cell_cut:-cell_cut] Y = Y[cell_cut:-cell_cut] Z = Z[cell_cut:-cell_cut] #- size = Bx.shape #- #- writing vts header f = open(os.path.join(path, 'VTS_files', 'ALaDyn_B_' + sf + '.vts'), 'w+') f.write('<?xml version="1.0"?>' + '\n') f.write( '<VTKFile type="StructuredGrid" version="0.1" byte_order="LittleEndian">' + '\n') f.write('<StructuredGrid WholeExtent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) f.write('<Piece Extent=" %d %d %d %d %d %d "> \n' % (0, size[1] - 1, 0, size[2] - 1, 0, size[0] - 1)) #--- ---# #- generating vector-MESH mesh = [] for i in range(0, size[0]): for j in range(0, size[1]): for k in range(0, size[2]): mesh.append(Y[j]) mesh.append(Z[k]) mesh.append(X[i]) #- Writing MESH -# f.write('<Points> \n') f.write( '<DataArray type="Float32" Name="Points" NumberOfComponents="3" format="binary"> \n' ) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') f.write('</Points> \n') #- -# #- Point Data Begin-# f.write('<PointData>\n') #- -# #- Writing B-field -# f.write( '<DataArray type="Float32" Name="B" NumberOfComponents="3" format="binary"> \n' ) mesh = matrix2vectorField(Bx, By, Bz) s = base64.b64encode(np.array(mesh, dtype=np.float32)) f.write(base64.b64encode(np.array(len(s), dtype=np.int32))) f.write(s) f.write('</DataArray> \n') #-Deallocate memory Bx = [0.] By = [0.] Bz = [0.] #Bxb=[0.];Byb=[0.];Bzb=[0.]; #- Point Data End-# f.write('</PointData> \n') #- -# f.write('</Piece> \n') f.write('</StructuredGrid> \n') f.write('</VTKFile>')
def plot_energy_density_sections(path,frame,Energy_density_min,Energy_density_max,isolines,celltocut,sliceposition_x,sliceposition_y,sliceposition_z,magnification_fig,savedata): s='%2.2i'%frame #conversion to 2-character-long-string file_name = 'Elenout'+s+'.bin' matrix3, x,y,z = read_ALaDyn_bin(path,file_name,'grid') #- cut & sign matrix3 = np.abs( matrix3 ) print('Energy_density_max >>', np.max([np.max(matrix3)])) print('Energy_density_min >>', np.min([np.min(matrix3)])) #---cut edges---# if celltocut > 0: matrix3 = matrix3[:,celltocut:-celltocut,celltocut:-celltocut] y = y[celltocut:-celltocut] z = z[celltocut:-celltocut] p = matrix3.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; sizeX, sizeZ = figure_dimension_inch(x,y,z,magnification_fig) levs_lin = np.linspace( Energy_density_min , Energy_density_max ,isolines) levs_log = np.logspace(log10(Energy_density_min),log10(Energy_density_max),isolines) #--------------------# #--- Linear plots ---# #--------------------# #- Plot Elenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix3[:,:,z2].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'Energy_density_XY_lin_'+s+'.png' savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix3[:,y2,:].T,levs_lin, linewidths = 0.00001) axis('tight') name_output = 'Energy_density_XZ_lin_'+s+'.png' fig.savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) #--------------------# #--- Log plots ---# #--------------------# #- Plot Elenout -# fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,y,matrix3[:,:,z2].T, levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'Energy_density_XY_log_'+s+'.png' savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) fig = figure(1, figsize=(sizeX, sizeZ)) contourf(x,z,matrix3[:,y2,:].T,levs_log, norm=colors.LogNorm()) axis('tight') name_output = 'Energy_density_XZ_log_'+s+'.png' fig.savefig( os.path.join(path,'plots','Energy_density',name_output) ) close(fig) # fig = figure(1, figsize=(sizeZ, sizeZ)) # contourf(y,z,matrix[x2,:,:].T, levs_log, norm=colors.LogNorm()) # axis('tight') # name_output = 'rho_Bunch_YZ_log_'+s+'.png' # fig.savefig( os.path.join(path,'plots','rho',name_output) ) # close(fig) #----- Save density sections data -----# if (savedata == 'True'): print('saving Energy_density data') Energy_density = matrix3 p = Energy_density.shape x2=p[0]/2+sliceposition_x; y2=p[1]/2+sliceposition_y; z2=p[2]/2+sliceposition_z; np.savetxt( os.path.join(path,'data','Energy_density',('Energy_Density'+('%2.2i'%frame)+'.dat')),Energy_density[:,:,z2].T,fmt='%15.14e')