Beispiel #1
0
    def test_source(self):

        print("\n#\n# SRW hdf5 test write/load source\n#\n")

        wfr = self.create_source()

        save_wfr_2_hdf5(wfr,
                        "tmp1.h5",
                        intensity=True,
                        phase=True,
                        overwrite=True)

        wfr_loaded = load_hdf5_2_wfr("tmp1.h5", "wfr")

        save_wfr_2_hdf5(wfr_loaded,
                        "tmp2.h5",
                        intensity=True,
                        phase=True,
                        overwrite=True)

        wf1 = load_hdf5_2_dictionary("tmp1.h5", "wfr")
        wf2 = load_hdf5_2_dictionary("tmp2.h5", "wfr")
        print("comparing wavefront at source")
        for key in wf1.keys():
            print("   checking field: ", key)
            numpy.testing.assert_almost_equal(wf1[key], wf2[key])

        os.remove("tmp1.h5")
        os.remove("tmp2.h5")
Beispiel #2
0
    def test_propagation(self):

        # calculate:
        wfr = self.create_source()

        save_wfr_2_hdf5(wfr,
                        "tmp3.h5",
                        intensity=True,
                        phase=True,
                        overwrite=True)

        wfr_end = self.propagate_beamline(wfr)

        save_wfr_2_hdf5(wfr_end,
                        "tmp3.h5",
                        intensity=True,
                        phase=False,
                        overwrite=False,
                        subgroupname="wfr_end")

        # load:
        wfr_loaded = load_hdf5_2_wfr("tmp3.h5", "wfr")

        save_wfr_2_hdf5(wfr_loaded,
                        "tmp3bis.h5",
                        intensity=True,
                        phase=False,
                        overwrite=True)

        wfr_end2 = self.propagate_beamline(wfr_loaded)

        save_wfr_2_hdf5(wfr_end2,
                        "tmp3bis.h5",
                        intensity=True,
                        phase=True,
                        overwrite=False,
                        subgroupname="wfr_end")

        wf1_source = load_hdf5_2_dictionary("tmp3.h5", "wfr")
        wf2_source = load_hdf5_2_dictionary("tmp3bis.h5", "wfr")
        print("comparing wavefront at source")
        for key in wf1_source.keys():
            print("   checking field: ", key)
            numpy.testing.assert_almost_equal(wf1_source[key], wf2_source[key])

        wf1_end = load_hdf5_2_dictionary("tmp3.h5", "wfr_end")
        wf2_end = load_hdf5_2_dictionary("tmp3bis.h5", "wfr_end")
        print("comparing wavefront propagated")
        for key in wf1_source.keys():
            print("   checking field: ", key)
            numpy.testing.assert_almost_equal(1e-6 * wf1_end[key],
                                              1e-6 * wf2_end[key], 1)

        os.remove("tmp3.h5")
        os.remove("tmp3bis.h5")
Beispiel #3
0
        save_wfr_2_hdf5(wfr_loaded,
                        "tmp2bis.h5",
                        intensity=True,
                        phase=False,
                        overwrite=True)

        wfr_end2 = propagate_beamline(wfr_loaded, do_plots=False)

        save_wfr_2_hdf5(wfr_end2,
                        "tmp2bis.h5",
                        intensity=True,
                        phase=True,
                        overwrite=False,
                        subgroupname="wfr_end")

    if do_compare:
        wf1_source = load_hdf5_2_dictionary("tmp2.h5", "wfr")
        wf2_source = load_hdf5_2_dictionary("tmp2bis.h5", "wfr")
        print("comparing wavefront at source")
        for key in wf1_source.keys():
            print("   checking field: ", key)
            numpy.testing.assert_almost_equal(wf1_source[key], wf2_source[key])

        wf1_end = load_hdf5_2_dictionary("tmp2.h5", "wfr_end")
        wf2_end = load_hdf5_2_dictionary("tmp2bis.h5", "wfr_end")
        print("comparing wavefront propagated")
        for key in wf1_source.keys():
            print("   checking field: ", key)
            numpy.testing.assert_almost_equal(1e-6 * wf1_end[key],
                                              1e-6 * wf2_end[key], 1)