Commit 7cffc9b2 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Merge branch 'ex2' into 'develop'

Examples; round parameters, etc

See merge request !10
parents 6a6a3f87 8cb37c04
Pipeline #33418 passed with stage
in 19 minutes and 17 seconds
......@@ -242,6 +242,11 @@ class ObserverCallbackWrapper(PyObserverCallback):
def finalize(self, minimizer_result):
return self.finalize_cpp(self.convert_result(minimizer_result))
def create_default_plotter(self):
import ba_fitmonitor as bafim
self.m_plotter = bafim.PlotterGISAS()
return self.m_plotter.plot
def initPlot(self, every_nth, callback = None):
if not callback:
callback = self.create_default_plotter()
......
.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32)
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40)
.\"
.\" Standard preamble:
.\" ========================================================================
......@@ -54,16 +54,20 @@
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.if !\nF .nr F 0
.if \nF>0 \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
......@@ -129,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "BORNAGAIN 1"
.TH BORNAGAIN 1 "2017-09-04" "perl v5.24.1" "BornAgain manual"
.TH BORNAGAIN 1 "2021-03-09" "perl v5.32.1" "BornAgain manual"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
......
......@@ -416,7 +416,7 @@ Controlled by the multi-threading machinery in ISimulation::runSingleSimulation(
C++ includes: DWBAComputation.h
";
%feature("docstring") DWBAComputation::DWBAComputation "DWBAComputation::DWBAComputation(const MultiLayer &multilayer, const SimulationOptions &options, ProgressHandler &progress, std::vector< SimulationElement >::iterator begin_it, std::vector< SimulationElement >::iterator end_it)
%feature("docstring") DWBAComputation::DWBAComputation "DWBAComputation::DWBAComputation(const MultiLayer &multilayer, const SimulationOptions &options, ProgressHandler &progress, std::vector< SimulationElement >::iterator begin_it, std::vector< SimulationElement >::iterator end_it, bool forcePolarized=false)
";
%feature("docstring") DWBAComputation::~DWBAComputation "DWBAComputation::~DWBAComputation() override
......@@ -896,7 +896,7 @@ Controlled by the multi-threading machinery in ISimulation::runSingleSimulation(
C++ includes: IComputation.h
";
%feature("docstring") IComputation::IComputation "IComputation::IComputation(const MultiLayer &sample, const SimulationOptions &options, ProgressHandler &progress)
%feature("docstring") IComputation::IComputation "IComputation::IComputation(const MultiLayer &sample, const SimulationOptions &options, ProgressHandler &progress, bool forcePolarized=false)
";
%feature("docstring") IComputation::~IComputation "IComputation::~IComputation()
......@@ -1034,11 +1034,6 @@ Run a simulation in a MPI environment.
%feature("docstring") ISimulation::setDetectorResolutionFunction "void ISimulation::setDetectorResolutionFunction(const IResolutionFunction2D &resolution_function)
";
%feature("docstring") ISimulation::setAnalyzerProperties "void ISimulation::setAnalyzerProperties(const kvector_t direction, double efficiency, double total_transmission)
Sets the polarization analyzer characteristics of the detector.
";
%feature("docstring") ISimulation::setSample "void ISimulation::setSample(const MultiLayer &sample)
The MultiLayer object will not be owned by the ISimulation object.
......@@ -2007,7 +2002,7 @@ Controlled by the multi-threading machinery in ISimulation::runSingleSimulation(
C++ includes: SpecularComputation.h
";
%feature("docstring") SpecularComputation::SpecularComputation "SpecularComputation::SpecularComputation(const MultiLayer &multilayer, const SimulationOptions &options, ProgressHandler &progress, SpecularElementIter begin_it, SpecularElementIter end_it)
%feature("docstring") SpecularComputation::SpecularComputation "SpecularComputation::SpecularComputation(const MultiLayer &multilayer, const SimulationOptions &options, ProgressHandler &progress, SpecularElementIter begin_it, SpecularElementIter end_it, bool forcePolarized=false)
";
%feature("docstring") SpecularComputation::~SpecularComputation "SpecularComputation::~SpecularComputation() override
......
......@@ -2561,6 +2561,9 @@ C++ includes: SpecularDetector1D.h
%feature("docstring") SpecularDetector1D::SpecularDetector1D "SpecularDetector1D::SpecularDetector1D(const IAxis &axis)
";
%feature("docstring") SpecularDetector1D::SpecularDetector1D "SpecularDetector1D::SpecularDetector1D()
";
%feature("docstring") SpecularDetector1D::~SpecularDetector1D "SpecularDetector1D::~SpecularDetector1D()
";
......@@ -2585,6 +2588,9 @@ Returns region of interest if exists.
Resets region of interest making whole detector plane available for the simulation.
";
%feature("docstring") SpecularDetector1D::setAxis "void SpecularDetector1D::setAxis(const IAxis &axis)
";
%feature("docstring") SpecularDetector1D::defaultAxesUnits "Axes::Units SpecularDetector1D::defaultAxesUnits() const override
Return default axes units.
......
......@@ -4685,6 +4685,9 @@ C++ includes: ISpecularStrategy.h
%feature("docstring") ISpecularStrategy::Execute "virtual coeffs_t ISpecularStrategy::Execute(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const =0
";
%feature("docstring") ISpecularStrategy::computeTopLayerR "virtual std::variant<complex_t, Eigen::Matrix2cd> ISpecularStrategy::computeTopLayerR(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const =0
";
// File: classLargeCylindersInDWBABuilder.xml
%feature("docstring") LargeCylindersInDWBABuilder "
......@@ -6403,7 +6406,7 @@ If the usage of average materials is requested, layers and particles are sliced
C++ includes: ProcessedSample.h
";
%feature("docstring") ProcessedSample::ProcessedSample "ProcessedSample::ProcessedSample(const MultiLayer &sample, const SimulationOptions &options)
%feature("docstring") ProcessedSample::ProcessedSample "ProcessedSample::ProcessedSample(const MultiLayer &sample, const SimulationOptions &options, bool forcePolarized=false)
";
%feature("docstring") ProcessedSample::~ProcessedSample "ProcessedSample::~ProcessedSample()
......@@ -7169,7 +7172,7 @@ C++ includes: Slice.h
%feature("docstring") Slice::setMaterial "void Slice::setMaterial(const Material &material)
";
%feature("docstring") Slice::material "Material Slice::material() const
%feature("docstring") Slice::material "const Material & Slice::material() const
";
%feature("docstring") Slice::thickness "double Slice::thickness() const
......@@ -7297,6 +7300,11 @@ Computes refraction angle reflection/transmission coefficients for given sliced
Computes refraction angle reflection/transmission coefficients for given sliced multilayer and a set of kz projections corresponding to each slice
";
%feature("docstring") SpecularMagneticStrategy::computeTopLayerR "std::variant< complex_t, Eigen::Matrix2cd > SpecularMagneticStrategy::computeTopLayerR(const std::vector< Slice > &slices, const std::vector< complex_t > &kzs) const override
Computes the Fresnel R coefficient for the top layer only Introduced in order to speed up pure reflectivity computations
";
// File: classSpecularMagneticStrategy__v1.xml
%feature("docstring") SpecularMagneticStrategy_v1 "
......@@ -7314,6 +7322,9 @@ Computes refraction angle reflection/transmission coefficients for given sliced
%feature("docstring") SpecularMagneticStrategy_v1::Execute "ISpecularStrategy::coeffs_t SpecularMagneticStrategy_v1::Execute(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const
";
%feature("docstring") SpecularMagneticStrategy_v1::computeTopLayerR "std::variant< complex_t, Eigen::Matrix2cd > SpecularMagneticStrategy_v1::computeTopLayerR(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const override
";
// File: classSpecularMagneticStrategy__v2.xml
%feature("docstring") SpecularMagneticStrategy_v2 "
......@@ -7335,6 +7346,9 @@ Computes refraction angle reflection/transmission coefficients for given sliced
Computes refraction angle reflection/transmission coefficients for given sliced multilayer and a set of kz projections corresponding to each slice
";
%feature("docstring") SpecularMagneticStrategy_v2::computeTopLayerR "std::variant< complex_t, Eigen::Matrix2cd > SpecularMagneticStrategy_v2::computeTopLayerR(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const override
";
// File: classSpecularMagneticTanhStrategy.xml
%feature("docstring") SpecularMagneticTanhStrategy "
......@@ -7378,6 +7392,11 @@ Computes refraction angles and transmission/reflection coefficients for given co
%feature("docstring") SpecularScalarStrategy::Execute "ISpecularStrategy::coeffs_t SpecularScalarStrategy::Execute(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const override
";
%feature("docstring") SpecularScalarStrategy::computeTopLayerR "std::variant< complex_t, Eigen::Matrix2cd > SpecularScalarStrategy::computeTopLayerR(const std::vector< Slice > &slices, const std::vector< complex_t > &kz) const override
Computes the Fresnel R coefficient for the top layer only Introduced in order to speed up pure reflectivity computations
";
// File: classSpecularScalarTanhStrategy.xml
%feature("docstring") SpecularScalarTanhStrategy "
......
......@@ -3045,6 +3045,11 @@ class FitObjective(object):
def finalize(self, minimizer_result):
return self.finalize_cpp(self.convert_result(minimizer_result))
def create_default_plotter(self):
import ba_fitmonitor as bafim
self.m_plotter = bafim.PlotterGISAS()
return self.m_plotter.plot
def initPlot(self, every_nth, callback = None):
if not callback:
callback = self.create_default_plotter()
......
......@@ -91,7 +91,9 @@ def update_all_files_of_one_type(example_root, dest_dir, extension):
log2(f'Update {len(dest_list)} {extension} files')
log2(f' from {example_root}')
log2(f' to {dest_dir}')
log(f' with source list {source_list}')
log(f' with source list')
for f in source_list:
log(f' - {f}')
nError = 0
nModified = 0
......
#!/usr/bin/env python3
"""
Fake GISAS data for testing and benchmarking 2D fits.
The sample model basically consists of dilute cylinders on a substrate.
There are, however, some systematic distortions:
* Refractive indices changed, and absorption strongly enhanced;
* Cylinders replaced by a mixture of cones and segmented spheroids;
* Beam wavelength and alpha_i slightly changed.
* Detector x-axis skewed;
"""
import bornagain as ba
from bornagain import deg, nm
import numpy as np
mat_vacuum = ba.HomogeneousMaterial("Vacuum", 0, 0)
# nominal material constants are (6e-6, 2e-8) and (6e-4, 2e-8)
mat_substrate = ba.HomogeneousMaterial("Substrate", 6.3e-6, 4e-7)
mat_particle = ba.HomogeneousMaterial("Particle", 5.8e-4, 2e-7)
def get_sample(params):
h = params["cylinder_height"]
r = params["cylinder_radius"]
ff1 = ba.FormFactorCone(1.1*r, h, 80*deg)
ff2 = ba.FormFactorTruncatedSpheroid(r, 3.3*h, 2.5*h/r, 2.2*h)
layout = ba.ParticleLayout()
layout.addParticle(ba.Particle(mat_particle, ff1), .4)
layout.addParticle(ba.Particle(mat_particle, ff2), .6)
layer_1 = ba.Layer(mat_vacuum)
layer_1.addLayout(layout)
layer_2 = ba.Layer(mat_substrate)
sample = ba.MultiLayer()
sample.addLayer(layer_1)
sample.addLayer(layer_2)
return sample
def get_simulation(params):
# nominal beam parameters are 0.1*nm, 0.2*deg
beam = ba.Beam(10**params['lg(intensity)'], 0.0993*nm,
ba.Direction(0.202*deg, 0))
# nominal detector x-axis starts from -1.5*deg
det = ba.SphericalDetector(100, -1.49*deg, 1.5*deg, 100, 0, 3*deg)
sample = get_sample(params)
simulation = ba.GISASSimulation(beam, sample, det)
if 'lg(background)' in params:
simulation.setBackground(
ba.ConstantBackground(10**params['lg(background)']))
return simulation
def model_parameters():
return {
'lg(intensity)': 6,
'lg(background)': 0.5,
'cylinder_height': 4*nm,
'cylinder_radius': 5*nm,
}
def fake_data():
"""
Generate fake "experimental" data, and save them as numpy array.
"""
params = model_parameters()
# Compute model distribution
simulation = get_simulation(params)
simulation.runSimulation()
theory = simulation.result().array()
# Draw noisy data
np.random.seed(0)
data = np.random.poisson(theory)
# Save to numpy
np.savetxt("faked-gisas1.txt.gz", data)
if __name__ == '__main__':
fake_data()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment