Angular detector axes

A scattering simulation with a SphericalDetector returns exit-angle axes phi_f (rad) and alpha_f (rad). Plots display radian axes in degrees. To access the converted coordinates directly:

degree_result = angular_result.plottableField()
phi_f_degrees = degree_result.xCenters()
alpha_f_degrees = degree_result.yCenters()

Convert angular axes to q axes

Use the beam wavelength in nm and incident grazing angle in rad:

transformation = ba.FrameTrafo.ScatteringToQ(wavelength, alpha_i)
q_result = transformation.transformedDatafield(angular_result)

For a nonzero incident azimuth, pass phi_i as the third argument. The transformation follows

$$ q_y = \frac{2\pi}{\lambda} \left(\sin\varphi_\mathrm{f}-\sin\varphi_\mathrm{i}\right), \qquad q_z = \frac{2\pi}{\lambda} \left(\sin\alpha_\mathrm{f}+\sin\alpha_\mathrm{i}\right). $$

The result has axes q_y (1/nm) and q_z (1/nm). Intensity values remain in the same bin order: ScatteringToQ changes the axes but does not rebin or interpolate the map. Its two independent equidistant q axes are a small-angle approximation.

The input must have the angular axis labels shown above. There is no inverse q-to-angle transformation, and offspec results are not supported.

Other axis operations

For a specular simulation, choose angular or q coordinates when creating the scan:

angular_scan = ba.AlphaScan(n, alpha_min, alpha_max)
q_scan = ba.QzScan(n, q_z_min, q_z_max)

To exchange both axes and transpose the values:

transposed_result = ba.FrameTrafo.Transpose(q_result)

For custom axes, construct a new frame and attach the corresponding values:

custom_frame = ba.Frame(
    ba.ListScan("x (nm)", x_coordinates.tolist()),
    ba.ListScan("y (nm)", y_coordinates.tolist()))
custom_result = ba.Datafield(custom_frame, transformed_values.ravel().tolist())

This constructor does not transform or interpolate values. For a reciprocal-space to real-space transformation, see Fourier transform.

Complete example

Scattering intensity

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26"]
# ///
"""
In this example we demonstrate how to plot a simulation result with
axes in different units (nbins, mm, degs and QyQz).
"""
import bornagain as ba
ba.require_versions("bornagain>=25,<26")
from bornagain import angstrom, deg, nm
from matplotlib import rcParams


def get_sample():
    # Materials
    air_color = (0.90, 0.93, 0.97)
    air_mat = ba.RefractiveMaterial("Air", air_color, 0, 0)
    particle_color = (0.86, 0.24, 0.18)
    particle_mat = ba.RefractiveMaterial("Particle", particle_color, 6e-5, 2e-08)
    substrate_color = (0.28, 0.57, 0.82)
    substrate_mat = ba.RefractiveMaterial("Substrate", substrate_color, 6e-06, 2e-08)

    # Particles
    R = 2.5*nm
    ff = ba.Spheroid(R, R)
    particle = ba.Particle(particle_mat, ff)

    # Interference function
    lattice = ba.SquareLattice2D(10*nm, 2*deg)
    layout = ba.Crystal2D(particle, lattice)
    pdf = ba.Profile2DCauchy(50*nm, 50*nm, 0)
    layout.setDecayFunction(pdf)

    # Layers
    l_air = ba.Layer(air_mat)
    l_air.deposit2D(layout)
    l_substrate = ba.Layer(substrate_mat)

    # Sample
    sample = ba.Sample()
    sample.addLayer(l_air)
    sample.addLayer(l_substrate)
    return sample


def get_simulation(sample, wavelength, alpha_i):
    beam = ba.Beam(1e9, wavelength, alpha_i)
    n = 200
    detector = ba.SphericalDetector(n, -1*deg, 1*deg, n, 0, 1*deg)
    simulation = ba.ScatteringSimulation(beam, sample, detector)
    return simulation

if __name__ == '__main__':
    sample = get_sample()
    wavelength = 0.04*nm
    alpha_i = 0.2*deg
    simulation = get_simulation(sample, wavelength, alpha_i)
    result = simulation.simulate()

    trafo = ba.FrameTrafo.ScatteringToQ(wavelength, alpha_i)
    res2 = trafo.transformedDatafield(result)

    ba.showSample3D(sample, sample_size=100*nm, seed=0)
    ba.plot_datafield(res2, unit_aspect=1)
    ba.plt.show()
auto/Examples/scatter2d/VsQ.py

History

This functionality was provided in completely different ways in BornAgain <=21. The present solution has been introduced in BornAgain 24.