Example #1
0
    def __init__(self,
                 script,
                 lib_dir,
                 user_filename,
                 arguments,
                 optics_func_name='set_optics'):
        self.lib_dir = lib_dir
        self.initial_lib_dir = lib_dir
        self.list_of_files = None
        self.optics_func_name = optics_func_name
        m = pkrunpy.run_path_as_module(script)
        varParam = getattr(m, 'varParam')
        if arguments:
            import shlex
            arguments = shlex.split(arguments)
        self.var_param = srwl_uti_parse_options(varParam,
                                                use_sys_argv=False,
                                                args=arguments)
        self.get_files()
        if self.initial_lib_dir:
            self.replace_mirror_files()
            self.replace_image_files()
        try:
            self.optics = getattr(m, self.optics_func_name)(self.var_param)
        except ValueError as e:
            if re.search('could not convert string to float', e.message):
                self.replace_mirror_files('mirror_2d.dat')
                self.optics = getattr(m, self.optics_func_name)(self.var_param)

        self.data = _parsed_dict(self.var_param, self.optics)
        self.data.models.simulation.name = _name(user_filename)
def setup_source(v):
    appV = srwl_bl.srwl_uti_parse_options(appParam)

    if appV.ueb:
        srwl_bl._USER_DEFINED_EBEAM = srwl_bl.SRWLPartBeam()
        srwl_bl._USER_DEFINED_EBEAM.from_Twiss(_e=appV.ueb_e, _sig_e=appV.ueb_sig_e, _emit_x=appV.ueb_emit_x, _beta_x=appV.ueb_beta_x, _alpha_x=appV.ueb_alpha_x, _eta_x=appV.ueb_eta_x, _eta_x_pr=appV.ueb_eta_x_pr, _emit_y=appV.ueb_emit_y, _beta_y=appV.ueb_beta_y, _alpha_y=appV.ueb_alpha_y, _eta_y=appV.ueb_eta_y, _eta_y_pr=appV.ueb_eta_y_pr)

    mag = None
    if appV.source_type == 'u':
        v.und_b = 1
    elif appV.source_type == 'g':
        GsnBm = srwlib.SRWLGsnBm()
        GsnBm.x = appV.gb_waist_x
        GsnBm.y = appV.gb_waist_y
        GsnBm.z = appV.gb_waist_z
        GsnBm.xp = appV.gb_waist_angle_x
        GsnBm.yp = appV.gb_waist_angle_y
        GsnBm.avgPhotEn = appV.gb_photon_energy
        GsnBm.pulseEn = appV.gb_energy_per_pulse
        GsnBm.polar = appV.gb_polarization
        GsnBm.sigX = appV.gb_rms_size_x
        GsnBm.sigY = appV.gb_rms_size_y
        GsnBm.sigT = appV.gb_rms_pulse_duration
        GsnBm.mx = 0 #Transverse Gauss-Hermite Mode Orders
        GsnBm.my = 0
        srwl_bl._GAUSSIAN_BEAM = GsnBm
    else:
        mag = srwlib.SRWLMagFldC()
        mag.arXc.append(0)
        mag.arYc.append(0)
        mag.arMagFld.append(srwlib.SRWLMagFldM(appV.mp_field, appV.mp_order, appV.mp_distribution, appV.mp_len))
        mag.arZc.append(appV.mp_zc)
    return appV.source_type, mag
Example #3
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    source_type, mag = srwl_bl.setup_source(v)
    op = set_optics(v)
    v.ws = True
    v.ws_pl = 'xy'
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #4
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    op = set_optics(v)
    v.ss = True
    v.ss_pl = 'e'
    v.sm = True
    v.sm_pl = 'e'
    v.pw = True
    v.pw_pl = 'xy'
    v.si = True
    v.si_pl = 'xy'
    v.tr = True
    v.tr_pl = 'xz'
    v.ws = True
    v.ws_pl = 'xy'
    mag = None
    if v.rs_type == 'm':
        mag = srwlib.SRWLMagFldC()
        mag.arXc.append(0)
        mag.arYc.append(0)
        mag.arMagFld.append(
            srwlib.SRWLMagFldM(v.mp_field, v.mp_order, v.mp_distribution,
                               v.mp_len))
        mag.arZc.append(v.mp_zc)
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #5
0
def _run_srw():
    run_dir = os.getcwd()
    with open('in.json') as f:
        data = json.load(f)
    #TODO(pjm): need to properly escape data values, untrusted from client
    # this defines the get_srw_params() and get_beamline_optics() functions
    exec(pkio.read_text('srw_parameters.py'), locals(), locals())
    v = srwl_bl.srwl_uti_parse_options(get_srw_params(), use_sys_argv=False)
    source_type, mag = setup_source(v)
    op = None
    if data['report'] == 'intensityReport':
        v.ss = True
        outfile = v.ss_fn
    elif data['report'] == 'fluxReport':
        v.sm = True
        outfile = v.sm_fn
    elif data['report'] == 'powerDensityReport':
        v.pw = True
        outfile = v.pw_fn
    elif data['report'] == 'initialIntensityReport' or data['report'] == 'sourceIntensityReport':
        v.si = True
        outfile = v.si_fn
    elif data['report'] == 'mirrorReport':
        _process_output(_mirror_plot(data), data)
        return
    elif re.search('^watchpointReport', data['report']):
        op = get_beamline_optics()
        v.ws = True
        outfile = v.ws_fni
    else:
        raise Exception('unknown report: {}'.format(data['report']))
    if isinstance(mag, srwlib.SRWLGsnBm):
        mag = None
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
    _process_output(outfile, data)
Example #6
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    source_type, mag = srwl_bl.setup_source(v)
    op = set_optics(v)
    v.ws = True
    v.ws_pl = 'xy'
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #7
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=False)
    source_type, mag = srwl_bl.setup_source(v)
    op = set_optics(v)

    v.wm_na = v.sm_na = 5
    # Number of "iterations" per save is best set to num processes
    v.wm_ns = v.sm_ns = 4
    srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)
Example #8
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    setup_magnetic_measurement_files(v, "configurations/magn_meas_u20_hxn.zip")
    op = set_optics(v)
    v.ws = True
    v.ws_pl = 'xy'
    mag = None
    if v.rs_type == 'm':
        mag = srwlib.SRWLMagFldC()
        mag.arXc.append(0)
        mag.arYc.append(0)
        mag.arMagFld.append(srwlib.SRWLMagFldM(v.mp_field, v.mp_order, v.mp_distribution, v.mp_len))
        mag.arZc.append(v.mp_zc)
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #9
0
 def __init__(self, script, user_filename, arguments, optics_func_name='set_optics'):
     m = pkrunpy.run_path_as_module(script)
     if arguments:
         import shlex
         arguments = shlex.split(arguments)
     self.var_param = srwl_bl.srwl_uti_parse_options(m.varParam, use_sys_argv=False, args=arguments)
     self.replace_mirror_files()
     self.replace_image_files()
     try:
         self.optics = getattr(m, optics_func_name)(self.var_param)
     except ValueError as e:
         if re.search('could not convert string to float', str(e.args)):
             self.replace_mirror_files('mirror_2d.dat')
             self.optics = getattr(m, optics_func_name)(self.var_param)
     self.data = _parsed_dict(self.var_param, self.optics)
     self.data.models.simulation.name = _name(user_filename)
def run_all_reports():
    v = srwl_bl.srwl_uti_parse_options(get_srw_params())
    source_type, mag = setup_source(v)
    if source_type != 'g':
        v.ss = True
        v.ss_pl = 'e'
        v.pw = True
        v.pw_pl = 'xy'
    if source_type == 'u':
        v.sm = True
        v.sm_pl = 'e'
    v.si = True
    v.ws = True
    v.ws_pl = 'xy'
    op = get_beamline_optics()
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    source_type, mag = srwl_bl.setup_source(v)
    setup_magnetic_measurement_files("magnetic_measurements.zip", v)
    op = set_optics(v)
    v.ss = True
    v.ss_pl = 'e'
    v.sm = True
    v.sm_pl = 'e'
    v.pw = True
    v.pw_pl = 'xy'
    v.si = True
    v.si_pl = 'xy'
    v.tr = True
    v.tr_pl = 'xz'
    v.ws = True
    v.ws_pl = 'xy'
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #12
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    source_type, mag = srwl_bl.setup_source(v)
    setup_magnetic_measurement_files("magn_meas_srx.zip", v)
    op = set_optics(v)
    v.ss = True
    v.ss_pl = 'e'
    v.sm = True
    v.sm_pl = 'e'
    v.pw = True
    v.pw_pl = 'xy'
    v.si = True
    v.si_pl = 'xy'
    v.tr = True
    v.tr_pl = 'xz'
    v.ws = True
    v.ws_pl = 'xy'
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #13
0
def run_experiment(other_params, propagation_params, set_up_funcs, plot=False):
    """
    names - [list] the name list of instruments.
    setting_params - [list] the meta information of the experiment.
    physics_params - [list] .
    propagation_params - [list] .
    """
    varParam = srwl_bl.srwl_uti_ext_options(other_params + propagation_params)
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
    op = None
    for n, func in enumerate(set_up_funcs):
        value = func(v)
        if func.__name__ == 'set_optics':
            op = value
    if op is None:
        raise ValueError(
            "set_optics() function should be included in set_up_funcs")
    # this part is different for different beamline?
    v.ws = True
    if plot:
        v.ws_pl = 'xy'
    mag = None
    if v.rs_type == 'm':
        mag = srwlib.SRWLMagFldC()
        mag.arXc.append(0)
        mag.arYc.append(0)
        mag.arMagFld.append(
            srwlib.SRWLMagFldM(v.mp_field, v.mp_order, v.mp_distribution,
                               v.mp_len))
        mag.arZc.append(v.mp_zc)
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
    # remove saved image.
    if plot:
        plt.show()
    else:
        for file in glob.glob('*.png'):
            os.remove(file)
        plt.close('all')
    return
Example #14
0
def _run_srw():
    run_dir = os.getcwd()
    with open('in.json') as f:
        data = json.load(f)
    #TODO(pjm): need to properly escape data values, untrusted from client
    # this defines the get_srw_params() and get_beamline_optics() functions
    exec(pkio.read_text('srw_parameters.py'), locals(), locals())
    v = srwl_bl.srwl_uti_parse_options(get_srw_params(), use_sys_argv=False)
    source_type, mag = setup_source(v)
    op = None
    if data['report'] == 'intensityReport':
        v.ss = True
        outfile = v.ss_fn
    elif data['report'] == 'fluxReport':
        v.sm = True
        outfile = v.sm_fn
    elif data['report'] == 'powerDensityReport':
        v.pw = True
        outfile = v.pw_fn
    elif data['report'] == 'initialIntensityReport' or data[
            'report'] == 'sourceIntensityReport':
        v.si = True
        outfile = v.si_fn
    elif data['report'] == 'mirrorReport':
        _process_output(_mirror_plot(data), data)
        return
    elif re.search('^watchpointReport', data['report']):
        op = get_beamline_optics()
        v.ws = True
        outfile = v.ws_fni
    else:
        raise Exception('unknown report: {}'.format(data['report']))
    if isinstance(mag, srwlib.SRWLGsnBm):
        mag = None
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
    _process_output(outfile, data)
Example #15
0
    def __init__(self, script, lib_dir, user_filename, arguments, optics_func_name='set_optics'):
        self.lib_dir = lib_dir
        self.initial_lib_dir = lib_dir
        self.list_of_files = None
        self.optics_func_name = optics_func_name
        m = pkrunpy.run_path_as_module(script)
        varParam = getattr(m, 'varParam')
        if arguments:
            import shlex
            arguments = shlex.split(arguments)
        self.var_param = srwl_uti_parse_options(varParam, use_sys_argv=False, args=arguments)
        self.get_files()
        if self.initial_lib_dir:
            self.replace_mirror_files()
            self.replace_image_files()
        try:
            self.optics = getattr(m, self.optics_func_name)(self.var_param)
        except ValueError as e:
            if re.search('could not convert string to float', e.message):
                self.replace_mirror_files('mirror_2d.dat')
                self.optics = getattr(m, self.optics_func_name)(self.var_param)

        self.data = _parsed_dict(self.var_param, self.optics)
        self.data.models.simulation.name = _name(user_filename)
Example #16
0
    ['ueb_beta_y', 'f', 1.06, 'vertical beta-function [m]'],
    ['ueb_alpha_y', 'f', 0.0, 'vertical alpha-function [rad]'],
    ['ueb_eta_y', 'f', 0.0, 'vertical dispersion function [m]'],
    [
        'ueb_eta_y_pr', 'f', 0.0,
        'vertical dispersion function derivative [rad]'
    ],
    ['ueb_rms_size_x', 'f', 4.26380112107e-05, "horizontal RMS size [m]"],
    [
        'ueb_rms_diverg_x', 'f', 2.11079263419e-05,
        "horizontal RMS divergence [rad]"
    ],
    ['ueb_xxpr_x', 'f', 0.0, "horizontal <(x-<x>)(x'-<x'>)> [m]"],
    ['ueb_rms_size_y', 'f', 2.91204395571e-06, "vertical RMS size [m]"],
    [
        'ueb_rms_diverg_y', 'f', 2.74721127897e-06,
        "vertical RMS divergence [rad]"
    ],
    ['ueb_xxpr_y', 'f', 0.0, "vertical <(x-<x>)(x'-<x'>)> [m]"],
])

import srwl_bl

v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
source_type, mag = srwl_bl.setup_source(v)
v.wm_na = v.sm_na = 5
# Number of "iterations" per save is best set to num processes
v.wm_ns = v.sm_ns = 2
op = set_optics()
srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)
Example #17
0
def main():
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=False)
    source_type, mag = srwl_bl.setup_source(v)
    op = set_optics(v)
Example #18
0
#---User Defined Electron Beam
    ['ueb', 'i', 0, 'Use user defined beam'],
    ['ueb_e', 'f', 3.0, 'energy [GeV]'],
    ['ueb_sig_e', 'f', 0.00089, 'RMS energy spread'],
    ['ueb_beam_definition', 's', 't', 'definition of the beam using Twiss Parameters (t) or Moments (m)'],
    ['ueb_emit_x', 'f', 9e-10, 'horizontal emittance [m]'],
    ['ueb_beta_x', 'f', 2.02, 'horizontal beta-function [m]'],
    ['ueb_alpha_x', 'f', 0.0, 'horizontal alpha-function [rad]'],
    ['ueb_eta_x', 'f', 0.0, 'horizontal dispersion function [m]'],
    ['ueb_eta_x_pr', 'f', 0.0, 'horizontal dispersion function derivative [rad]'],
    ['ueb_emit_y', 'f', 8e-12, 'vertical emittance [m]'],
    ['ueb_beta_y', 'f', 1.06, 'vertical beta-function [m]'],
    ['ueb_alpha_y', 'f', 0.0, 'vertical alpha-function [rad]'],
    ['ueb_eta_y', 'f', 0.0, 'vertical dispersion function [m]'],
    ['ueb_eta_y_pr', 'f', 0.0, 'vertical dispersion function derivative [rad]'],
    ['ueb_rms_size_x', 'f', 0.000372612, "horizontal RMS size [m]"],
    ['ueb_rms_diverg_x', 'f', 1.04666e-05, "horizontal RMS divergence [rad]"],
    ['ueb_xxpr_x', 'f', 0.0, "horizontal <(x-<x>)(x'-<x'>)> [m]"],
    ['ueb_rms_size_y', 'f', 9.87421e-06, "vertical RMS size [m]"],
    ['ueb_rms_diverg_y', 'f', 3.94968e-06, "vertical RMS divergence [rad]"],
    ['ueb_xxpr_y', 'f', 0.0, "vertical <(x-<x>)(x'-<x'>)> [m]"],
])

if __name__ == '__main__':
    v = srwl_bl.srwl_uti_parse_options(varParam)
    source_type, mag = srwl_bl.setup_source(v)
    op = None
    op = set_optics()
    v.ws = True
    v.ws_pl = 'xy'
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
Example #19
0
    except ImportError:
        NUMPY = False

    if NUMPY:
        with open(file_path) as f:
            data = np.loadtxt(f)
        condition = np.isfinite(data).all()
    else:
        import math
        import uti_io
        data = uti_io.read_ascii_data_cols(file_path, '\t', _i_col_start=0, _i_col_end=0, _n_line_skip=10)[0]
        first_value = data[0]
        condition = math.isinf(first_value) and not math.isnan(first_value)

    assert condition, \
        'data is not finite: [{}, ...]'.format(', '.join([str(x) for x in data[:10]]))

    return data

if __name__ == '__main__':
    import os
    import numpy as np
    v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=False)
    source_type, mag = srwl_bl.setup_source(v)
    op = None
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
    file_path = os.path.join(v.fdir, v.sm_fn)
    try:
        data = _check_finite(file_path)
    except AssertionError:
        exit(1)
Example #20
0
def run_srw_simulation(task_cut, hOffsetIdx, vOffsetIdx, hOffsetIdx2,
                       vOffsetIdx2, file_idx, nvx_idx, nvy_idx, nvz_idx,
                       nvx2_idx, nvy2_idx, nvz2_idx, wp_idx, process_number):
    """ Runs the number of SRW simulations as determined by the number of rows in task_cut. task_cut holds the parameters that will be updated to varParam to introduce offsets
        task_cut: 
             i: task number 
             offset_notation: binary values for which offsets/rotations are applied:  offsets_mirror1, offsets_mirror2, rotations_mirror1, rotations_mirror2
             dx1: the horizontal offset to mirror 1
             dy1: the vertical offset to mirror 1
             dx2: the horizontal offset to mirror 2 
             dy2: the vertical offset to mirror 2 
             thetax1: thetax for rotation matrix to be applied to mirror 1 
             thetay1: thetay for rotation matrix to be applied to mirror 1 
             thetaz1: thetaz for rotation matrix to be applied to mirror 1
             thetax2: thetax for rotation matrix to be applied to mirror 2
             thetay2: thetay for rotation matrix to be applied to mirror 2 
             thetaz2: thetaz for rotation matrix to be applied to mirror 2 
             wp: watchpoint location for final screen 
        hOffsetIdx: index of where to update horizontal offset in varParams for mirror 1 
        vOffsetIdx: index of where to update vertical offset in varParams for mirror 1 
        hOffsetIdx2: index of where to update horizontal offset in varParams for mirror 2
        vOffsetIdx2: index of where to update vertical offset in varParams for mirror 
        file_idx: the index of the output beam file 
        nvx_idx: index of where to update thetax in varParams for mirror 1 
        nvy_idx: index of where to update thetay in varParams for mirror 1 
        nvz_idx: index of where to update thetaz in varParams for mirror 1 
        nvx2_idx: index of where to update thetax in varParams for mirror 2
        nvy2_idx: index of where to update thetay in varParams for mirror 2 
        nvz2_idx: index of where to update thetaz in varParams for mirror 2 
        wp_idx: index of where to update the final screen 
        process_number: the process number running this task cut
    """
    print('Process ' + str(process_number) + ' to complete ' +
          str(len(task_cut)) + ' tasks')
    for t in range(len(task_cut)):

        varParam = get_reset_varParam()

        #print(len(task_cut))
        #print(task_cut)

        #### get task parameters based on which combo
        i, offset_notation, dx1, dy1, dx2, dy2, thetax1, thetay1, thetaz1, thetax2, thetay2, thetaz2, wp = task_cut[
            t]

        offsets_mirror1, offsets_mirror2, rotations_mirror1, rotations_mirror2, watchpoint_pos = offset_notation

        task_params = []
        #### update params
        if offsets_mirror1:
            varParam[hOffsetIdx][2] = dx1
            task_params.append(dx1.reshape(1, 1))
            varParam[vOffsetIdx][2] = dy1

        if offsets_mirror2:
            varParam[hOffsetIdx2][2] = dx2
            varParam[vOffsetIdx2][2] = dy2
            task_params.append(dy2.reshape(1, 1))

        if rotations_mirror1:
            vx = varParam[nvx_idx][2]
            vy = varParam[nvy_idx][2]
            vz = varParam[nvz_idx][2]

            Rx = np.array([[1, 0, 0], [0, np.cos(thetax1), -np.sin(thetax1)],
                           [0, np.sin(thetax1),
                            np.cos(thetax1)]])
            Ry = np.array([[np.cos(thetay1), 0,
                            np.sin(thetay1)], [0, 1, 0],
                           [-np.sin(thetay1), 0,
                            np.cos(thetay1)]])
            Rz = np.array([[np.cos(thetaz1), -np.sin(thetaz1), 0],
                           [np.sin(thetaz1),
                            np.cos(thetaz1), 0], [0, 0, 1]])

            Rxy = np.dot(Rx, Ry)
            R_tot = np.dot(Rxy, Rz)
            v = np.array([vx, vy, vz]).reshape(3, 1)

            rtot_v = np.dot(R_tot, v)

            varParam[nvx_idx][2] = rtot_v[0]

            varParam[nvy_idx][2] = rtot_v[1]

            varParam[nvz_idx][2] = rtot_v[2]

            #task_params.append(thetax1.reshape(1,1))
            task_params.append(thetay1.reshape(1, 1))
            task_params.append(thetaz1.reshape(1, 1))

        if rotations_mirror2:
            vx2 = varParam[nvx2_idx][2]
            vy2 = varParam[nvy2_idx][2]
            vz2 = varParam[nvz2_idx][2]

            Rx2 = np.array([[1, 0, 0], [0,
                                        np.cos(thetax2), -np.sin(thetax2)],
                            [0, np.sin(thetax2),
                             np.cos(thetax2)]])
            Ry2 = np.array([[np.cos(thetay2), 0,
                             np.sin(thetay2)], [0, 1, 0],
                            [-np.sin(thetay2), 0,
                             np.cos(thetay2)]])
            Rz2 = np.array([[np.cos(thetaz2), -np.sin(thetaz2), 0],
                            [np.sin(thetaz2),
                             np.cos(thetaz2), 0], [0, 0, 1]])

            Rxy2 = np.dot(Rx2, Ry2)
            R_tot2 = np.dot(Rxy2, Rz2)
            v2 = np.array([vx2, vy2, vz2]).reshape(3, 1)

            rtot_v2 = np.dot(R_tot2, v2)

            varParam[nvx2_idx][2] = rtot_v2[0]

            varParam[nvy2_idx][2] = rtot_v2[1]

            varParam[nvz2_idx][2] = rtot_v2[2]

            task_params.append(thetax2.reshape(1, 1))
            #task_params.append(thetay2.reshape(1,1))
            task_params.append(thetaz2.reshape(1, 1))

        if watchpoint_pos:
            print('updating with ' + str(wp))
            varParam[wp_idx][2] = wp
            task_params.append(wp.reshape(1, 1))

        save_dat = 'dat_files/res_int_se_' + str(i) + '.dat'
        varParam[file_idx][2] = save_dat

        v = srwl_bl.srwl_uti_parse_options(varParam, use_sys_argv=True)
        op = set_optics(v)
        v.si = True
        v.si_pl = ''
        v.ws = True
        v.ws_pl = ''
        mag = None
        if v.rs_type == 'm':
            mag = srwlib.SRWLMagFldC()
            mag.arXc.append(0)
            mag.arYc.append(0)
            mag.arMagFld.append(
                srwlib.SRWLMagFldM(v.mp_field, v.mp_order, v.mp_distribution,
                                   v.mp_len))
            mag.arZc.append(v.mp_zc)
        srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
        beam = read_srw_file(save_dat)
        h = beam.shape[0]
        w = beam.shape[1]
        beam = beam.reshape(1, h, w)
        task_params = np.concatenate(task_params, axis=1)

        np.save('beams/beam_' + str(int(i)) + '.npy', beam)
        np.save('parameters/offsets_' + str(int(i)) + '.npy', task_params)
        #time.sleep(0.5)
        print('Process ' + str(process_number) + ' finished task ' +
              str(int(i)))