Exemplo n.º 1
0
def wavefront_from_array(cfr,
                         nx,
                         ny,
                         nz,
                         dx,
                         dy,
                         dz,
                         ekev,
                         pulse_duration=40e-15,
                         sigma=4,
                         **kwargs):
    """
    function to produce a wpg wavefront object instance from a complex valued
    wavefront definition
    
    :param cfr: complex valued wavefield array [x,y,t] (complex128)
    :param nx: number of pixels along x-axis
    :param ny: number of pixels along y-axis
    :param nz: number of pixels along z-axis
    :param dx: pixels size along x-axis
    :param dy: pixels size along y-axis
    :param dz: pixels size along z-axis
    :param ekev: energy in kev
    :param pulse_duration: duration of the pulse (fwhm) in seconds, defaults to 40e-15
    :param sigma: integer number of width multiples over which time-axis should be defined, defaults to 4

    :returns: DESCRIPTION
    """

    # Initialize empty wavefront.
    wfr = Wavefront()

    # Setup E-field.
    wfr.data.arrEhor = np.zeros(shape=(nx, ny, nz, 2))
    wfr.data.arrEver = np.zeros(shape=(nx, ny, nz, 2))

    wfr.params.wEFieldUnit = 'sqrt(W/mm^2)'
    wfr.params.photonEnergy = ekev * 1000
    wfr.params.wDomain = 'time'
    wfr.params.Mesh.nSlices = nz
    wfr.params.Mesh.nx = nx
    wfr.params.Mesh.ny = ny

    wfr.params.Mesh.sliceMin = -pulse_duration * sigma / 2.
    wfr.params.Mesh.sliceMax = pulse_duration * sigma / 2.

    range_x = dx * nx
    range_y = dy * ny

    wfr.params.Mesh.xMin = -range_x / 2.
    wfr.params.Mesh.xMax = range_x / 2.
    wfr.params.Mesh.yMin = -range_y / 2.
    wfr.params.Mesh.yMax = range_y / 2.

    wfr.params.Rx = 2
    wfr.params.Ry = 1
    wfr.data.arrEhor = complex_to_wpg(cfr)

    wfr.set_electric_field_representation('f')

    wfr.custom_fields.update(**kwargs)

    return wfr
def propagate_NVE():

    wfr_directory = sys.argv[1].replace("*", "/")

    job_name = "NKB_4980eV_250pC_Source_to_NVE"
    python_command = propagate_NVE
    input_directory = dCache + "/NanoKB-Pulse/source/"

    save_directory = input_directory.replace("/source/", "/NVE/")
    mkdir_p(save_directory)

    log_directory = logs

    focus = "nano"
    analysis = False

    filename = __file__
    dt = datetime.now().__str__()
    function = python_command.__name__

    description = "Propagate NanoKB Pulses 4.98 keV, 250 pC from Undulator-exit to the NVE"

    crop = 'NVE'
    append = None

    print("info")
    print("wavefront directory: {}".format(wfr_directory))
    print("save directory: {}".format(save_directory))
    print("focus (i.e. beamline option): {}".format(focus))
    print("analysis: {}".format(analysis))
    print("datetime: {}".format(dt))
    print("filename: {}".format(filename))
    print("function: {}".format(function))
    print("description: {}".format(description))

    wfr = Wavefront()
    wfr.load_hdf5(wfr_directory)
    wfr.set_electric_field_representation('frequency')

    wfr = scale(wfr)

    print("wfr domain: {}".format(wfr.params.wDomain))

    bl = get_beamline_object(ekev=4.96,
                             options=focus,
                             crop=crop,
                             theta_KB=5e-03,
                             theta_HOM=3.5e-03)

    wfr.custom_fields['focus'] = focus
    wfr.custom_fields['job name'] = job_name
    wfr.custom_fields['input directory'] = wfr_directory
    wfr.custom_fields['datetime'] = dt
    wfr.custom_fields['function'] = function.__str__()
    wfr.custom_fields['filename'] = filename
    wfr.custom_fields['description'] = description
    #wfr.custom_fields['bl'] = bl.__str__

    bl.propagate(wfr)

    if analysis:
        wfr.analysis()

    wfr.store_hdf5(wfr_directory.replace("/source/", "/NVE/"))