예제 #1
0
    def test_spherical_wave(self, do_plot=do_plot):
        #
        # plane wave
        #
        print("#                                                             ")
        print("# Tests for a 1D spherical wave                               ")
        print("#                                                             ")

        wavelength = 1.24e-10

        wavefront_length_x = 400e-6

        npixels_x = 1024

        wavefront_x = numpy.linspace(-0.5 * wavefront_length_x,
                                     0.5 * wavefront_length_x, npixels_x)

        wf1 = Wavefront1D.initialize_wavefront_from_steps(
            x_start=wavefront_x[0],
            x_step=numpy.abs(wavefront_x[1] - wavefront_x[0]),
            number_of_points=npixels_x,
            wavelength=wavelength)

        wf2 = Wavefront1D.initialize_wavefront_from_steps(
            x_start=wavefront_x[0],
            x_step=numpy.abs(wavefront_x[1] - wavefront_x[0]),
            number_of_points=npixels_x,
            wavelength=wavelength)

        # an spherical wavefront is obtained 1) by creation, 2) focusing a planewave

        wf1.set_spherical_wave(-5.0, 3 + 0j)
        wf1.apply_slit(-50e-6, 10e-6)

        wf2.set_plane_wave_from_complex_amplitude(3 + 0j)
        wf2.apply_ideal_lens(5.0)
        wf2.apply_slit(-50e-6, 10e-6)

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf1.get_abscissas(),
                 wf1.get_phase(),
                 title="Phase of spherical wavefront",
                 show=0)
            plot(wf2.get_abscissas(),
                 wf2.get_phase(),
                 title="Phase of focused plane wavefront",
                 show=0)
            plot(wf1.get_abscissas(),
                 wf1.get_phase(from_minimum_intensity=0.1),
                 title="Phase of spherical wavefront (for intensity > 0.1)",
                 show=0)
            plot(
                wf2.get_abscissas(),
                wf2.get_phase(from_minimum_intensity=0.1),
                title="Phase of focused plane wavefront (for intensity > 0.1)",
                show=1)

        numpy.testing.assert_almost_equal(wf1.get_phase(), wf2.get_phase(), 5)
예제 #2
0
    def test_initializers(self,do_plot=do_plot):

        print("#                                                             ")
        print("# Tests for initializars (1D)                                 ")
        print("#                                                             ")

        x = numpy.linspace(-100,100,50)
        y = numpy.abs(x)**1.5 +  1j*numpy.abs(x)**1.8



        wf0 = Wavefront1D.initialize_wavefront_from_steps(x[0],numpy.abs(x[1]-x[0]),y.size)
        wf0.set_complex_amplitude(y)

        wf1 = Wavefront1D.initialize_wavefront_from_range(x[0],x[-1],y.size)
        wf1.set_complex_amplitude(y)

        wf2 = Wavefront1D.initialize_wavefront_from_arrays(x,y)

        print("wavefront sizes: ",wf1.size(),wf1.size(),wf2.size())

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf0.get_abscissas(),wf0.get_intensity(),
                       title="initialize_wavefront_from_steps",show=0)
            plot(wf1.get_abscissas(),wf1.get_intensity(),
                       title="initialize_wavefront_from_range",show=0)
            plot(wf2.get_abscissas(),wf2.get_intensity(),
                       title="initialize_wavefront_from_arrays",show=1)

        numpy.testing.assert_almost_equal(wf0.get_intensity(),numpy.abs(y)**2,5)
        numpy.testing.assert_almost_equal(wf1.get_intensity(),numpy.abs(y)**2,5)

        numpy.testing.assert_almost_equal(x,wf1.get_abscissas(),11)
        numpy.testing.assert_almost_equal(x,wf2.get_abscissas(),11)
예제 #3
0
    def test_spherical_wave(self,do_plot=do_plot):
        #
        # plane wave
        #
        print("#                                                             ")
        print("# Tests for a 1D spherical wave                               ")
        print("#                                                             ")

        wavelength        = 1.24e-10

        wavefront_length_x = 400e-6

        npixels_x =  1024

        wavefront_x = numpy.linspace(-0.5*wavefront_length_x,0.5*wavefront_length_x,npixels_x)



        wf1 = Wavefront1D.initialize_wavefront_from_steps(
                        x_start=wavefront_x[0],x_step=numpy.abs(wavefront_x[1]-wavefront_x[0]),
                        number_of_points=npixels_x,wavelength=wavelength)

        wf2 = Wavefront1D.initialize_wavefront_from_steps(
                        x_start=wavefront_x[0],x_step=numpy.abs(wavefront_x[1]-wavefront_x[0]),
                        number_of_points=npixels_x,wavelength=wavelength)

        # an spherical wavefront is obtained 1) by creation, 2) focusing a planewave

        wf1.set_spherical_wave(-5.0, 3+0j)
        wf1.apply_slit(-50e-6,10e-6)

        wf2.set_plane_wave_from_complex_amplitude(3+0j)
        wf2.apply_ideal_lens(5.0)
        wf2.apply_slit(-50e-6,10e-6)



        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf1.get_abscissas(),wf1.get_phase(),title="Phase of spherical wavefront",show=0)
            plot(wf2.get_abscissas(),wf2.get_phase(),title="Phase of focused plane wavefront",show=0)
            plot(wf1.get_abscissas(),wf1.get_phase(from_minimum_intensity=0.1),title="Phase of spherical wavefront (for intensity > 0.1)",show=0)
            plot(wf2.get_abscissas(),wf2.get_phase(from_minimum_intensity=0.1),title="Phase of focused plane wavefront (for intensity > 0.1)",show=1)


        numpy.testing.assert_almost_equal(wf1.get_phase(),wf2.get_phase(),5)
예제 #4
0
    def test_plane_wave(self,do_plot=do_plot):
        #
        # plane wave
        #
        print("#                                                             ")
        print("# Tests for a 1D plane wave                                   ")
        print("#                                                             ")

        wavelength        = 1.24e-10

        wavefront_length_x = 400e-6

        npixels_x =  1024

        wavefront_x = numpy.linspace(-0.5*wavefront_length_x,0.5*wavefront_length_x,npixels_x)


        wavefront = Wavefront1D.initialize_wavefront_from_steps(
                        x_start=wavefront_x[0],x_step=numpy.abs(wavefront_x[1]-wavefront_x[0]),
                        number_of_points=npixels_x,wavelength=wavelength)

        numpy.testing.assert_almost_equal(wavefront_x,wavefront.get_abscissas(),9)

        # possible modifications

        wavefront.set_plane_wave_from_amplitude_and_phase(5.0,numpy.pi/2)
        numpy.testing.assert_almost_equal(wavefront.get_intensity(),25,5)

        wavefront.set_plane_wave_from_complex_amplitude(2.0+3j)
        numpy.testing.assert_almost_equal(wavefront.get_intensity(),13,5)

        phase_before = wavefront.get_phase()
        wavefront.add_phase_shift(numpy.pi/2)
        phase_after = wavefront.get_phase()
        numpy.testing.assert_almost_equal(phase_before+numpy.pi/2,phase_after,5)

        intensity_before = wavefront.get_intensity()
        wavefront.rescale_amplitude(10.0)
        intensity_after = wavefront.get_intensity()
        numpy.testing.assert_almost_equal(intensity_before*100,intensity_after,5)

        # interpolation

        wavefront.set_plane_wave_from_complex_amplitude(2.0+3j)
        test_value1 = wavefront.get_interpolated_complex_amplitude(0.01)
        self.assertAlmostEqual( (2.0+3j).real, test_value1.real, 5)
        self.assertAlmostEqual( (2.0+3j).imag, test_value1.imag, 5)


        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wavefront.get_abscissas(),wavefront.get_intensity(),title="Intensity (plane wave)",show=0)
            plot(wavefront.get_abscissas(),wavefront.get_phase(),title="Phase (plane wave)",show=1)
예제 #5
0
    def test_interpolator(self, do_plot=do_plot):
        #
        # interpolator
        #
        print("#                                                             ")
        print("# Tests for 1D interpolator                                   ")
        print("#                                                             ")

        x = numpy.linspace(-10, 10, 100)

        sigma = 3.0
        Z = numpy.exp(-1.0 * x**2 / 2 / sigma**2)

        print("shape of Z", Z.shape)

        wf = Wavefront1D.initialize_wavefront_from_steps(x[0],
                                                         numpy.abs(x[1] -
                                                                   x[0]),
                                                         number_of_points=100)
        print("wf shape: ", wf.size())
        wf.set_complex_amplitude(Z)

        x1 = 3.2
        z1 = numpy.exp(x1**2 / -2 / sigma**2)
        print("complex ampl at (%g): %g+%gi (exact=%g)" %
              (x1, wf.get_interpolated_complex_amplitude(x1).real,
               wf.get_interpolated_complex_amplitude(x1).imag, z1))
        self.assertAlmostEqual(
            wf.get_interpolated_complex_amplitude(x1).real, z1, 4)

        print("intensity  at (%g):   %g (exact=%g)" %
              (x1, wf.get_interpolated_intensity(x1), z1**2))
        self.assertAlmostEqual(wf.get_interpolated_intensity(x1), z1**2, 4)

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf.get_abscissas(),
                 wf.get_intensity(),
                 title="Original",
                 show=1)
            xx = wf.get_abscissas()
            yy = wf.get_interpolated_intensities(wf.get_abscissas() - 1e-5)
            plot(xx, yy, title="interpolated on same grid", show=1)
예제 #6
0
    def test_initializers(self, do_plot=do_plot):

        print("#                                                             ")
        print("# Tests for initializars (1D)                                 ")
        print("#                                                             ")

        x = numpy.linspace(-100, 100, 50)
        y = numpy.abs(x)**1.5 + 1j * numpy.abs(x)**1.8

        wf0 = Wavefront1D.initialize_wavefront_from_steps(
            x[0], numpy.abs(x[1] - x[0]), y.size)
        wf0.set_complex_amplitude(y)

        wf1 = Wavefront1D.initialize_wavefront_from_range(x[0], x[-1], y.size)
        wf1.set_complex_amplitude(y)

        wf2 = Wavefront1D.initialize_wavefront_from_arrays(x, y)

        print("wavefront sizes: ", wf1.size(), wf1.size(), wf2.size())

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf0.get_abscissas(),
                 wf0.get_intensity(),
                 title="initialize_wavefront_from_steps",
                 show=0)
            plot(wf1.get_abscissas(),
                 wf1.get_intensity(),
                 title="initialize_wavefront_from_range",
                 show=0)
            plot(wf2.get_abscissas(),
                 wf2.get_intensity(),
                 title="initialize_wavefront_from_arrays",
                 show=1)

        numpy.testing.assert_almost_equal(wf0.get_intensity(),
                                          numpy.abs(y)**2, 5)
        numpy.testing.assert_almost_equal(wf1.get_intensity(),
                                          numpy.abs(y)**2, 5)

        numpy.testing.assert_almost_equal(x, wf1.get_abscissas(), 11)
        numpy.testing.assert_almost_equal(x, wf2.get_abscissas(), 11)
예제 #7
0
    def test_interpolator(self,do_plot=do_plot):
        #
        # interpolator
        #
        print("#                                                             ")
        print("# Tests for 1D interpolator                                   ")
        print("#                                                             ")

        x = numpy.linspace(-10,10,100)

        sigma = 3.0
        Z = numpy.exp(-1.0*x**2/2/sigma**2)

        print("shape of Z",Z.shape)

        wf = Wavefront1D.initialize_wavefront_from_steps(x[0],numpy.abs(x[1]-x[0]),number_of_points=100)
        print("wf shape: ",wf.size())
        wf.set_complex_amplitude( Z )

        x1 = 3.2
        z1 = numpy.exp(x1**2/-2/sigma**2)
        print("complex ampl at (%g): %g+%gi (exact=%g)"%(x1,
                                                        wf.get_interpolated_complex_amplitude(x1).real,
                                                        wf.get_interpolated_complex_amplitude(x1).imag,
                                                        z1))
        self.assertAlmostEqual(wf.get_interpolated_complex_amplitude(x1).real,z1,4)

        print("intensity  at (%g):   %g (exact=%g)"%(x1,wf.get_interpolated_intensity(x1),z1**2))
        self.assertAlmostEqual(wf.get_interpolated_intensity(x1),z1**2,4)


        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wf.get_abscissas(),wf.get_intensity(),title="Original",show=1)
            xx = wf.get_abscissas()
            yy = wf.get_interpolated_intensities(wf.get_abscissas()-1e-5)
            plot(xx,yy,title="interpolated on same grid",show=1)
예제 #8
0
    def test_plane_wave(self, do_plot=do_plot):
        #
        # plane wave
        #
        print("#                                                             ")
        print("# Tests for a 1D plane wave                                   ")
        print("#                                                             ")

        wavelength = 1.24e-10

        wavefront_length_x = 400e-6

        npixels_x = 1024

        wavefront_x = numpy.linspace(-0.5 * wavefront_length_x,
                                     0.5 * wavefront_length_x, npixels_x)

        wavefront = Wavefront1D.initialize_wavefront_from_steps(
            x_start=wavefront_x[0],
            x_step=numpy.abs(wavefront_x[1] - wavefront_x[0]),
            number_of_points=npixels_x,
            wavelength=wavelength)

        numpy.testing.assert_almost_equal(wavefront_x,
                                          wavefront.get_abscissas(), 9)

        # possible modifications

        wavefront.set_plane_wave_from_amplitude_and_phase(5.0, numpy.pi / 2)
        numpy.testing.assert_almost_equal(wavefront.get_intensity(), 25, 5)

        wavefront.set_plane_wave_from_complex_amplitude(2.0 + 3j)
        numpy.testing.assert_almost_equal(wavefront.get_intensity(), 13, 5)

        phase_before = wavefront.get_phase()
        wavefront.add_phase_shift(numpy.pi / 2)
        phase_after = wavefront.get_phase()
        numpy.testing.assert_almost_equal(phase_before + numpy.pi / 2,
                                          phase_after, 5)

        intensity_before = wavefront.get_intensity()
        wavefront.rescale_amplitude(10.0)
        intensity_after = wavefront.get_intensity()
        numpy.testing.assert_almost_equal(intensity_before * 100,
                                          intensity_after, 5)

        # interpolation

        wavefront.set_plane_wave_from_complex_amplitude(2.0 + 3j)
        test_value1 = wavefront.get_interpolated_complex_amplitude(0.01)
        self.assertAlmostEqual((2.0 + 3j).real, test_value1.real, 5)
        self.assertAlmostEqual((2.0 + 3j).imag, test_value1.imag, 5)

        if do_plot:
            from srxraylib.plot.gol import plot
            plot(wavefront.get_abscissas(),
                 wavefront.get_intensity(),
                 title="Intensity (plane wave)",
                 show=0)
            plot(wavefront.get_abscissas(),
                 wavefront.get_phase(),
                 title="Phase (plane wave)",
                 show=1)