示例#1
0
def KBv(input_wavefront):
    optical_element = WOIdealLens(name='', focal_x=0.099946, focal_y=None)

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.000000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     1.000000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_1D')
    return output_wavefront
示例#2
0
def propagate_in_vacuum(input_wavefront,magnification_x=10.0,propagator_flag='z'):
    #
    # Import section
    #
    import numpy
    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from syned.beamline.beamline_element import BeamlineElement
    from syned.beamline.element_coordinates import ElementCoordinates
    from wofry.propagator.propagators1D.fresnel_zoom import FresnelZoom1D
    from wofry.propagator.propagators1D.integral import Integral1D
    #
    # info on current oe
    #
    #
    #    -------WOScreen1D---------
    #        -------BoundaryShape---------
    #

    #
    # define current oe
    #
    from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen1D

    optical_element = WOScreen1D()

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(optical_element=optical_element,
                                       coordinates=ElementCoordinates(p=15.000000, q=0.000000,
                                                                      angle_radial=numpy.radians(0.000000),
                                                                      angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(wavefront=input_wavefront.duplicate(),
                                                   propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x', magnification_x)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
        propagator.add_propagator(Integral1D())
    except:
        pass

    if propagator_flag == 'z':
        handler_name = 'FRESNEL_ZOOM_1D'
    elif propagator_flag == 'i':
        handler_name = 'INTEGRAL_1D'

    output_wavefront = propagator.do_propagation(propagation_parameters=propagation_parameters,
                                                 handler_name=handler_name)

    return output_wavefront
示例#3
0
def propagate_from_M1_to_M3(wf_in, magnification_x=2.0):
    #
    # ===== Example of python code to create propagate current element =====
    #

    #
    # Import section
    #
    import numpy
    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from syned.beamline.beamline_element import BeamlineElement
    from syned.beamline.element_coordinates import ElementCoordinates
    from wofry.propagator.propagators1D.fresnel_zoom import FresnelZoom1D


    input_wavefront = wf_in.duplicate()

    #
    # info on current oe
    #
    #
    #    -------WOScreen1D---------
    #        -------BoundaryShape---------
    #

    #
    # define current oe
    #
    from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen1D

    optical_element = WOScreen1D()

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(optical_element=optical_element,
                                       coordinates=ElementCoordinates(p=0.000000, q=13.599000,
                                                                      angle_radial=numpy.radians(0.000000),
                                                                      angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(wavefront=input_wavefront.duplicate(),
                                                   propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x', magnification_x)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(propagation_parameters=propagation_parameters,
                                                 handler_name='FRESNEL_ZOOM_1D')
    return output_wavefront
示例#4
0
def apply_M3_focusing(wf_in,focal_x=2.407000):
    #
    # ===== Example of python code to create propagate current element =====
    #

    #
    # Import section
    #
    import numpy
    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from syned.beamline.beamline_element import BeamlineElement
    from syned.beamline.element_coordinates import ElementCoordinates
    from wofry.propagator.propagators1D.fresnel_zoom import FresnelZoom1D

    input_wavefront = wf_in.duplicate()

    #
    # info on current oe
    #
    #
    #    -------WOIdealLens---------
    #        focal_x: 2.407 m # Focal length in x [horizontal]
    #        focal_y: None m # Focal length in y [vertical]
    #

    #
    # define current oe
    #
    from wofry.beamline.optical_elements.ideal_elements.lens import WOIdealLens

    optical_element = WOIdealLens(name='', focal_x=focal_x, focal_y=None)

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(optical_element=optical_element,
                                       coordinates=ElementCoordinates(p=0.000000, q=0.000000,
                                                                      angle_radial=numpy.radians(0.000000),
                                                                      angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(wavefront=input_wavefront.duplicate(),
                                                   propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x', 1.000000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(propagation_parameters=propagation_parameters,
                                                 handler_name='FRESNEL_ZOOM_1D')
    return output_wavefront
    def _back_propagation_for_size_calculation(self,theta,radiation_flux,photon_energy,
                                                distance=100.0,magnification=0.010000):
        """
        Calculate the radiation_flux vs theta at a "distance"
        Back propagate to -distance
        The result is the size distrubution

        :param theta:
        :param radiation_flux:
        :param photon_energy:
        :param distance:
        :param magnification:
        :return: None; stores results in self._photon_size_distribution
        """

        from wofry.propagator.wavefront1D.generic_wavefront import GenericWavefront1D
        from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
        from syned.beamline.beamline_element import BeamlineElement
        from syned.beamline.element_coordinates import ElementCoordinates
        from wofry.propagator.propagators1D.fresnel_zoom import FresnelZoom1D
        from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen1D


        input_wavefront = GenericWavefront1D().initialize_wavefront_from_arrays(theta*distance,numpy.sqrt(radiation_flux)+0j)
        input_wavefront.set_photon_energy(photon_energy)
        input_wavefront.set_spherical_wave(radius=distance,complex_amplitude=numpy.sqrt(radiation_flux)+0j)
        # input_wavefront.save_h5_file("tmp2.h5","wfr")

        optical_element = WOScreen1D()
        #
        # propagating
        #
        #
        propagation_elements = PropagationElements()
        beamline_element = BeamlineElement(optical_element=optical_element,
                        coordinates=ElementCoordinates(p=0.0,q=-distance,
                        angle_radial=numpy.radians(0.000000),
                        angle_azimuthal=numpy.radians(0.000000)))
        propagation_elements.add_beamline_element(beamline_element)
        propagation_parameters = PropagationParameters(wavefront=input_wavefront.duplicate(),propagation_elements = propagation_elements)
        propagation_parameters.set_additional_parameters('magnification_x', magnification)

        #
        propagator = PropagationManager.Instance()
        try:
            propagator.add_propagator(FresnelZoom1D())
        except:
            pass
        output_wavefront = propagator.do_propagation(propagation_parameters=propagation_parameters,handler_name='FRESNEL_ZOOM_1D')

        self._result_photon_size_distribution = {"x":output_wavefront.get_abscissas(),"y":output_wavefront.get_intensity()}
示例#6
0
def Screen_v(input_wavefront, fresnel=True):
    boundary_shape = Rectangle(x_left=-0.5,
                               x_right=0.5,
                               y_bottom=-0.5,
                               y_top=0.5)

    from wofry.beamline.optical_elements.absorbers.slit import WOSlit1D
    optical_element = WOSlit1D(boundary_shape=boundary_shape)

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.050000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     0.000020)
    #
    propagator = PropagationManager.Instance()
    try:
        if fresnel:
            propagator.add_propagator(FresnelZoom1D())
        else:
            propagator.add_propagator(Integral1D())
    except:
        pass

    if fresnel:
        output_wavefront = propagator.do_propagation(
            propagation_parameters=propagation_parameters,
            handler_name='FRESNEL_ZOOM_1D')
    else:
        output_wavefront = propagator.do_propagation(
            propagation_parameters=propagation_parameters,
            handler_name='INTEGRAL_1D')

    return output_wavefront
示例#7
0
def propagation_in_vacuum(wf,
                          propagation_distance=30.0,
                          defocus_factor=1.0,
                          propagation_steps=1):
    #
    # define image plane
    #
    propagation_elements = PropagationElements()
    #

    if propagation_steps == 1:
        propagation_elements.add_beamline_element(
            BeamlineElement(optical_element=Screen(),
                            coordinates=ElementCoordinates(
                                p=0, q=propagation_distance)))
    else:
        for i in range(propagation_steps):
            propagation_elements.add_beamline_element(
                BeamlineElement(
                    optical_element=Screen(),
                    coordinates=ElementCoordinates(p=0,
                                                   q=propagation_distance /
                                                   propagation_steps)))
    propagation_parameters = PropagationParameters(
        wavefront=wf, propagation_elements=propagation_elements)

    if USE_PROPAGATOR == 'fft':
        propagation_parameters.set_additional_parameters(
            "shift_half_pixel", True)
        wf1 = propagator.do_propagation(propagation_parameters,
                                        Fresnel2D.HANDLER_NAME)
    elif USE_PROPAGATOR == 'srw':
        propagation_parameters.set_additional_parameters(
            "srw_autosetting", False)
        wf1 = propagator.do_propagation(propagation_parameters,
                                        FresnelSRW.HANDLER_NAME)
    elif USE_PROPAGATOR == 'convolution':
        propagation_parameters.set_additional_parameters(
            "shift_half_pixel", True)
        wf1 = propagator.do_propagation(propagation_parameters,
                                        FresnelConvolution2D.HANDLER_NAME)
    else:
        raise Exception("Not implemented method: %s" % USE_PROPAGATOR)

    horizontal_profile = wf1.get_intensity()[:, int(wf1.size()[1] / 2)]
    horizontal_profile /= horizontal_profile.max()
    print("FWHM of the horizontal profile: %g um" %
          (1e6 * line_fwhm(horizontal_profile) * wf1.delta()[0]))
    vertical_profile = wf1.get_intensity()[int(wf1.size()[0] / 2), :]
    vertical_profile /= vertical_profile.max()
    print("FWHM of the vertical profile: %g um" %
          (1e6 * line_fwhm(vertical_profile) * wf1.delta()[1]))

    print("Output intensity: ", wf1.get_intensity().sum())
    return wf1, wf1.get_coordinate_x(), horizontal_profile
示例#8
0
    def propagate(self, wofry_wavefront, mypropagator, return_wavefront_list=False):
        from srxraylib.plot.gol import plot_image

        # plot_image(wofry_wavefront.get_intensity(),1e6*wofry_wavefront.get_coordinate_x(),1e6*wofry_wavefront.get_coordinate_y(), title="source")

        if return_wavefront_list:
            w_out = wofry_wavefront.duplicate()
            output_wavefronts = []
            output_wavefronts.append(wofry_wavefront.duplicate())

            for i in range(self.get_beamline_elements_number()):
                w_in = w_out.duplicate()


                method = 0 # 0 = old, 1=New

                if method == 1:

                    propagation_elements = PropagationElements()
                    propagation_elements.add_beamline_element(beamline_element=self.get_beamline_element_at(i))

                    propagation_parameters = PropagationParameters(wavefront=w_in,
                                                                   propagation_elements=propagation_elements)
                    tmp = self.get_propagator_specific_parameters(i)

                    propagation_parameters.set_additional_parameters('shift_half_pixel',tmp['shift_half_pixel'])
                    propagation_parameters.set_additional_parameters('magnification_x',tmp['magnification_x'])
                    propagation_parameters.set_additional_parameters('magnification_y',tmp['magnification_y'])
                else:
                    propagation_elements = PropagationElements()
                    propagation_elements.add_beamline_element(beamline_element=self.get_beamline_element_at(i),
                                                              element_parameters=self.get_propagator_specific_parameters(i))
                    propagation_parameters = PropagationParameters(wavefront=w_in,
                                                                   propagation_elements=propagation_elements)

                w_out = mypropagator.do_propagation(propagation_parameters=propagation_parameters,
                                                    handler_name=self.get_propagator_handler(i))

                # plot_image(w_out.get_intensity(),1e6*w_out.get_coordinate_x(),1e6*w_out.get_coordinate_y(),title="oe index: %d"%(i),aspect="auto")
                output_wavefronts.append(w_out)

            return output_wavefronts

        else:
            # check all handler are identical
            for i in range(self.get_beamline_elements_number()):
                assert (self.get_propagator_handler(0) == self.get_propagator_handler(i))

            propagation_elements = PropagationElements()
            for i in range(self.get_beamline_elements_number()):
                propagation_elements.add_beamline_element(beamline_element=self._beamline_elements_list[i],
                                                          element_parameters=self.get_propagator_specific_parameters(i))

            propagation_parameters = PropagationParameters(wavefront=wofry_wavefront.duplicate(),
                                                           propagation_elements=propagation_elements)

            w_out = mypropagator.do_propagation(propagation_parameters=propagation_parameters,
                                                handler_name=self.get_propagator_handler(0))

            return [w_out]
    def do_propagation(self, parameters=PropagationParameters()):
        wavefront = parameters.get_wavefront()

        if not wavefront is None:
            is_generic_wavefront = isinstance(wavefront, GenericWavefront1D)
        else:
            is_generic_wavefront = False

        try:
            if not is_generic_wavefront and not wavefront is None:
                if isinstance(wavefront, WiserWavefront):
                    pass
        except Exception as e:
            QMessageBox.critical(self, "Wavefront cannot be managed by this propagator", str(e), QMessageBox.Ok)
            self.setStatusMessage("Wavefront cannot be managed by this propagator")

        if is_generic_wavefront:
            wavefront = WiserWavefront.fromGenericWavefront(wavefront)

        wise_propagation_elements = parameters.get_PropagationElements()

        beamline = wise_propagation_elements.get_wise_propagation_elements()
        beamline.ComputationSettings.NPools = int(parameters.get_additional_parameter("NPools"))

        # Element -1 is the last element of the array
        optical_element_end = wise_propagation_elements.get_propagation_element(-1).get_optical_element()

        oeEnd = optical_element_end.native_optical_element
        if parameters.get_additional_parameter("single_propagation"):
            oeStart = oeEnd.GetParent(SameOrientation=True, OnlyReference=False)
        else:
            oeStart = wise_propagation_elements.get_wise_propagation_element(0)

        # oeEnd = optical_element_end.native_optical_element
        # oeStart is the first element [0], or the previous element [-2]
        # print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
        # print(wise_propagation_elements.get_wise_propagation_element(-2 if parameters.get_additional_parameter("single_propagation") else 0).Name, type(wise_propagation_elements.get_wise_propagation_element(-2 if parameters.get_additional_parameter("single_propagation") else 0)))
        # print(oeStart.Name, oeEnd.Name)
        # print(oeStart.CoreOptics.Orientation, oeEnd.CoreOptics.Orientation)
        # print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
        # oeStart =wise_propagation_elements.get_wise_propagation_element(-2 if parameters.get_additional_parameter("single_propagation") else 0)# oeEnd.GetParent(SameOrientation=True)

        if PropagationManager.Instance().get_propagation_mode(WISE_APPLICATION) == PropagationMode.STEP_BY_STEP or parameters.get_additional_parameter("is_full_propagator"):

            beamline.RefreshPositions()
            beamline.ComputeFields(oeStart=oeStart, oeEnd=oeEnd, Verbose=False)

            result = WiserWavefront(wiser_computation_results=oeEnd.ComputationData)
        elif PropagationManager.Instance().get_propagation_mode(WISE_APPLICATION) == PropagationMode.WHOLE_BEAMLINE:
            result = wavefront
        else:
            result = None

        if is_generic_wavefront:
            return None if result is None else result.toGenericWavefront()
        else:
            return result
示例#10
0
def Aperture_40m(input_wavefront):
    # from syned.beamline.shape import Rectangle
    # note that wavefront 1d will be clipped using the first two coordinates!
    boundary_shape = Rectangle(x_left=-2.5e-05,
                               x_right=2.5e-05,
                               y_bottom=-2.5e-05,
                               y_top=2.5e-05)

    from wofry.beamline.optical_elements.absorbers.slit import WOSlit1D
    optical_element = WOSlit1D(boundary_shape=boundary_shape)

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=11.700000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     0.010000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())

    except:
        pass

    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_1D')

    return output_wavefront
示例#11
0
def ML_size(input_wavefront):
    # note that wavefront 1d will be clipped using the first two coordinates!
    boundary_shape = Rectangle(x_left=-0.0018849,
                               x_right=0.0018849,
                               y_bottom=-0.0018849,
                               y_top=0.0018849)

    optical_element = WOSlit1D(boundary_shape=boundary_shape)

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #

    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.000000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)

    propagation_parameters.set_additional_parameters('magnification_x',
                                                     1.000000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_1D')

    return output_wavefront
示例#12
0
def Aperture_40m_V_open(input_wavefront):
    boundary_shape = Rectangle(x_left=-0.5,
                               x_right=0.5,
                               y_bottom=-0.5,
                               y_top=0.5)

    optical_element = WOSlit1D(boundary_shape=boundary_shape)

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=11.700000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     0.640000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_1D')

    return output_wavefront
    def do_propagation(self, parameters=PropagationParameters()):
        wavefront = parameters.get_wavefront()

        if not wavefront is None:
            is_generic_wavefront = isinstance(wavefront, GenericWavefront1D)
        else:
            is_generic_wavefront = False

        if not is_generic_wavefront and not wavefront is None:
            if not isinstance(wavefront, WiseWavefront):
                raise ValueError(
                    "Wavefront cannot be managed by this propagator")

        if is_generic_wavefront:
            wavefront = WiseWavefront.fromGenericWavefront(wavefront)

        wise_propagation_elements = parameters.get_PropagationElements()

        beamline = wise_propagation_elements.get_wise_propagation_elements()
        beamline.ComputationSettings.NPools = int(
            parameters.get_additional_parameter("NPools"))

        optical_element_end = wise_propagation_elements.get_propagation_element(
            -1).get_optical_element()

        oeEnd = optical_element_end.wise_optical_element
        oeStart = wise_propagation_elements.get_wise_propagation_element(
            -2 if parameters.get_additional_parameter("single_propagation"
                                                      ) else 0)

        if PropagationManager.Instance().get_propagation_mode(
                WISE_APPLICATION
        ) == PropagationMode.STEP_BY_STEP or parameters.get_additional_parameter(
                "is_full_propagator"):
            beamline.RefreshPositions()
            beamline.ComputeFields(oeStart=oeStart, oeEnd=oeEnd, Verbose=False)

            result = WiseWavefront(
                wise_computation_results=oeEnd.ComputationResults)
        elif PropagationManager.Instance().get_propagation_mode(
                WISE_APPLICATION) == PropagationMode.WHOLE_BEAMLINE:
            result = wavefront
        else:
            result = None

        if is_generic_wavefront:
            return None if result is None else result.toGenericWavefront()
        else:
            return result
示例#14
0
def apply_lens(wf, focal_length):
    propagation_elements = PropagationElements()
    propagation_elements.add_beamline_element(
        BeamlineElement(optical_element=WOIdealLens("IdealLens",
                                                    focal_x=focal_length,
                                                    focal_y=focal_length),
                        coordinates=ElementCoordinates(p=0.0, q=0.0)))

    propagation_parameters = PropagationParameters(
        wavefront=wf, propagation_elements=propagation_elements)

    if USE_PROPAGATOR == 'fft':
        wfout = propagator.do_propagation(propagation_parameters,
                                          Fresnel2D.HANDLER_NAME)
    elif USE_PROPAGATOR == 'convolution':
        wfout = propagator.do_propagation(propagation_parameters,
                                          FresnelConvolution2D.HANDLER_NAME)

    return wfout
示例#15
0
    def do_propagation(self, parameters=PropagationParameters()):
        wavefront = parameters.get_wavefront()

        is_generic_wavefront = isinstance(wavefront, GenericWavefront2D)

        if is_generic_wavefront:
            wavefront = SRWWavefront.fromGenericWavefront(wavefront)
        else:
            if not isinstance(wavefront, SRWWavefront):
                raise ValueError(
                    "wavefront cannot be managed by this propagator")

        srw_oe_array = []
        srw_pp_array = []

        propagation_mode = PropagationManager.Instance().get_propagation_mode(
            SRW_APPLICATION)

        if propagation_mode == SRWPropagationMode.STEP_BY_STEP:
            self.add_optical_element(parameters, 0, srw_oe_array, srw_pp_array,
                                     wavefront)
        elif propagation_mode == SRWPropagationMode.WHOLE_BEAMLINE:
            srw_beamline = parameters.get_additional_parameter(
                "working_beamline")

            for index in range(srw_beamline.get_beamline_elements_number()):
                self.add_optical_element_from_beamline(srw_beamline, index,
                                                       srw_oe_array,
                                                       srw_pp_array, wavefront)
        else:
            raise ValueError(
                "Propagation Mode not supported by this Propagator")

        if len(srw_oe_array) > 0:
            optBL = SRWLOptC(srw_oe_array, srw_pp_array)
            srwl.PropagElecField(wavefront, optBL)

        if is_generic_wavefront:
            return wavefront.toGenericWavefront()
        else:
            return wavefront
示例#16
0
def propagate_wavefront(wf, propagation_distance, method='srw'):

    propagation_elements = PropagationElements()

    screen = WOScreen(name="Screen")

    propagation_elements.add_beamline_element(
        BeamlineElement(optical_element=screen,
                        coordinates=ElementCoordinates(
                            p=0, q=propagation_distance)))

    # initialize_default_propagator_2D()

    propagation_parameters = PropagationParameters(
        wavefront=wf, propagation_elements=propagation_elements)

    if method == 'fresnel':

        propagation_parameters.set_additional_parameters(
            "shift_half_pixel", True)
        wf1 = propagator.do_propagation(propagation_parameters,
                                        Fresnel2D.HANDLER_NAME)
    elif method == 'srw':
        propagation_parameters.set_additional_parameters("srw_autosetting", 0)
        wf1 = propagator.do_propagation(propagation_parameters,
                                        FresnelSRW.HANDLER_NAME)
    elif method == 'pynx':
        wf1 = propagator.do_propagation(propagation_parameters,
                                        FresnelPYNX.HANDLER_NAME)
    elif method == 'pynx2':
        wf1 = propagator.do_propagation(propagation_parameters,
                                        FraunhoferPYNX.HANDLER_NAME)
    elif method == 'pynx3':
        wf1 = propagator.do_propagation(propagation_parameters,
                                        FrtPYNX.HANDLER_NAME)
    else:
        raise Exception("Not implemented method: %s" % method)

    return wf1
示例#17
0
    def propagate_2D_fresnel(self,do_plot=do_plot,method='fft',
                                wavelength=1.24e-10,aperture_type='square',aperture_diameter=40e-6,
                                pixelsize_x=1e-6,pixelsize_y=1e-6,npixels_x=1024,npixels_y=1024,
                                propagation_distance = 30.0,show=1,
                                use_additional_parameters_input_way=1, # 0=default (common), 1=new (specific))
                             ):


        method_label = "fresnel (%s)"%method
        print("\n#                                                             ")
        print("# 2D near field fresnel (%s) diffraction from a %s aperture  "%(method_label,aperture_type))
        print("#                                                             ")


        # wf = Wavefront2D.initialize_wavefront_from_steps(x_start=-pixelsize_x*npixels_x/2,
        #                                                         x_step=pixelsize_x,
        #                                                         y_start=-pixelsize_y*npixels_y/2,
        #                                                         y_step=pixelsize_y,
        #                                                         wavelength=wavelength,
        #                                                         number_of_points=(npixels_x,npixels_y))

        wf = GenericWavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2,
                                                         y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2,
                                                         number_of_points=(npixels_x,npixels_y),wavelength=wavelength)

        wf.set_plane_wave_from_complex_amplitude((1.0+0j))


        propagation_elements = PropagationElements()

        slit = None

        if aperture_type == 'square':
            slit = WOSlit(boundary_shape=Rectangle(-aperture_diameter/2, aperture_diameter/2, -aperture_diameter/2, aperture_diameter/2))
        elif aperture_type == 'gaussian':
            slit = WOGaussianSlit(boundary_shape=Rectangle(-aperture_diameter/2, aperture_diameter/2, -aperture_diameter/2, aperture_diameter/2))
        else:
            raise Exception("Not implemented! (accepted: circle, square, gaussian)")


        if use_additional_parameters_input_way == 0:
            propagation_elements.add_beamline_element(BeamlineElement(optical_element=slit,
                                                                      coordinates=ElementCoordinates(p=0, q=propagation_distance)))


            propagator = PropagationManager.Instance()
            propagation_parameters = PropagationParameters(wavefront=wf,
                                                           propagation_elements=propagation_elements)

            if method == 'fft':
                propagation_parameters.set_additional_parameters("shift_half_pixel", True)
                wf1 = propagator.do_propagation(propagation_parameters, Fresnel2D.HANDLER_NAME)
            elif method == 'convolution':
                propagation_parameters.set_additional_parameters("shift_half_pixel", True)
                wf1 = propagator.do_propagation(propagation_parameters, FresnelConvolution2D.HANDLER_NAME)
            elif method == 'integral':
                propagation_parameters.set_additional_parameters("shuffle_interval", 0)
                propagation_parameters.set_additional_parameters("calculate_grid_only", 1)
                wf1 = propagator.do_propagation(propagation_parameters, Integral2D.HANDLER_NAME)
            elif method == 'zoom':
                propagation_parameters.set_additional_parameters("shift_half_pixel", True)
                propagation_parameters.set_additional_parameters("magnification_x", 2.0)
                propagation_parameters.set_additional_parameters("magnification_y", 0.5)
                wf1 = propagator.do_propagation(propagation_parameters, FresnelZoomXY2D.HANDLER_NAME)
            else:
                raise Exception("Not implemented method: %s"%method)
        else:

            if method == 'fft':
                additional_parameters = {"shift_half_pixel":True}
            elif method == 'convolution':
                additional_parameters = {"shift_half_pixel":True}
            elif method == 'integral':
                additional_parameters = {"shuffle_interval":0,
                                         "calculate_grid_only":1}
            elif method == 'zoom':
                additional_parameters = {"shift_half_pixel":True,
                                         "magnification_x":2.0,
                                         "magnification_y":0.5}
            else:
                raise Exception("Not implemented method: %s"%method)


            propagation_elements.add_beamline_element(
                        BeamlineElement(optical_element=slit,coordinates=ElementCoordinates(p=0, q=propagation_distance)),
                        element_parameters=additional_parameters)


            propagator = PropagationManager.Instance()
            propagation_parameters = PropagationParameters(wavefront=wf,
                                                           propagation_elements=propagation_elements)

            if method == 'fft':
                wf1 = propagator.do_propagation(propagation_parameters, Fresnel2D.HANDLER_NAME)
            elif method == 'convolution':
                wf1 = propagator.do_propagation(propagation_parameters, FresnelConvolution2D.HANDLER_NAME)
            elif method == 'integral':
                wf1 = propagator.do_propagation(propagation_parameters, Integral2D.HANDLER_NAME)
            elif method == 'zoom':
                wf1 = propagator.do_propagation(propagation_parameters, FresnelZoomXY2D.HANDLER_NAME)
            else:
                raise Exception("Not implemented method: %s"%method)


        if do_plot:
            from srxraylib.plot.gol import plot_image
            plot_image(wf.get_intensity(),1e6*wf.get_coordinate_x(),1e6*wf.get_coordinate_y(),
                       title="aperture intensity (%s), Diameter=%5.1f um"%
                             (aperture_type,1e6*aperture_diameter),xtitle="X [um]",ytitle="Y [um]",
                       show=0)

            plot_image(wf1.get_intensity(),
                       1e6*wf1.get_coordinate_x()/propagation_distance,
                       1e6*wf1.get_coordinate_y()/propagation_distance,
                       title="Diffracted intensity (%s) by a %s slit of aperture %3.1f um"%
                             (aperture_type,method_label,1e6*aperture_diameter),
                       xtitle="X [urad]",ytitle="Y [urad]",
                       show=0)

        # get the theoretical value
        angle_x = wf1.get_coordinate_x() / propagation_distance

        intensity_theory = get_theoretical_diffraction_pattern(angle_x,aperture_type=aperture_type,aperture_diameter=aperture_diameter,
                                            wavelength=wavelength,normalization=True)

        intensity_calculated =  wf1.get_intensity()[:,int(wf1.size()[1]/2)]
        intensity_calculated /= intensity_calculated.max()

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf1.get_coordinate_x()*1e6/propagation_distance,intensity_calculated,
                 angle_x*1e6,intensity_theory,
                 legend=["%s H profile"%method_label,"Theoretical (far field)"],
                 legend_position=(0.95, 0.95),
                 title="%s diffraction of a %s slit of %3.1f um at wavelength of %3.1f A"%
                       (method_label,aperture_type,aperture_diameter*1e6,wavelength*1e10),
                 xtitle="X (urad)", ytitle="Intensity",xrange=[-20,20],
                 show=show)

        return wf1.get_coordinate_x()/propagation_distance,intensity_calculated,angle_x,intensity_theory
def ideal_lens_KBh(input_wavefront):

    #
    # ===== Example of python code to create propagate current element =====
    #

    #
    # Import section
    #
    import numpy
    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from syned.beamline.beamline_element import BeamlineElement
    from syned.beamline.element_coordinates import ElementCoordinates
    from wofry.propagator.propagators2D.fresnel_zoom_xy import FresnelZoomXY2D

    #
    # info on current oe
    #
    #
    #    -------WOIdealLens---------
    #        focal_x: 0.049982758620701014 m # Focal length in x [horizontal]
    #        focal_y: 100000000.0 m # Focal length in y [vertical]
    #

    #
    # define current oe
    #
    from wofry.beamline.optical_elements.ideal_elements.lens import WOIdealLens

    optical_element = WOIdealLens(name='',
                                  focal_x=0.049983,
                                  focal_y=100000000.000000)

    #
    # propagating
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.000000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    #self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('shift_half_pixel', 1)
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     1.000000)
    propagation_parameters.set_additional_parameters('magnification_y',
                                                     1.000000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoomXY2D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_XY_2D')

    return output_wavefront, beamline_element
    wavefront = WiseWavefront(wise_computation_results=None)

    # Build the beamline
    beamline.add_beamline_element(WiserBeamlineElement(optical_element=ww_s))
    beamline.add_beamline_element(
        WiserBeamlineElement(optical_element=ww_pm1_h))
    beamline.add_beamline_element(
        WiserBeamlineElement(optical_element=ww_kb_v))
    beamline.add_beamline_element(
        WiserBeamlineElement(optical_element=ww_kb_h))
    beamline.add_beamline_element(WiserBeamlineElement(optical_element=ww_sl))
    beamline.add_beamline_element(WiserBeamlineElement(optical_element=ww_d_v))
    beamline.add_beamline_element(WiserBeamlineElement(optical_element=ww_d_h))

    parameters = PropagationParameters(
        wavefront=WiseWavefront(wise_computation_results=None),
        propagation_elements=beamline)
    parameters.set_additional_parameters("single_propagation", False)
    parameters.set_additional_parameters("NPools", 1)
    #
    wavefront = PropagationManager.Instance().do_propagation(
        propagation_parameters=parameters,
        handler_name=WiserPropagator.HANDLER_NAME)
    #
    beamline_before = beamline
    # # Plot the result

    plot(d_v)

    plot(d_h)
    #
def slit_schermo(input_wavefront):

    #
    # ===== Example of python code to create propagate current element =====
    #

    #
    # Import section
    #
    import numpy
    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from syned.beamline.beamline_element import BeamlineElement
    from syned.beamline.element_coordinates import ElementCoordinates
    from wofry.propagator.propagators2D.fresnel_zoom_xy import FresnelZoomXY2D

    #
    # info on current oe
    #
    #
    #    -------WOSlit---------
    #        -------Rectangle---------
    #        x_left    : -0.5 m # x (width) minimum (signed)
    #        x_right   : 0.5 m # x (width) maximum (signed)
    #        y_bottom  : -0.5 m # y (length) minimum (signed)
    #        y_top     : 0.5 m # y (length) maximum (signed)
    #

    #
    # define current oe
    #
    from syned.beamline.shape import Rectangle
    boundary_shape = Rectangle(x_left=-0.500000,
                               x_right=0.500000,
                               y_bottom=-0.500000,
                               y_top=0.500000)
    from wofry.beamline.optical_elements.absorbers.slit import WOSlit
    optical_element = WOSlit(boundary_shape=boundary_shape)

    #
    # propagating
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.050000,
            q=0.000000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    #self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('shift_half_pixel', 1)
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     0.000070)
    propagation_parameters.set_additional_parameters('magnification_y',
                                                     0.000090)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoomXY2D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_XY_2D')

    return output_wavefront, beamline_element
        wavelength=73e-12)

    radius = 28.3

    wavefront.set_spherical_wave(radius=radius)

    scale_factor = 1

    screen = WOScreen(name="PIRRONE")
    coordinates = ElementCoordinates(p=0.0, q=-scale_factor * radius)

    propagation_elements = PropagationElements()
    propagation_elements.add_beamline_element(
        BeamlineElement(optical_element=screen, coordinates=coordinates))

    parameters = PropagationParameters(
        wavefront=wavefront, propagation_elements=propagation_elements)
    parameters.set_additional_parameters("shift_half_pixel", 1)
    parameters.set_additional_parameters("magnification_x", 0.005)
    parameters.set_additional_parameters("magnification_y", 0.005)

    output_wf_1 = propagator.do_propagation(
        propagation_parameters=parameters, handler_name=Fresnel2D.HANDLER_NAME)

    output_wf_2 = propagator.do_propagation(
        propagation_parameters=parameters,
        handler_name=FresnelZoomXY2D.HANDLER_NAME)

    plot_image(output_wf_1.get_intensity(),
               output_wf_1.get_coordinate_x() * 1e6,
               output_wf_1.get_coordinate_y() * 1e6,
               title="WF1 - " + Fresnel2D.HANDLER_NAME)
    try:
        propagator.add_propagator(FresnelZoomXY2D())
    except:
        pass

    for i, beamline_element in enumerate(
            bl.get_beamline_elements()):  #bl.get_beamline_elements_number()):
        #
        # propagating single element
        #
        print(">> Propagating element %d of %d" %
              (i + 1, bl.get_beamline_elements_number()))
        propagation_elements = PropagationElements()
        propagation_elements.add_beamline_element(beamline_element)
        propagation_parameters = PropagationParameters(
            wavefront=wfr.duplicate(),
            propagation_elements=propagation_elements)

        propagation_parameters.set_additional_parameters('shift_half_pixel', 1)
        propagation_parameters.set_additional_parameters(
            'magnification_x', magnification_x[i])
        propagation_parameters.set_additional_parameters(
            'magnification_y', magnification_y[i])

        output_wavefront = propagator.do_propagation(
            propagation_parameters=propagation_parameters,
            handler_name='FRESNEL_ZOOM_XY_2D')
        wfr = output_wavefront

    plot_image(wfr.get_intensity(),
               1e6 * wfr.get_coordinate_x(),
示例#23
0
    def test_propagate_2D_fraunhofer_phase(self,do_plot=do_plot,aperture_type='square',
                                aperture_diameter=40e-6,
                                pixelsize_x=1e-6,pixelsize_y=1e-6,npixels_x=1024,npixels_y=1024,
                                propagation_distance=30.0,wavelength=1.24e-10):


        print("\n#                                                            ")
        print("# far field 2D (fraunhofer) diffraction from a square aperture  ")
        print("#                                                            ")

        method = "fraunhofer"

        print("Fraunhoffer diffraction valid for distances > > a^2/lambda = %f m"%((aperture_diameter/2)**2/wavelength))

        wf = GenericWavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2,
                                                         y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2,
                                                         number_of_points=(npixels_x,npixels_y),wavelength=wavelength)

        wf.set_plane_wave_from_complex_amplitude((1.0+0j))


        propagation_elements = PropagationElements()

        slit = None

        if aperture_type == 'square':
            slit = WOSlit(boundary_shape=Rectangle(-aperture_diameter/2, aperture_diameter/2, -aperture_diameter/2, aperture_diameter/2))
        elif aperture_type == 'gaussian':
            slit = WOGaussianSlit(boundary_shape=Rectangle(-aperture_diameter/2, aperture_diameter/2, -aperture_diameter/2, aperture_diameter/2))
        else:
            raise Exception("Not implemented! (accepted: circle, square, gaussian)")

        propagation_elements.add_beamline_element(BeamlineElement(optical_element=slit,
                                                                  coordinates=ElementCoordinates(p=0, q=propagation_distance)))


        propagator = PropagationManager.Instance()
        propagation_parameters = PropagationParameters(wavefront=wf,
                                                       propagation_elements=propagation_elements)


        propagation_parameters.set_additional_parameters("shift_half_pixel", True)
        wf1_fraunhofer = propagator.do_propagation(propagation_parameters, Fraunhofer2D.HANDLER_NAME)

        propagation_parameters.set_additional_parameters("shift_half_pixel", True)
        propagation_parameters.set_additional_parameters("magnification_x", 1.5)
        propagation_parameters.set_additional_parameters("magnification_y", 2.5)
        wf1_zoom = propagator.do_propagation(propagation_parameters, FresnelZoomXY2D.HANDLER_NAME)


        if aperture_type == 'circle':
            wf.clip_circle(aperture_diameter/2)
        elif aperture_type == 'square':
            wf.clip_square(-aperture_diameter/2, aperture_diameter/2,-aperture_diameter/2, aperture_diameter/2)
        elif aperture_type == 'gaussian':
            X = wf.get_mesh_x()
            Y = wf.get_mesh_y()
            window = numpy.exp(- (X*X + Y*Y)/2/(aperture_diameter/2.35)**2)
            wf.rescale_amplitudes(window)
        else:
            raise Exception("Not implemented! (accepted: circle, square, gaussian)")

        if do_plot:
            plot_image(wf.get_intensity(),1e6*wf.get_coordinate_x(),1e6*wf.get_coordinate_y(),
                       title="aperture intensity (%s), Diameter=%5.1f um"%
                             (aperture_type,1e6*aperture_diameter),xtitle="X [um]",ytitle="Y [um]",
                       show=0)

            plot_image(wf1_fraunhofer.get_intensity(),1e6*wf1_fraunhofer.get_coordinate_x(),1e6*wf1_fraunhofer.get_coordinate_y(),
                       title="2D Diffracted intensity (%s) by a %s slit of aperture %3.1f um"%
                             (aperture_type,"Fraunhofer",1e6*aperture_diameter),
                       xtitle="X [urad]",ytitle="Y [urad]",
                       show=0)

            plot_image(wf1_zoom.get_intensity(),1e6*wf1_zoom.get_coordinate_x(),1e6*wf1_zoom.get_coordinate_y(),
                       title="2D Diffracted intensity (%s) by a %s slit of aperture %3.1f um"%
                             (aperture_type,"Zoom",1e6*aperture_diameter),
                       xtitle="X [urad]",ytitle="Y [urad]",
                       show=0)

        intensity_calculated_fraunhofer =  wf1_fraunhofer.get_intensity()[:,int(wf1_fraunhofer.size()[1]/2)]
        intensity_calculated_fraunhofer /= intensity_calculated_fraunhofer.max()

        intensity_calculated_zoom =  wf1_zoom.get_intensity()[:,int(wf1_fraunhofer.size()[1]/2)]
        intensity_calculated_zoom /= intensity_calculated_zoom.max()

        phase_calculated_fraunhofer =  wf1_fraunhofer.get_phase()[:,int(wf1_fraunhofer.size()[1]/2)]
        phase_calculated_fraunhofer = numpy.unwrap(phase_calculated_fraunhofer)

        phase_calculated_zoom =  wf1_zoom.get_phase()[:,int(wf1_zoom.size()[1]/2)]
        phase_calculated_zoom = numpy.unwrap(phase_calculated_zoom)

        if do_plot:
            plot(wf1_fraunhofer.get_coordinate_x()*1e6/propagation_distance, intensity_calculated_fraunhofer,
                 wf1_zoom.get_coordinate_x()*1e6      /propagation_distance, intensity_calculated_zoom,
                 legend=["Fraunhofer H profile","Zoom H profile"],legend_position=(0.95, 0.95),
                 title="2D Diffraction of a %s slit of %3.1f um at wavelength of %3.1f A"%
                       (aperture_type,aperture_diameter*1e6,wavelength*1e10),
                 xtitle="X (urad)", ytitle="Intensity",xrange=[-80,80],show=0)

            plot(wf1_fraunhofer.get_coordinate_x()*1e6/propagation_distance, phase_calculated_fraunhofer,
                 wf1_zoom.get_coordinate_x()*1e6      /propagation_distance, phase_calculated_zoom,
                 legend=["Fraunhofer H profile","Zoom H profile"],legend_position=(0.95, 0.95),
                 title="2D Diffraction of a %s slit of %3.1f um at wavelength of %3.1f A"%
                       (aperture_type,aperture_diameter*1e6,wavelength*1e10),
                 xtitle="X (urad)", ytitle="Phase",xrange=[-80,80])


        numpy.testing.assert_almost_equal(1e-3*intensity_calculated_fraunhofer,1e-3*intensity_calculated_zoom,1)
示例#24
0
    def test_propagate_2D_fraunhofer(self,do_plot=do_plot,aperture_type='square',aperture_diameter=40e-6,
                    pixelsize_x=1e-6,pixelsize_y=1e-6,npixels_x=1024,npixels_y=1024,wavelength=1.24e-10):
        """

        :param do_plot: 0=No plot, 1=Do plot
        :param aperture_type: 'circle' 'square' 'gaussian' (Gaussian sigma = aperture_diameter/2.35)
        :param aperture_diameter:
        :param pixelsize_x:
        :param pixelsize_y:
        :param npixels_x:
        :param npixels_y:
        :param wavelength:
        :return:
        """

        print("\n#                                                            ")
        print("# far field 2D (fraunhofer) diffraction from a square aperture  ")
        print("#                                                            ")

        method = "fraunhofer"

        print("Fraunhoffer diffraction valid for distances > > a^2/lambda = %f m"%((aperture_diameter/2)**2/wavelength))

        wf = GenericWavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2,
                                                         y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2,
                                                         number_of_points=(npixels_x,npixels_y),wavelength=wavelength)

        wf.set_plane_wave_from_complex_amplitude((1.0+0j))


        propagation_elements = PropagationElements()

        slit = None

        if aperture_type == 'square':
            slit = WOSlit(boundary_shape=Rectangle(-aperture_diameter/2, aperture_diameter/2, -aperture_diameter/2, aperture_diameter/2))
        elif aperture_type == 'gaussian':
            slit = WOGaussianSlit(boundary_shape=Rectangle(-aperture_diameter/2, aperture_diameter/2, -aperture_diameter/2, aperture_diameter/2))
        else:
            raise Exception("Not implemented! (accepted: circle, square, gaussian)")

        propagation_elements.add_beamline_element(BeamlineElement(optical_element=slit,
                                                                  coordinates=ElementCoordinates(p=0, q=1.0)))


        propagator = PropagationManager.Instance()
        propagation_parameters = PropagationParameters(wavefront=wf,
                                                       propagation_elements=propagation_elements)
        propagation_parameters.set_additional_parameters("shift_half_pixel", True)

        wf1 = propagator.do_propagation(propagation_parameters, Fraunhofer2D.HANDLER_NAME)

        if aperture_type == 'circle':
            wf.clip_circle(aperture_diameter/2)
        elif aperture_type == 'square':
            wf.clip_square(-aperture_diameter/2, aperture_diameter/2,-aperture_diameter/2, aperture_diameter/2)
        elif aperture_type == 'gaussian':
            X = wf.get_mesh_x()
            Y = wf.get_mesh_y()
            window = numpy.exp(- (X*X + Y*Y)/2/(aperture_diameter/2.35)**2)
            wf.rescale_amplitudes(window)
        else:
            raise Exception("Not implemented! (accepted: circle, square, gaussian)")

        if do_plot:
            plot_image(wf.get_intensity(),1e6*wf.get_coordinate_x(),1e6*wf.get_coordinate_y(),
                       title="aperture intensity (%s), Diameter=%5.1f um"%
                             (aperture_type,1e6*aperture_diameter),xtitle="X [um]",ytitle="Y [um]",
                       show=0)

            plot_image(wf1.get_intensity(),1e6*wf1.get_coordinate_x(),1e6*wf1.get_coordinate_y(),
                       title="2D Diffracted intensity (%s) by a %s slit of aperture %3.1f um"%
                             (aperture_type,method,1e6*aperture_diameter),
                       xtitle="X [urad]",ytitle="Y [urad]",
                       show=0)

        angle_x = wf1.get_coordinate_x() # + 0.5*wf1.delta()[0] # shifted of half-pixel!!!
        intensity_theory = get_theoretical_diffraction_pattern(angle_x,
                                            aperture_type=aperture_type,aperture_diameter=aperture_diameter,
                                            wavelength=wavelength,normalization=True)


        intensity_calculated =  wf1.get_intensity()[:,int(wf1.size()[1]/2)]
        intensity_calculated /= intensity_calculated.max()

        if do_plot:
            plot(wf1.get_coordinate_x()*1e6,intensity_calculated,
                 angle_x*1e6,intensity_theory,
                 legend=["Calculated (FT) H profile","Theoretical"],legend_position=(0.95, 0.95),
                 title="2D Fraunhofer Diffraction of a %s slit of %3.1f um at wavelength of %3.1f A"%
                       (aperture_type,aperture_diameter*1e6,wavelength*1e10),
                 xtitle="X (urad)", ytitle="Intensity",xrange=[-80,80])

        numpy.testing.assert_almost_equal(intensity_calculated,intensity_theory,1)
示例#25
0
    def propagation_with_lens(self,do_plot=do_plot,method='fft',
                                wavelength=1.24e-10,
                                pixelsize_x=1e-6,npixels_x=2000,pixelsize_y=1e-6,npixels_y=2000,
                                propagation_distance=30.0,defocus_factor=1.0,propagation_steps=1,show=1):


        method_label = "fresnel (%s)"%method
        print("\n#                                                             ")
        print("# near field fresnel (%s) diffraction and focusing  "%(method_label))
        print("#                                                             ")

        #                               \ |  /
        #   *                           | | |                      *
        #                               / | \
        #   <-------    d  ---------------><---------   d   ------->
        #   d is propagation_distance

        # wf = Wavefront2D.initialize_wavefront_from_steps(x_start=-pixelsize_x*npixels_x/2,
        #                                                         x_step=pixelsize_x,
        #                                                         y_start=-pixelsize_y*npixels_y/2,
        #                                                         y_step=pixelsize_y,
        #                                                         wavelength=wavelength,
        #                                                         number_of_points=(npixels_x,npixels_y))

        wf = GenericWavefront2D.initialize_wavefront_from_range(x_min=-pixelsize_x*npixels_x/2,x_max=pixelsize_x*npixels_x/2,
                                                         y_min=-pixelsize_y*npixels_y/2,y_max=pixelsize_y*npixels_y/2,
                                                         number_of_points=(npixels_x,npixels_y),wavelength=wavelength)
        propagation_elements = PropagationElements()

        spherical_or_plane_and_lens = 1
        if spherical_or_plane_and_lens == 0:
            # set spherical wave at the lens entrance (radius=distance)
            wf.set_spherical_wave(complex_amplitude=1.0,radius=-propagation_distance)

            propagation_elements.add_beamline_element(BeamlineElement(optical_element=WOScreen(),
                                                                      coordinates=ElementCoordinates(p=0, q=propagation_distance)))

        else:
            # apply lens that will focus at propagation_distance downstream the lens.
            # Note that the vertical is a bit defocused
            wf.set_plane_wave_from_complex_amplitude(1.0+0j)

            focal_length = propagation_distance # / 2

            propagation_elements.add_beamline_element(BeamlineElement(optical_element=
                WOIdealLens("IdealLens",focal_x=focal_length, focal_y=focal_length),
                coordinates=ElementCoordinates(p=0, q=propagation_distance)))

        print("Incident intensity: ", wf.get_intensity().sum())

        propagator = PropagationManager.Instance()
        propagation_parameters = PropagationParameters(wavefront=wf,
                                                       propagation_elements=propagation_elements)

        if method == 'fft':
            propagation_parameters.set_additional_parameters("shift_half_pixel", True)
            wf1 = propagator.do_propagation(propagation_parameters, Fresnel2D.HANDLER_NAME)
        elif method == 'convolution':
            propagation_parameters.set_additional_parameters("shift_half_pixel", True)
            wf1 = propagator.do_propagation(propagation_parameters, FresnelConvolution2D.HANDLER_NAME)
        elif method == 'fraunhofer':
            propagation_parameters.set_additional_parameters("shift_half_pixel", True)
            wf1 = propagator.do_propagation(propagation_parameters, Fraunhofer2D.HANDLER_NAME)
        elif method == 'zoom':
            propagation_parameters.set_additional_parameters("shift_half_pixel", True)
            propagation_parameters.set_additional_parameters("magnification_x", 1.5)
            propagation_parameters.set_additional_parameters("magnification_y", 2.5)
            wf1 = propagator.do_propagation(propagation_parameters, FresnelZoomXY2D.HANDLER_NAME)
        else:
            raise Exception("Not implemented method: %s"%method)

        horizontal_profile = wf1.get_intensity()[:, int(wf.size()[1]/2)]
        horizontal_profile /= horizontal_profile.max()
        print("FWHM of the horizontal profile: %g um"%(1e6*line_fwhm(horizontal_profile)*wf1.delta()[0]))
        vertical_profile = wf1.get_intensity()[int(wf1.size()[0]/2),:]
        vertical_profile /= vertical_profile.max()
        print("FWHM of the vertical profile: %g um"%(1e6*line_fwhm(vertical_profile)*wf1.delta()[1]))

        if do_plot:
            from srxraylib.plot.gol import plot,plot_image
            plot_image(wf1.get_intensity(),wf1.get_coordinate_x(),wf1.get_coordinate_y(),title='intensity (%s)'%method,show=0)
            plot_image(wf1.get_phase(),wf1.get_coordinate_x(),wf1.get_coordinate_y(),title='phase (%s)'%method,show=0)

            plot(wf1.get_coordinate_x(),horizontal_profile,
                 wf1.get_coordinate_y(),vertical_profile,
                 legend=['Horizontal profile','Vertical profile'],title="%s"%method,show=show)

        print("Output intensity: ",wf1.get_intensity().sum())
        return wf1.get_coordinate_x(),horizontal_profile
