Exemple #1
0
def scale(wfr, nx=512, ny=512):
    """
    narrow functionality for scaling a wavefront (ie the number of pixels)
    in the source plane

    :param wfr: wpg wfr strucutre
    :param isc: ideal scale
    :param ifov: ideal field of view

    :returns wfr: scaled wpg wfr structure
    """

    ix, iy = wfr.params.Mesh.nx, wfr.params.Mesh.ny
    dx, dy = wfr.params.Mesh.xMax - wfr.params.Mesh.xMin, wfr.params.Mesh.yMax - wfr.params.Mesh.yMin

    print(dx, dy)
    print(nx / ix)

    scbl = Beamline()
    scbl.append(
        Aperture('r', 'a', 800e-06, 800e-06),
        propagation_parameters(800e-06 / dx, nx / ix, 800e-06 / dx, ny / iy))

    scbl.propagate(wfr)

    return wfr
Exemple #2
0
def sliceFocus(wfr,
               ekev,
               focus='nano',
               nslices=500,
               axisName='x',
               outdir=None):

    spb = get_beamline_object(apertures=False, surface=False)

    el_n = len(spb.propagation_options[0]['optical_elements']) - 1

    spb.propagation_options[0]['optical_elements'][el_n].L *= 0.98
    slice_interval = 2.2 - copy(
        spb.propagation_options[0]['optical_elements'][el_n].L / nslices)

    spb.propagation_options[0]['propagation_parameters'][
        el_n] = propagation_parameters(5, 1, 5, 1, mode='fresnel')

    spb.propagate(wfr)
    plotIntensity(wfr)

    if axisName == 'x':
        data_focslice = np.zeros([nslices, np.shape(wfr.data.arrEhor)[0]])
    elif axisName == 'y':
        data_focslice = np.zeros([nslices, np.shape(wfr.data.arrEhor)[1]])

    for n in range(nslices):
        print("Slice {}/{}".format(n + 1, nslices))

        bl = Beamline()
        bl.append(SRWLOptD(slice_interval),
                  propagation_parameters(1, 1, 1, 1, mode='quadratic'))
        bl.propagate(wfr)
        plotIntensity(wfr)
        data_focslice[-n - 1, :] = wfr.get_intensity()[:, :, 0].sum(-1)
        #plt.plot(data_focslice[-n-1, :])
        plt.show()

    y = np.linspace(
        spb.bl.propagation_options[0]['optical_elements'][el_n].L,
        spb.bl.propagation_options[0]['optical_elements'][el_n].L +
        nslices * slice_interval, nslices)

    # =============================================================================
    #     ax1 =     colorbar_plot(data_focslice,
    #               get_mesh(data_focslice,
    #                                wfr.get_spatial_resolution()[0]*1e6,
    #                                y[1]-y[0]),
    #               aspect = 'auto',
    #               scale = 1,
    #               #norm=mpl.colors.LogNorm(),
    #               xlabel = "x($\mu m$)",
    #               ylabel = "z(m)",
    #               return_axes = True)
    #
    # =============================================================================
    return data_focslice
Exemple #3
0
def propagate_NVE():
            
    wfr_directory = sys.argv[1].replace("*", "/")
 
    job_name = "NKB_4980eV_250pC_NVE_to_EHC"
    python_command = propagate_NVE
    input_directory = dCache + "/NanoKB-Pulse/NVE/"
    
    save_directory = input_directory.replace("/NVE/", "/EHC/")
    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 NVE mirror to the EHC Screen"
    
    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)
     
    bl = Beamline()
    bl.append(Drift(2.2+3.5), propagation_parameters(1/3,1,1/3,1,'quadratic'))
    bl.propagate(wfr)
    
    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
    wfr.custom_fields['filename'] = filename
    wfr.custom_fields['description'] = description
    #wfr.custom_fields['bl'] = bl.__str__
                
    if analysis: 
        wfr.analysis()
        
    wfr.store_hdf5(wfr_directory.replace("/NVE/", "/EHC/"))
Exemple #4
0
def simpleProp(wfr):
    
    print(calculate_fwhm(wfr))
    bl = Beamline()
    #bl.append(Aperture('c','a', 500e-06),propagation_parameters(1,1,1,1,mode = 'normal'))
    bl.append(Drift(100), propagation_parameters(1,1,1,1,mode = 'quadratic'))
    
    #bl.append(Drift(100), propagation_parameters(1,1,1,1,mode = 'quadratic'))
    bl.propagate(wfr)
    plotIntensity(wfr)
    print(calculate_fwhm(wfr))
Exemple #5
0
 def detect(self, wfr):
     
     xMin, xMax, yMax, yMin = wfr.get_limits()
     
     idx, idy = xMax-xMin, yMax-yMin
     inx, iny = wfr.params.Mesh.nx, wfr.params.Mesh.ny
     print(idx,idy)
     print((self.dy*self.ny)/idy)
     bl = Beamline()
     bl.append(Drift(0),
               propagation_parameters((self.dx*self.nx)/idx, self.nx/inx, (self.dy*self.ny)/idy, self.ny/iny))
 
     bl.propagate(wfr)
Exemple #6
0
    def detect(self, wfr):
        """
        return the detected intensity distribution
        """

        bl = Beamline()
        bl.append(
            Drift(0),
            propagation_parameters(self.mesh.dx / wfr.dx, 1,
                                   self.mesh.dy / wfr.dy, 1))
        bl.propagate(wfr)

        ii = wfr.get_intensity().sum(-1)
        ii = compress_and_average(ii, (self.mesh.nx, self.mesh.ny))

        return ii
Exemple #7
0
def modify_beam_divergence(wfr, sig, dtheta):
    """
    Construct a thin-lens with a focal length defined by a desired divergence,
    see: thin_lens_mod, and then propagate to 2f

    :param wfr: WPG wfr structure
    :params sig: beam fwhm [m]
    :params dtheta: pulse divergence [rad]
    """
    f = sig/(np.tan(dtheta))

    tl = thinLens(f,f)
    bl = Beamline()
    bl.append(tl, [0,0,0,0,0,1,1,1,1,0,0,0])
    bl.append(Drift(2*f), [0,0,0,0,0,1,1,1,1,0,0,0])
    bl.propagate(wfr)

    wfr.params.Mesh.zCoord = 0
Exemple #8
0
def propThruMaskLite(wfr, _x=0, _y=0):
    """
    propagate through the speckle generator
    """
    s = Sample("/opt/FELpy/felpy/data/samples/speckle.tif",
               rx=100e-06 / 1000,
               ry=100e-06 / 1000,
               thickness=60e-06,
               delta=3.35e-03,
               atten_len=20e-06,
               xc=0,
               yc=0,
               shift_x=_y,
               shift_y=_x)

    bl = Beamline()
    bl.append(s, propagation_parameters(1, 1, 1, 1, mode='fresnel'))
    bl.propagate(wfr)

    return wfr
Exemple #9
0
        src.store_hdf5("../data/tmp/source.h5")
    except (KeyError):
        os.remove("../data/tmp/source.h5")
        src.store_hdf5("../data/tmp/source.h5")

    src = Source()
    src.load_hdf5("../data/tmp/source.h5")
    from felpy.model.wavefront import Wavefront
    from wpg.wpg_uti_wf import plot_intensity_map
    wfr = Wavefront()

    from felpy.model.beamline import Beamline
    from wpg.optical_elements import Drift
    from felpy.model.tools import propagation_parameters
    from matplotlib import pyplot as plt

    bl = Beamline()
    bl.append(Drift(50), propagation_parameters(1, 1, 1, 1, mode='fresnel'))

    for w in src.pulses:

        wfr.load_hdf5(w)
        bl.propagate(wfr)
        plt.plot(wfr.x_axis,
                 wfr.get_x_profile(),
                 label="{} $\mu$ rad".format(wfr.source_properties['theta_x'] *
                                             1e6))
        #plot_intensity_map(wfr)
        print(wfr.com)

    plt.legend()
Exemple #10
0
# =============================================================================
q = 0.50
src = construct_SA1_wavefront(1024, 1024, 25.0, q)

plot_ii(src)

speckle = define_speckle_mask("../../data/samples/checkerboard-pattern.jpg",
                              rx=1e-8,
                              ry=1e-8,
                              sample_thickness=150e-06,
                              sample_delta=4e-04,
                              plot=True,
                              ekev=25)

bl.append(Drift(10), propagation_parameters(1, 1, 1, 1, mode='quadratic'))

bl.append(speckle, propagation_parameters(1, 1, 1, 1, mode='fresnel'))

#plot_ii(src)
bl.append(Drift(z2),
          propagation_parameters(1 / 4, 4, 1 / 4, 4, mode='quadratic'))
bl.propagate(src)
src.view()
# =============================================================================
# plot_ii(src)
#
# d = Detector(5e-07, 5e-07, 1024, 1024)
# d.detect(src)
# =============================================================================
plot_ii(src)
src.save_tif("/opt/test_{}nC".format(q))
Exemple #11
0
def sliceFocus(wfr,
               ekev,
               focus='micron',
               nslices=500,
               axisName='x',
               outdir=None):

    spb = Instrument(overwrite_mirrors=False)
    spb.setupHOMs(ekev)
    spb.build_elements(focus=focus)
    spb.buildBeamline(focus=focus)

    el_n = len(spb.bl.propagation_options[0]['optical_elements']) - 1

    slice_interval = copy(
        spb.bl.propagation_options[0]['optical_elements'][el_n].L / 1000)
    spb.bl.propagation_options[0]['optical_elements'][el_n].L *= 0.75
    spb.bl.propagation_options[0]['propagation_parameters'][
        el_n] = propagation_parameters(1 / 5, 5, 1 / 5, 5, mode='quadratic')
    bl = spb.get_beamline()
    bl.propagate(wfr)

    if axisName == 'x':
        data_focslice = np.zeros([nslices, np.shape(wfr.data.arrEhor)[0]])
    elif axisName == 'y':
        data_focslice = np.zeros([nslices, np.shape(wfr.data.arrEhor)[1]])

    fig = plt.figure()
    ax = fig.add_subplot(111)

    for n in range(nslices):
        print("Slice {}/{}".format(n + 1, nslices))

        bl = Beamline()
        bl.append(SRWLOptD(slice_interval),
                  propagation_parameters(1, 1, 1, 1, mode='normal'))
        bl.propagate(wfr)

        data_focslice[-n - 1, :] = wfr.get_profile_1d()[0]

    y = np.linspace(
        spb.bl.propagation_options[0]['optical_elements'][el_n].L,
        spb.bl.propagation_options[0]['optical_elements'][el_n].L +
        nslices * slice_interval, nslices)

    if axisName == 'x':
        extent = [
            wfr.params.Mesh.xMin * 1e6, wfr.params.Mesh.xMax * 1e6,
            y.min(),
            y.max()
        ]
    elif axisName == 'y':
        extent = [
            wfr.params.Mesh.yMin * 1e6, wfr.params.Mesh.yMax * 1e6,
            y.min(),
            y.max()
        ]
    ax.imshow(data_focslice,
              extent=extent,
              aspect='auto',
              norm=mpl.colors.LogNorm())

    if focus == "micron":
        ax.set_title("Micron Focus Location")
        ax.set_ylabel("Longitudinal Distance from MKB (m)")

        if axisName == 'x':
            x = np.linspace(wfr.params.Mesh.xMin * 1e6,
                            wfr.params.Mesh.xMax * 1e6, wfr.params.Mesh.nx)
            ax.set_xlabel("x ($\mu$m)")
        elif axisName == 'y':
            x = np.linspace(wfr.params.Mesh.yMin * 1e6,
                            wfr.params.Mesh.yMax * 1e6, wfr.params.Mesh.ny)
            ax.set_xlabel("y ($\mu$m)")

    if focus == "nano":
        ax.set_title("Nano Focus Location")
        ax.set_ylabel("Longitudinal Distance from NKB (m)")

        if axisName == 'x':
            x = np.linspace(wfr.params.Mesh.xMin * 1e6,
                            wfr.params.Mesh.xMax * 1e6, wfr.params.Mesh.nx)
            ax.set_xlabel("x ($\mu$m)")
        elif axisName == 'y':
            x = np.linspace(wfr.params.Mesh.yMin * 1e6,
                            wfr.params.Mesh.yMax * 1e6, wfr.params.Mesh.ny)
            ax.set_xlabel("y ($\mu$m)")

    ax.plot(x, np.ones(x.shape) * spb.bl.params["df"]["distance"], 'r--')
    plt.legend(["Design Focal Plane"])

    plt.show()

    estr = str(ekev).replace(".", "-")

    if outdir is not None:
        fig.savefig(outdir +
                    "{}_focus_slice_{}_{}".format(focus, estr, axisName))