def plot_laser_driven(self, out_num, if_laser_profile=False): ''' When if_laser_profile is Ture, plot the laser profile instead of original E-field''' h_fig = plt.figure(figsize=(6.5,5)) self.outfile.field_name='charge' self.outfile.spec_name=self.background_spec_name self.outfile.out_num=out_num h_ax = h_fig.add_subplot(111) #h_ax.set_aspect('equal', 'box') #plt.ylim(-10,10) self.outfile.open() self.outfile.read_data_slice(dir=self.dir) self.outfile.plot_data(h_fig, h_ax, cmap='gray', vmax=self.background_vmax, vmin=self.background_vmin) self.outfile._color_bar.set_label('$\\rho_e$') self.outfile.close() if self.trail_spec_name is not None: self.outfile.spec_name=self.trail_spec_name self.outfile.open() self.outfile.read_data_slice(dir=self.dir) self.outfile.plot_data(h_fig, h_ax, vmin=self.trail_vmin, vmax=self.trail_vmax, cmap=my_cmap.cmap_higher_range_transparent()) self.outfile._color_bar.set_label('$\\rho_t$') self.outfile.close() self.outfile.field_name='e3' self.outfile.open() self.outfile.read_data_slice(dir=self.dir) if if_laser_profile: self.outfile.data_profile2d() self.outfile.plot_data(h_fig, h_ax, cmap=my_cmap.cmap_lower_range_transparent(plt.cm.Reds, transparency_transition_region=[0.15,0.4])) else: self.outfile.plot_data(h_fig, h_ax, cmap=my_cmap.cmap_middle_range_transparent()) self.outfile._color_bar.set_label('$E_y$') self.outfile.close() plt.tight_layout() return h_fig
def plot_trail_phasespace_raw(self, out_num): h_fig = plt.figure(figsize=(6.5,5)) self.outfile.spec_name=self.plot_spec_name self.outfile.out_num=out_num h_ax = h_fig.add_subplot(111) self.outfile.open() self.outfile.plot_raw_hist2D(h_fig, h_ax, dims=self.plot_type, cmap=my_cmap.cmap_lower_range_transparent(), if_log_colorbar=False) self.outfile.close() plt.tight_layout() return h_fig
def N_inj_vs_psi_M_theta(self, if_plot=False, h_fig=None, h_ax=None, **kwargs): ''' Calculate 2D histogram of number of injectable particles vs psi_M and theta and save to self.N_inj. Plot pseudocolor if if_plot is true. One should have alreadt run self.pz_pr_vs_r0() to obtain self.pz_final and self.pr_final before calling this. ''' # z_prime and r_prime is the laser coordinate, while z is the main wake coordinate. p_z_prime = self.pz_final p_r_prime = self.pr_final gamma_final = np.sqrt(1. + np.square(p_z_prime) + np.square(p_r_prime)) self.N_inj = np.zeros((self.psi_M_bins, self.theta_bins)) for theta_ind in range(self.theta_bins): cos_theta = np.cos(self.theta_array_rad[theta_ind]) sin_theta = np.sin(self.theta_array_rad[theta_ind]) for psi_M_ind in range(self.psi_M_bins): for r0_ind in range(self.len_r0_array): # p_z = p_z_prime*cos_theta + p_r_prime*sin_theta cos_phi # particles with cos_phi smaller than this value should be added to N cos_phi = (gamma_final[r0_ind] - self.psi_M_array[psi_M_ind] - p_z_prime[r0_ind] * cos_theta) / p_r_prime[r0_ind] / sin_theta if cos_phi <= (-1): # phi from -pi to pi is injectable # Number proportional to r0 self.N_inj[psi_M_ind, theta_ind] += self.r0_array[r0_ind] * ( np.pi * 2) # * d_r0 for absolute number elif cos_phi < 1.: # -1<cos(phi)<1, phi in a range smaller than pi satisfies pn>pth # Number proportional to r0 self.N_inj[psi_M_ind, theta_ind] += self.r0_array[r0_ind] * ( np.arccos(cos_phi) * 2) # if cos(phi)>=1, none is injectable, do not add anything if if_plot: if h_fig is None: try: h_fig = self.h_fig except AttributeError: h_fig = self.h_fig = plt.figure() if h_ax is None: try: h_ax = self.h_ax except AttributeError: h_ax = self.h_ax = h_fig.add_subplot(111) h_plot = h_ax.pcolormesh( self.theta_array_degree, self.psi_M_array, self.N_inj, cmap=my_cmap.cmap_lower_range_transparent( transparency_transition_region=[0., 0.02]), **kwargs) h_ax.set_ylabel('$\\psi_M$') h_ax.set_xlabel('$\\theta$ [$^{{\\circ}}$]') h_cb = plt.colorbar(h_plot, ax=h_ax) h_cb.set_label('$N_{{\\rm trap}}$ [arb. unit]') return
def plot_laser_driven(self, out_num, if_laser_profile=False): ''' When if_laser_profile is Ture, plot the laser profile instead of original E-field''' h_fig = plt.figure(figsize=(6.5, 5)) self.outfile.field_name = 'charge' self.outfile.spec_name = self.background_spec_name self.outfile.out_num = out_num h_ax = h_fig.add_subplot(111) #h_ax.set_aspect('equal', 'box') #plt.ylim(-10,10) self.outfile.open() if self.outfile.num_dimensions >= 3: self.outfile.read_data_slice(dir=self.dir) else: self.outfile.read_data() self.outfile.plot_data(h_fig, h_ax, cmap='gray', vmax=self.background_vmax, vmin=self.background_vmin) self.outfile._color_bar.set_label('$\\rho_e$') self.outfile.close() if self.trail_spec_name is not None: self.outfile.spec_name = self.trail_spec_name self.outfile.open() if self.outfile.num_dimensions >= 3: self.outfile.read_data_slice(dir=self.dir) else: self.outfile.read_data() self.outfile.plot_data( h_fig, h_ax, vmin=self.trail_vmin, vmax=self.trail_vmax, cmap=my_cmap.cmap_higher_range_transparent()) self.outfile._color_bar.set_label('$\\rho_t$') self.outfile.close() if self.laser_field_name is not None: self.outfile.field_name = self.laser_field_name self.outfile.open() if self.outfile.num_dimensions >= 3: self.outfile.read_data_slice(dir=self.dir) else: self.outfile.read_data() if if_laser_profile: self.outfile.data_profile2d() self.outfile.plot_data( h_fig, h_ax, cmap=my_cmap.cmap_lower_range_transparent( plt.cm.Reds, transparency_transition_region=[0.15, 0.4])) else: self.outfile.plot_data( h_fig, h_ax, cmap=my_cmap.cmap_middle_range_transparent()) self.outfile._color_bar.set_label('$E_L$') self.outfile.close() if self.if_e1: self.outfile.field_name = 'e1' self.outfile.open() self.outfile.read_data_lineout() self.outfile.plot_data(h_fig, h_ax, if_ylabel=False, multiple=self.e1_multiple, c='r', ls='-') self.outfile.close() if self.if_psi: self.outfile.field_name = 'psi' if not os.path.isfile(self.outfile.path_filename): warnings.warn( 'Psi file not found. Try to get psi by integrating Ez.') # No psi file, get psi by integrating e1 if e1 is already read if self.if_e1: if self.code_name != 'quickpic': # For OSIRIS and HiPACE, psi is e1 integration from right to left e1 = np.flip(self.outfile._data) else: e1 = self.outfile._data np.cumsum(e1 * self.outfile._axis_slices[0].step, out=self.outfile._data) if self.code_name != 'quickpic': # For OSIRIS and HiPACE, flip the data self.outfile._data = np.flip(self.outfile._data) else: warnings.warn('Ez is not read. Please set if_e1 to True.') else: # There is psi file, read psi normally self.outfile.open() self.outfile.read_data_lineout() self.outfile.close() self.outfile.plot_data(h_fig, h_ax, if_ylabel=False, multiple=self.psi_multiple, c='b', ls='-') plt.tight_layout() return h_fig