From dea83df7cb6cfd16d95f1e614df6678332177aa0 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Tue, 8 Dec 2020 19:07:39 +0100 Subject: [PATCH] update examples; check_functionality -> batch-plot --- .../sim01_Particles/CylindersAndPrisms.py | 3 +- .../Python/sim01_Particles/CylindersInBA.py | 5 +-- .../Python/sim01_Particles/CylindersInDWBA.py | 5 +-- .../CylindersWithSizeDistribution.py | 3 +- .../Python/sim01_Particles/RotatedPyramids.py | 5 +-- ...TwoTypesOfCylindersWithSizeDistribution.py | 3 +- .../sim02_Complexes/BiMaterialCylinders.py | 3 +- .../sim02_Complexes/CoreShellNanoparticles.py | 3 +- .../HexagonalLatticesWithBasis.py | 5 +-- .../Python/sim02_Complexes/MesoCrystal.py | 5 +-- .../ParticlesCrossingInterface.py | 3 +- .../sim03_Structures/ApproximationDA.py | 3 +- .../sim03_Structures/ApproximationLMA.py | 3 +- .../sim03_Structures/ApproximationSSCA.py | 3 +- .../CosineRipplesAtRectLattice.py | 5 +-- .../Interference1DRadialParaCrystal.py | 5 +-- .../Interference2DCenteredSquareLattice.py | 5 +-- .../Interference2DLatticeSumOfRotated.py | 3 +- .../Interference2DParaCrystal.py | 5 +-- .../Interference2DRotatedSquareLattice.py | 5 +-- .../Interference2DSquareFiniteLattice.py | 5 +-- .../Interference2DSquareLattice.py | 5 +-- .../sim03_Structures/RectangularGrating.py | 5 +-- .../sim03_Structures/SpheresAtHexLattice.py | 5 +-- .../sim03_Structures/TriangularRipple.py | 5 +-- .../sim04_Multilayers/BuriedParticles.py | 3 +- .../sim04_Multilayers/CorrelatedRoughness.py | 3 +- .../CylindersInAverageLayer.py | 5 +-- .../HalfSpheresInAverageTopLayer.py | 5 +-- .../Python/sim05_Magnetism/MagneticSpheres.py | 3 +- .../Python/sim11_Device/BeamDivergence.py | 3 +- .../Python/sim11_Device/ConstantBackground.py | 3 +- .../DetectorResolutionFunction.py | 3 +- .../BoxesWithSpecularPeak.py | 5 +-- .../Python/PyExamples/CMakeLists.txt | 2 +- Wrap/Python/plot_utils.py | 2 +- cmake/BornAgain/Directories.cmake | 1 + cmake/BornAgain/LineLength.cmake | 2 +- .../code-tools/batch-plot.py | 34 +++++++++++++++++-- 39 files changed, 121 insertions(+), 58 deletions(-) rename Tests/Functional/Python/PyExamples/check_functionality.py => devtools/code-tools/batch-plot.py (65%) mode change 100644 => 100755 diff --git a/Examples/Python/sim01_Particles/CylindersAndPrisms.py b/Examples/Python/sim01_Particles/CylindersAndPrisms.py index e2c13192a9c..795c4f2f1ad 100644 --- a/Examples/Python/sim01_Particles/CylindersAndPrisms.py +++ b/Examples/Python/sim01_Particles/CylindersAndPrisms.py @@ -50,7 +50,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 0.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim01_Particles/CylindersInBA.py b/Examples/Python/sim01_Particles/CylindersInBA.py index 50c91c0e3a8..4ff161164ef 100644 --- a/Examples/Python/sim01_Particles/CylindersInBA.py +++ b/Examples/Python/sim01_Particles/CylindersInBA.py @@ -41,8 +41,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim01_Particles/CylindersInDWBA.py b/Examples/Python/sim01_Particles/CylindersInDWBA.py index 97f141dc869..73a903eb021 100644 --- a/Examples/Python/sim01_Particles/CylindersInDWBA.py +++ b/Examples/Python/sim01_Particles/CylindersInDWBA.py @@ -43,8 +43,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim01_Particles/CylindersWithSizeDistribution.py b/Examples/Python/sim01_Particles/CylindersWithSizeDistribution.py index b825706563d..81e115809de 100644 --- a/Examples/Python/sim01_Particles/CylindersWithSizeDistribution.py +++ b/Examples/Python/sim01_Particles/CylindersWithSizeDistribution.py @@ -47,7 +47,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim01_Particles/RotatedPyramids.py b/Examples/Python/sim01_Particles/RotatedPyramids.py index a758f45164b..7c83b39452a 100644 --- a/Examples/Python/sim01_Particles/RotatedPyramids.py +++ b/Examples/Python/sim01_Particles/RotatedPyramids.py @@ -45,8 +45,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim01_Particles/TwoTypesOfCylindersWithSizeDistribution.py b/Examples/Python/sim01_Particles/TwoTypesOfCylindersWithSizeDistribution.py index 1894c7a5aa2..6fa2b1f0786 100644 --- a/Examples/Python/sim01_Particles/TwoTypesOfCylindersWithSizeDistribution.py +++ b/Examples/Python/sim01_Particles/TwoTypesOfCylindersWithSizeDistribution.py @@ -56,7 +56,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim02_Complexes/BiMaterialCylinders.py b/Examples/Python/sim02_Complexes/BiMaterialCylinders.py index 3f7fbc62f61..6b4f501baa9 100644 --- a/Examples/Python/sim02_Complexes/BiMaterialCylinders.py +++ b/Examples/Python/sim02_Complexes/BiMaterialCylinders.py @@ -59,7 +59,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(100000000.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 0.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim02_Complexes/CoreShellNanoparticles.py b/Examples/Python/sim02_Complexes/CoreShellNanoparticles.py index bae3d599ae3..c6452b607b2 100644 --- a/Examples/Python/sim02_Complexes/CoreShellNanoparticles.py +++ b/Examples/Python/sim02_Complexes/CoreShellNanoparticles.py @@ -50,7 +50,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 0.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim02_Complexes/HexagonalLatticesWithBasis.py b/Examples/Python/sim02_Complexes/HexagonalLatticesWithBasis.py index 25aeb82c29f..4fc0c6d8f66 100644 --- a/Examples/Python/sim02_Complexes/HexagonalLatticesWithBasis.py +++ b/Examples/Python/sim02_Complexes/HexagonalLatticesWithBasis.py @@ -62,8 +62,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -1.0*deg, 1.0*deg, 200, 0.0*deg, - 1.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -1.0*deg, 1.0*deg, ny, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim02_Complexes/MesoCrystal.py b/Examples/Python/sim02_Complexes/MesoCrystal.py index de317479061..a3b78a2461f 100644 --- a/Examples/Python/sim02_Complexes/MesoCrystal.py +++ b/Examples/Python/sim02_Complexes/MesoCrystal.py @@ -55,8 +55,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim02_Complexes/ParticlesCrossingInterface.py b/Examples/Python/sim02_Complexes/ParticlesCrossingInterface.py index 3f84a0ee061..493b78308c0 100644 --- a/Examples/Python/sim02_Complexes/ParticlesCrossingInterface.py +++ b/Examples/Python/sim02_Complexes/ParticlesCrossingInterface.py @@ -69,7 +69,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 0.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/ApproximationDA.py b/Examples/Python/sim03_Structures/ApproximationDA.py index 41feff79dc3..bdac8aa5254 100644 --- a/Examples/Python/sim03_Structures/ApproximationDA.py +++ b/Examples/Python/sim03_Structures/ApproximationDA.py @@ -53,7 +53,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/ApproximationLMA.py b/Examples/Python/sim03_Structures/ApproximationLMA.py index 85dab0a77e1..158032846f1 100644 --- a/Examples/Python/sim03_Structures/ApproximationLMA.py +++ b/Examples/Python/sim03_Structures/ApproximationLMA.py @@ -61,7 +61,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/ApproximationSSCA.py b/Examples/Python/sim03_Structures/ApproximationSSCA.py index 790ac4aea4f..8530cfe49f7 100644 --- a/Examples/Python/sim03_Structures/ApproximationSSCA.py +++ b/Examples/Python/sim03_Structures/ApproximationSSCA.py @@ -54,7 +54,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/CosineRipplesAtRectLattice.py b/Examples/Python/sim03_Structures/CosineRipplesAtRectLattice.py index b14ee49a5cc..fc0993f33e7 100644 --- a/Examples/Python/sim03_Structures/CosineRipplesAtRectLattice.py +++ b/Examples/Python/sim03_Structures/CosineRipplesAtRectLattice.py @@ -53,8 +53,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.16*nm, ba.Direction(0.3*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, -1.5*deg, 1.5*deg, 100, 0.0*deg, - 2.5*deg) + nx = 100 + ny = 100 + detector = ba.SphericalDetector(nx, -1.5*deg, 1.5*deg, ny, 0.0*deg, 2.5*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/Interference1DRadialParaCrystal.py b/Examples/Python/sim03_Structures/Interference1DRadialParaCrystal.py index 29281c48b85..a411314da86 100644 --- a/Examples/Python/sim03_Structures/Interference1DRadialParaCrystal.py +++ b/Examples/Python/sim03_Structures/Interference1DRadialParaCrystal.py @@ -49,8 +49,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/Interference2DCenteredSquareLattice.py b/Examples/Python/sim03_Structures/Interference2DCenteredSquareLattice.py index 696953b7f76..5b5bb61fbc3 100644 --- a/Examples/Python/sim03_Structures/Interference2DCenteredSquareLattice.py +++ b/Examples/Python/sim03_Structures/Interference2DCenteredSquareLattice.py @@ -62,8 +62,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/Interference2DLatticeSumOfRotated.py b/Examples/Python/sim03_Structures/Interference2DLatticeSumOfRotated.py index 4b7b35ae00a..fb5b18b520b 100644 --- a/Examples/Python/sim03_Structures/Interference2DLatticeSumOfRotated.py +++ b/Examples/Python/sim03_Structures/Interference2DLatticeSumOfRotated.py @@ -38,7 +38,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) distr_1 = ba.DistributionGate(0.0*deg, 240.0*deg) diff --git a/Examples/Python/sim03_Structures/Interference2DParaCrystal.py b/Examples/Python/sim03_Structures/Interference2DParaCrystal.py index c6106e79db3..86ad4e6daaa 100644 --- a/Examples/Python/sim03_Structures/Interference2DParaCrystal.py +++ b/Examples/Python/sim03_Structures/Interference2DParaCrystal.py @@ -55,8 +55,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/Interference2DRotatedSquareLattice.py b/Examples/Python/sim03_Structures/Interference2DRotatedSquareLattice.py index bc6f76a91bf..2b1da4c2d66 100644 --- a/Examples/Python/sim03_Structures/Interference2DRotatedSquareLattice.py +++ b/Examples/Python/sim03_Structures/Interference2DRotatedSquareLattice.py @@ -53,8 +53,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/Interference2DSquareFiniteLattice.py b/Examples/Python/sim03_Structures/Interference2DSquareFiniteLattice.py index 5fee0b8c214..99a9af46b44 100644 --- a/Examples/Python/sim03_Structures/Interference2DSquareFiniteLattice.py +++ b/Examples/Python/sim03_Structures/Interference2DSquareFiniteLattice.py @@ -51,8 +51,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/Interference2DSquareLattice.py b/Examples/Python/sim03_Structures/Interference2DSquareLattice.py index 8ff54b2eb00..e7968d38fde 100644 --- a/Examples/Python/sim03_Structures/Interference2DSquareLattice.py +++ b/Examples/Python/sim03_Structures/Interference2DSquareLattice.py @@ -52,8 +52,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -2.0*deg, 2.0*deg, 200, 0.0*deg, - 2.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/RectangularGrating.py b/Examples/Python/sim03_Structures/RectangularGrating.py index d1f6722bd37..b720c9981db 100644 --- a/Examples/Python/sim03_Structures/RectangularGrating.py +++ b/Examples/Python/sim03_Structures/RectangularGrating.py @@ -54,8 +54,9 @@ def get_sample(lattice_rotation_angle=0.0*deg): def get_simulation(): beam = ba.Beam(100000000.0, 0.134*nm, ba.Direction(0.4*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -0.5*deg, 0.5*deg, 200, 0.0*deg, - 0.6*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -0.5*deg, 0.5*deg, ny, 0.0*deg, 0.6*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) simulation.getOptions().setMonteCarloIntegration(True, 100) diff --git a/Examples/Python/sim03_Structures/SpheresAtHexLattice.py b/Examples/Python/sim03_Structures/SpheresAtHexLattice.py index 8318bd33c93..cfff1d0eefe 100644 --- a/Examples/Python/sim03_Structures/SpheresAtHexLattice.py +++ b/Examples/Python/sim03_Structures/SpheresAtHexLattice.py @@ -53,8 +53,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -1.0*deg, 1.0*deg, 200, 0.0*deg, - 1.0*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -1.0*deg, 1.0*deg, ny, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim03_Structures/TriangularRipple.py b/Examples/Python/sim03_Structures/TriangularRipple.py index d89e7ecae0f..4082acffcbb 100644 --- a/Examples/Python/sim03_Structures/TriangularRipple.py +++ b/Examples/Python/sim03_Structures/TriangularRipple.py @@ -54,8 +54,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.16*nm, ba.Direction(0.3*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, -1.5*deg, 1.5*deg, 200, 0.0*deg, - 2.5*deg) + nx = 200 + ny = 200 + detector = ba.SphericalDetector(nx, -1.5*deg, 1.5*deg, ny, 0.0*deg, 2.5*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim04_Multilayers/BuriedParticles.py b/Examples/Python/sim04_Multilayers/BuriedParticles.py index 5e847140bf2..db574d201f1 100644 --- a/Examples/Python/sim04_Multilayers/BuriedParticles.py +++ b/Examples/Python/sim04_Multilayers/BuriedParticles.py @@ -50,7 +50,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.15*nm, ba.Direction(0.15*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 2.0*deg, 0.0*deg, 1.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 2.0*deg, 0.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim04_Multilayers/CorrelatedRoughness.py b/Examples/Python/sim04_Multilayers/CorrelatedRoughness.py index 4e8c4d0f1e1..f968871ae5b 100644 --- a/Examples/Python/sim04_Multilayers/CorrelatedRoughness.py +++ b/Examples/Python/sim04_Multilayers/CorrelatedRoughness.py @@ -47,7 +47,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(500000000000.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(200, 1.0*deg, 0.0*deg, 0.5*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 1.0*deg, 0.0*deg, 0.5*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) return simulation diff --git a/Examples/Python/sim04_Multilayers/CylindersInAverageLayer.py b/Examples/Python/sim04_Multilayers/CylindersInAverageLayer.py index e8c31fe3efc..dcbca06bfa7 100644 --- a/Examples/Python/sim04_Multilayers/CylindersInAverageLayer.py +++ b/Examples/Python/sim04_Multilayers/CylindersInAverageLayer.py @@ -44,8 +44,9 @@ def get_sample(cyl_height=5*nm): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, -2.0*deg, 2.0*deg, 100, 0.0*deg, - 2.0*deg) + nx = 100 + ny = 100 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) simulation.getOptions().setUseAvgMaterials(True) diff --git a/Examples/Python/sim04_Multilayers/HalfSpheresInAverageTopLayer.py b/Examples/Python/sim04_Multilayers/HalfSpheresInAverageTopLayer.py index eb9e7a9624d..5c5544d3d3a 100644 --- a/Examples/Python/sim04_Multilayers/HalfSpheresInAverageTopLayer.py +++ b/Examples/Python/sim04_Multilayers/HalfSpheresInAverageTopLayer.py @@ -54,8 +54,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, -2.0*deg, 2.0*deg, 100, 0.0*deg, - 2.0*deg) + nx = 100 + ny = 100 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) simulation.getOptions().setUseAvgMaterials(True) diff --git a/Examples/Python/sim05_Magnetism/MagneticSpheres.py b/Examples/Python/sim05_Magnetism/MagneticSpheres.py index 8702457988a..6d1e01bbaca 100644 --- a/Examples/Python/sim05_Magnetism/MagneticSpheres.py +++ b/Examples/Python/sim05_Magnetism/MagneticSpheres.py @@ -49,7 +49,8 @@ def get_simulation(): beam = ba.Beam(1e+12, 0.1*nm, ba.Direction(0.5*deg, 0.0*deg)) beam_polarization = kvector_t(0.0, 0.0, 1.0) beam.setPolarization(beam_polarization) - detector = ba.SphericalDetector(200, 6.0*deg, 0.0*deg, 3.0*deg) + nbin = 200 + detector = ba.SphericalDetector(nbin, 6.0*deg, 0.0*deg, 3.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) analyzer_direction = kvector_t(0.0, 0.0, -1.0) diff --git a/Examples/Python/sim11_Device/BeamDivergence.py b/Examples/Python/sim11_Device/BeamDivergence.py index 619354ded4b..088a9ab3e45 100644 --- a/Examples/Python/sim11_Device/BeamDivergence.py +++ b/Examples/Python/sim11_Device/BeamDivergence.py @@ -43,7 +43,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) distr_1 = ba.DistributionLogNormal(0.1*nm, 0.1) diff --git a/Examples/Python/sim11_Device/ConstantBackground.py b/Examples/Python/sim11_Device/ConstantBackground.py index 3b327dc23c0..0ca4ccd72eb 100644 --- a/Examples/Python/sim11_Device/ConstantBackground.py +++ b/Examples/Python/sim11_Device/ConstantBackground.py @@ -43,7 +43,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1000000.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) background = ba.ConstantBackground(1.0e+03) diff --git a/Examples/Python/sim11_Device/DetectorResolutionFunction.py b/Examples/Python/sim11_Device/DetectorResolutionFunction.py index 6db37134890..739ca5512b4 100644 --- a/Examples/Python/sim11_Device/DetectorResolutionFunction.py +++ b/Examples/Python/sim11_Device/DetectorResolutionFunction.py @@ -43,7 +43,8 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(100, 2.0*deg, 1.0*deg, 1.0*deg) + nbin = 100 + detector = ba.SphericalDetector(nbin, 2.0*deg, 1.0*deg, 1.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) simulation.setDetectorResolutionFunction( diff --git a/Examples/Python/sim22_OffSpecular/BoxesWithSpecularPeak.py b/Examples/Python/sim22_OffSpecular/BoxesWithSpecularPeak.py index ca4bda70e1c..6845d03748d 100644 --- a/Examples/Python/sim22_OffSpecular/BoxesWithSpecularPeak.py +++ b/Examples/Python/sim22_OffSpecular/BoxesWithSpecularPeak.py @@ -52,8 +52,9 @@ def get_sample(): def get_simulation(): beam = ba.Beam(1.0, 0.1*nm, ba.Direction(0.2*deg, 0.0*deg)) - detector = ba.SphericalDetector(101, -2.0*deg, 2.0*deg, 101, 0.0*deg, - 2.0*deg) + nx = 101 + ny = 101 + detector = ba.SphericalDetector(nx, -2.0*deg, 2.0*deg, ny, 0.0*deg, 2.0*deg) simulation = ba.GISASSimulation(beam, get_sample(), detector) simulation.getOptions().setUseAvgMaterials(True) diff --git a/Tests/Functional/Python/PyExamples/CMakeLists.txt b/Tests/Functional/Python/PyExamples/CMakeLists.txt index e0e23002018..7361798b926 100644 --- a/Tests/Functional/Python/PyExamples/CMakeLists.txt +++ b/Tests/Functional/Python/PyExamples/CMakeLists.txt @@ -18,7 +18,7 @@ endif() file(GLOB fit_examples ${PY_EXAMPLES_DIR}/fit55_Specular/FitSpecularBasics.py) set(examples ${sim_examples} ${fit_examples}) -set(test_script ${CMAKE_CURRENT_SOURCE_DIR}/check_functionality.py) +set(test_script ${TOOL_DIR}/code-tools/batch-plot.py) foreach(example_path ${examples}) get_filename_component(example_name ${example_path} NAME_WE) diff --git a/Wrap/Python/plot_utils.py b/Wrap/Python/plot_utils.py index b1d0eb67472..662eb550624 100644 --- a/Wrap/Python/plot_utils.py +++ b/Wrap/Python/plot_utils.py @@ -262,5 +262,5 @@ def plot_simulation_result(result, title=title, **kwargs) plt.tight_layout() - if not postpone_show: + if not (postpone_show): plt.show() diff --git a/cmake/BornAgain/Directories.cmake b/cmake/BornAgain/Directories.cmake index bc51aee1ac7..03eb4f79360 100644 --- a/cmake/BornAgain/Directories.cmake +++ b/cmake/BornAgain/Directories.cmake @@ -2,6 +2,7 @@ # source directories # ----------------------------------------------------------------------------- +set(TOOL_DIR ${CMAKE_SOURCE_DIR}/devtools) set(WRAP_DIR ${CMAKE_SOURCE_DIR}/Wrap) set(SWIG_DIR ${WRAP_DIR}/Swig) set(PY_EXAMPLES_DIR ${CMAKE_SOURCE_DIR}/Examples/Python) diff --git a/cmake/BornAgain/LineLength.cmake b/cmake/BornAgain/LineLength.cmake index 311637cedbd..c5025e90e94 100644 --- a/cmake/BornAgain/LineLength.cmake +++ b/cmake/BornAgain/LineLength.cmake @@ -4,7 +4,7 @@ set(WEB_LEN_LIM 85) # maximum line length of code for display in web docs if(NOT MSVC) set(LINECOUNT - ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/devtools/line-count/check-line-length.py) + ${Python3_EXECUTABLE} ${TOOL_DIR}/line-count/check-line-length.py) foreach(dir ${AllComponents}) file(GLOB_RECURSE src1 ${dir}/*.cpp) diff --git a/Tests/Functional/Python/PyExamples/check_functionality.py b/devtools/code-tools/batch-plot.py old mode 100644 new mode 100755 similarity index 65% rename from Tests/Functional/Python/PyExamples/check_functionality.py rename to devtools/code-tools/batch-plot.py index cdc65fc16a2..352810e4370 --- a/Tests/Functional/Python/PyExamples/check_functionality.py +++ b/devtools/code-tools/batch-plot.py @@ -1,8 +1,10 @@ +#!/usr/bin/env python3 """ -Checks functionality of BornAgain Python example by running it in 'embedded' way. +Run plotting code in batch mode: generate figure, but don't plot to terminal. -The check passes successfully if the example runs without exceptions thrown and -generates non-zero-size intensity image. +This script is used in BornAgain: +- with option -s in PyExamples tests, to check functionality of Python examples; +- with option -l to remake full-size images. """ import matplotlib, os, re, sys @@ -24,17 +26,36 @@ def exec_full(script, filename): sys.argv = [] exec(compile(script, filename, 'exec'), global_namespace) +def reduce_nbin(t): + """ + Overwrites script lines that set nbin, nx, ny + """ + pat = re.compile(r'(^\s+(nbin|nx|ny) = )(\d+)$') + ret = [] + for l in t.split('\n'): + m = re.match(pat, l) + if m: + oldsize = int(m.group(3)) + newsize = max(7, oldsize//20) + lout = re.sub(pat, m.group(1)+f'{newsize}', l) + else: + lout = l + ret.append(lout) + return '\n'.join(ret) + def run_example(filename, output_dir): """ Tries to run python example and produce a *.png image """ + # Read script from file. if not os.path.exists(filename): raise Exception("Example script '" + filename + "' not found") print("Input script: " + filename, flush=True) with open(filename, 'r') as file: script = file.read() + # Detect or impose figure size. m = re.search(r'plt\.figure\(.+?figsize=\((.+?),(.+?)\)', script) if m: # set figure size as in script figsize = (float(m.group(1)), float(m.group(2))) @@ -42,9 +63,15 @@ def run_example(filename, output_dir): figsize = (640/72, 480/72) fig = plt.figure(figsize=(figsize[0], figsize[1])) + # In -s mode, reduce detector size. + if True: + script = reduce_nbin(script) + + # Run modified script. exec_full(script, filename) print("Input script completed.", flush=True) + # Generate output figure. plot_file_name = os.path.join( output_dir, os.path.splitext(os.path.basename(filename))[0] + ".png") @@ -52,6 +79,7 @@ def run_example(filename, output_dir): plt.savefig(plot_file_name, bbox_inches='tight') plt.close(fig) + # Check obtained figure. imgSize = os.path.getsize(plot_file_name) if imgSize == 0: raise Exception("Image file is empty") -- GitLab