def profile_from_blmeas(file_, tt_halfrange, charge, energy_eV, subtract_min=False, zero_crossing=1): bl_meas = data_loader.load_blmeas(file_) time_meas0 = bl_meas['time_profile%i' % zero_crossing] current_meas0 = bl_meas['current%i' % zero_crossing] if subtract_min: current_meas0 = current_meas0 - current_meas0.min() if tt_halfrange is None: tt, cc = time_meas0, current_meas0 else: current_meas0 *= charge/current_meas0.sum() gf_blmeas = GaussFit(time_meas0, current_meas0) time_meas0 -= gf_blmeas.mean time_meas1 = np.arange(-tt_halfrange, time_meas0.min(), np.diff(time_meas0).mean()) time_meas2 = np.arange(time_meas0.max(), tt_halfrange, np.diff(time_meas0).mean()) time_meas = np.concatenate([time_meas1, time_meas0, time_meas2]) current_meas = np.concatenate([np.zeros_like(time_meas1), current_meas0, np.zeros_like(time_meas2)]) tt, cc = time_meas, current_meas return BeamProfile(tt, cc, energy_eV, charge)
import matplotlib.pyplot as plt import numpy as np from scipy.constants import c import data_loader import uwf_model as uwf import myplotstyle as ms plt.close('all') semigap = 4e-3 / 2. data_dir = '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/data_2020-02-03/' meas1 = 'Bunch_length_meas_2020-02-03_21-54-24.h5' lims = [25, 70] bl_meas = data_loader.load_blmeas(data_dir + meas1) charge = 200e-12 charge_xx = bl_meas['time_profile1'] * c charge_xx -= charge_xx.min() current_profile = bl_meas['current1'] charge_profile = current_profile * charge / np.sum(current_profile) energy_eV = bl_meas['energy_eV'] mask_charge = np.logical_and(charge_xx > lims[0] * 1e-6, charge_xx < lims[1] * 1e-6) assert np.any(mask_charge) charge_xx = charge_xx[mask_charge] charge_xx -= charge_xx.min() charge_profile = charge_profile[mask_charge]
import numpy as np np from scipy.constants import c import matplotlib.pyplot as plt from scipy.io import loadmat import myplotstyle as ms import wf_model import data_loader data_dir = '/storage/data_2020-02-03/' data_dir = '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/data_2020-02-03/' data_dir = '/sf/data/measurements//2020/02/03/' bl_meas_file = data_dir + 'Bunch_length_meas_2020-02-03_15-59-13.h5' bl_meas = data_loader.load_blmeas(bl_meas_file) total_charge = 200e-12 current_profile = bl_meas['current1'] charge_profile = current_profile * total_charge / np.sum(current_profile) charge_xx = bl_meas['time_profile1'] * c charge_xx -= charge_xx.min() energy_eV = bl_meas['energy_eV'] plt.close('all') files = [ data_dir + '/Eloss_DEH1.fig.mat', data_dir + '/Eloss_DEH2.fig.mat', data_dir + '/Eloss_DEH1-2.fig.mat' ] lengths = [1, 1, 2] titles = ['Structure 1', 'Structure 2', 'Structures 1+2']
subplot = ms.subplot_factory(3,3) sp_current = subplot(sp_ctr, title='Current') sp_ctr += 1 full_gap = 10e-3 offset0 = (-4.22e-3) - 0.52e-3 del_offset_arr = np.array([0,])*2*1e-6 n_particles = int(20e3) energy_eV = 5.95e9 bin_number = 200 timestamp = elegant_matrix.get_timestamp(2020, 10, 3, 15, 43, 29) timestamp = 1601681166 dl = data_loader.load_blmeas('/sf/data/measurements/2020/10/03/Bunch_length_meas_2020-10-03_15-43-29.h5') energy_eV = dl["energy_eV"] arr0 = np.zeros([len(del_offset_arr), bin_number], float) output = { 'energy_eV': energy_eV, 'full_gap_s2': full_gap, 'delta_offset': del_offset_arr, 'proj_no_streak': arr0.copy(), 'axis_no_streak': arr0.copy(), 'proj_streak': arr0.copy(), 'axis_streak': arr0.copy(), } curr = dl['current1'][::-1] xx = dl['time_profile1']
ms.figure('All blmeas of 03.02.2020') sp_ctr = 1 subplot = ms.subplot_factory(2,2) sp_current = subplot(sp_ctr, title='Current 1', xlabel='z [$\mu$m]', ylabel='I [kA]') sp_ctr += 1 sp_current2 = subplot(sp_ctr, title='Current 2') sp_ctr += 1 for ctr, (blmeas, charge) in enumerate(meas_charge): label = ctr meas = data_loader.load_blmeas(data_dir + blmeas) xx = meas['time_profile1']*c yy = meas['current1'] sp_current.plot(xx*1e6, yy/1e3, label=label) print(ctr, '%.1e' % np.trapz(yy, xx)) if meas['time_profile2'] is not None: xx = meas['time_profile2']*c yy = meas['current2'] sp_current2.plot(xx*1e6, yy/1e3, label=label) xlim = sp_current.get_xlim()
meas2 = 'Bunch_length_meas_2020-02-03_22-08-38.h5' meas3 = 'Bunch_length_meas_2020-02-03_23-55-33.h5' charge_lims1 = [25, 70] charge_lims2 = [40, 125] charge_lims3 = [40, 100] mat_files_current_charge_lims = [ ('Eloss_UNDbis.mat', meas1, 200e-12, charge_lims1), ('Eloss_UND2ndStreak.mat', meas1, 200e-12, charge_lims1), ('Eloss_UND-COMP2.mat', meas2, 100e-12, charge_lims2), ('Eloss_UND-COMP3.mat', meas3, 100e-12, charge_lims3), ] for mat_file, current_file, charge, lims in mat_files_current_charge_lims: bl_meas = data_loader.load_blmeas(data_dir + current_file) charge_xx = bl_meas['time_profile1'] * c charge_xx -= charge_xx.min() current_profile = bl_meas['current1'] charge_profile = current_profile * charge / np.sum(current_profile) energy_eV = bl_meas['energy_eV'] mask_charge = np.logical_and(charge_xx > lims[0] * 1e-6, charge_xx < lims[1] * 1e-6) assert np.any(mask_charge) charge_xx = charge_xx[mask_charge] charge_xx -= charge_xx.min() charge_profile = charge_profile[mask_charge] wf_meas = loadmat(data_dir + mat_file)