Ejemplo n.º 1
0
srcs = [GaussianSource(position=(0, row.source_y, row.source_x),
                       rotation=(angle, 0, 0),
                       size=(xslit, yslit, 0),
                       divergence=(xdisp, ydisp, 0),
                       wavelength=6.626068e-34*2.9979e8/(en*1.60217e-19))
        for en in (energy-dE, energy, energy+dE)]

# putting the whole system together
s = Group((Group(srcs), sg, det))

pprint(s.to_dict())

n_rays = 100000  # number of rays to calculate (per source)

print("Tracing %d rays..." % n_rays)
t0 = time()
trace = s.trace(n=n_rays)
print("Done, took %f s" % (time() - t0))

datafile = "rowland.dat"
print("Writing detector image to '%s'" % datafile)
with open(datafile, "w") as f:
    f.write("# xpos [m]\typos [m]\twavelength [m]\n")
    w = csv.writer(f, delimiter="\t")
    for energy in list(s.children[-1].footprint.values()):
        w.writerows(energy)

import json
with open("rowland.json", "w") as f:
    json.dump(s.to_dict(), f, indent=4)