In this tutorial we explain how to access GISAS simulation results, how to plot the simulated detector 2D intensity map as a color map and how to export the result into various formats.
The detector intensity in BornAgain can be retrieved via special object of
simulation = GISASSimulation() simulation.setDetectorParameters(20, -1.0*deg, 1.0*deg, 10, 0.0*deg, 1.0*deg) simulation.setSample(sample) simulation.runSimulation() result = simulation.result()
SimulationResult object allows
The user can convert a
SimulationResult object into a numpy array and proceed
with it in the manner he is more comfortable with.
In the code snippet below the method
array() returns a numpy array of the same shape as the detector pixel array.
numpy.savetxt from the numpy library saves the data to an ASCII file.
arr = simulation.result().array() numpy.savetxt("intensity.txt", arr)
BornAgain provides few convenient functions to plot simulation result as color map. Internally they are using not more than
plot_simulation_result makes a plot and holds the graphics, while
plot_colormap makes the plot
and let the program continue to allow more plots on same figure, for example.
The code snippet below gives few examples
result = simulation.result() # plot color map with automatic axes labels and min/max calculated ba.plot_simulation_result(result) # plot color map with custom labels and min/max defined. ba.plot_colormap(result, zmin=1e-04, zmax=1e+05, xlabel="")
It is possible to convert
SimulationResult to BornAgain’s
Histogram2D object. It allows to perform
some additional data treatment tasks:
In the code snippet below simulation results are converted to
Histogram2D object with axes converted into Q-space,
then it is cropped to the region of interest, plotted and then saved to disk into BornAgain internal format.
hist = simulation.result().histogram2d(units=ba.AxesUnits.QSPACE) hist = hist.crop(-1.0, 0.5, 1.0, 1.0) ba.plot_histogram(hist) hist.save("result.int.gz")
Additional information can be found in the following pages: