Exemple #1
0
    def test_save_load_h5_file(self):

        wfr = GenericWavefront2D.initialize_wavefront_from_range(
            -0.004, 0.004, -0.001, 0.001, (500, 200))
        wfr.set_gaussian(0.002 / 6, 0.001 / 12)
        wfr.save_h5_file("tmp_wofry.h5",
                         subgroupname="wfr",
                         intensity=True,
                         phase=True,
                         overwrite=True)

        wfr.set_gaussian(0.002 / 6 / 2, 0.001 / 12 / 2)
        print("Writing file: tmp_wofry.h5")
        wfr.save_h5_file("tmp_wofry.h5",
                         subgroupname="wfr2",
                         intensity=True,
                         phase=False,
                         overwrite=False)

        # test same amplitudes:
        print("Accessing file, path: ", "tmp_wofry.h5", "wfr2")
        wfr2 = GenericWavefront2D.load_h5_file("tmp_wofry.h5", "wfr2")
        print("Cleaning file tmp_wofry.h5")
        os.remove("tmp_wofry.h5")
        assert (wfr2.is_identical(wfr))
if __name__ == "__main__":

    from json_tools import load_from_json_file
    from wofry.propagator.wavefront2D.generic_wavefront import GenericWavefront2D
    from srxraylib.plot.gol import plot_image

    from wofry.propagator.propagator import PropagationManager, PropagationElements, PropagationParameters
    from wofryimpl.propagator.propagators2D.fresnel_zoom_xy import FresnelZoomXY2D

    wfr = GenericWavefront2D.load_h5_file("source.h5", "wfr")
    plot_image(wfr.get_intensity(),
               1e6 * wfr.get_coordinate_x(),
               1e6 * wfr.get_coordinate_y(),
               title="Source",
               xtitle="X [um]",
               ytitle="Y [um]")

    bl = load_from_json_file("beamline.json")

    #
    # propagate elements using Fresnel Zoom propagator
    #
    magnification_x = [1, 1, 0.01, 440, 1, 1, 1, 0.00007]
    magnification_y = [1, 1, 1, 5, 1, 0.5, 1, 0.00009]

    # define propagator to be used
    propagator = PropagationManager.Instance()

    try:
        propagator.add_propagator(FresnelZoomXY2D())
    except:
Exemple #3
0
                   wfr.get_coordinate_y(),
                   title="PHI in rads")

    wfr2 = wfr.duplicate()

    wfr2.add_phase_shifts(PHI, polarization=Polarization.SIGMA)
    wfr2.add_phase_shifts(PHI, polarization=Polarization.PI)

    return wfr2


if __name__ == "__main__":
    from srxraylib.plot.gol import plot, plot_image, set_qt
    #
    file_name = "/home/manuel/Oasys/tmp.h5"
    wfr = GenericWavefront2D.load_h5_file(file_name, "wfr")

    phase = wfr.get_phase(polarization=Polarization.SIGMA)
    plot_image(phase,
               wfr.get_coordinate_x(),
               wfr.get_coordinate_y(),
               title="before",
               show=False)

    wfr2 = generic_wfr_add_grating_error(wfr, "LEG_300 l_mm.txt", do_plot=True)

    phase2 = wfr2.get_phase(polarization=Polarization.SIGMA)
    plot_image(phase2,
               wfr2.get_coordinate_x(),
               wfr2.get_coordinate_y(),
               title="after")
Exemple #4
0
def run_wofry():
    #
    # create/import your input_wavefront (THIS IS A PLACEHOLDER - REPLACE WITH YOUR SOURCE)
    #
    #
    from wofry.propagator.wavefront2D.generic_wavefront import GenericWavefront2D
    input_wavefront = GenericWavefront2D.load_h5_file(
        "/users/srio/Working/paper-hierarchical/WORKSPACES/tmp.h5", "wfr")
    # initialize_wavefront_from_range(-10e-6,10e-6,-100e-6,100e-6,(200,100),1e-10)

    #
    # info on current oe
    #
    #
    #    -------WOScreen---------
    #        -------BoundaryShape---------
    #

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

    optical_element = WOScreen()

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=0.000000,
            q=28.300000,
            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',
                                                     8.000000)
    propagation_parameters.set_additional_parameters('magnification_y',
                                                     10.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')

    input_wavefront = output_wavefront

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

    #
    # define current oe
    #
    from syned.beamline.shape import Rectangle
    boundary_shape = Rectangle(x_left=-0.0018849,
                               x_right=0.0018849,
                               y_bottom=-0.0018849,
                               y_top=0.0018849)

    from wofry.beamline.optical_elements.absorbers.slit import WOSlit
    optical_element = WOSlit(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)
    #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')

    input_wavefront = output_wavefront

    #
    # info on current oe
    #
    #
    #    -------WOIdealLens---------
    #        focal_x: 8.319 m # Focal length in x [horizontal]
    #        focal_y: 99999999999999.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=8.319000,
                                  focal_y=99999999999999.000000)

    #
    # 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('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')

    input_wavefront = output_wavefront

    #
    # info on current oe
    #
    #
    #    -------WOSlit---------
    #        -------Rectangle---------
    #        x_left: -2.5e-05 m # x (width) minimum (signed)
    #        x_right: 2.5e-05 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=-2.5e-05,
                               x_right=2.5e-05,
                               y_bottom=-0.5,
                               y_top=0.5)

    from wofry.beamline.optical_elements.absorbers.slit import WOSlit
    optical_element = WOSlit(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('shift_half_pixel', 1)
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     0.010000)
    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')

    input_wavefront = output_wavefront

    #
    #
    # #########################   KB  #########################################
    #
    #

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

    #
    # define current oe
    #
    from syned.beamline.shape import Rectangle
    boundary_shape = Rectangle(x_left=-0.025,
                               x_right=0.025,
                               y_bottom=-0.00045,
                               y_top=0.00045)

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

    #
    # propagating (***  ONLY THE ZOOM PROPAGATOR IS IMPLEMENTED ***)
    #
    #
    propagation_elements = PropagationElements()
    beamline_element = BeamlineElement(
        optical_element=optical_element,
        coordinates=ElementCoordinates(
            p=144.900000,
            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',
                                                     440.000000)
    propagation_parameters.set_additional_parameters('magnification_y',
                                                     5.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')

    input_wavefront = output_wavefront

    #
    # info on current oe
    #
    #
    #    -------WOIdealLens---------
    #        focal_x: 100000000.0 m # Focal length in x [horizontal]
    #        focal_y: 0.09994594594594594 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=100000000.000000,
                                  focal_y=0.099946)

    #
    # 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('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')

    input_wavefront = output_wavefront

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

    #
    # define current oe
    #
    from syned.beamline.shape import Rectangle
    boundary_shape = Rectangle(x_left=-0.000195,
                               x_right=0.000195,
                               y_bottom=-0.0065,
                               y_top=0.0065)

    from wofry.beamline.optical_elements.absorbers.slit import WOSlit
    optical_element = WOSlit(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('shift_half_pixel', 1)
    propagation_parameters.set_additional_parameters('magnification_x',
                                                     1.000000)
    propagation_parameters.set_additional_parameters('magnification_y',
                                                     0.500000)
    #
    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')

    input_wavefront = output_wavefront

    #
    # 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 (***  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('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')

    input_wavefront = output_wavefront

    #
    # 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.5,
                               x_right=0.5,
                               y_bottom=-0.5,
                               y_top=0.5)

    from wofry.beamline.optical_elements.absorbers.slit import WOSlit
    optical_element = WOSlit(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('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')

    input_wavefront = output_wavefront

    return input_wavefront