示例#26
0
    def do_wise_calculation(self):
        if self.input_data is None:
            raise Exception("No Input Data!")

        optical_element = self.get_optical_element(
            self.get_inner_wise_optical_element())

        wise_optical_element = optical_element.wise_optical_element

        wise_optical_element.CoreOptics.ComputationSettings.Ignore = (
            self.ignore == 1)

        if self.use_small_displacements == 1:
            wise_optical_element.CoreOptics.ComputationSettings.UseSmallDisplacements = True  # serve per traslare/ruotare l'EO
            wise_optical_element.CoreOptics.SmallDisplacements.Rotation = numpy.deg2rad(
                self.rotation)
            wise_optical_element.CoreOptics.SmallDisplacements.Trans = self.transverse * self.workspace_units_to_m  # Transverse displacement (rispetto al raggio uscente, magari faremo scegliere)
            wise_optical_element.CoreOptics.SmallDisplacements.Long = self.longitudinal * self.workspace_units_to_m  # Longitudinal displacement (idem)
        else:
            wise_optical_element.CoreOptics.ComputationSettings.UseSmallDisplacements = False
            wise_optical_element.CoreOptics.SmallDisplacements.Rotation = 0.0
            wise_optical_element.CoreOptics.SmallDisplacements.Trans = 0.0
            wise_optical_element.CoreOptics.SmallDisplacements.Long = 0.0

        if self.use_figure_error == 1:
            wise_optical_element.CoreOptics.ComputationSettings.UseFigureError = True

            wise_optical_element.CoreOptics.FigureErrorLoad(
                File=self.figure_error_file,
                Step=self.figure_error_step *
                self.workspace_units_to_m,  # passo del file
                AmplitudeScaling=self.figure_error_amplitude_scaling *
                self.figure_error_um_conversion  # fattore di scala
            )
        else:
            wise_optical_element.CoreOptics.ComputationSettings.UseFigureError = False

        if self.use_roughness == 1:
            self.use_roughness = 0
            self.set_UseRoughness()

            raise NotImplementedError("Roughness Not yet supported")
        else:
            wise_optical_element.CoreOptics.ComputationSettings.UseRoughness = False

        if self.calculation_type == 0:
            wise_optical_element.ComputationSettings.UseCustomSampling = False
        else:
            # l'utente decide di impostare a mano il campionamento
            wise_optical_element.ComputationSettings.UseCustomSampling = True
            wise_optical_element.ComputationSettings.NSamples = self.number_of_points

        output_data = self.input_data.duplicate()
        input_wavefront = output_data.wise_wavefront

        if output_data.wise_beamline is None:
            output_data.wise_beamline = WisePropagationElements()

        output_data.wise_beamline.add_beamline_element(
            WiseBeamlineElement(optical_element=optical_element))

        parameters = PropagationParameters(
            wavefront=input_wavefront if not input_wavefront is None else
            WiseWavefront(wise_computation_results=None),
            propagation_elements=output_data.wise_beamline)

        parameters.set_additional_parameters(
            "single_propagation",
            True if PropagationManager.Instance().get_propagation_mode(
                WISE_APPLICATION) == PropagationMode.STEP_BY_STEP else
            (not self.is_full_propagator))
        parameters.set_additional_parameters(
            "NPools", self.n_pools if self.use_multipool == 1 else 1)
        parameters.set_additional_parameters("is_full_propagator",
                                             self.is_full_propagator)

        output_data.wise_wavefront = PropagationManager.Instance(
        ).do_propagation(propagation_parameters=parameters,
                         handler_name=WisePropagator.HANDLER_NAME)

        return output_data
示例#27
0
    def test_propagate_1D_fraunhofer_phase(self, do_plot=do_plot):

        # aperture_type="square"
        # aperture_diameter = 40e-6
        # wavefront_length = 800e-6
        # wavelength = 1.24e-10
        # npoints=1024
        # propagation_distance=40
        show = 1

        aperture_type = "square"
        aperture_diameter = 40e-6
        wavefront_length = 800e-6
        wavelength = 1.24e-10
        propagation_distance = 30.0
        npoints = 1024

        print(
            "\n#                                                            ")
        print(
            "# far field 1D (fraunhofer and zoom) diffraction from a %s aperture  "
            % aperture_type)
        print("#                                                            ")

        wf = GenericWavefront1D.initialize_wavefront_from_range(
            x_min=-wavefront_length / 2,
            x_max=wavefront_length / 2,
            number_of_points=npoints,
            wavelength=wavelength)

        wf.set_plane_wave_from_complex_amplitude(
            (2.0 + 1.0j))  # an arbitraty value

        propagation_elements = PropagationElements()

        if aperture_type == 'square':
            slit = WOSlit1D(boundary_shape=Rectangle(-aperture_diameter /
                                                     2, aperture_diameter /
                                                     2, 0, 0))
        else:
            raise Exception("Not implemented! ")

        propagation_elements.add_beamline_element(
            BeamlineElement(optical_element=slit,
                            coordinates=ElementCoordinates(
                                p=0, q=propagation_distance)))

        propagator = PropagationManager.Instance()
        propagation_parameters = PropagationParameters(
            wavefront=wf, propagation_elements=propagation_elements)

        wf1_franuhofer = propagator.do_propagation(propagation_parameters,
                                                   Fraunhofer1D.HANDLER_NAME)

        propagation_parameters.set_additional_parameters(
            "shift_half_pixel", True)
        propagation_parameters.set_additional_parameters(
            "magnification_x", 1.5)
        wf1_zoom = propagator.do_propagation(propagation_parameters,
                                             FresnelZoom1D.HANDLER_NAME)

        intensity_fraunhofer = wf1_franuhofer.get_intensity(
        ) / wf1_franuhofer.get_intensity().max()
        intensity_zoom = wf1_zoom.get_intensity() / wf1_zoom.get_intensity(
        ).max()

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(
                wf1_franuhofer.get_abscissas() * 1e6 / propagation_distance,
                intensity_fraunhofer,
                wf1_zoom.get_abscissas() * 1e6 / propagation_distance,
                intensity_zoom,
                legend=["Fraunhofer", "Zoom"],
                legend_position=(0.95, 0.95),
                title=
                "1D  INTENSITY diffraction from aperture of %3.1f um at wavelength of %3.1f A"
                % (aperture_diameter * 1e6, wavelength * 1e10),
                xtitle="X (urad)",
                ytitle="Intensity",
                xrange=[-20, 20],
                show=show)
            plot(
                wf1_franuhofer.get_abscissas() * 1e6 / propagation_distance,
                wf1_franuhofer.get_phase(unwrap=1),
                wf1_zoom.get_abscissas() * 1e6 / propagation_distance,
                wf1_zoom.get_phase(unwrap=1),
                legend=["Fraunhofer", "Zoom"],
                legend_position=(0.95, 0.95),
                title=
                "1D  diffraction from a %s aperture of %3.1f um at wavelength of %3.1f A"
                % (aperture_type, aperture_diameter * 1e6, wavelength * 1e10),
                xtitle="X (urad)",
                ytitle="Intensity",
                xrange=[-20, 20],
                show=show)
示例#28
0
    def propagate_1D(
        self,
        do_plot=do_plot,
        method='fft',
        wavelength=1.24e-10,
        aperture_type='square',
        aperture_diameter=40e-6,
        wavefront_length=100e-6,
        npoints=500,
        propagation_distance=30.0,
        normalization=True,  # TODO put False
        show=1,
        amplitude=(0.0 + 1.0j)):

        print(
            "\n#                                                            ")
        print("# 1D (%s) propagation from a %s aperture  " %
              (method, aperture_type))
        print("#                                                            ")

        wf = GenericWavefront1D.initialize_wavefront_from_range(
            x_min=-wavefront_length / 2,
            x_max=wavefront_length / 2,
            number_of_points=npoints,
            wavelength=wavelength)

        wf.set_plane_wave_from_complex_amplitude(
            amplitude)  # an arbitraty value

        deltax = wf.get_abscissas()[1] - wf.get_abscissas()[0]

        propagation_elements = PropagationElements()

        slit = None

        if aperture_type == 'square':
            slit = WOSlit1D(boundary_shape=Rectangle(-aperture_diameter /
                                                     2, aperture_diameter /
                                                     2, 0, 0))
        elif aperture_type == 'gaussian':
            slit = WOGaussianSlit1D(
                boundary_shape=Rectangle(-aperture_diameter /
                                         2, aperture_diameter / 2, 0, 0))
        else:
            raise Exception(
                "Not implemented! (accepted: circle, square, gaussian)")

        propagation_elements.add_beamline_element(
            BeamlineElement(optical_element=slit,
                            coordinates=ElementCoordinates(
                                p=0, q=propagation_distance)))

        propagator = PropagationManager.Instance()
        propagation_parameters = PropagationParameters(
            wavefront=wf, propagation_elements=propagation_elements)

        print("Using propagator method:  ", method)
        fresnel_analytical = True
        if method == 'fft':
            wf1 = propagator.do_propagation(propagation_parameters,
                                            Fresnel1D.HANDLER_NAME)
        elif method == 'convolution':
            wf1 = propagator.do_propagation(propagation_parameters,
                                            FresnelConvolution1D.HANDLER_NAME)
        elif method == 'integral':
            propagation_parameters.set_additional_parameters(
                "magnification_x", 1.5)
            propagation_parameters.set_additional_parameters(
                "magnification_N", 2.0)
            wf1 = propagator.do_propagation(propagation_parameters,
                                            Integral1D.HANDLER_NAME)
        elif method == 'fraunhofer':
            fresnel_analytical = False
            # propagation_parameters.set_additional_parameters("shift_half_pixel", 0)
            wf1 = propagator.do_propagation(propagation_parameters,
                                            Fraunhofer1D.HANDLER_NAME)
        elif method == 'zoom':
            propagation_parameters.set_additional_parameters(
                "magnification_x", 1.5)
            wf1 = propagator.do_propagation(propagation_parameters,
                                            FresnelZoom1D.HANDLER_NAME)
        else:
            raise Exception("Not implemented method: %s" % method)

        if fresnel_analytical:
            xx, alpha = fresnel_analytical_rectangle(
                fresnel_number=None,
                propagation_distance=propagation_distance,
                aperture_half=0.5 * aperture_diameter,
                wavelength=wavelength,
                detector_array=wf1.get_abscissas(),
                npoints=None)
        else:
            xx, alpha = fraunhofer_analytical_rectangle(
                fresnel_number=None,
                propagation_distance=propagation_distance,
                aperture_half=0.5 * aperture_diameter,
                wavelength=wavelength,
                detector_array=wf1.get_abscissas(),
                npoints=None)

        angle_x = xx / propagation_distance
        intensity_theory = numpy.abs(amplitude * alpha)**2

        intensity_calculated = wf1.get_intensity()

        if normalization:
            intensity_calculated /= intensity_calculated.max()
            intensity_theory /= intensity_theory.max()

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(
                wf1.get_abscissas() * 1e6 / propagation_distance,
                intensity_calculated,
                angle_x * 1e6,
                intensity_theory,
                legend=["%s " % method, "analytical"],
                legend_position=(0.95, 0.95),
                title=
                "1D (%s) diffraction from a %s aperture of %3.1f um at \n wavelength of %3.1f A"
                % (method, aperture_type, aperture_diameter * 1e6,
                   wavelength * 1e10),
                xtitle="X (urad)",
                ytitle="Intensity",
                xrange=[-20, 20],
                ylog=True,
                show=show)

            plot(
                wf1.get_abscissas() * 1e6,
                wf1.get_phase(unwrap=True),
                1e6 * xx,
                numpy.unwrap(numpy.angle(alpha)),
                legend=["%s " % method, "analytical"],
                title=
                "1D (%s) diffraction from a %s aperture of %3.1f um at \n wavelength of %3.1f A NOT ASSERTED!!"
                % (method, aperture_type, aperture_diameter * 1e6,
                   wavelength * 1e10),
                xtitle="X (urad)",
                ytitle="Phase",
                # xrange=[-20, 20],
            )

        return wf1.get_abscissas(
        ) / propagation_distance, intensity_calculated, intensity_theory
示例#29
0
    def propagate(self,
                  wofry_wavefront,
                  mypropagator,
                  return_wavefront_list=False):
        from srxraylib.plot.gol import plot_image

        # plot_image(wofry_wavefront.get_intensity(),1e6*wofry_wavefront.get_coordinate_x(),1e6*wofry_wavefront.get_coordinate_y(), title="source")

        if return_wavefront_list:
            w_out = wofry_wavefront.duplicate()
            output_wavefronts = []
            output_wavefronts.append(wofry_wavefront.duplicate())

            for i in range(self.get_beamline_elements_number()):
                w_in = w_out.duplicate()

                method = 0  # 0 = old, 1=New

                if method == 1:

                    propagation_elements = PropagationElements()
                    propagation_elements.add_beamline_element(
                        beamline_element=self.get_beamline_element_at(i))

                    propagation_parameters = PropagationParameters(
                        wavefront=w_in,
                        propagation_elements=propagation_elements)
                    tmp = self.get_propagator_specific_parameters(i)

                    propagation_parameters.set_additional_parameters(
                        'shift_half_pixel', tmp['shift_half_pixel'])
                    propagation_parameters.set_additional_parameters(
                        'magnification_x', tmp['magnification_x'])
                    propagation_parameters.set_additional_parameters(
                        'magnification_y', tmp['magnification_y'])
                else:
                    propagation_elements = PropagationElements()
                    propagation_elements.add_beamline_element(
                        beamline_element=self.get_beamline_element_at(i),
                        element_parameters=self.
                        get_propagator_specific_parameters(i))
                    propagation_parameters = PropagationParameters(
                        wavefront=w_in,
                        propagation_elements=propagation_elements)

                w_out = mypropagator.do_propagation(
                    propagation_parameters=propagation_parameters,
                    handler_name=self.get_propagator_handler(i))

                # plot_image(w_out.get_intensity(),1e6*w_out.get_coordinate_x(),1e6*w_out.get_coordinate_y(),title="oe index: %d"%(i),aspect="auto")
                output_wavefronts.append(w_out)

            return output_wavefronts

        else:
            # check all handler are identical
            for i in range(self.get_beamline_elements_number()):
                assert (self.get_propagator_handler(0) ==
                        self.get_propagator_handler(i))

            propagation_elements = PropagationElements()
            for i in range(self.get_beamline_elements_number()):
                propagation_elements.add_beamline_element(
                    beamline_element=self._beamline_elements_list[i],
                    element_parameters=self.get_propagator_specific_parameters(
                        i))

            propagation_parameters = PropagationParameters(
                wavefront=wofry_wavefront.duplicate(),
                propagation_elements=propagation_elements)

            w_out = mypropagator.do_propagation(
                propagation_parameters=propagation_parameters,
                handler_name=self.get_propagator_handler(0))

            return [w_out]
示例#30
0
optical_element = WOScreen1D()

#
# propagating
#
#
propagation_elements = PropagationElements()
beamline_element = BeamlineElement(
    optical_element=optical_element,
    coordinates=ElementCoordinates(p=-100.000000,
                                   q=0.000000,
                                   angle_radial=numpy.radians(0.000000),
                                   angle_azimuthal=numpy.radians(0.000000)))
propagation_elements.add_beamline_element(beamline_element)
propagation_parameters = PropagationParameters(
    wavefront=input_wavefront.duplicate(),
    propagation_elements=propagation_elements)
propagation_parameters.set_additional_parameters('magnification_x',
                                                 0.01)  #0.010000)

#
propagator = PropagationManager.Instance()
try:
    propagator.add_propagator(FresnelZoom1D())
except:
    pass
output_wavefront = propagator.do_propagation(
    propagation_parameters=propagation_parameters,
    handler_name='FRESNEL_ZOOM_1D')

plot(output_wavefront.get_abscissas() * 1e6, output_wavefront.get_intensity())
示例#31
0
def run_whole_beamline(
        error_file_M1="/home/manuel/Oasys/dabam_profile_140327232022424.dat",
        correction_file_M3=None,
        calculate_correction=True):
    #
    # source
    #
    output_wavefront = calculate_wavefront1D(wavelength=4.9593679373280105e-09,
                                             wavefront_position=1,
                                             undulator_length=3.98,
                                             undulator_distance=13.73,
                                             x_min=-0.00147,
                                             x_max=0.00147,
                                             number_of_points=3000,
                                             add_random_phase=False)

    #
    # M1
    #
    input_wavefront = output_wavefront
    output_wavefront, abscissas_on_mirror, height = calculate_output_wavefront_after_reflector1D(
        input_wavefront,
        radius=496600.0,
        grazing_angle=0.0218,
        error_flag=1,
        error_file=error_file_M1,
        write_profile=1)

    #
    # screen at M3 position
    #

    #
    # Import section
    #
    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from syned.beamline.beamline_element import BeamlineElement
    from syned.beamline.element_coordinates import ElementCoordinates
    from wofry.propagator.propagators1D.fresnel_zoom import FresnelZoom1D

    input_wavefront = output_wavefront

    #
    # info on current oe
    #
    #
    #    -------WOScreen1D---------
    #        -------BoundaryShape---------
    #

    #
    # define current oe
    #
    from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen1D

    optical_element = WOScreen1D()

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.000000,
            q=13.599000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     2.000000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_1D')

    #
    # M3 circlular mirror
    #

    input_wavefront = output_wavefront
    output_wavefront, abscissas_on_mirror, height = calculate_output_wavefront_after_reflector1D(
        input_wavefront,
        radius=220.71532,
        grazing_angle=0.02181,
        error_flag=0,
        error_file="",
        write_profile=0)

    #
    # M3 corrector (not needed)
    #

    if calculate_correction:
        input_wavefront = output_wavefront

        output_wavefront, target_wavefront, abscissas_on_mirror, height = calculate_output_wavefront_after_corrector1D(
            input_wavefront,
            grazing_angle=0.02181,
            focus_at=2.64,
            apodization=0,
            apodization_ratio=6.0,
            write_correction_profile=1)

    # from srxraylib.plot.gol import plot
    # plot(output_wavefront.get_abscissas(),output_wavefront.get_intensity())

    if correction_file_M3 is not None:
        #
        # M3 corrector from external file
        #

        input_wavefront = output_wavefront
        output_wavefront, abscissas_on_mirror, height = calculate_output_wavefront_after_reflector1D(
            input_wavefront,
            radius=100000000.0,
            grazing_angle=0.02181,
            error_flag=1,
            error_file=correction_file_M3,
            write_profile=0)

    #
    # propagation to sample
    #

    input_wavefront = output_wavefront

    #
    # define current oe
    #
    from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen1D

    optical_element = WOScreen1D()

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.000000,
            q=2.640000,
            angle_radial=numpy.radians(0.000000),
            angle_azimuthal=numpy.radians(0.000000)))
    propagation_elements.add_beamline_element(beamline_element)
    propagation_parameters = PropagationParameters(
        wavefront=input_wavefront.duplicate(),
        propagation_elements=propagation_elements)
    # self.set_additional_parameters(propagation_parameters)
    #
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     0.020000)
    #
    propagator = PropagationManager.Instance()
    try:
        propagator.add_propagator(FresnelZoom1D())
    except:
        pass
    output_wavefront = propagator.do_propagation(
        propagation_parameters=propagation_parameters,
        handler_name='FRESNEL_ZOOM_1D')

    return output_wavefront