Ejemplo n.º 1
0
def get_timestamp(filename):
    match = re_file.match(filename)
    args = [int(x) for x in match.groups()]
    if match is None:
        print(filename)
        raise ValueError
    return elegant_matrix.get_timestamp(*args)
Ejemplo n.º 2
0
charge = 200e-12
screen_cutoff = 2e-3
profile_cutoff = 2e-2
len_profile = int(2e3)
struct_lengths = [1., 1.]
screen_bins = 400
smoothen = 30e-6
n_emittances = [900e-9, 500e-9]
n_particles = int(100e3)
n_streaker = 1
self_consistent = True
quad_wake = False
bp_smoothen = 1e-15
invert_offset = True
magnet_file = archiver_dir + '2021-03-16.h5'
timestamp = elegant_matrix.get_timestamp(2021, 3, 16, 20, 14, 10)
sig_t_range = np.arange(20, 50.01, 5) * 1e-15
n_streaker = 1
compensate_negative_screen = False

tracker = tracking.Tracker(
    magnet_file,
    timestamp,
    struct_lengths,
    n_particles,
    n_emittances,
    screen_bins,
    screen_cutoff,
    smoothen,
    profile_cutoff,
    len_profile,
import myplotstyle as ms

plt.close('all')

hostname = socket.gethostname()
elegant_matrix.set_tmp_dir('/home/philipp/tmp_elegant/')

#energy_eV = 6.14e9
gaps = [10e-3, 10e-3]
beam_offsets = [4.7e-3, 0.]
fit_order = 4
sig_t = 30e-15  # for Gaussian beam
tt_halfrange = 200e-15
charge = 200e-12
timestamp = elegant_matrix.get_timestamp(2020, 7, 26, 17, 49, 0)
backtrack_cutoff = 0.05
len_profile = 1e3
struct_lengths = [1., 1.]

if hostname == 'desktop':
    magnet_file = '/storage/Philipp_data_folder/archiver_api_data/2020-07-26.h5'
    bl_meas_file = '/storage/data_2020-02-03/Bunch_length_meas_2020-02-03_15-59-13.h5'
else:
    magnet_file = '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/archiver_api_data/2020-07-26.h5'
    bl_meas_file = '/sf/data/measurements/2020/02/03/Bunch_length_meas_2020-02-03_15-59-13.h5'

tracker = tracking.Tracker(magnet_file,
                           timestamp,
                           charge,
                           struct_lengths,
quad_wake = False
bp_smoothen = 1e-15
invert_offset = True
#sig_t_range = np.arange(20, 40.01, 2)*1e-15

#mean_struct2 = 472e-6 # see 026_script
fudge_factor = 30e-6
mean_struct2 = 466e-6 + fudge_factor
gap2_correcting_summand = 0 #-3e-6
sig_t_range = np.arange(20, 40.01, 5)*1e-15
gaps = [10e-3, 10e-3]
subtract_min = True
fit_emittance = True
archiver_dir = '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/'
magnet_file = archiver_dir + 'archiver_api_data/2021-03-16.h5'
timestamp = elegant_matrix.get_timestamp(2021, 3, 16, 20, 41, 39)
beam_offsets = [-0.0, -0.004724]

median_screen = misc.image_to_screen(image_on.image, x_axis, False, x0)
median_screen.cutoff2(3e-2)
median_screen.crop()
median_screen.reshape(len_profile)

tracker = tracking.Tracker(magnet_file=magnet_file, timestamp=timestamp, n_particles=n_particles, n_emittances=n_emittances, screen_bins=screen_bins, screen_cutoff=screen_cutoff, smoothen=smoothen, profile_cutoff=profile_cutoff, len_screen=len_profile, bp_smoothen=bp_smoothen, quad_wake=False)

energy_eV = tracker.energy_eV
blmeas = data_dir+'113876237_bunch_length_meas.h5'

profile_meas = iap.profile_from_blmeas(blmeas, 200e-15, charge, energy_eV)
profile_meas.cutoff(5e-2)
profile_meas.reshape(len_profile)
Ejemplo n.º 5
0
import data_loader
import elegant_matrix
import wf_model

import myplotstyle as ms

plt.close('all')

n_particles = int(20e3)  # for elegant
ele_dir0 = '/home/philipp/elegant/wakefield/001_cut_sim/'
ele_dir = '/home/philipp/elegant/wakefield/001a_test_measured_current_prof/'
bl_meas_file = '/sf/data/measurements/2020/02/03/Bunch_length_meas_2020-02-03_21-54-24.h5'

displacement = (3.0884 - 0.65) * 1e-3
gap = 6e-3
timestamp = elegant_matrix.get_timestamp(2020, 2, 3, 21, 54, 24)
simulator = elegant_matrix.get_simulator(
    '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data//archiver_api_data/2020-02-03.json11'
)

# Shift day was 3.2.2020

bl_meas = data_loader.load_blmeas(bl_meas_file)

tt = bl_meas['time_profile1']
tt -= tt.mean()

curr0 = bl_meas['current1']
curr = curr0.copy()

curr[curr < curr.max() * 0.05] = 0
import socket
import matplotlib.pyplot as plt
import numpy as np
import mat73
from scipy.constants import c

import tracking
import elegant_matrix

import myplotstyle as ms


charge = 200e-12
timestamp = elegant_matrix.get_timestamp(2020, 10, 3, 23, 19, 58)
struct_lengths = [1., 1.]
n_particles = int(50e3)
n_emittances = [300e-9, 300e-9]
screen_bins = 200
screen_cutoff = 1e-3
smoothen = 0
profile_cutoff = 0
len_profile = int(1e3)
gap2_correcting_summand = -40e-6
gaps = [10e-3, 10e-3+gap2_correcting_summand]
mean_struct2 = 472e-6 # see 026_script



plt.close('all')

hostname = socket.gethostname()
Ejemplo n.º 7
0
for n_streaker, gap_file in [
    (1, gap_file1),
    #(2, gap_file2),
        ]:

    for gap_mm, files in gap_file:

        xx_list = []
        bpm_list_dict = {key: [] for key in bpms}
        semigap_m = gap_mm*1e-3/2.
        for n_file, file_ in enumerate(files):
            # Measurement

            file_ = os.path.join(data_dir, os.path.basename(file_))
            _, year, month, day, hour, minute, second, _ = os.path.basename(file_).split('_')
            timestamp = elegant_matrix.get_timestamp(year, month, day, hour, minute, second)
            with h5py.File(file_, 'r') as dict_:
                for bpm in bpms:
                    bpm_list_dict[bpm].append(np.array(dict_['scan 1']['data'][bpm]['X1'])*1e-3)

                offset = np.array(dict_['scan 1']['method']['actuators']['SARUN18-UDCP%i00' % n_streaker]['CENTER'])*1e-3
            xx_list.append(offset)

        # Combine different measurements
        len2 = sum(x.shape[-1] for x in bpm_list_dict[bpms[0]])
        bpm_data = {bpm: np.zeros((len(xx_list[0]), len2)) for bpm in bpms}

        for key, ll in bpm_list_dict.items():
            ctr = 0
            for l_ in ll:
                l_len = l_.shape[-1]
Ejemplo n.º 8
0
import ImageSlicer.imageSlicer as slicer
import elegant_matrix

import myplotstyle as ms

transpose = True
n_slices = 31

plt.close('all')

data_dir = '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/data_2020-02-03/'
#data_dir = '/mnt/usb/work/data_2020-02-03/'
data_file = data_dir + 'Eloss_UNDbis.mat'
result_dict = loadH5Recursive(os.path.basename(data_file) + '_wake.h5')

timestamp = elegant_matrix.get_timestamp(2020, 2, 3, 21, 35, 8)

simulator = elegant_matrix.get_simulator(
    '/afs/psi.ch/intranet/SF/Beamdynamics/Philipp/data/archiver_api_data/2020-02-03.json11'
)
_, disp_dict = simulator.get_elegant_matrix(1, timestamp)
energy_eV = simulator.get_data('SARBD01-MBND100:P-SET', timestamp) * 1e6

disp_factor = disp_dict['SARBD02.DSCR050'] / energy_eV

data_dict = loadmat(data_file)
x_axis = data_dict['x_axis'].squeeze() * 1e-6
y_axis = data_dict['y_axis'].squeeze() * 1e-6

n_images, n_gaps = data_dict['Image'].shape
Ejemplo n.º 9
0
elegant_matrix.set_tmp_dir('~/tmp_elegant')

data_dir = '/mnt/data/data_2021-03-16/'
archiver_dir = '/mnt/data/archiver_api_data/'
lasing_on_file = data_dir + '20210316_202944_SARBD02-DSCR050_camera_snapshot.h5'
lasing_off_file = data_dir + '20210316_204139_SARBD02-DSCR050_camera_snapshot.h5'
cutoff = 0.03
cutoff_proj = 0.1
x0 = 0.0005552048387736093
n_slices = 50

streaker_data_file = archiver_dir + '2021-03-16_1.h5'
streaker_data = data_loader.DataLoader(file_h5=streaker_data_file)
streaker = 'SARUN18-UDCP020'

timestamp1 = elegant_matrix.get_timestamp(2021, 3, 16, 20, 29, 44)
timestamp2 = elegant_matrix.get_timestamp(2021, 3, 16, 20, 41, 39)

for timestamp in timestamp1, timestamp2:
    streaker_gap = streaker_data.get_prev_datapoint(streaker + ':GAP',
                                                    timestamp) * 1e-3
    streaker_center = streaker_data.get_prev_datapoint(streaker + ':CENTER',
                                                       timestamp) * 1e-3
    print('Streaker properties [mm]', timestamp, streaker_gap * 1e3,
          streaker_center * 1e3)

lasing_on = loadH5Recursive(lasing_on_file)
lasing_off = loadH5Recursive(lasing_off_file)

image_on = lasing_on['camera1']['image'].astype(float)
image_off = lasing_off['camera1']['image'].astype(float)
Ejemplo n.º 10
0
struct_lengths = [1., 1.]
n_particles = int(1e5)
n_emittances = [500e-9, 500e-9]
screen_bins = 500
screen_cutoff = 1e-2
smoothen = 30e-6
profile_cutoff = 1e-2
gaps = [10e-3, 10e-3]
streaker_center = streaker_analysis['meta_data']['streaker_offset']
n_streaker = 1
tt_halfrange = 200e-15
bp_smoothen = 1e-15
invert_offset = True
quad_wake = False
override_quad_beamsize = False
timestamp = elegant_matrix.get_timestamp(2020, 10, 4, 17, 24, 25)

tracker = tracking.Tracker(magnet_file,
                           timestamp,
                           struct_lengths,
                           n_particles,
                           n_emittances,
                           screen_bins,
                           screen_cutoff,
                           smoothen,
                           profile_cutoff,
                           len_profile,
                           bp_smoothen=bp_smoothen,
                           quad_wake=quad_wake)

ms.figure('Tracking')
fig = ms.figure('Track current beam')
sp_ctr = 1
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(),
        }