示例#1
0
 def read(self, index):
     #as_array = list()
     # filename = self._file.replace(".npz", "") + str(index)+".wfs.npz"
     # srio
     filename = self._file.replace(".npz", "_") + "%04d"%(index)+".wfs.npz"
     #for i in range(3):
     #    as_array.append(np.load(filename))
     #wavefront = NumpyWavefront.fromNumpyArray(as_array[0], as_array[1], as_array[2])
     wavefront = NumpyWavefront.load(filename)
     return wavefront
示例#2
0
def propagateWavefrontWofry(beamline,
                            wavefront,
                            i_mode,
                            python_to_be_used="python",
                            keep_temp_files=False):

    s_id = str(mpi.COMM_WORLD.Get_rank()) + "_" + gethostname()

    wavefront.save("./tmp/tmp%s_in" % s_id)

    parameter_lines = "s_id=\"%s\"" % (s_id)
    pickle.dump(beamline, open("./tmp/tmp%s_beamline.p" % s_id, "wb"))
    lines = """
import pickle
from wofry.propagator.propagator import PropagationManager
from wofry.propagator.propagators2D.fresnel_zoom_xy import FresnelZoomXY2D
from comsyl.waveoptics.ComsylWofryBeamline import ComsylWofryBeamline

# initialize propagator
mypropagator = PropagationManager.Instance()
try:
    mypropagator.add_propagator(FresnelZoomXY2D())
except:
    print("May be you alreay initialized propagator and stored FresnelZoomXY2D")

beamline = pickle.load(open("./tmp/tmp%s_beamline.p"%s_id,"rb"))

ComsylWofryBeamline.propagate_numpy_wavefront(
    "./tmp/tmp%s_in.npz"%s_id,
    "./tmp/tmp%s_out.npz"%s_id,
    beamline,mypropagator)
"""

    file = open("./tmp/tmp%s.py" % s_id, "w")
    file.writelines(parameter_lines)
    file.writelines("\ni_mode=%d\n" % i_mode)  # added srio
    file.writelines(lines)
    file.close()

    os.system(python_to_be_used + " ./tmp/tmp%s.py" % s_id)
    if keep_temp_files:  # keep a copy of all files
        logAll("cp %s  %s" %
               ("./tmp/tmp%s_in.npz" % s_id, "./tmp/tmp%s_in_mode%d.npz" %
                (s_id, i_mode)))
        logAll("cp %s  %s" %
               ("./tmp/tmp%s_out.npz" % s_id, "./tmp/tmp%s_out_mode%d.npz" %
                (s_id, i_mode)))
        os.system("cp %s  %s" %
                  ("./tmp/tmp%s_in.npz" % s_id, "./tmp/tmp%s_in_mode%d.npz" %
                   (s_id, i_mode)))
        os.system("cp %s  %s" %
                  ("./tmp/tmp%s_out.npz" % s_id, "./tmp/tmp%s_out_mode%d.npz" %
                   (s_id, i_mode)))

    return NumpyWavefront.load("./tmp/tmp%s_out.npz" % s_id)
示例#3
0
def propagateWavefront(srw_beamline,
                       wavefront,
                       rx,
                       drx,
                       ry,
                       dry,
                       rescale_x,
                       rescale_y,
                       i_mode,
                       python_to_be_used="python"):
    if isMaster():
        if not os.path.exists("tmp"):
            os.mkdir("tmp")

    s_id = str(mpi.COMM_WORLD.Get_rank()) + "_" + gethostname()
    wavefront.save("./tmp/tmp%s_in" % s_id)

    parameter_lines = "rx=%f\ndrx=%f\nry=%f\ndry=%f\nrescale_x=%f\nrescale_y=%f\ns_id=\"%s\"" % (
        rx, drx, ry, dry, rescale_x, rescale_y, s_id)
    pickle.dump(srw_beamline, open("./tmp/tmp%s_beamline.p" % s_id, "wb"))
    lines = """
import pickle
from srwlib import *
from comsyl.waveoptics.SRWAdapter import SRWAdapter
from comsyl.waveoptics.Wavefront import NumpyWavefront, SRWWavefront

wavefront = NumpyWavefront.load("./tmp/tmp%s_in.npz"%s_id)
adapter = SRWAdapter()
wfr = adapter.SRWWavefrontFromWavefront(wavefront,
                                        rx,
                                        drx,
                                        ry,
                                        dry,rescale_x,rescale_y)
#print("Doing propagation in external call")
srw_beamline = pickle.load(open("./tmp/tmp%s_beamline.p"%s_id,"rb"))
srwl.PropagElecField(wfr, srw_beamline)

tmp = SRWWavefront(wfr).toNumpyWavefront()
wfr = None
tmp.save("./tmp/tmp%s_out" % s_id)
"""

    file = open("./tmp/tmp%s.py" % s_id, "w")
    file.writelines(parameter_lines)
    file.writelines("\ni_mode=%d\n" % i_mode)  # added srio
    file.writelines(lines)
    file.close()

    os.system(python_to_be_used + " ./tmp/tmp%s.py" % s_id)

    return NumpyWavefront.load("./tmp/tmp%s_out.npz" % s_id)
def propagateWavefrontWofry(beamline, wavefront, i_mode, python_to_be_used="python", keep_temp_files=False):

    s_id=str(mpi.COMM_WORLD.Get_rank())+"_"+gethostname()

    wavefront.save("./tmp/tmp%s_in"%s_id)

    parameter_lines = "s_id=\"%s\"" % (s_id)
    pickle.dump(beamline, open("./tmp/tmp%s_beamline.p"%s_id,"wb"))
    lines ="""
import pickle
from wofry.propagator.propagator import PropagationManager
from wofry.propagator.propagators2D.fresnel_zoom_xy import FresnelZoomXY2D
from comsyl.waveoptics.ComsylWofryBeamline import ComsylWofryBeamline

# initialize propagator
mypropagator = PropagationManager.Instance()
try:
    mypropagator.add_propagator(FresnelZoomXY2D())
except:
    print("May be you alreay initialized propagator and stored FresnelZoomXY2D")

beamline = pickle.load(open("./tmp/tmp%s_beamline.p"%s_id,"rb"))

ComsylWofryBeamline.propagate_numpy_wavefront(
    "./tmp/tmp%s_in.npz"%s_id,
    "./tmp/tmp%s_out.npz"%s_id,
    beamline,mypropagator)
"""

    file = open("./tmp/tmp%s.py"%s_id, "w")
    file.writelines(parameter_lines)
    file.writelines("\ni_mode=%d\n"%i_mode) # added srio
    file.writelines(lines)
    file.close()

    os.system(python_to_be_used+" ./tmp/tmp%s.py"%s_id)
    if keep_temp_files: # keep a copy of all files
        logAll("cp %s  %s" % ("./tmp/tmp%s_in.npz" % s_id,   "./tmp/tmp%s_in_mode%d.npz" % (s_id, i_mode)))
        logAll("cp %s  %s" % ("./tmp/tmp%s_out.npz" % s_id, "./tmp/tmp%s_out_mode%d.npz" % (s_id, i_mode)))
        os.system("cp %s  %s" % ("./tmp/tmp%s_in.npz" % s_id,  "./tmp/tmp%s_in_mode%d.npz" % (s_id, i_mode)))
        os.system("cp %s  %s" % ("./tmp/tmp%s_out.npz" % s_id, "./tmp/tmp%s_out_mode%d.npz" % (s_id, i_mode)))

    return NumpyWavefront.load("./tmp/tmp%s_out.npz"%s_id)
def propagateWavefront(srw_beamline, wavefront, rx, drx, ry, dry, rescale_x, rescale_y, i_mode, python_to_be_used="python"):
    if isMaster():
        if not os.path.exists("tmp"):
            os.mkdir("tmp")

    s_id=str(mpi.COMM_WORLD.Get_rank())+"_"+gethostname()
    wavefront.save("./tmp/tmp%s_in"%s_id)

    parameter_lines = "rx=%f\ndrx=%f\nry=%f\ndry=%f\nrescale_x=%f\nrescale_y=%f\ns_id=\"%s\"" % (rx, drx, ry, dry, rescale_x, rescale_y, s_id)
    pickle.dump(srw_beamline, open("./tmp/tmp%s_beamline.p"%s_id,"wb"))
    lines ="""
import pickle
from srwlib import *
from comsyl.waveoptics.SRWAdapter import SRWAdapter
from comsyl.waveoptics.Wavefront import NumpyWavefront, SRWWavefront

wavefront = NumpyWavefront.load("./tmp/tmp%s_in.npz"%s_id)
adapter = SRWAdapter()
wfr = adapter.SRWWavefrontFromWavefront(wavefront,
                                        rx,
                                        drx,
                                        ry,
                                        dry,rescale_x,rescale_y)
#print("Doing propagation in external call")
srw_beamline = pickle.load(open("./tmp/tmp%s_beamline.p"%s_id,"rb"))
srwl.PropagElecField(wfr, srw_beamline)

tmp = SRWWavefront(wfr).toNumpyWavefront()
wfr = None
tmp.save("./tmp/tmp%s_out" % s_id)
"""

    file = open("./tmp/tmp%s.py"%s_id, "w")
    file.writelines(parameter_lines)
    file.writelines("\ni_mode=%d\n"%i_mode) # added srio
    file.writelines(lines)
    file.close()

    os.system(python_to_be_used+" ./tmp/tmp%s.py"%s_id)

    return NumpyWavefront.load("./tmp/tmp%s_out.npz"%s_id)
示例#6
0
    #
    # # just to test
    # a = ComsylWofryBeamline.initialize_from_lists(
    #     list_with_syned_optical_elements=[WOScreen(),WOScreen(),WOScreen()],
    #     list_with_syned_coordinates=[
    #                 ElementCoordinates(p=0.0, q=28.3, angle_radial=0.0, angle_azimuthal=0.0),
    #                 ElementCoordinates(p=0.0, q=28.3, angle_radial=0.0, angle_azimuthal=0.0),
    #                 ElementCoordinates(p=0.0, q=28.3, angle_radial=0.0, angle_azimuthal=0.0),],
    #     list_with_wofry_propagator_handlers=['FRESNEL_ZOOM_XY_2D','FRESNEL_ZOOM_XY_2D','FRESNEL_ZOOM_XY_2D',],
    #     list_with_wofry_propagator_specific_parameters=[
    #                 {'shift_half_pixel': 1, 'magnification_x': 8.0, 'magnification_y': 8.0},
    #                 {'shift_half_pixel': 1, 'magnification_x': 8.0, 'magnification_y': 8.0},
    #                 {'shift_half_pixel': 1, 'magnification_x': 8.0, 'magnification_y': 8.0},])
    #
    #
    # print(a.info())
    #
    # print(a.to_json())

    bl = ComsylWofryBeamline.load_pickle(
        "/users/srio/Working/paper-hierarchical/CODE-COMSYL/tmp/tmp0_chac_beamline.p"
    )
    print(bl.info())

    from comsyl.waveoptics.Wavefront import NumpyWavefront

    w0 = NumpyWavefront.load(
        "/users/srio/Working/paper-hierarchical/CODE-COMSYL/tmp/tmp0_chac_in.npz"
    )
    print(w0)
示例#7
0
    # from wofry.beamline.optical_elements.ideal_elements.screen import WOScreen
    #
    #
    # # just to test
    # a = ComsylWofryBeamline.initialize_from_lists(
    #     list_with_syned_optical_elements=[WOScreen(),WOScreen(),WOScreen()],
    #     list_with_syned_coordinates=[
    #                 ElementCoordinates(p=0.0, q=28.3, angle_radial=0.0, angle_azimuthal=0.0),
    #                 ElementCoordinates(p=0.0, q=28.3, angle_radial=0.0, angle_azimuthal=0.0),
    #                 ElementCoordinates(p=0.0, q=28.3, angle_radial=0.0, angle_azimuthal=0.0),],
    #     list_with_wofry_propagator_handlers=['FRESNEL_ZOOM_XY_2D','FRESNEL_ZOOM_XY_2D','FRESNEL_ZOOM_XY_2D',],
    #     list_with_wofry_propagator_specific_parameters=[
    #                 {'shift_half_pixel': 1, 'magnification_x': 8.0, 'magnification_y': 8.0},
    #                 {'shift_half_pixel': 1, 'magnification_x': 8.0, 'magnification_y': 8.0},
    #                 {'shift_half_pixel': 1, 'magnification_x': 8.0, 'magnification_y': 8.0},])
    #
    #
    # print(a.info())
    #
    # print(a.to_json())

    bl = ComsylWofryBeamline.load_pickle("/users/srio/Working/paper-hierarchical/CODE-COMSYL/tmp/tmp0_chac_beamline.p")
    print(bl.info())

    from comsyl.waveoptics.Wavefront import NumpyWavefront

    w0 = NumpyWavefront.load("/users/srio/Working/paper-hierarchical/CODE-COMSYL/tmp/tmp0_chac_in.npz")
    print(w0)