def interpolate__gridData_onto_line( Data=None, gridFile="dat/grid.dat", lineFile=None, \ x1 =[ 0.0, 0.0 ], x2=[ 1.0, 1.0 ], nDiv=101, \ x_=0, y_=1, v_=2 ): # -- for vector field. -- # # x_,y_,v_ = 0, 1, 5 # -- # ------------------------------------------------- # # --- [1] grid & line Loading --- # # ------------------------------------------------- # # -- [1-1] grid Data Loading -- # if ( Data is not None ): gridData = np.copy( Data ) elif ( gridFile is not None ): import nkUtilities.load__pointFile as lpf gridData = lpf.load__pointFile( inpFile=gridFile, returnType="structured" ) gridData = gridData[:,:,(x_,y_,v_)] else: print( "[interpolate__gridData_onto_line] no Data & no gridFile... [ERROR]" ) sys.exit() gridData_ = ( np.reshape( gridData, (-1,3) ) ) # -- [1-2] line Data Loading -- # if ( lineFile is None ): lineData = generate__line2d( x1=x1, x2=x2, nDiv=nDiv ) else: lineData = lpf.load__pointFile( inpFile=lineFile, returnType="point" ) lineData_ = np.zeros( (lineData.shape[0],3) ) lineData_[:,0:2] = np.copy( lineData[:,0:2] ) # ------------------------------------------------- # # --- [2] linear Interpolation --- # # ------------------------------------------------- # import nkInterpolator.LinearInterp2D as li2 ret = li2.LinearInterp2D( gridData =gridData, pointData=lineData_, \ gridDataType="structured" ) # ------------------------------------------------- # # --- [3] grid Data contouring --- # # ------------------------------------------------- # import nkUtilities.plot1D as pl1 import nkUtilities.LoadConfig as lcf config = lcf.LoadConfig() config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [ 0.0,+1.0] config["plt_yRange"] = [-1.0,+0.0] pl1.plot1D( xAxis=ret[:,0], yAxis=ret[:,2], pngFile="interpolate__gridData_onto_line.png", config=config ) return( ret )
def display__phasespace(): x_, y_, z_ = 1, 2, 3 vx_, vy_, vz_ = 4, 5, 6 MeV = 1.e+6 # ------------------------------------------------- # # --- [1] load config & data --- # # ------------------------------------------------- # # -- [2-1] load config -- # cnsFile = "dat/parameter.conf" import nkUtilities.load__constants as lcn const = lcn.load__constants(inpFile=cnsFile) # -- [2-2] load data & energy calculation -- # inpFile = "prb/collected.dat" with open(inpFile, "r") as f: Data = np.loadtxt(f) Data = Data[np.where(Data[:, x_] < 0.010)] Data = Data[np.where(Data[:, 13] > 0.0)] Data[:, vx_:vz_ + 1] = Data[:, vx_:vz_ + 1] / const["cv"] # ------------------------------------------------- # # --- [3] ploting --- # # ------------------------------------------------- # # -- [3-1] settings -- # pngFile = "png/phasespace_{0}.png" config = lcf.load__config() config["FigSize"] = (5, 5) config["plt_marker"] = "o" config["plt_markersize"] = 0.3 config["plt_linewidth"] = 0.0 # -- [3-2] xAxis -- # fig = pl1.plot1D(pngFile=pngFile.format("x_vx"), config=config) fig.add__plot(xAxis=Data[:, x_], yAxis=Data[:, vx_]) fig.set__axis() fig.save__figure() # -- [3-3] yAxis -- # fig = pl1.plot1D(pngFile=pngFile.format("y_vy"), config=config) fig.add__plot(xAxis=Data[:, y_], yAxis=Data[:, vy_]) fig.set__axis() fig.save__figure() # -- [3-4] zAxis -- # fig = pl1.plot1D(pngFile=pngFile.format("z_vz"), config=config) fig.add__plot(xAxis=Data[:, z_], yAxis=Data[:, vz_]) fig.set__axis() fig.save__figure()
def child_langmuir_law(): Va_min = 0.0 Va_max = 500e3 nVa = 101 de_min = 10.0e-3 de_max = 50.0e-3 nde = 5 pngFile = "png/child_langmuir.png" # ------------------------------------------------- # # --- [1] calculation --- # # ------------------------------------------------- # epsilon = 8.854187e-12 qe = 1.602176e-19 me = 9.109383e-31 Va = np.linspace(Va_min, Va_max, nVa) de = np.linspace(de_min, de_max, nde) Jcl = np.zeros((nVa, nde)) for ide in range(nde): Jcl[:, ide] = 4.0 * epsilon / 9.0 * np.sqrt( 2.0 * qe / me) * Va**(3.0 / 2.0) / de[ide]**2 Amm2_unit = 1.e-6 kV_unit = 1.e-3 Jcl_ = Jcl * Amm2_unit Va_ = Va * kV_unit # ------------------------------------------------- # # --- [2] plot characteristic --- # # ------------------------------------------------- # import nkUtilities.plot1D as pl1 import nkUtilities.load__config as lcf config = lcf.load__config() config["xTitle"] = "V (kV)" config["yTitle"] = "J (A/mm^2)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [0.0, 500.0] config["plt_yRange"] = [0.0, 2.0] config["plt_linewidth"] = 2.0 config["xMajor_Nticks"] = 6 config["yMajor_Nticks"] = 6 fig = pl1.plot1D(config=config, pngFile=pngFile) for ide in range(nde): hlabel = "d={0:.5}".format(de[ide]) fig.add__plot(xAxis=Va_, yAxis=Jcl_[:, ide], label=hlabel) fig.add__legend() fig.set__axis() fig.save__figure()
def show__profile(): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # config = lcf.load__config() datFile = "dat/2a_Rs.dat" pngFile = datFile.replace("dat", "png") # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # import nkUtilities.load__pointFile as lpf Data = lpf.load__pointFile(inpFile=datFile, returnType="point") xr_ = Data[:, 0] yr_ = Data[:, 1] from scipy import interpolate f = interpolate.interp1d(xr_, yr_, kind="cubic") xAxis = np.linspace(22, 30, 5) yAxis = f(xAxis) # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) config["plt_position"] = [0.24, 0.24, 0.94, 0.94] config["FigSize"] = (2.5, 2.5) config["xTitle"] = "2a (mm)" config["yTitle"] = "Rs (M" + "$\Omega$" + "/m)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False # config["plt_yAutoRange"] = True config["plt_xRange"] = [+20.0, +32.0] config["plt_yRange"] = [+40, +64] config["plt_linewidth"] = 1.8 config["xMajor_Nticks"] = 7 config["yMajor_Nticks"] = 7 config["xMinor_Nticks"] = 1 config["yMinor_Nticks"] = 1 config["plt_color"] = "Orange" config["plt_marker"] = "o" # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=xAxis, yAxis=yAxis) fig.set__axis() fig.save__figure()
def beam_loading_curve(): # ------------------------------------------------- # # --- [1] make beam loading curve --- # # ------------------------------------------------- # import nkUtilities.load__constants as lcn cnsFile = "dat/parameter.conf" const = lcn.load__constants( inpFile=cnsFile ) Ibeam = np.linspace( const["Ibeam_Min"], const["Ibeam_Max"], const["Ibeam_num"] ) P0_RFs = np.linspace( const["P0_RF_Min"], const["P0_RF_Max"], const["P0_RF_num"] ) BeamCurve = np.zeros( (const["Ibeam_num"],const["P0_RF_num"]) ) tau_attenuation = const["alpha_attenuation"] * const["length_cavity"] for ik,P0_RF in enumerate( P0_RFs ): term1 = np.sqrt( const["shunt_impedance"]*const["length_cavity"]*P0_RF*( 1.0 - np.exp( -2.0*tau_attenuation ) ) ) term2 = Ibeam*const["shunt_impedance"]*const["length_cavity"] / 2.0 * ( 1.0 - 2.0*tau_attenuation*np.exp( -2.0*tau_attenuation ) / ( 1.0 - np.exp( -2.0*tau_attenuation ) ) ) BeamCurve[:,ik] = ( term1 - term2 ) outFile = "dat/beam_loading_curve.dat" import nkUtilities.save__pointFile as spf spf.save__pointFile( outFile=outFile, Data=BeamCurve ) # ------------------------------------------------- # # --- [2] config settings --- # # ------------------------------------------------- # import nkUtilities.load__config as lcf config = lcf.load__config() config["xTitle"] = "Beam Current (mA)" config["yTitle"] = "Beam Energy (MeV)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [ 0.0, 300 ] config["plt_yRange"] = [ 0.0, 30.0 ] pngFile = "png/beam_loading_curve.png" # ------------------------------------------------- # # --- [3] plot --- # # ------------------------------------------------- # Ibeam = Ibeam / const["current_unit"] BeamCurve = BeamCurve / const["energy_unit"] import nkUtilities.plot1D as pl1 fig = pl1.plot1D( config=config, pngFile=pngFile ) for ik in range( const["P0_RF_num"] ): fig.add__plot( xAxis=Ibeam, yAxis=BeamCurve[:,ik] ) fig.set__axis() fig.save__figure()
def display(): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # config = lcf.load__config() datFile = "dat/superfish.dat" pngFile = "png/alongAxis.png" # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # import nkUtilities.load__pointFile as lpf Data = lpf.load__pointFile(inpFile=datFile, returnType="point") eps = 1.e-8 val = 1.e-3 index = np.where(np.abs(Data[:, 1] - val) <= eps) Data = Data[index][:] xAxis = Data[:, 0] - 0.5 * (Data[0, 0] + Data[-1, 0]) Ez = Data[:, 3] * 1.e-6 Er = Data[:, 4] / (val * 100.0) * 1.e-6 # Hp = Data[:,6] / ( val * 100.0 ) # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) config["FigSize"] = (4, 4) config["yTitle"] = "Ez (MV/m), Er/r (MV/m/cm)" config["xTitle"] = "Z (m)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [-0.0, +0.05] config["plt_yRange"] = [-0.0, +3.0] config["plt_linewidth"] = 1.8 config["xMajor_Nticks"] = 6 config["yMajor_Nticks"] = 4 # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=xAxis, yAxis=Er, label="Er/r") fig.add__plot(xAxis=xAxis, yAxis=Ez, label="Ez") # fig.add__plot( xAxis=xAxis, yAxis=Hp, label="Hp" ) fig.add__legend() fig.set__axis() fig.save__figure()
def display(datFile=None, pngFile=None, config=None): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (datFile is None): datFile = "bfield_xAxis.dat" if (pngFile is None): pngFile = "bfield_xAxis.png" if (config is None): config = lcf.LoadConfig() # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # with open(datFile, "r") as f: Data = np.loadtxt(f) xAxis = Data[:, 3] yAxis = Data[:, 8] index = np.argsort(xAxis) xAxis = xAxis[index] yAxis = yAxis[index] # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) config["xTitle"] = "r (m)" config["yTitle"] = "B (T)" config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [-5.0, +5.0] config["plt_yRange"] = [-5.0, +5.0] config["plt_linewidth"] = 1.0 config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 config["plt_marker"] = "o" config["plt_linewidth"] = 0.5 # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=xAxis, yAxis=yAxis, label="ans") fig.add__legend() fig.set__axis() fig.save__figure()
def display( datFile1=None, datFile2=None, pngFile=None, config=None ): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if ( datFile1 is None ): datFile1 = "dat/xa_fa.dat" if ( datFile2 is None ): datFile2 = "dat/xp_fp.dat" if ( pngFile is None ): pngFile = "png/out.png" if ( config is None ): config = lcf.LoadConfig() # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # with open( datFile1, "r" ) as f: Data = np.loadtxt( f ) xa = Data[:,0] fa = Data[:,1] with open( datFile2, "r" ) as f: Data = np.loadtxt( f ) xp = Data[:,0] fp = Data[:,1] # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings( configType="plot1D_def", config=config ) config["xTitle"] = "X" config["yTitle"] = "Y" config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [-5.0,+5.0] config["plt_yRange"] = [-5.0,+5.0] config["plt_linewidth"] = 1.0 config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D( config=config, pngFile=pngFile ) fig.add__plot( xAxis=xa, yAxis=fa, label="fa" ) fig.add__plot( xAxis=xp, yAxis=fp, label="fp", linestyle="--" ) fig.add__legend() fig.set__axis() fig.save__figure()
def make__histogram( Data=None, bins=None, range=None, \ color=None, alpha=None, width=None, \ pngFile=None, draw=True, config=None, ): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (Data is None): sys.exit("[draw__histogram.py] Data == ???") if (config is None): config = lcf.load__config() if (bins is None): bins = config["histo_bins"] # ------------------------------------------------- # # --- [2] make histogram --- # # ------------------------------------------------- # hist, bound = np.histogram(Data, bins=bins, range=range) axis = 0.5 * (bound[:-1] + bound[1:]) # ------------------------------------------------- # # --- [3] plotting --- # # ------------------------------------------------- # if (draw): if (pngFile is None): print( "[make__histogram.py] make__histogram.py :: None pngFile .. --> out.png" ) pngFile = "out.png" fig = pl1.plot1D(pngFile=pngFile, config=config) fig.add__bar( xAxis=axis, yAxis=hist, alpha=alpha, color=color, ) fig.set__axis() fig.save__figure() # ------------------------------------------------- # # --- [4] return --- # # ------------------------------------------------- # return (hist, axis)
Flib.ndpointer( dtype=np.float64 ), ctypes.POINTER( ctypes.c_int64 ), ctypes.POINTER( ctypes.c_int64 ), ctypes.POINTER( ctypes.c_int64 ), ] pyLIB.linearinterp1d_.restype = ctypes.c_void_p # ---------------------------------------- # # --- [4] 関数呼出 / 返却 --- # # ---------------------------------------- # pyLIB.linearinterp1d_( xa_, fa_, xp_, fp_, nData_, nIntp_, Flag_ ) return( fp_ ) # ================================================================ # # === テスト用 呼び出し === # # ================================================================ # if ( __name__=='__main__' ): xa = np.linspace( 0.0, 2.0, 11 ) xp = np.linspace( 0.0, 2.0, 101 ) fa = xa**2 fp = LinearInterp1D( xa=xa, xp=xp, fa=fa ) import nkUtilities.plot1D as pl1 fig = pl1.plot1D( pngFile="png/out.png" ) fig.add__plot( xAxis=xa, yAxis=fa, label="fa" ) fig.add__plot( xAxis=xp, yAxis=fp, label="fp", linestyle="--" ) fig.set__axis() fig.save__figure()
def display__initialAxisymmField(): x_, y_, z_ = 0, 1, 2 vx_, vy_, vz_ = 3, 4, 5 # ------------------------------------------------- # # --- [1] Load Config & Eigenmode --- # # ------------------------------------------------- # import nkUtilities.load__constants as lcn cnsFile = "dat/parameter.conf" const = lcn.load__constants(inpFile=cnsFile) import nkUtilities.load__pointFile as lpf efield = lpf.load__pointFile(inpFile=const["EFieldFile"], returnType="point") bfield = lpf.load__pointFile(inpFile=const["BFieldFile"], returnType="point") config = lcf.load__config() pngFile = "png/field_init_{0}.png" # ------------------------------------------------- # # --- [2] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="cMap_def", config=config) config["FigSize"] = (8, 4) config["cmp_position"] = [0.16, 0.12, 0.97, 0.88] config["xTitle"] = "Z (m)" config["yTitle"] = "R (m)" config["cmp_xAutoRange"] = True config["cmp_yAutoRange"] = True config["cmp_xRange"] = [-5.0, +5.0] config["cmp_yRange"] = [-5.0, +5.0] config["vec_AutoScale"] = True config["vec_AutoRange"] = True config["vec_AutoScaleRef"] = 200.0 config["vec_nvec_x"] = 24 config["vec_nvec_y"] = 6 config["vec_interpolation"] = "nearest" # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # xAxis = np.copy(efield[:, z_]) yAxis = np.copy(efield[:, x_]) cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vz_], \ pngFile=pngFile.format( "Ez" ), config=config ) cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=efield[:,vx_], \ pngFile=pngFile.format( "Er" ), config=config ) cmt.cMapTri( xAxis=xAxis, yAxis=yAxis, cMap=bfield[:,vy_], \ pngFile=pngFile.format( "Hp" ), config=config ) fig = cmt.cMapTri(pngFile=pngFile.format("Ev"), config=config) fig.add__contour(xAxis=xAxis, yAxis=yAxis, Cntr=bfield[:, vy_]) fig.add__cMap(xAxis=xAxis, yAxis=yAxis, cMap=bfield[:, vy_]) fig.add__vector ( xAxis=xAxis, yAxis=yAxis, uvec=efield[:,vz_], vvec=efield[:,vx_], \ color="blue" ) fig.save__figure() # ------------------------------------------------- # # --- [5] 1D plot --- # # ------------------------------------------------- # config["xTitle"] = "Z (m)" config["yTitle"] = "E (V/m)" val = 0.005 eps = 1.e-10 index = np.where((efield[:, x_] >= val - eps) & (efield[:, x_] <= val + eps)) xAxis = np.copy(efield[index][:, z_]) ez = np.copy(efield[index][:, vz_]) ex = np.copy(efield[index][:, vx_]) import nkUtilities.plot1D as pl1 fig = pl1.plot1D(config=config, pngFile=pngFile.format("1D")) fig.add__plot(xAxis=xAxis, yAxis=ez, color="royalblue", label="Ez") fig.add__plot(xAxis=xAxis, yAxis=ex, color="magenta", label="Ex") fig.add__legend() fig.set__axis() fig.save__figure()
def time_vs_energy(nums=None): t_ = 0 x_, y_, z_ = 1, 2, 3 vx_, vy_, vz_ = 4, 5, 6 ex_, ey_, ez_ = 7, 8, 9 bx_, by_, bz_ = 10, 11, 12 cnsFile = "dat/particle.conf" import nkUtilities.load__constants as lcn pconst = lcn.load__constants(inpFile=cnsFile) # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (nums is None): print( "[time_vs_energy] please input particle number : ( def. :: all ) >>> ", end="") nums = input() if (len(nums) == 0): nums = list(range(1, pconst["npt"] + 1)) # import glob # files = glob.glob( "prb/probe*.dat" ) # nums = [ int(num+1) for num in range( len(files) ) ] else: nums = [int(num) for num in nums.split()] pngFile = "png/time_vs_energy.png" config = lcf.load__config() cnsFile = "dat/parameter.conf" const = lcn.load__constants(inpFile=cnsFile) # ------------------------------------------------- # # --- [2] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) config["xTitle"] = "Time (s)" config["yTitle"] = "Energy (MeV)" config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [-5.0, +5.0] config["plt_yRange"] = [-5.0, +5.0] config["plt_linewidth"] = 1.0 config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 config["plt_marker"] = None import nkUtilities.generate__colors as col colors = col.generate__colors(nColors=len(nums)) # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) for ik, num in enumerate(nums): inpFile = "prb/probe{0:06}.dat".format(num) Data = lpf.load__pointFile(inpFile=inpFile, returnType="point") xAxis = Data[:, t_] beta = np.sqrt(Data[:, vx_]**2 + Data[:, vy_]**2 + Data[:, vz_]**2) / const["cv"] gamma = 1.0 / (np.sqrt(1.0 - beta**2)) yAxis = (gamma - 1.0) * const["mp"] * const["cv"]**2 / const["qe"] / 1.e6 fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik]) fig.set__axis() fig.save__figure()
def time_vs_probeData(nums=None, axis=None): t_ = 0 x_, y_, z_ = 1, 2, 3 vx_, vy_, vz_ = 4, 5, 6 ex_, ey_, ez_ = 7, 8, 9 bx_, by_, bz_ = 10, 11, 12 cnsFile = "dat/particle.conf" import nkUtilities.load__constants as lcn pconst = lcn.load__constants(inpFile=cnsFile) # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (nums is None): print( "[trajectory__tx] please input particle number : ( e.g. :: 1 2 3, 1-4, [empty::all] ) >>> ", end="") nums = input() if (len(nums) == 0): nums = list(range(1, pconst["npt"] + 1)) elif (len(nums.split("-")) == 2): imin = int((nums.split("-")[0]).strip()) imax = int((nums.split("-")[0]).strip()) nums = list(range(imin, imax + 1)) else: nums = [int(num) for num in nums.split()] if (axis is None): print( "[trajectory__tx] please input axis ( x/y/z ) : ( e.g. :: x ) >>> ", end="") axis = input() if ( not( axis.lower() in ["x" ,"y" ,"z" ,"vx","vy","vz",\ "ex","ey","ez","bx","by","bz"] ) ): print("[trajectory__tx] axis != x/y/z [ERROR] ") sys.exit() pngFile = "png/time_vs_{0}.png".format(axis) config = lcf.load__config() # ------------------------------------------------- # # --- [2] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) config["xTitle"] = "Time (s)" config["yTitle"] = yTitle config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [-5.0, +5.0] config["plt_yRange"] = [-5.0, +5.0] config["plt_linewidth"] = 1.0 config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 config["plt_marker"] = None import nkUtilities.generate__colors as col colors = col.generate__colors(nColors=len(nums)) # ------------------------------------------------- # # --- [3] axis settings --- # # ------------------------------------------------- # if (axis.lower() == "x"): p_ = x_ yTitle = "x (m)" config["plt_xAutoRange"] = False config["plt_xRange"] = [0.0, 0.020] elif (axis.lower() == "y"): p_ = y_ yTitle = "y (m)" elif (axis.lower() == "z"): p_ = z_ yTitle = "z (m)" elif (axis.lower() == "vx"): p_ = vx_ yTitle = "vx (m/s)" elif (axis.lower() == "vy"): p_ = vy_ yTitle = "vy (m/s)" elif (axis.lower() == "vz"): p_ = vz_ yTitle = "vz (m/s)" elif (axis.lower() == "ex"): p_ = ex_ yTitle = "ex (V/m)" elif (axis.lower() == "ey"): p_ = ey_ yTitle = "ey (V/m)" elif (axis.lower() == "ez"): p_ = ez_ yTitle = "ez (V/m)" elif (axis.lower() == "bx"): p_ = bx_ yTitle = "bx (T)" elif (axis.lower() == "by"): p_ = by_ yTitle = "by (T)" elif (axis.lower() == "bz"): p_ = bz_ yTitle = "bz (T)" # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) for ik, num in enumerate(nums): inpFile = "prb/probe{0:06}.dat".format(num) Data = lpf.load__pointFile(inpFile=inpFile, returnType="point") xAxis = Data[:, t_] yAxis = Data[:, p_] fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik]) fig.set__axis() fig.save__figure()
colors = sns.color_palette(palette=colorType, n_colors=nColors) # ------------------------------------------------- # # --- [2] return --- # # ------------------------------------------------- # return (colors) # ========================================================= # # === 実行部 === # # ========================================================= # if (__name__ == "__main__"): generate__colors(howto=True) wnum_max = 5 xAxis = np.linspace(0.0, 1.0, 101) * 2.0 * np.pi colors = generate__colors(colorType="default", nColors=wnum_max) print(colors) import nkUtilities.plot1D as pl1 pngFile = "out.png" fig = pl1.plot1D(pngFile=pngFile) for ik in range(wnum_max): yAxis = np.sin(xAxis * (ik + 1) / float(wnum_max) * 2.0) fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik]) fig.set__axis() fig.save__figure()
def ideal_fringe_field(): # ------------------------------------------------- # # --- [1] parameter settings --- # # ------------------------------------------------- # # -- [1-1] Load parameter file -- # import nkUtilities.load__constants as lcn inpFile = "dat/parameter.conf" params = lcn.load__constants(inpFile=inpFile) # ------------------------------------------------- # # --- [2] grid making --- # # ------------------------------------------------- # import nkUtilities.equiSpaceGrid as esg x1MinMaxNum = [params["xMin"], params["xMax"], params["LI"]] x2MinMaxNum = [params["yMin"], params["yMax"], params["LJ"]] x3MinMaxNum = [0.0, 0.0, 1] ret = esg.equiSpaceGrid( x1MinMaxNum=x1MinMaxNum, x2MinMaxNum=x2MinMaxNum, \ x3MinMaxNum=x3MinMaxNum, returnType = "point" ) radii = np.sqrt(ret[:, 0]**2 + ret[:, 1]**2) xg = np.copy(ret[:, 0]) yg = np.copy(ret[:, 1]) zg = np.copy(ret[:, 2]) bz = np.copy(ret[:, 2]) * 0.0 # ------------------------------------------------- # # --- [3] ideal aoki main field --- # # ------------------------------------------------- # index = np.where(radii <= params["r_main"]) radii_h = radii[index] bz[index] = mainAokiField(radii_h, params=params) # ------------------------------------------------- # # --- [4] buffer field --- # # ------------------------------------------------- # index = np.where((radii > params["r_main"]) & (radii < params["r_fringe"])) rh = radii[index] xh = xg[index] yh = yg[index] nBuff = xh.shape[0] theta = np.arctan2(yh, xh) r1, r2, r3 = params["r_main"], params["r_main"] - params[ "r_delta"], params["r_main"] - 2.0 * params["r_delta"] xp1, yp1 = r1 * np.cos(theta), r1 * np.sin(theta) xp2, yp2 = r2 * np.cos(theta), r2 * np.sin(theta) xp3, yp3 = r3 * np.cos(theta), r3 * np.sin(theta) bp1 = mainAokiField(np.sqrt(xp1**2 + yp1**2), params=params) bp2 = mainAokiField(np.sqrt(xp2**2 + yp2**2), params=params) bp3 = mainAokiField(np.sqrt(xp3**2 + yp3**2), params=params) dbdr_main = (bp1 - bp3) / params["r_delta"] dbdr_fringe = params["fringe_grad"] * np.ones((nBuff, )) b_fringe_edge = np.ones((nBuff)) * params["fringe_fixed"] rhat = (rh - r2) / (params["r_fringe"] - r2) delta_main = rh - r2 delta_fringe = rh - params["r_fringe"] approx_main = linear_approx(delta_main, dbdr_main, bp2) approx_fringe = linear_approx(delta_fringe, dbdr_fringe, b_fringe_edge) rate_main = rateFunc_main(rhat) rate_fringe = rateFunc_fringe(rhat) bz_buffer = rate_main * approx_main + rate_fringe * approx_fringe bz[index] = np.copy(bz_buffer) # ------------------------------------------------- # # --- [5] main fringe field --- # # ------------------------------------------------- # index = np.where(radii >= params["r_fringe"]) radii_h = radii[index] bz[index] = mainFringeField(radii_h, params=params) # ------------------------------------------------- # # --- [6] output field --- # # ------------------------------------------------- # # -- [6-1] save in file -- # ret = np.zeros((bz.shape[0], 4)) ret[:, 0] = np.copy(xg) ret[:, 1] = np.copy(yg) ret[:, 2] = np.copy(zg) ret[:, 3] = np.copy(bz) shape = (params["LJ"], params["LI"], 4) ret_ = np.reshape(ret, shape) import nkUtilities.save__pointFile as spf outFile = "dat/extended_idealField.dat" spf.save__pointFile(outFile=outFile, Data=ret_, shape=shape) # -- [6-2] 2d color map -- # import nkUtilities.cMapTri as cmt cmt.cMapTri(xAxis=ret[:, 0], yAxis=ret[:, 1], cMap=ret[:, 3], pngFile="png/out.png") import nkBasicAlgs.extract__data_onAxis as ext onXAxis = ext.extract__data_onAxis(Data=ret, axis="y") onYAxis = ext.extract__data_onAxis(Data=ret, axis="x") import nkUtilities.plot1D as pl1 import nkUtilities.LoadConfig as lcf config = lcf.LoadConfig() config["plt_linewidth"] = 0.0 config["plt_marker"] = "x" # -- [6-3] 1d plot (x) -- # xAxis = onXAxis[:, 0] bAxis = onXAxis[:, 3] xAxis1 = xAxis[np.where(np.abs(xAxis) <= params["r_main"])] bAxis1 = bAxis[np.where(np.abs(xAxis) <= params["r_main"])] xAxis2 = xAxis[np.where((np.abs(xAxis) > params["r_main"]) & (np.abs(xAxis) < params["r_fringe"]))] bAxis2 = bAxis[np.where((np.abs(xAxis) > params["r_main"]) & (np.abs(xAxis) < params["r_fringe"]))] xAxis3 = xAxis[np.where(np.abs(xAxis) >= params["r_fringe"])] bAxis3 = bAxis[np.where(np.abs(xAxis) >= params["r_fringe"])] pngFile = "png/onXAxis.png" fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=xAxis1, yAxis=bAxis1, label="main") fig.add__plot(xAxis=xAxis2, yAxis=bAxis2, label="buffer") fig.add__plot(xAxis=xAxis3, yAxis=bAxis3, label="fringe") fig.add__legend() fig.set__axis() fig.save__figure() # -- [6-4] 1d plot (y) -- # yAxis = onYAxis[:, 1] bAxis = onYAxis[:, 3] yAxis1 = yAxis[np.where(np.abs(yAxis) <= params["r_main"])] bAxis1 = bAxis[np.where(np.abs(yAxis) <= params["r_main"])] yAxis2 = yAxis[np.where((np.abs(yAxis) > params["r_main"]) & (np.abs(yAxis) < params["r_fringe"]))] bAxis2 = bAxis[np.where((np.abs(yAxis) > params["r_main"]) & (np.abs(yAxis) < params["r_fringe"]))] yAxis3 = yAxis[np.where(np.abs(yAxis) >= params["r_fringe"])] bAxis3 = bAxis[np.where(np.abs(yAxis) >= params["r_fringe"])] pngFile = "png/onYAxis.png" fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=yAxis1, yAxis=bAxis1, label="main") fig.add__plot(xAxis=yAxis2, yAxis=bAxis2, label="buffer") fig.add__plot(xAxis=yAxis3, yAxis=bAxis3, label="fringe") fig.add__legend() fig.set__axis() fig.save__figure() return ()
def trajectory__xy(nums=None, plain=None): x_, y_, z_ = 1, 2, 3 # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # if (nums is None): print( "[trajectory__tx] please input particle number >> ( e.g. :: 1 2 3 )" ) nums = input() nums = [int(num) for num in nums.split()] if (plain is None): print( "[trajectory__tx] please input plain (xy/yx/yz/zy/zx/xz/) >> ( e.g. :: xy )" ) plain = input() if (not (plain.lower() in ["xy", "yz", "zx", "yx", "zy", "xz"])): print("[trajectory__tx] plain != (xy/yx/yz/zy/zx/xz/) [ERROR] ") sys.exit() pngFile = "png/trajectory__{0}.png".format(plain) config = lcf.load__config() # ------------------------------------------------- # # --- [2] axis settings --- # # ------------------------------------------------- # if (plain.lower() == "xy"): a1_, a2_ = x_, y_ xTitle, yTitle = "X (m)", "Y (m)" elif (plain.lower() == "yx"): a1_, a2_ = y_, x_ xTitle, yTitle = "Y (m)", "X (m)" elif (plain.lower() == "yz"): a1_, a2_ = y_, z_ xTitle, yTitle = "Y (m)", "Z (m)" elif (plain.lower() == "zy"): a1_, a2_ = z_, y_ xTitle, yTitle = "Z (m)", "Y (m)" elif (plain.lower() == "zx"): a1_, a2_ = z_, x_ xTitle, yTitle = "Z (m)", "X (m)" elif (plain.lower() == "xz"): a1_, a2_ = x_, z_ xTitle, yTitle = "X (m)", "Z (m)" # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) config["xTitle"] = xTitle config["yTitle"] = yTitle config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [-5.0, +5.0] config["plt_yRange"] = [-5.0, +5.0] config["plt_linewidth"] = 1.0 config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 import nkUtilities.generate__colors as col colors = col.generate__colors(nColors=len(nums)) # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) for ik, num in enumerate(nums): # inpFile = "trk/track{0:06}.dat".format( num ) inpFile = "prb/probe{0:06}.dat".format(num) Data = lpf.load__pointFile(inpFile=inpFile, returnType="point") xAxis = Data[:, a1_] yAxis = Data[:, a2_] fig.add__plot(xAxis=xAxis, yAxis=yAxis, color=colors[ik]) fig.set__axis() fig.save__figure()
def plot__particle_statistic(): x_ , y_ , z_ = 1, 2, 3 vx_, vy_, vz_ = 4, 5, 6 MeV = 1.e+6 # ------------------------------------------------- # # --- [1] load config & data --- # # ------------------------------------------------- # cnsFile = "dat/parameter.conf" import nkUtilities.load__constants as lcn const = lcn.load__constants( inpFile=cnsFile ) inpFile = "prb/collected.dat" with open( inpFile, "r" ) as f: Data = np.loadtxt( f ) xpos = Data[:,x_] ypos = Data[:,y_] zpos = Data[:,z_] vx = Data[:,vx_] vy = Data[:,vy_] vz = Data[:,vz_] beta = np.sqrt( vx**2 + vy**2 + vz**2 ) / const["cv"] gamma = 1.0 / ( np.sqrt( 1.0 - beta**2 ) ) energy = ( gamma - 1.0 ) * const["mp"] * const["cv"]**2 / const["qe"] / MeV # ------------------------------------------------- # # --- [2] distribution at target_time --- # # ------------------------------------------------- # pngFile = "png/p_pos_histogram_{0}.png" # -- [2-1] xpos -- # import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot() ax.hist( xpos, bins=300 ) fig.savefig( pngFile.format("x") ) print( "[collect__particles.py] outFile :: {0} ".format( pngFile.format("x") ) ) # -- [2-2] ypos -- # import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot() ax.hist( ypos, bins=300 ) fig.savefig( pngFile.format("y") ) print( "[collect__particles.py] outFile :: {0} ".format( pngFile.format("y") ) ) # -- [2-3] zpos -- # import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot() ax.hist( zpos, bins=300 ) fig.savefig( pngFile.format("z") ) print( "[collect__particles.py] outFile :: {0} ".format( pngFile.format("z") ) ) # ------------------------------------------------- # # --- [3] plot particls positions --- # # ------------------------------------------------- # # -- [3-0] common settings -- # import nkUtilities.plot1D as pl1 import nkUtilities.load__config as lcf config = lcf.load__config() config["plt_linewidth"] = 0.0 config["plt_marker"] = "o" pngFile = "png/dist_at_time_{0}.png" # -- [3-1] xy dist -- # config["xTitle"] = "x (m)" config["yTitle"] = "y (m)" fig = pl1.plot1D( xAxis=xpos, yAxis=ypos, config=config, pngFile=pngFile.format( "x" ) ) # -- [3-2] zx dist -- # config["xTitle"] = "z (m)" config["yTitle"] = "x (m)" fig = pl1.plot1D( xAxis=zpos, yAxis=xpos, config=config, pngFile=pngFile.format( "y" ) ) # -- [3-3] zy dist -- # config["xTitle"] = "z (m)" config["yTitle"] = "y (m)" fig = pl1.plot1D( xAxis=zpos, yAxis=ypos, config=config, pngFile=pngFile.format( "z" ) ) # ------------------------------------------------- # # --- [4] energy dist. --- # # ------------------------------------------------- # # -- [4-0] config settings -- # config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [0.0,0.8] config["plt_yRange"] = [0.0,0.2] config["xTitle"] = "z (m)" config["yTitle"] = "Energy (MeV)" # -- [4-1] plot energy dist. -- # pngFile = "png/dist_at_time_z_energy.png" fig = pl1.plot1D( xAxis=zpos, yAxis=energy, config=config, pngFile=pngFile )
def display__particles(): # ------------------------------------------------- # # --- [1] Arguments --- # # ------------------------------------------------- # config = lcf.load__config() datFile = "dat/particles.dat" vtkFile = "png/particles.vtu" pngFile = (datFile.replace("dat", "png")).replace(".png", "_{0}.png") # ------------------------------------------------- # # --- [2] Fetch Data --- # # ------------------------------------------------- # import nkUtilities.load__pointFile as lpf Data = lpf.load__pointFile(inpFile=datFile, returnType="point") xAxis = Data[:, 0] yAxis = Data[:, 1] zAxis = Data[:, 2] # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # cfs.configSettings(configType="plot1D_def", config=config) cfs.configSettings(configType="plot1D_mark", config=config) config["xTitle"] = "X (m)" config["yTitle"] = "Y (m)" config["plt_xAutoRange"] = True config["plt_yAutoRange"] = True config["plt_xRange"] = [-5.0, +5.0] config["plt_yRange"] = [-5.0, +5.0] config["plt_linewidth"] = 1.0 config["xMajor_Nticks"] = 5 config["yMajor_Nticks"] = 5 config["plt_linewidth"] = 0.0 # ------------------------------------------------- # # --- [4] x-y plot Figure --- # # ------------------------------------------------- # config["xTitle"] = "X (m)" config["yTitle"] = "Y (m)" fig = pl1.plot1D(config=config, pngFile=pngFile.format("xy")) fig.add__plot(xAxis=xAxis, yAxis=yAxis) fig.add__legend() fig.set__axis() fig.save__figure() # ------------------------------------------------- # # --- [5] y-z plot Figure --- # # ------------------------------------------------- # config["xTitle"] = "Y (m)" config["yTitle"] = "Z (m)" fig = pl1.plot1D(config=config, pngFile=pngFile.format("yz")) fig.add__plot(xAxis=yAxis, yAxis=zAxis) fig.add__legend() fig.set__axis() fig.save__figure() # ------------------------------------------------- # # --- [6] z-x plot Figure --- # # ------------------------------------------------- # config["xTitle"] = "X (m)" config["yTitle"] = "Z (m)" fig = pl1.plot1D(config=config, pngFile=pngFile.format("xz")) fig.add__plot(xAxis=xAxis, yAxis=zAxis) fig.add__legend() fig.set__axis() fig.save__figure() # ------------------------------------------------- # # --- [7] convert particles plot into vtk --- # # ------------------------------------------------- # import nkVTKRoutines.scatter__vtkPoint as sct sct.scatter__vtkPoint(Data=Data, vtkFile=vtkFile)
def display__beamline(color="blue", colormode="energy", eRange=None): eRange = [15e6, 30e6] # ------------------------------------------------- # # --- [1] Preparation --- # # ------------------------------------------------- # # -- [1-1] input / output -- # x_, y_, z_ = 1, 2, 3 vx_, vy_, vz_ = 4, 5, 6 config = lcf.load__config() cnsFile = "dat/parameter.conf" const = lcn.load__constants(inpFile=cnsFile) pngFile = "png/beamline.png" inpFile = "prb/probe{0:06}.dat" # -- [1-2] load__selected -- # import select__particles as spf FileList = spf.load__selected() nFile = (FileList.shape[0]) # -- [1-3] eRange -- # if (eRange is not None): eMin, eMax = eRange[0], eRange[1] AutoRange = False else: eMin, eMax = 1.e64, 0.0 AutoRange = True # ------------------------------------------------- # # --- [2] calculate energy --- # # ------------------------------------------------- # if (colormode == "single"): colors = np.repeat(color, nFile) elif (colormode == "random"): import matplotlib.pyplot as plt colors = plt.get_cmap("jet") colors = colors(np.linspace(0.0, 1.0, nFile)) elif (colormode == "energy"): energy_list = [] colors = [] for ik, num in enumerate(FileList): # -- load -- # Data = lpf.load__pointFile(inpFile=inpFile.format(num)) # -- energy -- # beta = np.sqrt(Data[:, vx_]**2 + Data[:, vy_]**2 + Data[:, vz_]**2) / const["cv"] gamma = 1.0 / (np.sqrt(1.0 - beta**2)) energy = (gamma - 1.0) * const["mp"] * const["cv"]**2 / np.abs( const["qe"]) # -- eMax -- # if (AutoRange): eMin = np.min([eMin, np.min(energy)]) eMax = np.max([eMax, np.max(energy)]) # -- packing -- # energy_list.append(energy) print("[display__beamline] ( eMin, eMax ) = ( {0}, {1} ) ".format( eMin, eMax)) for ik, henergy in enumerate(energy_list): henergy = (henergy - eMin) / (eMax - eMin) henergy[np.where(henergy < 0.0)] = 0.0 henergy[np.where(henergy > 1.0)] = 1.0 colors.append(henergy) # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # config["FigSize"] = (8.0, 2.0) config["plt_position"] = [0.16, 0.24, 0.94, 0.94] config["xTitle"] = "Z (m)" config["yTitle"] = "R (m)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [-0.5, +3.0] config["plt_yRange"] = [-0.000, +0.020] config["plt_linewidth"] = 0.2 config["xMajor_Nticks"] = 8 config["yMajor_Nticks"] = 3 # ------------------------------------------------- # # --- [4] plot Figure --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) for ik, num in enumerate(FileList): Data = lpf.load__pointFile(inpFile=inpFile.format(num)) if (colormode in ["energy"]): fig.add__colorline(xAxis=Data[:, z_], yAxis=Data[:, x_], color=colors[ik], cmap="jet") else: fig.add__plot(xAxis=Data[:, z_], yAxis=Data[:, x_], color=colors[ik]) fig.set__axis() fig.save__figure()
# ------------------------------------------------- # if (Data is None): sys.exit("[medianFilter] Data == ?? ") if (width is None): width = 3 # ------------------------------------------------- # # --- [2] call median filter --- # # ------------------------------------------------- # Data = sig.medfilt(Data, kernel_size=width) return (Data) # ======================================== # # === 実行部 === # # ======================================== # if (__name__ == "__main__"): nAmp = 0.5 Nx = 1000 noise = np.random.rand(Nx) * nAmp - nAmp / 2.0 xAxis = np.linspace(0.0, 6.28, Nx) yAxis = np.sin(xAxis * 2.0) for i in range(Nx): if (i % 20 == 0): yAxis[i] = yAxis[i] + noise[i] import nkUtilities.plot1D as pl1 med = medianFilter(Data=yAxis, width=7) fig = pl1.plot1D(FigName="out.png") fig.addPlot(xAxis=xAxis, yAxis=yAxis, label="Raw Data") fig.addPlot(xAxis=xAxis, yAxis=med, label="Filtered") fig.setAxis() fig.addLegend() fig.writeFigure()
# ---------------------------------------- # # --- [3] 関数呼出 / 返却 --- # # ---------------------------------------- # pyLIB.linearfilter1d_(Data_, ret_, alpha_, nFilter_, LI_) return (ret_) # ======================================== # # === テスト用 === # # ======================================== # if (__name__ == '__main__'): # ---- テスト用 プロファイル ---- # # -- 座標系 xg, yg -- # xa = np.linspace(0.0, 4.0 * np.pi, 1000) ya = 1.0 * np.sin(xa) + 0.2 * np.random.random(1000) import nkUtilities.plot1D as pl1 fig = pl1.plot1D(pngFile="f1d.png") ret = LinearFilter1D(Data=ya, alpha=0.0) fig.add__plot(xAxis=xa, yAxis=ret, label=r"$\alpha=0$") ret = LinearFilter1D(Data=ya, alpha=0.2) fig.add__plot(xAxis=xa, yAxis=ret, label=r"$\alpha=0.2$") ret = LinearFilter1D(Data=ya, alpha=0.5) fig.add__plot(xAxis=xa, yAxis=ret, label=r"$\alpha=0.5$") ret = LinearFilter1D(Data=ya, alpha=0.5, nFilter=10) fig.add__plot(xAxis=xa, yAxis=ret, label=r"$\alpha=0.5\times10$") fig.set__axis() fig.add__legend() fig.save__figure()
# -- 最小プロット (白地) -- # self.fig.savefig(pngFile, dpi=dpi, bbox_inches="tight", pad_inches=0.0) else: # -- 通常プロット -- # self.fig.savefig(pngFile, dpi=dpi, pad_inches=0) plt.close() print("[ save__figure -@plot1d- ] out :: {0}".format(pngFile)) # ======================================== # # === 実行部 === # # ======================================== # if (__name__ == "__main__"): import numpy as np xAxis = np.linspace(0., 1., 21) yAxis = -(xAxis - 0.5)**2 + 1.0 import nkUtilities.plot1D as pl1 import nkUtilities.load__config as lcf pngFile = "out.png" config = lcf.load__config() fig = pl1.plot1D(config=config, pngFile=pngFile) fig.add__plot(xAxis=xAxis, yAxis=yAxis, marker="x", linewidth=0.0) fig.set__axis() fig.save__figure()
def display__axial_interaction(time=0.0, nRepeat=1): x_, y_, z_ = 0, 1, 2 vx_, vy_, vz_ = 3, 4, 5 # ------------------------------------------------- # # --- [1] Load Config & Eigenmode --- # # ------------------------------------------------- # import nkUtilities.load__constants as lcn cnsFile = "dat/parameter.conf" pngFile = "png/axial/axial_interaction_{0}.png" config = lcf.load__config() const = lcn.load__constants(inpFile=cnsFile) import nkUtilities.load__pointFile as lpf wave1 = lpf.load__pointFile(inpFile=const["tw_cosEigenFile"], returnType="point") wave2 = lpf.load__pointFile(inpFile=const["tw_sinEigenFile"], returnType="point") val = 0.0 eps = 1.e-10 index1 = np.where(np.abs(wave1[:, x_] - val) <= eps) index2 = np.where(np.abs(wave2[:, x_] - val) <= eps) wave1 = wave1[index1] wave2 = wave2[index2] zAxis = wave1[:, z_] ez1 = wave1[:, vz_] ez2 = wave2[:, vz_] ez1Stack = np.copy(ez1) ez2Stack = np.copy(ez2) zStack = np.copy(zAxis) zLeng = np.max(zAxis) - np.min(zAxis) for ik in range(1, nRepeat): ez1_ = (np.copy(ez1))[1:] ez2_ = (np.copy(ez2))[1:] zAxis_ = (np.copy(zAxis) + zLeng * float(ik))[1:] ez1Stack = np.concatenate([ez1Stack, ez1_]) ez2Stack = np.concatenate([ez2Stack, ez2_]) zStack = np.concatenate([zStack, zAxis_]) zAxis = zStack ez1 = ez1Stack ez2 = ez2Stack # ------------------------------------------------- # # --- [2] prepare cos & sin theta --- # # ------------------------------------------------- # theta = 2.0 * np.pi * const["tw_frequency"] * time + const["tw_phase"] costh = +np.cos(theta) sinth = +np.sin(theta) # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # config["FigSize"] = (10, 3) config["cmp_position"] = [0.12, 0.16, 0.97, 0.92] config["xTitle"] = "Z (m)" config["yTitle"] = "Ez (V/m)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [0.0, 1.40] config["plt_yRange"] = [-6.e+6, 6.e+6] config["xMajor_Nticks"] = 6 # ------------------------------------------------- # # --- [4] collect particles --- # # ------------------------------------------------- # import collect__particles as clp ret = clp.collect__particles(target_time=time) npt = ret.shape[0] height = 3.e6 ppos = np.linspace(-height, +height, npt) zpos = ret[:, 3] # ------------------------------------------------- # # --- [4] plot Figure ( bfield ) --- # # ------------------------------------------------- # stime = "t{0:.3f}ns".format(time / 1e-9) Ez = ez1 * costh + ez2 * sinth fig = pl1.plot1D(config=config, pngFile=pngFile.format(stime)) fig.add__plot(xAxis=zAxis, yAxis=Ez) fig.add__plot(xAxis=zpos, yAxis=ppos, marker="o") fig.set__axis() fig.save__figure()
def display__axial_wavePropagation(inpFile=None): x_, y_, z_ = 0, 1, 2 vx_, vy_, vz_ = 3, 4, 5 # ------------------------------------------------- # # --- [1] Load Config & Eigenmode --- # # ------------------------------------------------- # import nkUtilities.load__constants as lcn cnsFile = "dat/parameter.conf" pngFile = "png/axial_wavePropagation.png" config = lcf.load__config() const = lcn.load__constants(inpFile=cnsFile) import nkUtilities.load__pointFile as lpf wave1 = lpf.load__pointFile(inpFile=const["tw_cosEigenFile"], returnType="point") wave2 = lpf.load__pointFile(inpFile=const["tw_sinEigenFile"], returnType="point") val = 0.0 eps = 1.e-10 index1 = np.where(np.abs(wave1[:, x_] - val) <= eps) index2 = np.where(np.abs(wave2[:, x_] - val) <= eps) wave1 = wave1[index1] wave2 = wave2[index2] zAxis = wave1[:, z_] ez1 = wave1[:, vz_] ez2 = wave2[:, vz_] # ------------------------------------------------- # # --- [2] prepare cos & sin theta --- # # ------------------------------------------------- # flag__easyplot = True if (flag__easyplot): const["tw_timeStart"] = 0.0 const["tw_nCycle"] = 1 const["tw_nTime"] = 12 t_period = 1.0 / (const["tw_frequency"]) tStart = const["tw_timeStart"] tEnd = const["tw_timeStart"] + t_period * const["tw_nCycle"] time = np.linspace(tStart, tEnd, const["tw_nTime"]) theta = 2.0 * np.pi * const["tw_frequency"] * time + const["tw_phase"] costh = +np.cos(theta) sinth = +np.sin(theta) # ------------------------------------------------- # # --- [3] config Settings --- # # ------------------------------------------------- # config["FigSize"] = (8, 4) config["cmp_position"] = [0.16, 0.12, 0.97, 0.88] config["xTitle"] = "Z (m)" config["yTitle"] = "Ez (V/m)" config["plt_xAutoRange"] = False config["plt_yAutoRange"] = False config["plt_xRange"] = [0.0, 0.15] config["plt_yRange"] = [-6.e+6, 6.e+6] config["xMajor_Nticks"] = 6 # ------------------------------------------------- # # --- [4] plot Figure ( bfield ) --- # # ------------------------------------------------- # fig = pl1.plot1D(config=config, pngFile=pngFile) import matplotlib.cm colors = matplotlib.cm.jet(np.linspace(0, 1, const["tw_nTime"])) for ik in range(const["tw_nTime"]): Ez = ez1 * costh[ik] + ez2 * sinth[ik] fig.add__plot(xAxis=zAxis, yAxis=Ez, label="t={0:.3}".format(time[ik] / 1e-9), color=colors[ik]) fig.add__legend() fig.set__axis() fig.save__figure()