Commit 663cc0ca authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

SpecularSimulation(scan, sample)

parent 4cbf14e3
......@@ -449,7 +449,6 @@ def simulate(sample,
if qmax:
qzs = np.linspace(0., qmax[0]/angstrom, scan_size)
simulation = ba.SpecularSimulation()
n_sig = 4.0
n_samples = 25
......@@ -462,11 +461,9 @@ def simulate(sample,
else:
scan.setRelativeQResolution(distr, 0.5*resolution)
simulation.setScan(scan)
simulation = ba.SpecularSimulation(scan, sample)
simulation.setBackground(ba.ConstantBackground(background/scale))
simulation.setSample(sample)
result = simulation.simulate()
return np.array(result.axis(
......
......@@ -76,15 +76,13 @@ def get_real_data():
# Define the simulation
def get_simulation(alpha):
def get_simulation(sample, alpha):
"""
Defines and returns a specular simulation.
"""
wavelength = 0.154 #nm
scan = ba.AlphaScan(wavelength, alpha)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
return simulation
return ba.SpecularSimulation(scan, sample)
# Run the simulation
......@@ -97,8 +95,8 @@ def run_simulation(alpha, ni_thickness, ti_thickness):
:return: simulated reflected intensity
"""
sample = get_sample(ni_thickness, ti_thickness)
simulation = get_simulation(alpha)
simulation.setSample(sample)
simulation = get_simulation(sample, alpha)
result = simulation.simulate()
return result.array()
......
......@@ -92,12 +92,10 @@ def get_simulation(params):
Create and return specular simulation with its instrument defined
"""
wavelength = 1.54*ba.angstrom # beam wavelength
simulation = ba.SpecularSimulation()
scan = ba.AlphaScan(wavelength, get_real_data_axis())
simulation.setScan(scan)
simulation.setSample(get_sample(params))
return simulation
sample = get_sample(params)
return ba.SpecularSimulation(scan, sample)
def run_fitting():
......
......@@ -88,9 +88,6 @@ def get_simulation(q_axis, fitParams, sign, ms150=False):
scan = ba.QzScan(q_axis)
scan.setAbsoluteQResolution(q_distr, dq)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
simulation.beam().setIntensity(parameters["intensity"])
if ms150:
sample = get_sample(parameters=parameters,
......@@ -99,7 +96,8 @@ def get_simulation(q_axis, fitParams, sign, ms150=False):
else:
sample = get_sample(parameters=parameters, sign=sign, ms150=1)
simulation.setSample(sample)
simulation = ba.SpecularSimulation(scan, sample)
simulation.beam().setIntensity(parameters["intensity"])
simulation.setBackground(ba.ConstantBackground(5e-7))
return simulation
......
......@@ -56,6 +56,8 @@ def get_sample(params):
def get_simulation(q_axis, parameters):
sample = get_sample(parameters)
scan = ba.QzScan(q_axis)
scan.setOffset(parameters["q_offset"])
......@@ -65,21 +67,18 @@ def get_simulation(q_axis, parameters):
distr = ba.RangedDistributionGaussian(n_samples, n_sig)
scan.setAbsoluteQResolution(distr, parameters["q_res/q"])
simulation = ba.SpecularSimulation()
simulation = ba.SpecularSimulation(scan, sample)
simulation.beam().setIntensity(parameters["intensity"])
simulation.setScan(scan)
return simulation
def run_simulation(q_axis, fitParams):
parameters = dict(fitParams, **fixedParams)
sample = get_sample(parameters)
simulation = get_simulation(q_axis, parameters)
simulation.setSample(sample)
return simulation.simulate()
......
......@@ -88,7 +88,7 @@ def get_weights(start, end):
return expdata[start:end, 2]
def create_simulation(arg_dict, bin_start, bin_end):
def create_simulation(sample, arg_dict, bin_start, bin_end):
"""
Creates and returns specular simulation
"""
......@@ -100,8 +100,7 @@ def create_simulation(arg_dict, bin_start, bin_end):
scan.setAbsoluteAngularResolution(alpha_distr, arg_dict["divergence"])
scan.setFootprintFactor(footprint)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
simulation = ba.SpecularSimulation(scan, sample)
simulation.beam().setIntensity(arg_dict["intensity"])
return simulation
......@@ -139,8 +138,8 @@ def run_simulation(arg_dict, bin_start=0, bin_end=-1):
Runs simulation and returns its result
"""
simulation = create_simulation(arg_dict, bin_start, bin_end)
simulation.setSample(buildSample(arg_dict))
sample = buildSample(arg_dict)
simulation = create_simulation(sample, arg_dict, bin_start, bin_end)
return simulation.simulate()
......
......@@ -42,11 +42,8 @@ def get_simulation(sample):
A standard specular simulation setup.
"""
n = bp.simargs['n']
simulation = ba.SpecularSimulation()
scan = ba.AlphaScan(1.54*angstrom, n, 0, 2*deg)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
if __name__ == '__main__':
......
......@@ -18,11 +18,8 @@ def get_simulation(sample):
A standard specular simulation setup.
"""
n = bp.simargs['n']
simulation = ba.SpecularSimulation()
scan = ba.AlphaScan(1.54*angstrom, n, 0, 2*deg)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
if __name__ == '__main__':
......
......@@ -36,18 +36,10 @@ def get_sample():
return sample
def get_simulation(sample, scan_size=500):
"""
Defines and returns a specular simulation.
"""
def simulate(polarizer_dir, analyzer_dir, title):
def simulate(sample, polarizer_dir, analyzer_dir, title):
n = bp.simargs['n']
simulation = ba.SpecularSimulation()
scan = ba.AlphaScan(1.54*angstrom, n, 0, 5*deg)
simulation.setScan(scan)
simulation.setSample(get_sample())
simulation = ba.SpecularSimulation(scan, sample)
simulation.setPolarization(polarizer_dir)
simulation.setAnalyzer(analyzer_dir, 1, 0.5)
......@@ -57,16 +49,13 @@ def simulate(polarizer_dir, analyzer_dir, title):
return result
def run_simulations():
return ret
if __name__ == '__main__':
bp.parse_args(sim_n=500)
sample = get_sample()
results = [
simulate(ba.R3(0, +1, 0), ba.R3(0, +1, 0), "$++$"),
simulate(ba.R3(0, -1, 0), ba.R3(0, -1, 0), "$--$"),
simulate(sample, ba.R3(0, +1, 0), ba.R3(0, +1, 0), "$++$"),
simulate(sample, ba.R3(0, -1, 0), ba.R3(0, -1, 0), "$--$"),
]
bp.plot_multicurve_specular(results)
......@@ -51,11 +51,7 @@ def get_simulation(sample, **kwargs):
scan.setFootprintFactor(footprint)
scan.setAbsoluteAngularResolution(alpha_distr, d_ang)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
if __name__ == '__main__':
......
......@@ -35,9 +35,7 @@ def get_simulation(sample):
scan.setAbsoluteAngularResolution(alpha_distr, d_ang)
scan.setAbsoluteWavelengthResolution(wavelength_distr, d_wl)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
simulation.setSample(sample)
return ba.SpecularSimulation(scan, sample)
return simulation
......
......@@ -12,12 +12,11 @@ sample = std_samples.alternating_layers()
def simulate(footprint, title):
simulation = ba.SpecularSimulation()
n = bp.simargs['n']
scan = ba.AlphaScan(1.54*angstrom, n, 0, 0.6*deg)
scan.setFootprintFactor(footprint)
simulation.setScan(scan)
simulation.setSample(sample)
simulation = ba.SpecularSimulation(scan, sample)
result = simulation.simulate()
result.setTitle(title)
return result
......
......@@ -40,12 +40,9 @@ def get_simulation(sample):
"""
Defines and returns a specular simulation.
"""
simulation = ba.SpecularSimulation()
n = bp.simargs['n']
scan = ba.AlphaScan(1.54*angstrom, n, 0, 5*deg)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
def run_simulation(polarizer_dir=R3(0, 1, 0), analyzer_dir=None):
......
......@@ -54,7 +54,6 @@ def get_simulation(sample, scan_size=1500):
"""
Defines and returns a specular simulation.
"""
simulation = ba.SpecularSimulation()
qzs = numpy.linspace(0.1, 1.5, scan_size)
n_sig = 4.0
......@@ -64,9 +63,7 @@ def get_simulation(sample, scan_size=1500):
scan = ba.QzScan(qzs)
scan.setAbsoluteQResolution(distr, 0.008)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
def run_simulation(*,
......
......@@ -63,13 +63,12 @@ def get_sample(params):
return multi_layer
def get_simulation(q_axis, parameters, polarizer_dir, analyzer_dir):
def get_simulation(sample, q_axis, parameters, polarizer_dir, analyzer_dir):
"""
Returns a simulation object.
Polarization, analyzer and resolution are set
from given parameters
"""
simulation = ba.SpecularSimulation()
q_axis = q_axis + parameters["q_offset"]
scan = ba.QzScan(q_axis)
......@@ -80,10 +79,10 @@ def get_simulation(q_axis, parameters, polarizer_dir, analyzer_dir):
distr = ba.RangedDistributionGaussian(n_samples, n_sig)
scan.setAbsoluteQResolution(distr, parameters["q_res"])
simulation = ba.SpecularSimulation(scan, sample)
simulation.setPolarization(polarizer_dir)
simulation.setAnalyzer(analyzer_dir, 1, 0.5)
simulation.setScan(scan)
return simulation
......@@ -96,10 +95,9 @@ def run_simulation(q_axis, fitParams, *, polarizer_dir, analyzer_dir):
parameters = dict(fitParams, **fixedParams)
sample = get_sample(parameters)
simulation = get_simulation(q_axis, parameters, polarizer_dir,
simulation = get_simulation(sample, q_axis, parameters, polarizer_dir,
analyzer_dir)
simulation.setSample(sample)
return simulation.simulate()
......
......@@ -36,25 +36,14 @@ def get_sample():
return sample
def get_simulation(sample, scan_size=500):
"""
Defines and returns a specular simulation.
"""
simulation = ba.SpecularSimulation()
scan = ba.AlphaScan(1.54*angstrom, scan_size, 0, 5*deg)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
def run_simulation(polarizer_dir=ba.R3(0, 1, 0),
def run_simulation(sample, polarizer_dir=ba.R3(0, 1, 0),
analyzer_dir=ba.R3(0, 1, 0)):
"""
Runs simulation and returns its result.
"""
sample = get_sample()
simulation = get_simulation(sample)
scan = ba.AlphaScan(1.54*angstrom, 500, 0, 5*deg)
simulation = ba.SpecularSimulation(scan, sample)
simulation.setPolarization(polarizer_dir)
simulation.setAnalyzer(analyzer_dir, 1, 0.5)
......@@ -81,11 +70,12 @@ def plot(data, labels):
if __name__ == '__main__':
bp.parse_args()
results_pp = run_simulation(ba.R3(0, 1, 0), ba.R3(0, 1, 0))
results_mm = run_simulation(ba.R3(0, -1, 0), ba.R3(0, -1, 0))
sample = get_sample()
results_pm = run_simulation(ba.R3(0, 1, 0), ba.R3(0, -1, 0))
results_mp = run_simulation(ba.R3(0, -1, 0), ba.R3(0, 1, 0))
results_pp = run_simulation(sample, ba.R3(0, 1, 0), ba.R3(0, 1, 0))
results_mm = run_simulation(sample, ba.R3(0, -1, 0), ba.R3(0, -1, 0))
results_pm = run_simulation(sample, ba.R3(0, 1, 0), ba.R3(0, -1, 0))
results_mp = run_simulation(sample, ba.R3(0, -1, 0), ba.R3(0, 1, 0))
plot([results_pp, results_mm, results_pm, results_mp],
["$++$", "$--$", "$+-$", "$-+$"])
......
......@@ -47,12 +47,10 @@ def get_simulation(sample):
"""
Defines and returns a specular simulation.
"""
simulation = ba.SpecularSimulation()
n = bp.simargs['n']
scan = ba.AlphaScan(1.54*angstrom, n, 0, 2*deg)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
def simulate(roughness_model, title):
......
......@@ -35,12 +35,9 @@ def get_sample():
def get_simulation(sample):
simulation = ba.SpecularSimulation()
n = bp.simargs['n']
scan = ba.AlphaScan(1.54*angstrom, n, 0, 2*deg)
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
if __name__ == '__main__':
......
......@@ -36,11 +36,7 @@ def get_simulation(sample):
scan = ba.QzScan(qzs)
scan.setAbsoluteQResolution(distr, dq)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
if __name__ == '__main__':
......
......@@ -25,10 +25,7 @@ def get_simulation(sample):
n = bp.simargs['n']
qzs = np.linspace(0.01, 1, n) # qz-values
scan = ba.QzScan(qzs)
simulation = ba.SpecularSimulation()
simulation.setScan(scan)
simulation.setSample(sample)
return simulation
return ba.SpecularSimulation(scan, sample)
if __name__ == '__main__':
......
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