File: AxesInDifferentUnits.py

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (86 lines) | stat: -rwxr-xr-x 2,488 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
"""
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
from bornagain import angstrom, ba_plot as bp, deg, nm
from matplotlib import rcParams


def get_sample():
    # Materials
    material_air = ba.RefractiveMaterial("Air", 0, 0)
    material_particle = ba.RefractiveMaterial("Particle", 0.0006, 2e-08)
    material_substrate = ba.RefractiveMaterial("Substrate", 6e-06, 2e-08)

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

    # Interference function
    lattice = ba.SquareLattice2D(10*nm, 2*deg)
    interference = ba.Interference2DLattice(lattice)
    interference_pdf = ba.Profile2DCauchy(50*nm, 50*nm, 0)
    interference.setDecayFunction(interference_pdf)

    # Particle layout
    layout = ba.ParticleLayout()
    layout.addParticle(particle)
    layout.setInterference(interference)

    # Layers
    l_air = ba.Layer(material_air)
    l_air.addLayout(layout)
    l_substrate = ba.Layer(material_substrate)

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


def transformed_plot(i, result, title):
    """
    Plots simulation result for different detectors.
    """

    bp.plt.subplot(2, 2, i)
    bp.plot_simres(result,
                   # xlabel=r'$x \;({\rm mm})$',
                   # ylabel=r'$y \;({\rm mm})$',
                   zlabel=None,
                   with_cb=False)
    bp.plt.title(title, loc='left')


if __name__ == '__main__':
    beam = ba.Beam(1e9, 1*angstrom, 0.5*deg)
    n = 11
    width = 170  # nm
    detector = ba.FlatDetector(n, n, width, width, beam, ba.FlatDetector.R, 2000.)
    simulation = ba.ScatteringSimulation(beam, get_sample(), detector)
    result = simulation.simulate()

    # setup plot
    rcParams['image.aspect'] = 'auto'
    bp.plt.figure(figsize=(10, 10))

    transformed_plot(1, result, "Real-space detector coordinates")
    transformed_plot(2, detector.field2bins(result), "Bin indices")
    transformed_plot(3, detector.field2angles(result), "Deflection angles")
    transformed_plot(4, detector.field2q(result), "Q space")

    # finish plot
    bp.plt.subplots_adjust(
        left=0.07,
        right=0.97,
        top=0.9,
        bottom=0.1,
        hspace=0.35,
        wspace=0.,
    )
    from bornagain import ba_check
    ba_check.persistence_test(result)