Exemple #1
0
def build_beamline():
    beamLine = raycing.BeamLine()
    beamLine.oe = ToroidMirrorDistorted(beamLine,
                                        'warped',
                                        center=[0, p, 0],
                                        pitch=pitch,
                                        R=Rnom,
                                        r=rdefocus)
    dx = beamLine.oe.limPhysX[1] - beamLine.oe.limPhysX[0]
    dy = beamLine.oe.limPhysY[1] - beamLine.oe.limPhysY[0]
    #    beamLine.source = rs.GeometricSource(
    #        beamLine, 'CollimatedSource', nrays=nrays, dx=source_dX, dz=source_dZ,
    #        dxprime=dx/p/2, dzprime=dy/p*np.sin(pitch)/2)
    kwargs = dict(eE=3.,
                  eI=0.5,
                  eEspread=0,
                  eEpsilonX=eEpsilonX * 1e9 * emittanceFactor,
                  eEpsilonZ=eEpsilonZ * 1e9 * emittanceFactor,
                  betaX=betaX,
                  betaZ=betaZ,
                  period=18.5,
                  n=108,
                  K=K,
                  filamentBeam=(what != 'rays'),
                  xPrimeMax=dx / 2 / p * 1e3,
                  zPrimeMax=dy / 2 / p * np.sin(pitch) * 1e3,
                  xPrimeMaxAutoReduce=False,
                  zPrimeMaxAutoReduce=False,
                  eMin=E0 - dE / 2,
                  eMax=E0 + dE / 2)
    beamLine.source = rs.Undulator(beamLine, nrays=nrays, **kwargs)
    beamLine.fsm0 = rsc.Screen(beamLine, 'FSM0', [0, p + q, 0])
    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1',
                               [0, p + q, q * np.tan(2 * pitch)])
    return beamLine
Exemple #2
0
def build_beamline(nrays=1e5):
    beamLine = raycing.BeamLine(height=0)
#    source=rs.GeometricSource(
#        beamLine, 'GeometricSource', (0, 0, 0),
#        nrays=nrays, distx='flat', dx=0.12, distz='flat', dz=0.12,
#        dxprime=0, dzprime=0,
#        distE='flat', energies=(E0-dE, E0+dE), polarization='horizontal')
    rs.GeometricSource(
        beamLine, 'GeometricSource', (0, 0, 0),
        nrays=nrays, distx='annulus', dx=(0, 0.056),
        dxprime=0, dzprime=0,
        distE='flat', energies=(E0-dE, E0+dE), polarization='horizontal')

    beamLine.fsm1 = rsc.Screen(beamLine, 'DiamondFSM1', (0, 10., 0))
#    beamLine.fzp = roe.NormalFZP(beamLine, 'FZP', [0, 10., 0], pitch=np.pi/2,
#      material=mGold, f=2., E=E0, N=50)
    beamLine.fzp = roe.GeneralFZPin0YZ(
        beamLine, 'FZP', [0, 10., 0], pitch=np.pi/2,
        material=mGold, f1='inf', f2=(0, 0, 2.), E=E0, N=500, phaseShift=np.pi)

#    source.dx = 2 * beamLine.fzp.rn[-1]
#    source.dz = source.dx
    beamLine.fzp.order = 1
    beamLine.fsm2 = rsc.Screen(beamLine, 'DiamondFSM2', (0, 12., 0))
    return beamLine
Exemple #3
0
def build_beamline():
    bl = raycing.BeamLine()

    # Source
    bl.source = LCLS_source(bl=bl, instrument=instrument, **source_kwargs)

    # Optical elements
    oes = []
    print('OEs position:')
    for kwargs in oes_kwargs:
        if 'crystal' in kwargs['name']:
            oes.append(OE(bl=bl, **kwargs))
        elif 'parabolic_mirror' in kwargs['name']:
            oes.append(ParabolicalMirrorParam(bl=bl, **kwargs))
        elif 'elliptical_mirror' in kwargs['name']:
            oes.append(EllipticalMirrorParam(bl=bl, **kwargs))
        elif 'flat_mirror' in kwargs['name']:
            oes.append(OE(bl=bl, **kwargs))
        print(oes[-1].center)
    bl.oes = oes

    # Screens
    print('\nScreens position:')
    for kwargs in s_kwargs:
        Screen(bl=bl, **kwargs)
        print(bl.screens[-1].center)
    # manual screens:
    bl.on_focus = Screen(bl=bl, **focus_kwargs)
    print('Focus:' + str(bl.screens[-1].center))
    bl.detector = Screen(bl=bl, **detector_kwargs)
    print('Detector:' + str(bl.screens[-1].center))
    print('\n')
    return bl
Exemple #4
0
def build_beamline():
    bl = raycing.BeamLine()
    bl.source = LSource(bl,
                        nrays=nrays,
                        energies=[E0, dE],
                        enstep=enstep,
                        distx='flat',
                        dx=[-bsize[0] / 2, bsize[0] / 2],
                        distz='flat',
                        dz=[-bsize[1] / 2, bsize[1] / 2],
                        distxprime='flat',
                        dxprime=[-bdiv[0], bdiv[0]],
                        distzprime='flat',
                        dzprime=[-bdiv[1], bdiv[1]])

    bl.mirr = PMirror(bl,
                      center=mirr_pos,
                      material=mL,
                      pitch=braggML,
                      limPhysY=[-mirr_len / 2, mirr_len / 2],
                      limPhysX=[-mirr_width / 2, mirr_width / 2],
                      f1=mirr_p,
                      slope_error=slope_error)

    bl.s0 = Screen(bl, center=mirr_pos)
    bl.det = Screen(bl,
                    center=mirr_pos + n1 * 100,
                    z=get_perpendicular_vector(n1))
    return bl
Exemple #5
0
def build_beamline():
    bl = raycing.BeamLine()

    # Source and optical elements
    bl.source = GeometricSource(bl=bl, **oes_kwargs[0])
    oes = []
    print('OEs position:')
    for kwargs in oes_kwargs[1:]:
        if 'crystal' in kwargs['name']:
            oes.append(OE(bl=bl, **kwargs))
        elif 'parabolic_mirror' in kwargs['name']:
            oes.append(ParabolicalMirrorParam(bl=bl, **kwargs))
        elif 'flat_mirror' in kwargs['name']:
            oes.append(OE(bl=bl, **kwargs))
        elif 'crl' in kwargs['name']:
            oes.append(DoubleParaboloidLens(bl=bl, **kwargs))
        elif 'slits' in kwargs['name']:
            oes.append(RectangularAperture(bl=bl, **kwargs))
        else:
            print('OE not implemented (build beamline)')
        print('\t' + oes[-1].name + ': ' + str(oes[-1].center))
    bl.oes = oes

    # Screens
    print('\nScreens position:')
    for kwargs in screens_kwargs:
        Screen(bl=bl, **kwargs)
        print('\t' + kwargs['name'] + ': ' + str(bl.screens[-1].center))
    print('\n')
    return bl
Exemple #6
0
def build_beamline(nrays=2e5):
    beamLine = raycing.BeamLine()
    rs.Undulator(
        beamLine,
        'P06',
        nrays=nrays,
        eEspread=0.0011,
        eSigmaX=34.64,
        eSigmaZ=6.285,
        eEpsilonX=1.,
        eEpsilonZ=0.01,
        period=31.4,
        K=2.1392 - 0.002,
        n=63,
        eE=6.08,
        eI=0.1,
        xPrimeMax=1.5e-2,
        zPrimeMax=1.5e-2,
        eMin=eMin,
        eMax=eMax,
        distE='BW',
        xPrimeMaxAutoReduce=False,
        zPrimeMaxAutoReduce=False,
        #        targetOpenCL='CPU',
        taper=(1.09, 11.254))
    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, 90000, 0))
    return beamLine
Exemple #7
0
def build_beamline(nrays=1e4):
    beamLine = raycing.BeamLine(height=0)
    rs.GeometricSource(
        beamLine, 'CollimatedSource', nrays=nrays,
        dx=0.5, dz=0.5, distxprime=None, distzprime=None, energies=(E0,))

    beamLine.lenses = []
    ilens = 0
    while True:
        roll = 0.
        if Lens == roe.ParabolicCylinderFlatLens:
            roll = -np.pi/4 if ilens % 2 == 0 else np.pi/4
        lens = Lens(
            beamLine, 'Lens{0:02d}'.format(ilens), center=[0, p + dz*ilens, 0],
            pitch=np.pi/2, roll=roll, t=0.1, material=material,
            limPhysX=[-2, 2], limPhysY=[-2, 2], shape='round',
            focus=parabolaParam, zmax=zmax, alarmLevel=0.1)
        beamLine.lenses.append(lens)
        if ilens == 0:
            nCRL = lens.get_nCRL(q, E0)
        ilens += 1
        if nCRL - ilens < 0.5:
            break

    beamLine.fsmF = rsc.Screen(beamLine, 'FSM-focus', [0, p+q, 0])
    return beamLine
Exemple #8
0
def build_beamline(nrays=1e5):
    beamLine = raycing.BeamLine(height=0)
#    rs.GeometricSource(beamLine, 'GeometricSource', (0, 0, 0),
#      nrays=nrays, dx=0, dz=0, distxprime='flat', dxprime=1e-4,
#      distzprime='flat', dzprime=1e-4,
#      distE='flat', energies=(E0-dE, E0+dE), polarization='horizontal')
    rs.GeometricSource(
        beamLine, 'GeometricSource', (0, 0, 0),
        nrays=nrays, distx='annulus', dx=(0, 1), dxprime=0, dzprime=0,
        distE='flat', energies=(E0-dE, E0+dE), polarization='horizontal')
    beamLine.fsm1 = rsc.Screen(beamLine, 'DiamondFSM1', (0., p-100, 0.))
    siCryst = rm.CrystalSi(hkl=(1, 1, 1), geom='Bragg-Fresnel')
    pitch = \
        siCryst.get_Bragg_angle(E0) - siCryst.get_dtheta_symmetric_Bragg(E0)
#    pitch = np.pi/2
    f = 0, p * np.cos(pitch), p * np.sin(pitch)
    beamLine.fzp = roe.GeneralFZPin0YZ(
        beamLine, 'FZP', [0., p, 0.], pitch=pitch,
        material=siCryst, f1='inf', f2=f, E=E0, N=340)
    beamLine.fzp.order = 1
    beamLine.fsm2 = rsc.Screen(beamLine, 'DiamondFSM2', [0, 0, 0],
                               z=(0, -np.sin(2*pitch), np.cos(2*pitch)))
    if showIn3D:
        beamLine.fsm2RelPos = [p]
    else:
        beamLine.fsm2RelPos = np.linspace(0, p, 21)
    return beamLine
Exemple #9
0
def build_beamline(nrays=1e5):
    beamLine = raycing.BeamLine()
    beamLine.source = Source(
        beamLine, eN=1000, nx=40, nz=20, nrays=nrays, **kwargs)
    beamLine.fsm0 = rsc.Screen(beamLine, 'FSM0', (0, 0, 0))
    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, R0, 0))
    return beamLine
Exemple #10
0
def build_beamline(nrays=1e5):
    beamLine = raycing.BeamLine(height=0)
    sourceCenter = [0, 0, 0]
    mirrorCenter = [0, p, p*np.tan(inclination)]

    kw = dict(
        nrays=nrays, distE='flat', energies=(E0-dE, E0+dE),
        polarization='horizontal', pitch=inclination)
    if case == 'elliptical':  # point source
        kw.update(dict(
            dx=0, dz=0, distxprime='flat', dxprime=1e-4,
            distzprime='flat', dzprime=1e-4))
        Mirror = roe.EllipticalMirrorParam
        kwMirror = dict(f1=sourceCenter, q=q)
    elif case == 'parabolical':  # collimated source
        kw.update(dict(
            dx=1, dz=1, distx='flat', distz='flat',
            distxprime=None, distzprime=None))
        Mirror = roe.ParabolicalMirrorParam
        dp = q * np.sin(2*pitch)
        di = q * np.sin(inclination)
        kwMirror = dict(f2=[mirrorCenter[0] + dp*np.sin(globalRoll),
                            mirrorCenter[1] + q,
                            mirrorCenter[2] + dp*np.cos(globalRoll) + di])
    rs.GeometricSource(
        beamLine, 'GeometricSource', sourceCenter, **kw)
    beamLine.fsm1 = rsc.Screen(beamLine, 'beforeMirror', mirrorCenter)
    beamLine.ellMirror = Mirror(
        beamLine, 'EllM', mirrorCenter, rotationSequence='RyRzRx',
        pitch=pitch+inclination*np.cos(globalRoll), positionRoll=globalRoll,
        yaw=inclination*np.sin(globalRoll), **kwMirror)

    beamLine.fsm2 = rsc.Screen(beamLine, '@focus', [0, 0, 0])
    beamLine.fsm2dY = np.linspace(-2, 2, 5) * q*0.1
    return beamLine
Exemple #11
0
def build_beamline(nrays=nrays):
    beamLine = raycing.BeamLine()
    rs.GeometricSource(beamLine,
                       'source',
                       nrays=nrays,
                       polarization=polarization,
                       **kw)

    #    beamLine.bg = BlazedGratingAlt(
    beamLine.bg = roe.BlazedGrating(beamLine,
                                    'BlazedGrating', (0, p, 0),
                                    pitch=pitch,
                                    material=coating,
                                    blaze=blaze,
                                    rho=rho)
    drho = beamLine.bg.get_grating_area_fraction()
    beamLine.bg.area = dx * dz / np.sin(pitch) * drho

    beamLine.gr = Grating(beamLine,
                          'Grating', (0, p, 0),
                          pitch=pitch,
                          material=coatingGr,
                          order=range(minOrder, maxOrder + 1))

    beamLine.fsm = rsc.HemisphericScreen(beamLine,
                                         'FSM', (0, p, 0),
                                         R=q,
                                         x=(0, -np.sin(thetaOffset),
                                            np.cos(thetaOffset)),
                                         z=(0, np.cos(thetaOffset),
                                            np.sin(thetaOffset)))
    return beamLine
Exemple #12
0
def build_beamline(nrays=1e4):
    beamLine = raycing.BeamLine(height=0)
    #    rs.CollimatedMeshSource(beamLine, 'CollimatedMeshSource', dx=2, dz=2,
    #      nx=21, nz=21, energies=(E0,), withCentralRay=False, autoAppendToBL=True)
    rs.GeometricSource(beamLine,
                       'CollimatedSource',
                       nrays=nrays,
                       dx=0.5,
                       dz=0.5,
                       distxprime=None,
                       distzprime=None,
                       energies=(E0, ))

    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, p - 100, 0))

    beamLine.lens = Lens(beamLine,
                         'CRL', [0, p, 0],
                         pitch=np.pi / 2,
                         t=0,
                         material=mBeryllium,
                         focus=parabolaParam,
                         zmax=zmax,
                         nCRL=(q, E0),
                         alarmLevel=0.1)

    beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2')
    beamLine.fsm2.dqs = np.linspace(-140, 140, 71)
    #    beamLine.fsm2.dqs = np.linspace(-70, 70, 15)
    return beamLine
Exemple #13
0
def build_beamline(nrays=raycing.nrays):
    fixedExit = 15.

    beamLine = raycing.BeamLine(azimuth=0, height=0)
    hDiv = 1.5e-3
    vDiv = 2.5e-4
    beamLine.source = rs.GeometricSource(beamLine,
                                         'GeometricSource', (0, 0, 0),
                                         nrays=nrays,
                                         dx=0.1,
                                         dy=0,
                                         dz=2.,
                                         dxprime=hDiv / 2,
                                         dzprime=0,
                                         distE='flat',
                                         energies=eLimits,
                                         polarization='horizontal')

    beamLine.feMovableMask = ra.RectangularAperture(
        beamLine, 'FEMovableMask', [0, 10000, 0],
        ('left', 'top', 'right', 'bottom'), [-10, 3., 10, -3.])
    beamLine.feMovableMask.set_divergence(
        beamLine.source, [-hDiv / 2, vDiv / 2, hDiv / 2, -vDiv / 2])

    yDCM = 21000.
    si111 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171 + 273.15)
    beamLine.dcm = roe.DCM(beamLine,
                           'DCM', (0, yDCM, 0),
                           surface=('Si111', ),
                           material=(si111, ))
    beamLine.dcm.bragg = math.asin(rm.ch / (2 * si111.d * E0))
    beamLine.dcm.cryst2perpTransl = fixedExit / 2. / math.cos(
        beamLine.dcm.bragg)

    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, yDCM + 700, 0))

    yVFM = 24000.
    beamLine.vfm = roe.ToroidMirror(beamLine,
                                    'VFM', (0, yVFM, fixedExit),
                                    pitch=4.0e-3)
    beamLine.vfm.R = yVFM / beamLine.vfm.pitch
    beamLine.vfm.r = 2. / 3. * yVFM * beamLine.vfm.pitch
    yFlatMirror = yVFM + 2000.
    zFlatMirror = (yFlatMirror - yVFM) * 2. * beamLine.vfm.pitch + fixedExit
    beamLine.vdm = roe.OE(beamLine,
                          'FlatMirror', (0, yFlatMirror, zFlatMirror),
                          pitch=-beamLine.vfm.pitch,
                          positionRoll=math.pi)

    ySample = 1.5 * yVFM
    yQWP = ySample - 3000.
    beamLine.qwp = roe.OE(beamLine,
                          'QWP', (0, yQWP, zFlatMirror),
                          roll=math.pi / 4,
                          material=(crystalDiamond, ))
    beamLine.qwp.pitch = theta0

    beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2', (0, ySample, zFlatMirror))

    return beamLine
Exemple #14
0
    def __init__(self):
        """ Tania przestrzen reklamowa """
        # This is neccessary
        self.beamLine = raycing.BeamLine()
        self.beamTotal = None

        # This is supposed to be an atomic iterator
        self.beam_iterator = itertools.count()
        # Process that many photons in one raytraycing_run
        self.beam_chunk_size = 1000

        # Default capillary position and radius
        # must be held by the test-object
        self.x_entrance = 0.0
        self.z_entrance = 0.0
        self.R_in = 0.5

        # Default capillary dimensions: (constant in this test)
        # 10cm capillary starting at 40mm
        self.y_entrance = 40
        self.y_outrance = 140

        # We also need to control materials
        self.material = None

        # Far screen distance from the end of capillary
        self.far_screen_dist = 20
        # Savename prefix (colon helps with vim-folding)
        self.prefix = 'dupa';
Exemple #15
0
def build_beamline():
    beamLine = raycing.BeamLine()

    beamLine.geometricSource01 = rsources.GeometricSource(
        bl=beamLine,
        name=None,
        center=[0, 0, 0],
        nrays=1000,
        distE=r"flat",
        dx=0.001,
        dz=0.001,
        dxprime=0,
        dzprime=0,
        energies=[Emin, Emax])

    beamLine.screen02 = rscreens.Screen(bl=beamLine, center=[0, 10000, 0])

    beamLine.lauePlate01 = roes.BentLaueCylinder(
        #    beamLine.lauePlate01 = roes.LauePlate(
        bl=beamLine,
        name=None,
        center=[0, 10000, 0],
        pitch=0.0,
        R=1e4,
        crossSection='parabolic',
        material=crystalSi01,
        targetOpenCL='CPU')

    beamLine.screen01 = rscreens.Screen(bl=beamLine,
                                        name=None,
                                        center=[0.0, 20000, 0.0])

    return beamLine
Exemple #16
0
def build_beamline(nrays=1e5):
    beamLine = raycing.BeamLine(azimuth=0, height=0)
    rs.GeometricSource(beamLine,
                       'GeometricSource',
                       nrays=nrays,
                       dx=beamH,
                       dy=0,
                       dz=beamV,
                       distxprime='flat',
                       distzprime='flat',
                       polarization=None)
    beamLine.analyzer = Toroid(beamLine,
                               analyzerName,
                               surface=('', ),
                               limPhysX=(-dxCrystal / 2, dxCrystal / 2),
                               limPhysY=(-dyCrystal / 2, dyCrystal / 2),
                               Rm=Rm,
                               Rs=Rs,
                               shape='rect',
                               **facetKWargs)
    beamLine.detector = rsc.Screen(beamLine, 'Detector', z=(0, 0, 1))
    #    beamLine.s1h = ra.RectangularAperture(
    #        beamLine, 'horizontal. slit', 0, Rs-10.,
    #        ('left', 'right'), [-0.1, 0.1])
    return beamLine
Exemple #17
0
def build_beamline():
    beamLine = raycing.BeamLine(height=0)
    beamLine.source = rs.LaguerreGaussianBeam(
        beamLine, 'Laguerre-Gaussian', w0=w0, vortex=(lVortex, pVortex),
        energies=(E0,))
    beamLine.fsmFar = rsc.Screen(beamLine, 'FSM', [0, 0, 0])
    return beamLine
Exemple #18
0
def build_beamline(nrays=raycing.nrays):
    fixedExit = 15.

    beamLine = raycing.BeamLine(azimuth=0, height=0)
    rs.GeometricSource(
        beamLine, 'GeometricSource', (0, 0, -fixedExit),
        nrays=nrays, dx=5., dy=0, dz=5., dxprime=0., dzprime=0.,
        distE='flat', energies=eLimits, polarization='horizontal')

    p = 20000.
    si111 = rm.CrystalSi(hkl=(1, 1, 1), tK=-171+273.15)
    beamLine.dcm = roe.DCM(beamLine, 'DCM', (0, p - 2000, -fixedExit),
                           surface=('Si111',), material=(si111,))
    beamLine.dcm.bragg = math.asin(rm.ch / (2 * si111.d * E0))
    beamLine.dcm.cryst2perpTransl = fixedExit/2./math.cos(beamLine.dcm.bragg)

    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, p - 1000, 0))

    beamLine.qwp = roe.LauePlate(beamLine, 'QWP', (0, p, 0),
                                 material=(crystalDiamond,))
    beamLine.qwp.pitch = theta0 + math.pi/2
    q = 50.
    beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2', (0, p + q, 0))

    return beamLine
Exemple #19
0
def main():
    E = 9000
    energy = np.linspace(8500, 9500, 501)
    theta = np.linspace(-1, 1, 512) * 20e-6
    psi = np.linspace(-1, 1, 512) * 20e-6
#    kwargs = dict(eE=3.0, eI=0.5, eEpsilonX=0.263, eEpsilonZ=0.008,
#                  betaX=9.539, betaZ=1.982, period=18.5, n=108, K=0.52,
#                  eEspread=1e-3,
#                  xPrimeMax=theta[-1]*1e3, zPrimeMax=psi[-1]*1e3,
#                  targetOpenCL='CPU',
#                  distE='BW')
    kwargs = dict(eE=6.083,
                      eEpsilonX = 1.3, #0.02,#1.3, #1300 pmrad
                      eEpsilonZ = 0.01,#0.004,#0.01, #10pmrad
                      period=32.8,
                      n=63,
                      targetE=[9000, 3],
                      eMin= E + 500,
                      eMax= E - 500,
                      xPrimeMax=0.02, #xPrimeMax=0.1,
                      zPrimeMax=0.02, #xPrimeMax=0.1,
                      gp=1e-06,
                      distE='BW',
                      taper = (1., 12.),
                      targetOpenCL='GPU')
#    energy = [200000., 200000.]
#    theta = np.linspace(-2./25000., 2./25000., 51)
#    psi = np.linspace(-2./25000., 2./25000., 51)
#    kwargs = dict(name='IVU18.5', eE=3.0, eI=0.5,
#                  eEpsilonX=0.263, eEpsilonZ=0.008,
#                  betaX=9., betaZ=2.,
#                  period=18.5, n=108, K=1.92,
#                  xPrimeMax=theta[-1]*1e3, zPrimeMax=psi[-1]*1e3, distE='BW')

    if True:  # xrt Undulator
        source = rs.Undulator(**kwargs)
        I0, l1, l2, l3 = source.intensities_on_mesh(energy, theta, psi)
    else:  # Urgent
        kwargs['eSigmaX'] = (kwargs['eEpsilonX']*kwargs['betaX']*1e3)**0.5
        kwargs['eSigmaZ'] = (kwargs['eEpsilonZ']*kwargs['betaZ']*1e3)**0.5
        del(kwargs['distE'])
        del(kwargs['betaX'])
        del(kwargs['betaZ'])
        kwargs['eMin'] = energy[0]
        kwargs['eMax'] = energy[-1]
        kwargs['eN'] = len(energy)
        kwargs['icalc'] = 3
        kwargs['nx'] = len(theta)//2
        kwargs['nz'] = len(psi)//2
        import xrt.backends.raycing as raycing
        beamLine = raycing.BeamLine(azimuth=0, height=0)
        source = rs.UndulatorUrgent(beamLine, **kwargs)

        I0, l1, l2, l3 = source.intensities_on_mesh()
        I0 = np.concatenate((I0[:, :0:-1, :], I0), axis=1)
        I0 = np.concatenate((I0[:, :, :0:-1], I0), axis=2)

#    flux_through_aperture(energy, theta, psi, I0)
    save_3dMatrix(energy, theta, psi, I0)
Exemple #20
0
def build_beamline():
    beamLine = raycing.BeamLine(height=0)
    rs.GeometricSource(beamLine, 'GeometricSource', dx=3., dz=3.,
                       dxprime=1.6e-4, distzprime=None)
    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', (0, pLaueSCM - 100, 0))
    beamLine.laueSCM = roe.BentLaueCylinder(
        beamLine, 'LaueSCM', (0, pLaueSCM, 0), material=(siCrystal,))
    beamLine.fsm2 = rsc.Screen(beamLine, 'FSM2', [0, pLaueSCM + qLaueSCM, 0])
    return beamLine
