test.py

Script to reproduce the issue - ganeva, 19 Nov 2018 14:27

Download (2.02 KB)

 
1
import numpy as np
2
from matplotlib import pyplot as plt
3
import bornagain as ba
4
from bornagain import deg, angstrom, nm, kvector_t
5

    
6
sld_D2O = 6.34e-06
7

    
8

    
9
def get_sample():
10
    # Defining Materials
11
    material_1 = ba.MaterialBySLD("Substrate", 2.07e-06, 0.0)
12
    material_2 = ba.MaterialBySLD("SiO2", 3.4e-06, 0.0)
13
    material_4 = ba.MaterialBySLD("D2O", sld_D2O, 0.0)
14

    
15
    # Defining Layers
16
    layer_1 = ba.Layer(material_1)
17
    layer_2 = ba.Layer(material_2, 1.0*nm)
18
    layer_4 = ba.Layer(material_4)
19

    
20
    # Defining Multilayers
21
    multiLayer_1 = ba.MultiLayer()
22
    multiLayer_1.addLayer(layer_1)
23
    multiLayer_1.addLayer(layer_2)
24
    multiLayer_1.addLayer(layer_4)
25
    return multiLayer_1
26

    
27

    
28
def get_simulation(distr=True):
29
    simulation = ba.SpecularSimulation()
30
    alpha_i_axis = ba.FixedBinAxis("alpha_i", 500, 0.0*deg, 6.5*deg)
31
    simulation.setBeamParameters(8.0*angstrom, alpha_i_axis)
32
    simulation.setBeamIntensity(1.0)
33
    if distr:
34
        distr_1 = ba.DistributionCosine(8.0*angstrom, 0.8*angstrom)
35
        simulation.addParameterDistribution("*/Beam/Wavelength", distr_1, 50, 2.0, ba.RealLimits.positive())
36
    return simulation
37

    
38

    
39
def run_simulation(distr=True):
40
    sample = get_sample()
41
    simulation = get_simulation(distr)
42
    simulation.setSample(sample)
43
    simulation.runSimulation()
44
    return simulation.result()
45

    
46

    
47
if __name__ == '__main__':
48
    result = run_simulation(False)
49
    units=ba.AxesUnits.QSPACE
50
    data = result.data(units)
51
    intensity = data.getArray()
52

    
53
    x_axis = np.array(data.getAxis(0).getBinCenters())
54
    print("Xmin={}, Xmax={}".format(np.min(x_axis), np.max(x_axis)))
55

    
56
    ymax = np.amax(intensity) * 2.0
57
    ymin = 1.0e-08
58

    
59
    xlabel = r'$\mathrm{Q}$ $(\mathrm{\AA^{-1}})$'
60
    ylabel = "Intensity (a. u.)"
61

    
62

    
63
    plt.plot(x_axis/10.0, intensity, color='k', label=r'Simulation')
64

    
65
    plt.ylim([ymin, ymax])
66
    plt.yscale('log')
67

    
68
    label_fontsize=14
69
    plt.xlabel(xlabel, fontsize=label_fontsize)
70
    plt.ylabel(ylabel, fontsize=label_fontsize)
71
    plt.legend(loc='upper right', fontsize=16)
72
    plt.show()