Skip to content
Snippets Groups Projects
Commit aac3eeb5 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

repair tests

parent 51789fec
No related branches found
No related tags found
1 merge request!773new mechanism to steer simulation size in examples and tests, based on command-line argument sim_n
......@@ -22,15 +22,16 @@ def get_sample():
return std_samples.alternating_layers()
def get_simulation(sample, scan_size=500):
def get_simulation(sample, **simargs):
"""
Returns a specular simulation with beam and detector defined.
"""
n = simargs['n']
alpha_distr = ba.RangedDistributionGaussian(n_points, n_sig)
wavelength_distr = ba.RangedDistributionGaussian(n_points, n_sig)
scan = ba.AlphaScan(wavelength, scan_size, alpha_i_min, alpha_i_max)
scan = ba.AlphaScan(wavelength, n, alpha_i_min, alpha_i_max)
scan.setAbsoluteAngularResolution(alpha_distr, d_ang)
scan.setAbsoluteWavelengthResolution(wavelength_distr, d_wl)
......@@ -42,7 +43,7 @@ def get_simulation(sample, scan_size=500):
if __name__ == '__main__':
plotargs, simargs = bp.kwargs_from_cmdline(sim_n=0)
plotargs, simargs = bp.kwargs_from_cmdline(sim_n=500)
sample = get_sample()
simulation = get_simulation(sample, **simargs)
result = simulation.simulate()
......
......@@ -4,6 +4,7 @@ Simulation of grating using very long boxes and 1D lattice.
Monte-carlo integration is used to get rid of
large-particle form factor oscillations.
"""
import sys
import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, micrometer, nm
from matplotlib import pyplot as plt
......@@ -63,26 +64,29 @@ def get_simulation(sample, **simargs):
return simulation
def run_simulation():
if __name__ == '__main__':
"""
Runs simulation and returns intensity map.
"""
plotargs, simargs = bp.kwargs_from_cmdline(sim_n=200)
sample = get_sample()
simulation = get_simulation(sample)
simulation = get_simulation(sample, **simargs)
if not "__no_terminal__" in globals():
simulation.setTerminalProgressMonitor()
simulation.simulate()
return simulation.result()
result = simulation.simulate()
datfile = plotargs.pop('datfile', None)
if datfile:
ba.IntensityDataIOFactory.writeSimulationResult(result, datfile)
histogram = result.histogram2d()
bp.plot_histogram(histogram)
def simulate_and_plot():
result = run_simulation().histogram2d()
bp.plot_histogram(result)
peaks = ba.FindPeaks(result, 2, "nomarkov", 0.001)
peaks = ba.FindPeaks(histogram, 2, "nomarkov", 0.001)
xpeaks = [peak[0] for peak in peaks]
ypeaks = [peak[1] for peak in peaks]
print(peaks)
if not plotargs.pop('plot', 'on') in ['on']:
sys.exit(0)
plt.plot(xpeaks,
ypeaks,
linestyle='None',
......@@ -90,7 +94,3 @@ def simulate_and_plot():
color='white',
markersize=10)
plt.show()
if __name__ == '__main__':
simulate_and_plot()
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment