Exemple #1
0
def oneD(raw, args):

    appstr = ''

    psv, xlabel, savename = get_props(raw, args.psv)

    if args.nbins == None:
        nbins = np.int(10 + np.power(np.log(raw.get_npart()), 3))
    else:
        nbins = args.nbins

    hist, bin_edges = np.histogram( psv,\
                                    bins=nbins,\
                                    weights=raw.get('q'),\
                                    density=True,\
                                    range=args.range)
    x_array = bin_edges[0:-1] + (bin_edges[1] - bin_edges[0]) / 2

    if args.psv == 'r':
        ## Scaling dr with 1/r
        # rmax = np.max(psv)
        # r_range = [0, rmax]
        # r_lsp = np.linspace(0,rmax,nbins)
        # lsp_centers = r_lsp[:-1] + np.diff(r_lsp)
        # dr_unnormed = np.divide(np.diff(r_lsp),lsp_centers)
        # dr_normed =  rmax * dr_unnormed/np.sum(dr_unnormed)
        # r_bin_edges = np.insert(np.cumsum(dr_normed),0,0)
        #hist, bin_edges = np.histogram(psv,bins=r_bin_edges,weights=raw.get('q'),density=True,range=args.range)

        ## Scaling number of hits with 1/r
        hist = np.divide(hist, x_array) / (2 * math.pi)

    fig = plt.figure(figsize=(6, 5))
    plt.plot(x_array, hist)
    ax = plt.gca()
    ax.set_xlabel(xlabel, fontsize=14)
    plt.gcf().subplots_adjust(left=0.15, bottom=0.15)

    if args.part_selection_criterion != '' or args.tagfile_in != None:
        appstr += '_sel'

    raw.read_attrs()
    timestamp = '_%08.1f' % (raw.get_time())
    savename += get_zeta_range_str(args.zeta_range)  \
                + appstr \
                + timestamp

    if args.file_format == 'png':
        saveas_png(fig, args.savepath, savename, verbose=True)
    else:
        saveas_eps_pdf(fig,
                       args.savepath,
                       savename,
                       h5plot=True,
                       verbose=True,
                       fformat=args.file_format)
    plt.close(fig)
Exemple #2
0
def twoD(raw, args):

    appstr = ''

    varx, xlabel, savenamex = get_props(raw, args.psv[0])
    vary, ylabel, savenamey = get_props(raw, args.psv[1])

    if args.nbins == None:
        nbins = np.int(10 + np.power(np.log(raw.get_npart()), 2.2))
    else:
        nbins = args.nbins

    if args.range != None:
        hrange = [[args.range[0], args.range[1]],
                  [args.range[2], args.range[3]]]
    else:
        hrange = None

    if args.verbose:
        print("Generating 2d histogram...")
    H, xedges, yedges = np.histogram2d(varx,
                                       vary,
                                       bins=nbins,
                                       weights=raw.get('q'),
                                       range=hrange)
    x_array = xedges[0:-1] + (xedges[1] - xedges[0]) / 2
    y_array = yedges[0:-1] + (yedges[1] - yedges[0]) / 2

    if args.verbose:
        print("Generating plot...")
    fig = plt.figure(figsize=(6, 5))
    cax = plt.pcolor(x_array, y_array, H.transpose(), cmap='PuBu')
    plt.gcf().subplots_adjust(left=0.15, bottom=0.15)
    #cax.cmap = self.colormap
    # if args.clog:
    #     cax.norm = matplotlib.colors.LogNorm(vmin=self.clim[0], vmax=self.clim[1])

    ax = plt.gca()
    ax.set_ylabel(ylabel, fontsize=14)
    ax.set_xlabel(xlabel, fontsize=14)
    cbar = fig.colorbar(cax)

    if args.part_selection_criterion != '' or args.tagfile_in != None:
        appstr += '_sel'

    raw.read_attrs()
    timestamp = '_%08.1f' % (raw.get_time())
    savename = savenamex \
                + '_' \
                + savenamey \
                + get_zeta_range_str(args.zeta_range) \
                + appstr \
                + timestamp

    saveas_png(fig, args.savepath, savename, verbose=True)
    plt.close(fig)
Exemple #3
0
def plot_curr_profile(slm, savepath, time = None, h5plot=True, t_is_z=True):
    dzeta = abs(slm.get_zeta_array()[1] - slm.get_zeta_array()[0]);
    curr = slm.get_charge() / dzeta

    if t_is_z:
        xlabel_str = r'$k_p z$'
    else:
        xlabel_str = r'$\omega_p t$'

    # print('Q = %0.3e' % (np.sum(curr) * dzeta ))

    # I_A = 4 * pi * epsilon_0 * m * c^3 / e
    # [curr] = epsilon_0 * m * c^3 / e
    # curr * 4 * pi = I_b/I_A
    Ib_per_IA = curr/(4 * math.pi)

    if time == None:
        tidx = [0,-1];
    else:
        tidx = [(np.abs(slm.get_time_array() - time)).argmin()]

    for i in tidx:
        fig = plt.figure()
        plt.plot(slm.get_zeta_array(), Ib_per_IA[i,:])
        ax = plt.gca()
        ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
        ax.set_ylabel(r'$I_{b}/I_A$', fontsize=14)
        saveas_eps_pdf(fig, savepath, ('Ib_time_%0.1f' % (slm.get_time_array()[i])), h5plot=h5plot)
        plt.close(fig)    


    figIb = plt.figure()
    cax = plt.pcolormesh(   slm.get_zeta_array(),
                            slm.get_time_array(),
                            Ib_per_IA,
                            cmap=cm.Greys,
                            vmin=0, 
                            vmax=np.amax(abs(Ib_per_IA)))
    cbar = figIb.colorbar(cax)   
    cbar.ax.set_ylabel('$I_b/I_A$', fontsize=14)
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14) 
    saveas_png(figIb, savepath, 'Ib')
    plt.close(figIb)
Exemple #4
0
def plot_save_slice_ene(slm, savepath, time = None, h5plot=True, t_is_z=True):

    if t_is_z:
        xlabel_str = r'$k_p z$'
    else:
        xlabel_str = r'$\omega_p t$'
    
    gamma = np.sqrt( 1 + np.power(slm.get(pz=1),2) 
                       + np.power(slm.get(px=1),2)
                       + np.power(slm.get(py=1),2) )

    if time == None:
        tidx = [0,-1];
    else:
        tidx = [(np.abs(slm.get_time_array() - time)).argmin()]

    for i in tidx:
        fig = plt.figure()
        plt.plot(slm.get_zeta_array(), gamma[i,:])
        ax = plt.gca()
        ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
        ax.set_ylabel(r'$\gamma$', fontsize=14)
        saveas_eps_pdf(fig, savepath, ('gamma_time_%0.1f' % (slm.get_time_array()[i])), h5plot=h5plot)
        plt.close(fig)    



    figG = plt.figure()
    cax = plt.pcolormesh( slm.get_zeta_array(),
                          slm.get_time_array(),
                          gamma,
                          cmap=cm.GnBu,
                          vmin=np.amin(gamma), vmax=np.amax(gamma))
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)    
    cbar = figG.colorbar( cax )
    cbar.ax.set_ylabel(r'$\gamma$', fontsize=14)
    saveas_png(figG, savepath, 'gamma')
    plt.close(figG)    
Exemple #5
0
def main():
    parser = parseargs()
    args = parser.parse_args()

    for zeta_pos in args.zeta_pos:
        nbdat = Data_xy_slice(args.nb_path, zeta_pos)
        x_n, y_n, nb_xy = nbdat.read(navg=args.nzetaavg)

        nb_abs_filtered = filters.gaussian_filter(np.abs(nb_xy),
                                                  args.smooth_sigma,
                                                  mode='mirror')
        # nb_abs_filtered = np.abs(nb_xy)

        fig = plt.figure()
        cax = plt.pcolor(np.abs(nb_xy))
        ax = plt.gca()
        ax.set_xlabel(r'$x$', fontsize=14)
        ax.set_ylabel(r'$y$', fontsize=14)
        cbar = fig.colorbar(cax)
        saveas_png(fig, args.savepath, 'nb_%0.2f' % zeta_pos)
        plt.close(fig)

        fig = plt.figure()
        cax = plt.pcolor(nb_abs_filtered)
        ax = plt.gca()
        ax.set_xlabel(r'$x$', fontsize=14)
        ax.set_ylabel(r'$y$', fontsize=14)
        cbar = fig.colorbar(cax)
        saveas_png(fig, args.savepath, 'nb_filtered_%0.2f' % zeta_pos)
        plt.close(fig)

        fig = plt.figure()
        cax = plt.pcolor(np.abs(nb_xy) - nb_abs_filtered)
        ax = plt.gca()
        ax.set_xlabel(r'$x$', fontsize=14)
        ax.set_ylabel(r'$y$', fontsize=14)
        cbar = fig.colorbar(cax)
        saveas_png(fig, args.savepath, 'nb_diff_%0.2f' % zeta_pos)
        plt.close(fig)

        r_n, nbr = cart_to_r_transform(x_n,
                                       y_n,
                                       nb_abs_filtered,
                                       rlim=args.rlim)

        if (args.mpsi_path != None):
            psidat = Data_xy_slice(args.mpsi_path, zeta_pos)
            x_psi, y_psi, mpsi_xy = psidat.read(navg=args.nzetaavg)

        else:
            wxdat = Data_xy_slice(args.wx_path, zeta_pos)
            x_wx, y_wy, wx_xy = wxdat.read(navg=args.nzetaavg)
            x_psi, y_psi, mpsi_xy = cart_int(x_wx, y_wy, wx_xy, axis='x')

        r_psi, mpsi = cart_to_r_transform(x_psi,
                                          y_psi,
                                          mpsi_xy,
                                          rlim=args.rlim)

        x, F = density_inversion(r_n,
                                 nbr,
                                 r_psi,
                                 mpsi,
                                 zeta_pos=zeta_pos,
                                 savepath=args.savepath,
                                 ifplot=True)
Exemple #6
0
def plot_save_slice_ene_spread(slm, savepath, h5plot=True, time=None, zeta_pos=None, t_is_z=True):

    if t_is_z:
        xlabel_str = r'$k_p z$'
    else:
        xlabel_str = r'$\omega_p t$'
    
    sigma_gamma_per_gamma = np.divide( np.sqrt( slm.get(pz=2) ),slm.get(pz=1))

    if time == None:
        time = slm.get_time_array()[-1]
        tidx = [-1];
    else:
        tidx = [(np.abs(slm.get_time_array() - time)).argmin()]

    if len(tidx) == 1:
        time = [time]

    for i in range(0,len(tidx)):
        sig_gam_per_gam_savename = 'sigma_gamma_per_gamma_time_%0.2f' % time[i]
        sig_gam_per_gam_ylab = r'$\sigma_{\gamma}/\gamma(t=%0.1f)$' % time[i]
        
        fig_sig_gam_per_gam = plt.figure()
        plt.plot(slm.get_zeta_array(), sigma_gamma_per_gamma[tidx[i],:]  ) #/ 
        # np.mean(np.sqrt(1 + np.power(slm.get(px=1)[tidx[i],:],2)
        # + np.power(slm.get(py=1)[tidx[i],:],2)
        # + np.power(slm.get(pz=1)[tidx[i],:],2) ))  )
        ax = plt.gca()
        ymin, ymax = ax.get_ylim()
        if ymin > 0 and ymax > 0:
            plt.ylim(0, ymax*1.2)
        elif ymin < 0 and ymax < 0:
            plt.ylim(ymin*1.2, 0)        
        ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
        ax.set_ylabel(sig_gam_per_gam_ylab, fontsize=14)
        saveas_eps_pdf(fig_sig_gam_per_gam, savepath, sig_gam_per_gam_savename, h5plot=h5plot)
        plt.close(fig_sig_gam_per_gam)


    figsigma_gamma_per_gamma = plt.figure()
    cax = plt.pcolormesh(   slm.get_zeta_array(),
                            slm.get_time_array(),
                            sigma_gamma_per_gamma,
                            cmap=cm.GnBu,
                            vmin=np.amin(abs(sigma_gamma_per_gamma)), 
                            vmax=np.amax(abs(sigma_gamma_per_gamma)))
    cbar = figsigma_gamma_per_gamma.colorbar(cax)   
    cbar.ax.set_ylabel(r'$\sigma_{\gamma} / \gamma$', fontsize=14)
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14) 
    saveas_png(figsigma_gamma_per_gamma, savepath, 'sigma_gamma_per_gamma')
    plt.close(figsigma_gamma_per_gamma)



    figXb0 = plt.figure()
    plt.plot(slm.get_zeta_array(), sigma_gamma_per_gamma[0,:])
    ax = plt.gca()
    ymin, ymax = ax.get_ylim()
    if ymin > 0 and ymax > 0:
        plt.ylim(0, ymax*1.2)
    elif ymin < 0 and ymax < 0:
        plt.ylim(ymin*1.2, 0)        
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(r'$\sigma_{\gamma} / \gamma$', fontsize=14)
    saveas_eps_pdf(figXb0, savepath, 'sigma_gamma_per_gamma_time_0', h5plot=h5plot)
    plt.close(figXb0)


    if zeta_pos != None:
        zetaidx = [(np.abs(slm.get_zeta_array() - zeta_pos)).argmin()]
        sg_per_g_zeta_savename = 'sigma_gamma_per_gamma_zeta_%0.2f' % zeta_pos
    # 
        figsigma_gamma_per_gamma_zetapos = plt.figure()
        plt.plot(slm.get_time_array(), sigma_gamma_per_gamma[:,zetaidx])
        ax = plt.gca()
        ax.set_xlabel(xlabel_str, fontsize=14)
        ax.set_ylabel(r'$\sigma_{\gamma} / \gamma$', fontsize=14)
        if magn_check(sigma_gamma_per_gamma[:,zetaidx]):    
            ax.yaxis.set_major_formatter(FormatStrFormatter('%.1e'))
            plt.gcf().subplots_adjust(left=0.18)
        else:
            plt.gcf().subplots_adjust(left=0.15)
        saveas_eps_pdf(figsigma_gamma_per_gamma_zetapos, savepath, sg_per_g_zeta_savename, h5plot=h5plot)    
        plt.close(figsigma_gamma_per_gamma_zetapos)
Exemple #7
0
def plot_save_slice_centroids(slm, savepath, h5plot=True, time=None, zeta_pos=None, t_is_z=True):

    if t_is_z:
        xlabel_str = r'$k_p z$'
    else:
        xlabel_str = r'$\omega_p t$'

    Xb0_for_norm = np.ones(slm.get(x=1)[0,:].shape)
    Yb0_for_norm = np.ones(slm.get(y=1)[0,:].shape)
    for i in range(0,len(slm.get_zeta_array())):
        if (slm.get(x=1)[0,i] != 0.0):
            Xb0_for_norm[i] = slm.get(x=1)[0,i]
            Yb0_for_norm[i] = slm.get(y=1)[0,i]

    if time == None:
        time = slm.get_time_array()[-1]
        tidx = [-1];
    else:
        tidx = [(np.abs(slm.get_time_array() - time)).argmin()]

    if len(tidx) == 1:
        time = [time]

    for i in range(0,len(tidx)):
        Xb_lout_savename = 'Xb_time_%0.2f' % time[i]
        Yb_lout_savename = 'Yb_time_%0.2f' % time[i] 
        Xb_lout_ylab = r'$k_p X_{b}(t=%0.1f)$' % time[i]
        Yb_lout_ylab = r'$k_p Y_{b}(t=%0.1f)$' % time[i]

        figXb_lout = plt.figure()
        plt.plot(slm.get_zeta_array(), slm.get(x=1)[tidx[i],:])
        ax = plt.gca()
        ymin, ymax = ax.get_ylim()
        if ymin > 0 and ymax > 0:
            plt.ylim(0, ymax*1.2)
        elif ymin < 0 and ymax < 0:
            plt.ylim(ymin*1.2, 0)        
        ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
        ax.set_ylabel(Xb_lout_ylab, fontsize=14)
        saveas_eps_pdf(figXb_lout, savepath, Xb_lout_savename, h5plot=h5plot)
        plt.close(figXb_lout)

        figYb_lout = plt.figure()
        plt.plot(slm.get_zeta_array(), slm.get(y=1)[tidx[i],:])
        ax = plt.gca()
        ymin, ymax = ax.get_ylim()
        if ymin > 0 and ymax > 0:
            plt.ylim(0, ymax*1.2)
        elif ymin < 0 and ymax < 0:
            plt.ylim(ymin*1.2, 0)    
        ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
        ax.set_ylabel(Yb_lout_ylab, fontsize=14)  
        saveas_eps_pdf(figYb_lout, savepath, Yb_lout_savename, h5plot=h5plot)
        plt.close(figYb_lout)

    Xb_norm = np.zeros( slm.get(x=1).shape )
    Yb_norm = np.zeros( slm.get(y=1).shape )
#    zeta_hseed = np.min(slm.get_zeta_array())
#    idx_hseed = (np.abs(slm.get_zeta_array()-zeta_hseed)).argmin()

    for i in range(0,len(slm.get_zeta_array())):
#        if (slm.get_zeta_array()[i] <= zeta_hseed):
        Xb_norm[:,i] = np.absolute( slm.get(x=1)[:,i]/Xb0_for_norm[i] )
        Yb_norm[:,i] = np.absolute( slm.get(y=1)[:,i]/Yb0_for_norm[i] )

    figXb = plt.figure()
    cax = plt.pcolormesh(   slm.get_zeta_array(),
                            slm.get_time_array(),
                            slm.get(x=1),
                            cmap=cm.PuOr,
                            vmin=-np.amax(abs(slm.get(x=1))), 
                            vmax=np.amax(abs(slm.get(x=1))))
    cbar = figXb.colorbar(cax)   
    cbar.ax.set_ylabel('$k_p X_b$', fontsize=14)
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14) 
    saveas_png(figXb, savepath, 'Xb')
    plt.close(figXb)

    figYb = plt.figure()
    cax = plt.pcolormesh(   slm.get_zeta_array(),
                            slm.get_time_array(),
                            slm.get(y=1),
                            cmap=cm.PuOr,
                            vmin=-np.amax(abs(slm.get(y=1))), 
                            vmax=np.amax(abs(slm.get(y=1))))
    cbar = figYb.colorbar(cax)
    cbar.ax.set_ylabel('$k_p Y_b$', fontsize=14)
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)     
    saveas_png(figYb, savepath, 'Yb')
    plt.close(figYb)

    figXbnorm = plt.figure()
    cax = plt.pcolormesh(   slm.get_zeta_array(),
                            slm.get_time_array(),
                            Xb_norm,
                            cmap=cm.Blues,
                            vmin=0, 
                            vmax=np.amax(Xb_norm))
    cbar = figXbnorm.colorbar(cax)
    cbar.ax.set_ylabel('$|X_b/X_{b,0}|$', fontsize=14)
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)  
    saveas_png(figXbnorm, savepath, 'Xb_rel')
    plt.close(figXbnorm)

    figYbnorm = plt.figure()
    cax = plt.pcolormesh(   slm.get_zeta_array(),
                            slm.get_time_array(),
                            Yb_norm,
                            cmap=cm.Blues,
                            vmin=0, 
                            vmax=np.amax(Yb_norm))
    cbar = figYbnorm.colorbar(cax)
    cbar.ax.set_ylabel('$|Y_b/Y_{b,0}|$', fontsize=14)
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)
    saveas_png(figYbnorm, savepath, 'Yb_rel')
    plt.close(figYbnorm)

    figXb0 = plt.figure()
    plt.plot(slm.get_zeta_array(), slm.get(x=1)[0,:])
    ax = plt.gca()
    ymin, ymax = ax.get_ylim()
    if ymin > 0 and ymax > 0:
        plt.ylim(0, ymax*1.2)
    elif ymin < 0 and ymax < 0:
        plt.ylim(ymin*1.2, 0)        
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(r'$k_p X_{b,0}$', fontsize=14)
    saveas_eps_pdf(figXb0, savepath, 'Xb0', h5plot=h5plot)
    plt.close(figXb0)

    figYb0 = plt.figure()
    plt.plot(slm.get_zeta_array(), slm.get(y=1)[0,:])
    ax = plt.gca()
    ymin, ymax = ax.get_ylim()
    if ymin > 0 and ymax > 0:
        plt.ylim(0, ymax*1.2)
    elif ymin < 0 and ymax < 0:
        plt.ylim(ymin*1.2, 0)    
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(r'$k_p Y_{b,0}$', fontsize=14)     
    saveas_eps_pdf(figYb0, savepath, 'Yb0', h5plot=h5plot)
    plt.close(figYb0)

    if zeta_pos != None:
        zetaidx = [(np.abs(slm.get_zeta_array() - zeta_pos)).argmin()]
        Xb_savename = 'Xb_zeta_%0.2f' % zeta_pos
        Yb_savename = 'Yb_zeta_%0.2f' % zeta_pos 
    else:
        zetaidx = 0
        Xb_savename = 'Xb_tail'
        Yb_savename = 'Yb_tail'

    figXbtail = plt.figure()
    plt.plot(slm.get_time_array(), slm.get(x=1)[:,zetaidx])
    ax = plt.gca()
    ax.set_xlabel(xlabel_str, fontsize=14)
    ax.set_ylabel(r'$k_p X_{b,\mathrm{tail}}$', fontsize=14)
    if magn_check(slm.get(x=1)[:,zetaidx]):    
        ax.yaxis.set_major_formatter(FormatStrFormatter('%.1e'))
        plt.gcf().subplots_adjust(left=0.18)
    else:
        plt.gcf().subplots_adjust(left=0.15)
    saveas_eps_pdf(figXbtail, savepath, Xb_savename, h5plot=h5plot)    
    plt.close(figXbtail)

    figYbtail = plt.figure()
    plt.plot(slm.get_time_array(), slm.get(y=1)[:,zetaidx])
    ax = plt.gca()
    ax.set_xlabel(xlabel_str, fontsize=14)
    ax.set_ylabel(r'$k_p Y_{b,\mathrm{tail}}$', fontsize=14)
    if magn_check(slm.get(y=1)[:,zetaidx]):    
        ax.yaxis.set_major_formatter(FormatStrFormatter('%.1e'))
        plt.gcf().subplots_adjust(left=0.18)
    else:
        plt.gcf().subplots_adjust(left=0.15)    
    saveas_eps_pdf(figYbtail, savepath, Yb_savename, h5plot=h5plot)   
    plt.close(figYbtail)  
Exemple #8
0
def plot_save_slice_rms(slm, savepath, verbose=True, t_is_z=True):

    x = slm.get_zeta_array()
    y = slm.get_time_array()

    if t_is_z:
        xlabel_str = r'$k_p z$'
    else:
        xlabel_str = r'$\omega_p t$'

    sigma_x = np.sqrt( np.absolute( slm.get(x=2) ) )
    fig_sx = plt.figure()
    cax = plt.pcolormesh( x,
                          y,
                          sigma_x,
                          cmap=cm.Blues,
                          vmin=0, vmax=np.amax(abs(sigma_x)) )
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)    
    cbar = fig_sx.colorbar( cax )
    cbar.ax.set_ylabel(r'$k_p \sigma_x$', fontsize=14)
    saveas_png(fig_sx, savepath, 'sigma_x')
    plt.close(fig_sx)

    sigma_px = np.sqrt( np.absolute( slm.get(px=2) ) )
    fig_spx = plt.figure()
    cax = plt.pcolormesh( x,
                          y,
                          sigma_px,
                          cmap=cm.YlGn,
                          vmin=0, vmax=np.amax(sigma_px) )
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)    
    cbar = fig_spx.colorbar( cax )
    cbar.ax.set_ylabel(r'$k_p \sigma_{p_x}$', fontsize=14)  
    saveas_png(fig_spx, savepath, 'sigma_px')
    plt.close(fig_spx)

    xpx = slm.get(x=1,px=1)
    fig_xpx = plt.figure()
    cax = plt.pcolormesh( x,
                          y,
                          xpx,
                          cmap=cm.BrBG,
                          vmin=-np.amax(np.abs(xpx)), vmax=np.amax(np.abs(xpx)) )
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)    
    cbar = fig_xpx.colorbar( cax )
    cbar.ax.set_ylabel(r'$k_p \left\langle x p_x\right\rangle$', fontsize=14)
    saveas_png(fig_xpx, savepath, 'xpx')
    plt.close(fig_xpx)

    emittance = np.sqrt( np.multiply(slm.get(x=2), slm.get(px=2)) 
                         - np.power(slm.get(x=1,px=1),2) )
    fig_e = plt.figure()
    cax = plt.pcolormesh( x,
                          y,
                          emittance,
                          cmap=cm.Reds,
                          vmin=np.amin(emittance), vmax=np.amax(emittance) )
    ax = plt.gca()
    ax.set_xlabel(r'$k_p \zeta$', fontsize=14)
    ax.set_ylabel(xlabel_str, fontsize=14)    
    cbar = fig_e.colorbar( cax )
    cbar.ax.set_ylabel(r'$k_p \epsilon_x$', fontsize=14)
    saveas_png(fig_e, savepath, 'slice_emittance_x')
    plt.close(fig_e)
Exemple #9
0
def main():


    parser = h5plot_parser()
    args = parser.parse_args()

    if args.maketitle:
        ''' Calculating plasma frequency for length '''
        ELECTRON_CHARGE_IN_COUL   =    1.60217657e-19
        ELECTRON_MASS_IN_KG       =    9.10938291e-31
        VAC_PERMIT_FARAD_PER_M    =    8.854187817e-12
        SPEED_OF_LIGHT_IN_M_PER_S =    299792458.0

        omega_p = np.sqrt( args.n0 * (ELECTRON_CHARGE_IN_COUL**2)/ (VAC_PERMIT_FARAD_PER_M * ELECTRON_MASS_IN_KG));
        skin_depth = SPEED_OF_LIGHT_IN_M_PER_S/omega_p
        
        

    if len(sys.argv)==1:
        parser.print_help()
        sys.exit(1)

    saveformat = args.file_format

    h5lp = []

    linestyles = ['-', '--', '-.', ':']
    save_append_str = ''
    type_str = 'comp'

    if args.latexon:
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif') 

    j = 0

    i = 0
    
    
    
    for path in args.paths:
        fig = plt.figure(figsize=(7,5))
        if not os.path.isfile(path):
            print('ERROR: File %s does not exist!' % path)
            sys.exit(1)          
            
        h5lp.append(H5Plot())
        h5lp[i].read(path)
        timestamp = path.split("_")[-1].split(".h5")[0]
        
        if args.data2:
            for files in args.data2:
                if timestamp in files or args.manual:
                    print('Reading second data set...')
                    h5secondlp = H5Plot()
                    h5secondlp.read(files)

        
        
        
        if args.cno == None:
            argcolor = plt.cm.tab20(6)
        else:
            argcolor = plt.cm.tab20(args.cno[0])
        
        j = 0
        for (x, y, label, linestyle, color) in h5lp[i].get_line_plots():
            if args.labels != None:
                save_append_str += '_' + args.labels[i]
                label = args.labels[i]

            if label == '_line0':
                label = path

            if args.latexon:
                if label[0] != '$' or label[-1] != '$':
                    label = r'$\textrm{' + label + '}$'


            if args.abs:
                y = np.abs(y)

            if args.lstyle == None:
                linestyle_code = linestyles[0]
            else:
                linestyle_code = linestyles[args.lstyle[0]]

            
            if args.absylog:
                plt.semilogy( x, y, label=label, linestyle=linestyle_code, color=argcolor, zorder=20)
            else:    
                #plt.plot(x, y, label=label, linestyle=linestyle, color=color)
                plt.plot(x, y, label=label, linestyle=linestyle_code, color=argcolor, zorder=20)      
            

        ax = plt.gca()
        ax.tick_params('y', colors=argcolor)
        plt.gcf().subplots_adjust(left=0.15, bottom=0.15, right=1-0.15)       
        if not (-3.0 < math.log(np.max(abs(y)),10) < 3.0):
            ax.yaxis.set_major_formatter(FormatStrFormatter('%.1e'))
            plt.gcf().subplots_adjust(left=0.18) 
        ax2 = ax.twinx()
        
        ''' PLOTTING THE SECOND PLOT '''
        if args.cno == None:
            argcolor = plt.cm.tab20(1)
        else:
            argcolor = plt.cm.tab20(args.cno[1])
        ax2.tick_params('y', colors=argcolor)
        j = 0
        for (x2, y2, label, linestyle, color) in h5secondlp.get_line_plots():
            if args.labels != None:
                save_append_str += '_' + args.labels[i]
                label = args.labels[i]

            if label == '_line0':
                label = path

            if args.latexon:
                if label[0] != '$' or label[-1] != '$':
                    label = r'$\textrm{' + label + '}$'

            if args.abs:
                y2 = np.abs(y2)

            if args.lstyle == None:
                linestyle_code = linestyles[0]
            else:
                linestyle_code = linestyles[args.lstyle[1]]

            
            if args.absy2log:
                plt.semilogy( x2, y2, label=label, linestyle=linestyle_code, color=argcolor, zorder=0)
            else:    
                #plt.plot(x, y, label=label, linestyle=linestyle, color=color)
                plt.plot(x2, y2, label=label, linestyle=linestyle_code, color=argcolor, zorder=0)      
            



        if args.xlim != None:
            ax.set_xlim(args.xlim[0],args.xlim[1])
        if args.ylim != None:
            ax.set_ylim(args.ylim[0],args.ylim[1])
        if args.y2lim != None:
            ax2.set_ylim(args.y2lim[0],args.y2lim[1])
            
        if args.xlab != None:
            xlab = args.xlab
        else:
            xlab = h5lp[0].get_xlab()
    

        if args.ylab != None:
            ylab = args.ylab
        else:
            ylab = []
            ylab.append(h5lp[0].get_ylab())
            ylab.append(h5secondlp.get_ylab())
            
        if args.latexon:
            if xlab[0] != '$' or xlab[-1] != '$':
                        xlab = r'$' + xlab + '$'
                        
                        
        if args.latexon:
            if ylab[0,0] != '$' or ylab[0,-1] != '$':
                        ylab[0] = r'$' + ylab[0] + '$'
                        ylab[1] = r'$' + ylab[1] + '$'

        ax.set_xlabel(xlab, fontsize=14)
        ax.set_ylabel(ylab[0], fontsize=14)
        ax2.set_ylabel(ylab[1], fontsize=14)   
        
        
        ax.set_zorder(ax2.get_zorder()+1) # put ax in front of ax2
        ax.patch.set_visible(False) # hide the 'canvas' 
        # handles, labels = ax.get_legend_handles_labels()
        # #plt.legend(flip(handles, 2), flip(labels, 2), ncol=2)
        # plt.legend(frameon=False)
        #plt.gcf().subplots_adjust(left=0.15, bottom=0.15, right=0.15)       
        if not (-3.0 < math.log(np.max(abs(y2)),10) < 3.0):
            ax2.yaxis.set_major_formatter(FormatStrFormatter('%.1e'))
            plt.gcf().subplots_adjust(right=1-0.18)          
        #plt.show()

        ''' make the title '''
        if args.maketitle:
            time = np.around(float(timestamp))
            distance = time*skin_depth*1e2
            title = 'Time: ' + str(time) + r'$\,\omega_p^{-1}$ ' + '   Distance: ' + str(np.around(distance,2)) + r'$\,$cm'
            plt.title(title)
            
        if args.show:
            plt.show()
            
        spath, fname  = os.path.split(args.paths[0])
        if args.savepath != None:
            spath = args.savepath

        if not args.manual:
            save_name = type_str + '_' + fname + save_append_str + '_' +  timestamp
        else:
            save_name = type_str + '_' + fname + save_append_str
        
        if saveformat==args.file_format:
            saveas_png(fig, spath, save_name, args.dpi)
        else:
            saveas_eps_pdf(fig, savepath=spath, savename=save_name)
        

        
        plt.close(fig)