Skip to content

Question on how to save "raw data" #265

@davpan01-spec

Description

@davpan01-spec

Hi everyone, I am new to XRT and I am learning how to use it.
I am running some scripts to simulate the performance of our tabletop XAS system. I would like to save the outgoing ray positions and energy from my Monochromator Crystal so that I can do a XYC plot independently outside of xrt. However I have no clue on how to this. Here is my current script.
Thanks in advance for helping me.

`

`def build_beamline():
beamLine = raycing.BeamLine(
alignE=r"")

beamLine.geometricSource01 = rsources.GeometricSource(
    bl=beamLine,
    name=r"TUBE",
    center=[0, 2*R*np.sin(2*t)*np.cos(t+a), 2*R*np.sin(2*t)*np.sin(t+a)],
    pitch=-(np.pi-2*t),
    nrays=N,
    dx=0.05,  # Source size in mm (horizontal)
    dz=0.05,  # Source size in mm (vertical)
    # DIVERGENCE SETTINGS:
    distxprime='flat',  # Angular distribution in horizontal plane
    distzprime='flat',  # Angular distribution in vertical plane
    dxprime=0.218,  # Horizontal divergence in radians (0.002 rad ≈ 0.114°)
    dzprime=0.218,  # Vertical divergence in radians
    distE=r"flat",
    energies=[E_target-E_low, E_target+E_high],
    polarization=None,
    filamentBeam=False)

beamLine.johannToroid01 = roes.JohannToroid(
    bl=beamLine,
    name=r"CRYSTAL",
    center=[0, 2*R*np.sin(t-a), 0],
    pitch=t-a,
    material=crystalSi02,
    limPhysX=[-50, 50],
    limPhysY=[-50, 50],
    shape=r"round",
    Rm=500,
    Rs=500)

beamLine.screen01 = rscreens.Screen(
    bl=beamLine,
    name=None,
    center=[0,0,0],
    x=[1, 0, 0],
    z=[0, 0, 1])

return beamLine

def run_process(beamLine):
geometricSource01beamGlobal01 = beamLine.geometricSource01.shine()

johannToroid01beamGlobal01, johannToroid01beamLocal01 = beamLine.johannToroid01.reflect(
    beam=geometricSource01beamGlobal01)

screen01beamLocal01 = beamLine.screen01.expose(
    beam=johannToroid01beamGlobal01)

outDict = {
    'geometricSource01beamGlobal01': geometricSource01beamGlobal01,
    'johannToroid01beamGlobal01': johannToroid01beamGlobal01,
    'johannToroid01beamLocal01': johannToroid01beamLocal01,
    'screen01beamLocal01': screen01beamLocal01}

# REQUIRED FOR 3D: Stores ray paths for the visualizer
if showIn3D:
    beamLine.prepare_flow()
    
return outDict

rrun.run_process = run_process

def define_plots():
plots = []

plot01 = xrtplot.XYCPlot(
    beam=r"geometricSource01beamGlobal01",
    xaxis=xrtplot.XYCAxis(label=r"x",bins=100),
    yaxis=xrtplot.XYCAxis(label=r"y",bins=100),
    caxis=xrtplot.XYCAxis(label=r"energy", unit=r"eV",offset=E_target),
    aspect=r"auto",
    title=r"Source Beam")
plots.append(plot01)


plot02 = xrtplot.XYCPlot(
    beam=r"johannToroid01beamLocal01",
    xaxis=xrtplot.XYCAxis(label=r"x",bins=100),
    yaxis=xrtplot.XYCAxis(label=r"y",bins=100),
    caxis=xrtplot.XYCAxis(label=r"energy", unit=r"eV",offset=E_target),
    aspect=r"auto",
    title=r"Crystal Surface (Local Coordinates)")
plots.append(plot02)


plot03 = xrtplot.XYCPlot(
    beam=r"johannToroid01beamGlobal01",
    xaxis=xrtplot.XYCAxis(label=r"x",bins=100),
    yaxis=xrtplot.XYCAxis(label=r"y",bins=100),
    caxis=xrtplot.XYCAxis(label=r"energy", unit=r"eV",offset=E_target),
    aspect=r"auto",
    title=r"Reflected Beam (Global Coordinates)")
plots.append(plot03)

plot04 = xrtplot.XYCPlot(
    beam=r"screen01beamLocal01",
    xaxis=xrtplot.XYCAxis(label=r"x",bins=100),
    yaxis=xrtplot.XYCAxis(label=r"y",bins=100),
    caxis=xrtplot.XYCAxis(label=r"energy", unit=r"eV",offset=E_target),
    aspect=r"auto")
plots.append(plot04)

return plots

def main():
beamLine = build_beamline()

if showIn3D:
    # scale: adjust camera zoom (lower = more zoomed out)
    # centerAt: object to focus on initially
    beamLine.glow(
        scale=2, 
        centerAt="CRYSTAL")
else:
    plots = define_plots()
    xrtrun.run_ray_tracing(
        plots=plots,
        backend=r"raycing",
        beamLine=beamLine,
        threads=3

if name == 'main':
main()`

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions