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

BuriedParticles.py copied as ex02_BuriedParticles.py into test directory. In...

BuriedParticles.py copied as ex02_BuriedParticles.py into test directory. In the next step it will be converted into a wrapper.
Also simplified things in CMakeLists.txt and PyPersistenceTest.cpp.
parent 78e2e775
No related branches found
No related tags found
No related merge requests found
......@@ -29,52 +29,53 @@ target_link_libraries(PyPersistenceTest BornAgainCore BornAgainTestMachinery)
foreach(example ${PY_EXAMPLES})
endforeach()
# ppt = python persistence test:
function(ppt example tolerance)
set(script ${PY_EXAMPLES_DIR}/${example})
get_filename_component(script_dir ${script} DIRECTORY)
get_filename_component(script_name ${script} NAME_WE)
get_filename_component(script_ext ${script} EXT)
if (NOT ${script_ext} STREQUAL ".py" )
message(SEND_ERROR
"Unexpected file name extension '${script_ext}' in Python script ${script}")
continue()
endif()
# lppt = legacy python persistence test:
function(lppt example tolerance)
set(script_path ${PY_EXAMPLES_DIR}/${example}.py)
get_filename_component(script_name ${script_path} NAME_WE)
add_test(PyPersistenceTest/${script_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/PyPersistenceTest
${script_dir} ${script_name} ${tolerance})
${script_path} ${script_name} ${tolerance})
endfunction()
lppt("simulation/ex01_BasicParticles/AllFormFactorsAvailable" 2e-10)
lppt("simulation/ex01_BasicParticles/CylindersAndPrisms" 2e-10)
lppt("simulation/ex01_BasicParticles/CylindersInBA" 2e-10)
lppt("simulation/ex01_BasicParticles/CylindersInDWBA" 2e-10)
lppt("simulation/ex01_BasicParticles/CylindersWithSizeDistribution" 2e-10)
lppt("simulation/ex01_BasicParticles/RotatedPyramids" 2e-10)
lppt("simulation/ex01_BasicParticles/TwoTypesOfCylindersWithSizeDistribution" 2e-10)
lppt("simulation/ex02_LayeredStructures/BuriedParticles" 2e-10)
lppt("simulation/ex02_LayeredStructures/CorrelatedRoughness" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/ApproximationDA" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/ApproximationLMA" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/ApproximationSSCA" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/CosineRipplesAtRectLattice" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference1DLattice" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference1DRadialParaCrystal" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference2DCenteredSquareLattice" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference2DLatticeSumOfRotated" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference2DParaCrystal" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference2DRotatedSquareLattice" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/Interference2DSquareLattice" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/RectangularGrating" 0.5)
lppt("simulation/ex03_InterferenceFunctions/SpheresAtHexLattice" 2e-10)
lppt("simulation/ex03_InterferenceFunctions/TriangularRipple" 2e-10)
lppt("simulation/ex04_ComplexShapes/CoreShellNanoparticles" 2e-10)
lppt("simulation/ex04_ComplexShapes/CustomFormFactor" 2e-10)
lppt("simulation/ex04_ComplexShapes/HexagonalLatticesWithBasis" 2e-10)
lppt("simulation/ex04_ComplexShapes/LargeParticlesFormFactor" 0.5)
lppt("simulation/ex05_BeamAndDetector/BeamDivergence" 2e-10)
lppt("simulation/ex05_BeamAndDetector/DetectorResolutionFunction" 2e-10)
lppt("simulation/ex05_BeamAndDetector/OffSpecularSimulation" 2e-10)
lppt("simulation/ex05_BeamAndDetector/RectangularDetector" 2e-10)
lppt("simulation/ex05_BeamAndDetector/SpecularSimulation" 2e-10)
lppt("simulation/ex06_Miscellaneous/AxesInDifferentUnits" 2e-10)
lppt("fitting/ex01_SampleParametersIntro/SampleParametersIntro" 2e-10)
# ppt = python persistence test:
function(ppt script tolerance)
add_test(PyPersistenceTest/${script} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/PyPersistenceTest
${CMAKE_CURRENT_SOURCE_DIR}/${script}.py ${script} ${tolerance})
endfunction()
ppt("simulation/ex01_BasicParticles/AllFormFactorsAvailable.py" 2e-10)
ppt("simulation/ex01_BasicParticles/CylindersAndPrisms.py" 2e-10)
ppt("simulation/ex01_BasicParticles/CylindersInBA.py" 2e-10)
ppt("simulation/ex01_BasicParticles/CylindersInDWBA.py" 2e-10)
ppt("simulation/ex01_BasicParticles/CylindersWithSizeDistribution.py" 2e-10)
ppt("simulation/ex01_BasicParticles/RotatedPyramids.py" 2e-10)
ppt("simulation/ex01_BasicParticles/TwoTypesOfCylindersWithSizeDistribution.py" 2e-10)
ppt("simulation/ex02_LayeredStructures/BuriedParticles.py" 2e-10)
ppt("simulation/ex02_LayeredStructures/CorrelatedRoughness.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/ApproximationDA.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/ApproximationLMA.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/ApproximationSSCA.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/CosineRipplesAtRectLattice.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference1DLattice.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference1DRadialParaCrystal.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference2DCenteredSquareLattice.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference2DLatticeSumOfRotated.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference2DParaCrystal.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference2DRotatedSquareLattice.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/Interference2DSquareLattice.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/RectangularGrating.py" 0.5)
ppt("simulation/ex03_InterferenceFunctions/SpheresAtHexLattice.py" 2e-10)
ppt("simulation/ex03_InterferenceFunctions/TriangularRipple.py" 2e-10)
ppt("simulation/ex04_ComplexShapes/CoreShellNanoparticles.py" 2e-10)
ppt("simulation/ex04_ComplexShapes/CustomFormFactor.py" 2e-10)
ppt("simulation/ex04_ComplexShapes/HexagonalLatticesWithBasis.py" 2e-10)
ppt("simulation/ex04_ComplexShapes/LargeParticlesFormFactor.py" 0.5)
ppt("simulation/ex05_BeamAndDetector/BeamDivergence.py" 2e-10)
ppt("simulation/ex05_BeamAndDetector/DetectorResolutionFunction.py" 2e-10)
ppt("simulation/ex05_BeamAndDetector/OffSpecularSimulation.py" 2e-10)
ppt("simulation/ex05_BeamAndDetector/RectangularDetector.py" 2e-10)
ppt("simulation/ex05_BeamAndDetector/SpecularSimulation.py" 2e-10)
ppt("simulation/ex06_Miscellaneous/AxesInDifferentUnits.py" 2e-10)
ppt("fitting/ex01_SampleParametersIntro/SampleParametersIntro.py" 2e-10)
ppt("ex02_BuriedParticles" 2e-10)
......@@ -28,9 +28,9 @@
#include <iomanip>
PyPersistenceTest::PyPersistenceTest(
const std::string& directory, const std::string& name, double threshold)
const std::string& path, const std::string& name, double threshold)
: IReferencedTest(name, "persistence test on script "+name, threshold)
, m_directory(directory)
, m_path(path)
{}
//! Runs a Python script, and returns true if the output of the script agrees with reference data.
......@@ -43,10 +43,9 @@ bool PyPersistenceTest::runTest()
std::cout << "Removed old output " << fname.c_str() << "\n";
}
// Run Python script
std::string pyscript_filename = FileSystemUtils::jointPath(m_directory, getName()+".py");
// Run Python script, which writes output to PYPERSIST_OUT_DIR.
std::string dat_stem = FileSystemUtils::jointPath(PYPERSIST_OUT_DIR, getName());
if (!runPython(pyscript_filename + " " + dat_stem))
if (!runPython(m_path + " " + dat_stem))
return false;
// Retrieve new output and reference files
......@@ -62,9 +61,7 @@ bool PyPersistenceTest::runTest()
// Compare files one by one
for (auto const& it: dat)
if (!compareFilePair(
FileSystemUtils::jointPath(PYPERSIST_OUT_DIR, it.second),
FileSystemUtils::jointPath(PYPERSIST_REF_DIR, ref[it.first])))
if (!compareFilePair(it.second, ref[it.first]))
return false;
return true;
}
......@@ -78,7 +75,8 @@ PyPersistenceTest::glob2map(const std::string& dir, const std::string& stem)
for (const std::string& fname: FileSystemUtils::glob(dir, stem+"\\.\\w+\\..+")) {
std::vector<std::string> fname_segments =
StringUtils::split(FileSystemUtils::filename(fname), ".");
ret.insert(make_pair(fname_segments[1]+"."+fname_segments[2], fname));
ret.insert(make_pair(fname_segments[1]+"."+fname_segments[2],
FileSystemUtils::jointPath(dir, fname)));
}
return ret;
}
......@@ -92,7 +90,7 @@ bool PyPersistenceTest::compareFileMaps(
// All dat files present in ref?
for (auto const& it: dat) {
if (ref.find(it.first)==ref.end()) {
std::cerr << "For test output " << it.second
std::cerr << "For test output " << it.second
<< " there is no reference file in " << PYPERSIST_REF_DIR << "\n";
success = false;
}
......@@ -100,7 +98,7 @@ bool PyPersistenceTest::compareFileMaps(
// All ref files present in dat?
for (auto const& it: ref) {
if (dat.find(it.first)==dat.end()) {
std::cerr << "For reference file " << it.second
std::cerr << "For reference file " << it.second
<< " there is no test output in " << PYPERSIST_OUT_DIR << "\n";
success = false;
}
......
......@@ -36,13 +36,13 @@ namespace YAML {
class PyPersistenceTest : public IReferencedTest
{
public:
PyPersistenceTest(const std::string& directory, const std::string& name, double threshold);
PyPersistenceTest(const std::string& path, const std::string& name, double threshold);
~PyPersistenceTest() final {}
bool runTest() final;
private:
std::string m_directory;
std::string m_path;
static std::map<const std::string, const std::string>
glob2map(const std::string& dir, const std::string& stem);
......
"""
Spherical particles embedded in the middle of the layer on top of substrate.
"""
import numpy
import bornagain as ba
from bornagain import deg, angstrom, nm
def get_sample():
"""
Returns a sample with spherical particles in an layer between air and substrate.
"""
# defining materials
m_ambience = ba.HomogeneousMaterial("Air", 0.0, 0.0)
m_interm_layer = ba.HomogeneousMaterial("IntermLayer", 3.45e-6, 5.24e-9)
m_substrate = ba.HomogeneousMaterial("Substrate", 7.43e-6, 1.72e-7)
m_particle = ba.HomogeneousMaterial("Particle", 0.0, 0.0)
# collection of particles
ff_sphere = ba.FormFactorFullSphere(10.2*nm)
sphere = ba.Particle(m_particle, ff_sphere)
sphere.setPosition(0.0, 0.0, -25.2)
particle_layout = ba.ParticleLayout()
particle_layout.addParticle(sphere, 1.0)
# assembling the sample
air_layer = ba.Layer(m_ambience)
intermediate_layer = ba.Layer(m_interm_layer, 30.*nm)
intermediate_layer.addLayout(particle_layout)
substrate_layer = ba.Layer(m_substrate, 0)
multi_layer = ba.MultiLayer()
multi_layer.addLayer(air_layer)
multi_layer.addLayer(intermediate_layer)
multi_layer.addLayer(substrate_layer)
return multi_layer
def get_simulation():
"""
Returns a GISAXS simulation.
"""
simulation = ba.GISASSimulation()
simulation.setSample(get_sample())
simulation.setDetectorParameters(200, -1*deg, +1*deg, 200, 0*deg, +2*deg)
simulation.setBeamParameters(1.5*angstrom, 0.15*deg, 0.0*deg)
return simulation
if __name__ == '__main__':
simulation = get_simulation()
simulation.runSimulation()
result = simulation.getIntensityData()
ba.plot_intensity_data(result)
File added
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