Exemplo n.º 1
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/"))
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
0
    def add_screen(self, position, distance, screenName=None):
        """
        add a screening plane at drift beyond some element position
        
        :param position: last optical element before screen
        :param distance: position from last optical element to screen
        :param screenName: name of the screen element (ie., MKB-scr etc) [str]
        """
        self.crop_beamline(element1=position)

        drift2screen = Drift(distance)
        if screenName is not None:
            drift2screen.name = "screen"
        else:
            drift2screen.name = screenName
        self.bl.append(Drift(distance),
                       propagation_parameters(1, 1, 1, 1, m='quadratic'))
Exemplo n.º 5
0
    def scale(self, wfr, iscx=1024, iscy=1024, ifov=800e-06):
        """
        DEPR.
        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
        """

        nx, ny = 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

        scbl = Beamline()
        scbl.append(
            Aperture('r', 'a', 800e-06, 800e-06),
            propagation_parameters(dx / ifov, iscx / nx, dy / ifov, iscy / ny))
        scbl.propagate(wfr)

        return wfr
Exemplo n.º 6
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()
Exemplo n.º 7
0
ny = 25

plt.imshow(create_mask(nx, ny))
wfr = construct_SA1_wavefront(512, 512, 5, .8, mx=0, xoff=0, tiltX=0)

period = nx * wfr.get_spatial_resolution()[0] * (512 / (nx))
print(period)
wav = wfr.get_wavelength()

d = (2 * period**2) / wav

arr = create_mask(nx, ny)
np.save("/opt/arr", arr)
im = Image.fromarray(arr)
im = im.convert('RGB')
im.save("/opt/arr.png")

obj = srwloptT("/opt/arr.png",
               wfr.get_spatial_resolution()[0] * (512 / 75),
               wfr.get_spatial_resolution()[1] * (512 / 75),
               1e-06,
               1e-8,
               atten_len=1e-08)

bl = Beamline()
bl.append(Drift(50), propagation_parameters(1, 1, 1, 1, mode='quadratic'))
bl.append(obj, propagation_parameters(1, 1, 1, 1))
bl.append(Drift(d),
          propagation_parameters(1 / 3, 4, 1 / 3, 4, mode='fraunhofer'))
bl.propagate(wfr)
plot_intensity_map(wfr)
Exemplo n.º 8
0
    def build_beamline(self, focus="nano", screens="false"):
        """
        Construct the beamline object
        
        :param focus: what beamline configuration (micron or nano)
        """

        self.bl = Beamline()

        if focus == "micron":

            self.bl.append(
                self.d1, propagation_parameters(1, 1, 1, 1, mode="fraunhofer"))

            self.bl.append(self.HOM1,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d2, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.HOM2,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d3, propagation_parameters(1, 1, 1, 1, mode='fraunhofer'))

            self.bl.append(
                self.MKB_pslit,
                propagation_parameters(1 / 5, 1, 1 / 5, 1, mode='fresnel'))
            self.bl.append(
                self.d4, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.MHP,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d5, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.MHE,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.MHE_error,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d6, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.MVE,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.MVE_error,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d8, propagation_parameters(1, 1, 1, 1, mode='quadratic'))

            self.bl.append(self.MVP,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.df,
                           propagation_parameters(5, 1, 5, 1, mode='converge'))

        elif focus == "nano":

            self.bl.append(
                self.d1, propagation_parameters(1, 1, 1, 1, mode="fraunhofer"))

            self.bl.append(self.HOM1,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d2, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.HOM2,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d3, propagation_parameters(1, 1, 1, 1, mode='fraunhofer'))

            self.bl.append(
                self.NKB_pslit,
                propagation_parameters(1 / 10, 1, 1 / 10, 1, mode='fresnel'))
            self.bl.append(
                self.d4, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.NHE_error,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.NHE,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))

            self.bl.append(
                self.d5, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.NVE_error,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.NVE,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))

            self.bl.append(
                self.df,
                propagation_parameters(1 / 20, 1, 1 / 20, 1, mode='converge'))

        self.bl.params = self.params
Exemplo n.º 9
0
    def build_beamline(self, focus="nano", screens="false"):
        """
        Construct the beamline object

        :param focus: what beamline configuration (micron or nano)
        """

        self.bl = Beamline()

        if focus == 'direct':

            self.bl.append(
                self.d1, propagation_parameters(1, 1, 1, 1, mode="quadratic"))

            self.bl.append(self.HOM1,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d2, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.HOM2,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d3, propagation_parameters(2, 1, 2, 1, mode='fraunhofer'))

            self.bl.append(
                self.NKB_PSlit,
                propagation_parameters(1 / 10, 1, 1 / 10, 1, mode='fresnel'))
            self.bl.append(
                self.d4, propagation_parameters(1, 1, 1, 1, mode='fraunhofer'))
            self.bl.append(
                self.d5, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(
                self.df, propagation_parameters(1, 1, 1, 1, mode='quadratic'))

        if focus == "micron":

            self.bl.append(
                self.d1, propagation_parameters(1, 1, 1, 1, mode="fraunhofer"))

            self.bl.append(self.HOM1,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d2, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.HOM2,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d3, propagation_parameters(1, 1, 1, 1, mode='fraunhofer'))

            self.bl.append(
                self.d4, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.MHP,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d5, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.MHE,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.MHE_error,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d6, propagation_parameters(1, 1, 1, 1, mode='quadratic'))
            self.bl.append(self.MVE,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.MVE_error,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(
                self.d8, propagation_parameters(1, 1, 1, 1, mode='quadratic'))

            self.bl.append(self.MVP,
                           propagation_parameters(1, 1, 1, 1, mode='fresnel'))
            self.bl.append(self.df,
                           propagation_parameters(5, 1, 5, 1, mode='converge'))

        elif focus == "nano":

            self.bl.append(self.d1,
                           propagation_parameters(*self.params['d1']['pp']))

            self.bl.append(self.HOM1,
                           propagation_parameters(*self.params['HOM1']['pp']))
            self.bl.append(self.d2,
                           propagation_parameters(*self.params['d2']['pp']))
            self.bl.append(self.HOM2,
                           propagation_parameters(*self.params['HOM2']['pp']))
            self.bl.append(self.d3,
                           propagation_parameters(*self.params['d3']['pp']))

            self.bl.append(
                self.NKB_PSlit,
                propagation_parameters(*self.params['NKB_PSlit']['pp']))
            self.bl.append(self.d4,
                           propagation_parameters(*self.params['d4']['pp']))
            self.bl.append(
                self.NHE_error,
                propagation_parameters(*self.params['NHE_error']['pp']))
            self.bl.append(self.NHE,
                           propagation_parameters(*self.params['NHE']['pp']))

            self.bl.append(self.d5,
                           propagation_parameters(*self.params['d5']['pp']))
            self.bl.append(
                self.NVE_error,
                propagation_parameters(*self.params['NVE_error']['pp']))
            self.bl.append(self.NVE,
                           propagation_parameters(*self.params['NVE']['pp']))

            #self.bl.append(self.df, propagation_parameters(1,1,1,1, mode = 'converge'))
            #self.bl.append(self.df, propagation_parameters(15,1,15,1, mode = 'converge')) ### perfect mirrors

        self.bl.params = self.params
Exemplo n.º 10
0
# -*- coding: utf-8 -*-

import sys

from felpy.model.wavefront import Wavefront
from felpy.model.beamline import Beamline
from wpg.optical_elements import Drift
from felpy.model.tools import propagation_parameters
from felpy.utils.os_utils import mkdir_p

if __name__ == '__main__':
    print("working")
    in_directory = sys.argv[1]
    print("in: ", in_directory)
    out_directory = sys.argv[2]
    print("out: ", out_directory)
    wfr = Wavefront()
    wfr.load_hdf5(in_directory)
    print("wfr loaded")
    bl = Beamline()
    bl.append(Drift(3.644 - 2.2),
              propagation_parameters(1, 1, 1, 1, 'quadratic'))
    bl.propagate(wfr)
    print("wfr propagated")
    wfr.store_hdf5(out_directory)
    print("wfr stored")
    wfr.analysis(VERBOSE=True, DEBUG=True)
    #print(wfr.custom_fields) ## good debug
Exemplo n.º 11
0
                print(oe)
             
            
            srwl.PropagElecField(wfr._srwl_wf, bl)
            
            if return_intensity:
                intensity.append(wfr.get_intensity().sum(-1))
            if return_mesh:
                mesh.append(wfr.get_mesh())
                    
            plot_intensity_map(wfr)
            
        if return_intensity:
            
            if return_mesh:
                return intensity, mesh
            else:
                return intensity
            
            
if __name__ == '__main__':

    from felpy.model.src.coherent import construct_SA1_pulse
    from felpy.model.tools import propagation_parameters
    from wpg.optical_elements import Drift
    wfr = construct_SA1_pulse(512,512,2,5.0,1)
    print(wfr.params.wDomain)
    wfr.plot()
    bl = Beamline()
    bl.append(Drift(10), propagation_parameters(2,1,2,1,'quadratic'))
    bl.propagate_sequential(wfr)
Exemplo n.º 12
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)
Exemplo n.º 13
0
k = np.pi * 2 / wav
delta = 4e-07
d2waist = (wav) / (np.arctan(.27 / 8) * np.pi)

r = 75e-03

wfr = Wavefront(
    construct_gaussian(1024, 1024, 25, -15e-02, 15e-02, -15e-02, 15e-02, 3e-2,
                       3e-02, d2waist))

### PLOT 1
plot_intensity_map(wfr)

bl = Beamline()

bl.append(Drift(1), propagation_parameters(1, 1, 1, 1))
bl.propagate(wfr)

x = np.linspace(wfr.params.Mesh.xMin, wfr.params.Mesh.xMax, wfr.params.Mesh.nx)
y = np.ones([wfr.params.Mesh.nx, wfr.params.Mesh.ny])

thickness = norm(cylinder_thickness(x, r, offset=0), lim=(0, 255))

sdir = "../../data/samples/cylinder_thickness.png"

im = Image.fromarray(thickness * y)
im = im.convert("L")
im.save(sdir)

np.save(sdir, thickness)
rx, ry = wfr.get_spatial_resolution()