Exemple #21
0
def build_beamline():

    ## beamline
    BL = raycing.BeamLine()

    BL.source = LSource(BL,
                        nrays=nrays,
                        energies=[E0, dE],
                        enstep=enstep,
                        ensig=ensig,
                        enmix=enmix,
                        distx='flat',
                        dx=[-bsize[0] / 2, bsize[0] / 2],
                        distz='flat',
                        dz=[-bsize[1] / 2, bsize[1] / 2],
                        distxprime='flat',
                        dxprime=[-bdiv[0], bdiv[0]],
                        distzprime='flat',
                        dzprime=[-bdiv[1], bdiv[1]])

    BL.c1 = OE(BL, center=c1_pos, material=c_1, pitch=c1_pitch, alpha=alpha_1)
    BL.c2 = OE(BL,
               center=c2_pos,
               material=c_2,
               positionRoll=pi,
               pitch=c2_pitch,
               alpha=alpha_2)
    BL.c3 = OE(BL,
               center=c3_pos,
               material=c_3,
               positionRoll=pi,
               pitch=c3_pitch,
               alpha=alpha_3)
    BL.c4 = OE(BL, center=c4_pos, material=c_4, pitch=c4_pitch, alpha=alpha_4)
    BL.c5 = OE(BL, center=c5_pos, material=c_5, pitch=c5_pitch, alpha=alpha_5)
    BL.c6 = OE(BL,
               center=c6_pos,
               material=c_6,
               positionRoll=pi,
               pitch=c6_pitch,
               alpha=alpha_6)

    #BL.slt1 = RectangularAperture(BL, center=slit_pos,
    #                              opening=[-0.2, 0.2, -1, 1])

    ## virtual screens
    BL.s0 = Screen(BL, center=c1_pos)
    BL.s1 = Screen(BL, center=c2_pos, z=[0, -sin(c1_out), cos(c1_out)])
    BL.s2 = Screen(BL, center=c3_pos, z=[0, -sin(c2_out), cos(c2_out)])
    BL.s3 = Screen(BL, center=c4_pos, z=[0, -sin(c3_out), cos(c3_out)])
    BL.s4 = Screen(BL, center=c5_pos, z=[0, -sin(c4_out), cos(c5_out)])
    BL.s5 = Screen(BL, center=c6_pos, z=[0, -sin(c5_out), cos(c6_out)])
    BL.s6 = Screen(BL,
                   center=c6_pos + [0, 1000, 0],
                   z=[0, -sin(c6_out), cos(c6_out)])

    return BL
Exemple #22
0
def build_beamline(nrays=mynrays):
    beamLine = raycing.BeamLine()
    beamLine.source = rs.Undulator(beamLine, nrays=nrays, **kwargs)
    beamLine.fsm0 = rsc.Screen(beamLine, 'FSM0', (0, R0, 0))
    beamLine.slit = ra.RectangularAperture(beamLine, 'squareSlit', [0, R0, 0],
                                           ('left', 'right', 'bottom', 'top'),
                                           [-slitDx, slitDx, -slitDz, slitDz])

    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', [0, R0, 0])
    return beamLine
Exemple #23
0
def build_beamline(nrays=mynrays):
    beamLine = raycing.BeamLine()
    rs.Undulator(beamLine, nrays=nrays, **kwargs)

    beamLine.fsm0 = rsc.Screen(beamLine, 'FSM0', (0, R0-1, 0))
    beamLine.slit = ra.DoubleSlit(
        beamLine, 'squareSlit', [0, R0, 0], ('left', 'right', 'bottom', 'top'),
        [-slitDx/2, slitDx/2, -slitDz/2, slitDz/2], shadeFraction=0.1)
    beamLine.fsm1 = rsc.Screen(beamLine, 'FSM1', [0, R0+dR, 0])
    return beamLine
Exemple #24
0
def build_beamline():
    bl = raycing.BeamLine()

    # Source
    bl.source = GeometricSource(bl=bl,
                                dx=0.02,
                                dz=0.02,
                                dxprime=4E-6,
                                dzprime=4E-6,
                                energies=[E0])
    # bl.source = GeometricSource(
    #     bl=bl, dx=0.02, dz=0.02, dxprime=0, dzprime=0, energies=[E0])

    # Optical elements
    bl.oes = []
    ParabolicalMirrorParam(bl=bl,
                           center=np.array([0, D, 0]),
                           pitch=m_pitch,
                           q=q,
                           material=m_mat,
                           isCylindrical=True,
                           limPhysY=[-200, 200])

    ParabolicalMirrorParam(bl=bl,
                           center=bl.oes[0].center + 2 * q * n,
                           pitch=-m_pitch,
                           positionRoll=np.pi,
                           p=q,
                           material=m_mat,
                           isCylindrical=True,
                           limPhysY=[-200, 200])

    # Screens
    bl.s1 = Screen(bl=bl, name='source', center=np.asarray(bl.source.center))
    bl.s2 = Screen(bl=bl,
                   name='focus',
                   center=bl.oes[0].center + q * n,
                   z=get_perpendicular_vector(n))
    bl.s3 = Screen(
        bl=bl,
        name='detector',
        center=bl.oes[1].center + np.array([0, 300, 0]),
    )

    print('\n\n')
    print('OEs position:')
    print(bl.oes[0].center)
    print(bl.oes[1].center)
    print('\n')
    print('\nScreens position:')
    print(bl.s1.center)
    print(bl.s2.center)
    print(bl.s3.center)
    print('\n\n')
    return bl
Exemple #25
0
def visualize_grating():
    beamLine = raycing.BeamLine()
    #    bg = BlazedGratingAlt(
    bg = roe.BlazedGrating(
        beamLine,
        'BlazedGrating',
        (0, p, 0),
        pitch=pitch,
        material=coating,
        blaze=blaze,
        #antiblaze=pitch,
        rho=rho)

    fig1 = plt.figure(figsize=(8, 6), dpi=72)
    rect2d = [0.1, 0.1, 0.8, 0.8]
    ax = fig1.add_axes(rect2d, aspect='auto')
    ax.set_xlabel(u'y (µm)')
    ax.set_ylabel(u'z (nm)')
    ax.set_title(
        u'Grating profile with {0:.0f} lines/mm and {1}° blaze angle\n'.format(
            rho, np.degrees(blaze)) +
        u'and beam footprint at {0}° pitch angle'.format(np.degrees(pitch)))

    maxY = 2.2 * bg.rho_1
    y = np.linspace(-2 * maxY, 2 * maxY, 280)
    z = bg.local_z(0, y)
    ax.plot(y * 1e3, z * 1e6, '-k', lw=2)

    beamSource = rs.Beam(nrays=len(y), forceState=1)
    beamSourceLoc = rs.Beam(copyFrom=beamSource)
    raycing.global_to_virgin_local(bg.bl, beamSource, beamSourceLoc, bg.center,
                                   slice(None))
    raycing.rotate_beam(beamSourceLoc, slice(None), pitch=-pitch)

    beamSource.z[:] = y * np.tan(pitch)
    beamGloSG, beamLoSG = bg.reflect(beamSource)

    ax.plot([beamSourceLoc.y * 1e3, beamLoSG.y * 1e3],
            [beamSourceLoc.z * 1e6, beamLoSG.z * 1e6],
            '-r',
            alpha=0.2,
            lw=0.5)
    ax.plot(beamLoSG.y * 1e3, beamLoSG.z * 1e6, 'or', alpha=0.5, lw=3)

    ax.set_xlim(-maxY * 1e3, maxY * 1e3)
    mz = bg.rho_1 * np.tan(blaze)
    ax.set_ylim(-mz * 1.1e6, mz * 0.2e6)

    y1, y2, z1, z2, d = get_grating_area_fraction(rho, blaze, pitch)
    xs = np.array([y1, y2]) * 1e3
    ys = np.array([z1, z2]) * 1e6
    ax.plot(xs, ys, 'og', lw=3)

    fig1.savefig(prefix + '_profile.png')
    plt.show()
Exemple #26
0
def build_beamline(nrays=raycing.nrays):
    beamLine = raycing.BeamLine(azimuth=0, height=0)
    rs.GeometricSource(
        beamLine, 'GeometricSource', nrays=nrays, dx=beamH, dy=0,
        dz=0.05, distxprime='flat', distzprime='flat', polarization=None)
    beamLine.analyzer = Cylinder(
        beamLine, analyzerName, surface=('',), R=Rm,
        limPhysX=(-dxCrystal/2, dxCrystal/2),
        limPhysY=(-dyCrystal/2, dyCrystal/2))
    beamLine.detector = rsc.Screen(beamLine, 'Detector')
    return beamLine
def build_beamline(nrays=1000):
    beamLine = raycing.BeamLine(height=0)
    rs.GeometricSource(beamLine,
                       'GeometricSource', (0, 0, 0),
                       nrays=nrays,
                       dx=0.,
                       dz=0.,
                       distxprime='annulus',
                       distE='lines',
                       energies=(E0, ),
                       polarization='horizontal')
    beamLine.fsm1 = rsc.Screen(beamLine, 'DiamondFSM1', (0, rSample, 0))
    beamLine.capillaries = []
    beamLine.firstInLayer = []
    beamLine.xzMax = 0
    for n in range(layers):
        if n > 0:
            ms = range(n)
            i6 = range(6)
        else:
            ms = 0,
            i6 = 0,
        beamLine.firstInLayer.append(len(beamLine.capillaries))
        for i in i6:
            for m in ms:
                x = 2 * (r0 + wall) * (n**2 + m**2 - n * m)**0.5
                alpha = np.arcsin(x / rSample)
                roll1 = -np.arctan2(np.sqrt(3) * m, 2 * n - m)
                roll = roll1 + i * np.pi / 3.
                capillary = BentCapillary(
                    beamLine,
                    'BentCapillary', [0, 0, 0],
                    roll=roll,
                    material=mGlass,
                    limPhysY=[rSample * np.cos(alpha), f],
                    f=f,
                    rSample=rSample,
                    entranceAlpha=alpha,
                    rIn=r0,
                    rOut=r0)
                beamLine.capillaries.append(capillary)
                if beamLine.xzMax < capillary.b0:
                    beamLine.xzMax = capillary.b0
    print('max divergence =', alpha)
    beamLine.xzMax += 2 * r0
    print(len(beamLine.capillaries))
    beamLine.sources[0].dxprime = 0, np.arcsin(
        (2 * n + 1) * (r0 + wall) / rSample)
    #    beamLine.sources[0].dxprime = (np.arcsin((2*n-3) * (r0+wall) / rSample),
    #        np.arcsin((2*n+1) * (r0+wall) / rSample))
    #    beamLine.sources[0].dxprime = 0, np.arcsin(r0 / rSample)
    beamLine.fsm2 = rsc.Screen(beamLine, 'DiamondFSM2', (0, f, 0))
    return beamLine
Exemple #28
0
def main():
    energy = np.linspace(3850, 4150, 601)
    theta = np.linspace(-1, 1, 51) * 30e-6
    psi = np.linspace(-1, 1, 51) * 30e-6
    kwargs = dict(
        eE=3.0,
        eI=0.5,
        eEpsilonX=0.263,
        eEpsilonZ=0.008,
        betaX=9.539,
        betaZ=1.982,
        period=18.5,
        n=108,
        K=0.52,
        #                  eEspread=1e-3,
        xPrimeMax=theta[-1] * 1e3,
        zPrimeMax=psi[-1] * 1e3,
        #                  targetOpenCL='CPU',
        distE='BW')

    #    energy = [200000., 200000.]
    #    theta = np.linspace(-2./25000., 2./25000., 51)
    #    psi = np.linspace(-2./25000., 2./25000., 51)
    #    kwargs = dict(name='IVU18.5', eE=3.0, eI=0.5,
    #                  eEpsilonX=0.263, eEpsilonZ=0.008,
    #                  betaX=9., betaZ=2.,
    #                  period=18.5, n=108, K=1.92,
    #                  xPrimeMax=theta[-1]*1e3, zPrimeMax=psi[-1]*1e3, distE='BW')

    if True:  # xrt Undulator
        source = rs.Undulator(**kwargs)
        I0, l1, l2, l3 = source.intensities_on_mesh(energy, theta, psi)
    else:  # Urgent
        kwargs['eSigmaX'] = (kwargs['eEpsilonX'] * kwargs['betaX'] * 1e3)**0.5
        kwargs['eSigmaZ'] = (kwargs['eEpsilonZ'] * kwargs['betaZ'] * 1e3)**0.5
        del (kwargs['distE'])
        del (kwargs['betaX'])
        del (kwargs['betaZ'])
        kwargs['eMin'] = energy[0]
        kwargs['eMax'] = energy[-1]
        kwargs['eN'] = len(energy)
        kwargs['icalc'] = 3
        kwargs['nx'] = len(theta) // 2
        kwargs['nz'] = len(psi) // 2
        import xrt.backends.raycing as raycing
        beamLine = raycing.BeamLine(azimuth=0, height=0)
        source = rs.UndulatorUrgent(beamLine, **kwargs)

        I0, l1, l2, l3 = source.intensities_on_mesh()
        I0 = np.concatenate((I0[:, :0:-1, :], I0), axis=1)
        I0 = np.concatenate((I0[:, :, :0:-1], I0), axis=2)

    flux_through_aperture(energy, theta, psi, I0)
Exemple #29
0
def build_beamline():
    P02_2 = raycing.BeamLine()

    P02_2.Undulator01 = rsources.GeometricSource(
        bl=P02_2,
        nrays=5e4,
        name='source',
        polarization='horizontal',
        dx=0.5,
        dz=0.5,
        dxprime=0.005e-3,
        dzprime=0.005e-3,
        distx='normal',
        distz='normal',
        energies=(60000, 60) if powder else (1000, 100000),
        distE='normal' if powder else 'flat')

    P02_2.FSM_Source = rscreens.Screen(bl=P02_2,
                                       name=r"FSM_Source",
                                       center=[0, 29001, 0])

    P02_2.Sample = roes.LauePlate(
        bl=P02_2,
        name=r"CeO2 Powder Sample" if powder else "Silicon 001 wafer",
        center=[0, 65000, 0],
        pitch='90deg',
        yaw=0 if powder else '45deg',
        rotationSequence='RxRyRz',
        material=PowderSample if powder else MonoCrystalSample,
        targetOpenCL=(0, 0),
        precisionOpenCL='float32')

    P02_2.FSM_Sample = rscreens.Screen(bl=P02_2,
                                       name=r"After Sample",
                                       center=[0, 65100, 0])

    P02_2.RoundBeamStop01 = rapts.RoundBeamStop(bl=P02_2,
                                                name=r"BeamStop",
                                                center=[0, 65149, 0],
                                                r=5)

    P02_2.Frame = rapts.RectangularAperture(
        bl=P02_2,
        name=r"Frame",
        center=[0, 65149.5, 0],
        opening=[-dSize, dSize, -dSize, dSize])

    P02_2.FSM_Detector = rscreens.Screen(bl=P02_2,
                                         name=r"Detector",
                                         center=[0, 65150, 0])

    return P02_2
Exemple #30
0
def build_beamline(nrays=raycing.nrays):
    beamLine = raycing.BeamLine(height=0)
    rs.GeometricSource(beamLine,
                       'GeometricSource', (0, 0, 0),
                       nrays=nrays,
                       dx=0.,
                       dz=0.,
                       dxprime=2e-4,
                       dzprime=1e-4,
                       distE='lines',
                       energies=(E0, ),
                       polarization='horizontal')

    if case == 'parabolic':
        mirrorVFM = roe.BentFlatMirror
        mirrorHFM = roe.BentFlatMirror
        RVFM = 2 * p / np.sin(pitchVFM)
        kwargsVFM = {'R': RVFM}
        RHFM = 2 * p / np.sin(pitchHFM)
        kwargsHFM = {'R': RHFM}
    elif case == 'elliptical':
        mirrorVFM = roe.EllipticalMirrorParam
        mirrorHFM = roe.EllipticalMirrorParam
        kwargsVFM = {'p': pVFM, 'q': qVFM, 'isCylindrical': True}
        kwargsHFM = {'p': pHFM, 'q': qHFM, 'isCylindrical': True}
    else:
        raise

    beamLine.VFM = mirrorVFM(beamLine,
                             'VFM', [0, p, 0],
                             material=mGold,
                             limPhysX=[gap / 2, W],
                             limPhysY=[-L / 2, L / 2],
                             rotationSequence='RxRyRz',
                             pitch=pitchVFM,
                             yaw=-pitchHFM,
                             **kwargsVFM)
    beamLine.HFM = mirrorHFM(beamLine,
                             'HFM', [0, p, 0],
                             material=mGold,
                             limPhysX=[-W, -gap / 2],
                             limPhysY=[-L / 2, L / 2],
                             rotationSequence='RyRzRx',
                             positionRoll=np.pi / 2,
                             pitch=pitchHFM,
                             yaw=pitchVFM,
                             **kwargsHFM)
    beamLine.fsmMontel = rsc.Screen(beamLine, 'FSM-Montel', (0, p + q, 0))
    return beamLine