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

repair test

parent e0d2c4de
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
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
An example of taking into account beam angular divergence An example of taking into account beam angular divergence
and beam footprint correction in reflectometry calculations. and beam footprint correction in reflectometry calculations.
""" """
import os, numpy as np import numpy as np, os, sys
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
import bornagain as ba import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, std_samples from bornagain import angstrom, ba_plot as bp, deg, std_samples
...@@ -39,14 +39,15 @@ def get_sample(): ...@@ -39,14 +39,15 @@ def get_sample():
return std_samples.alternating_layers() return std_samples.alternating_layers()
def get_simulation(sample, scan_size=500): def get_simulation(sample, **kwargs):
""" """
Returns a specular simulation with beam and detector defined. Returns a specular simulation with beam and detector defined.
""" """
n = simargs['n']
footprint = ba.FootprintSquare(beam_sample_ratio) footprint = ba.FootprintSquare(beam_sample_ratio)
alpha_distr = ba.RangedDistributionGaussian(n_points, n_sig) alpha_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.setFootprintFactor(footprint) scan.setFootprintFactor(footprint)
scan.setAbsoluteAngularResolution(alpha_distr, d_ang) scan.setAbsoluteAngularResolution(alpha_distr, d_ang)
...@@ -58,14 +59,18 @@ def get_simulation(sample, scan_size=500): ...@@ -58,14 +59,18 @@ def get_simulation(sample, scan_size=500):
if __name__ == '__main__': if __name__ == '__main__':
plotargs, simargs = bp.kwargs_from_cmdline(sim_n=0) plotargs, simargs = bp.kwargs_from_cmdline(sim_n=500)
datadir = os.getenv('BA_EXAMPLE_DATA_DIR', '') datadir = os.getenv('BA_EXAMPLE_DATA_DIR', '')
data_fname = os.path.join(datadir, "genx_angular_divergence.dat.gz") data_fname = os.path.join(datadir, "genx_angular_divergence.dat.gz")
print(f"DIR={datadir} NAM={data_fname}")
sample = get_sample() sample = get_sample()
simulation = get_simulation(sample, **simargs) simulation = get_simulation(sample, **simargs)
result = simulation.simulate() result = simulation.simulate()
bp.plot_simulation_result(result, **plotargs) bp.plot_simulation_result(result, **plotargs)
if not plotargs.pop('plot', 'on') in ['on']:
sys.exit(0)
genx_axis, genx_values = reference_data(data_fname) genx_axis, genx_values = reference_data(data_fname)
plt.semilogy(genx_axis, genx_values, 'ko', markevery=300) plt.semilogy(genx_axis, genx_values, 'ko', markevery=300)
plt.legend(['BornAgain', 'GenX'], loc='upper right') plt.legend(['BornAgain', 'GenX'], loc='upper right')
......
...@@ -47,6 +47,7 @@ function(test_equality example reference tolerance) ...@@ -47,6 +47,7 @@ function(test_equality example reference tolerance)
set(test_name Example.persist.${EXAMPLE_NAME}) set(test_name Example.persist.${EXAMPLE_NAME})
add_test(NAME ${test_name} add_test(NAME ${test_name}
COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
"BA_EXAMPLE_DATA_DIR=${EXAMPLES_DIR}/data"
${Python3_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/RunPersistenceTest.py ${Python3_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/RunPersistenceTest.py
${script_path} ${reference} ${script_path} ${reference}
${TEST_REFERENCE_DIR_EXAMPLES_MINI} ${TEST_OUTPUT_DIR_PY_PERSIST} 11 ${tolerance}) ${TEST_REFERENCE_DIR_EXAMPLES_MINI} ${TEST_OUTPUT_DIR_PY_PERSIST} 11 ${tolerance})
...@@ -80,7 +81,7 @@ test_example(scatter2d/CylindersInAverageLayer 2e-10) ...@@ -80,7 +81,7 @@ test_example(scatter2d/CylindersInAverageLayer 2e-10)
test_example(scatter2d/CylindersInBA 2e-10) test_example(scatter2d/CylindersInBA 2e-10)
# test_example(scatter2d/CylindersWithSizeDistribution 2e-10) # test_example(scatter2d/CylindersWithSizeDistribution 2e-10)
test_example(scatter2d/DetectorResolutionFunction 2e-10) test_example(scatter2d/DetectorResolutionFunction 2e-10)
test_example(scatter2d/DodecahedraSAS.py 2e-10) test_example(scatter2d/DodecahedraSAS 2e-10)
test_example(scatter2d/HalfSpheresInAverageTopLayer 2e-10) test_example(scatter2d/HalfSpheresInAverageTopLayer 2e-10)
test_example(scatter2d/HexagonalLatticesWithBasis 2e-10) test_example(scatter2d/HexagonalLatticesWithBasis 2e-10)
test_example(scatter2d/Interference1DRadialParaCrystal 2e-10) test_example(scatter2d/Interference1DRadialParaCrystal 2e-10)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment