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

rm remnant of example AccessingSimulationResults

parent 03c5aba6
No related branches found
No related tags found
1 merge request!1878rm remnant of example AccessingSimulationResults
Pipeline #109315 passed
...@@ -196,7 +196,6 @@ test_example(varia/TransmissionVsAlpha 2e-10) ...@@ -196,7 +196,6 @@ test_example(varia/TransmissionVsAlpha 2e-10)
test_example(varia/TransmissionVsDepth 2e-10) test_example(varia/TransmissionVsDepth 2e-10)
test_example(varia/TransmittedModulus 2e-10) test_example(varia/TransmittedModulus 2e-10)
test_example(varia/Resonator 2e-10) test_example(varia/Resonator 2e-10)
# TODO disabled while refactoring scales&coords: test_example(varia/AccessingSimulationResults 2e-10)
run_example(varia/MaterialProfile) run_example(varia/MaterialProfile)
run_example(varia/MaterialProfileWithParticles) run_example(varia/MaterialProfileWithParticles)
......
#!/usr/bin/env python3
"""
Extended example for simulation results treatment (cropping, slicing, exporting)
"""
import math
import random
import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, std_samples
from matplotlib import pyplot as plt
import datetime
def get_sample():
return std_samples.cylinders()
def get_simulation(sample):
"""
A GISAXS simulation with beam and detector defined.
"""
beam = ba.Beam(1e5, 1*angstrom, 0.2*deg)
n = 200
det = ba.SphericalDetector(n, -2*deg, 2*deg, n, 0, 2*deg)
simulation = ba.ScatteringSimulation(beam, sample, det)
return simulation
def get_noisy_image(field):
"""
Returns clone of input field filled with additional noise
"""
result = field.clone()
noise_factor = 2.0
for i in range(0, result.size()):
amplitude = field.valAt(i)
sigma = noise_factor*math.sqrt(amplitude)
noisy_amplitude = random.gauss(amplitude, sigma)
result.setAt(i, noisy_amplitude)
return result
def plot_histogram(field, **kwargs):
bp.plot_histogram(field,
xlabel=r'$\varphi_f ^{\circ}$',
ylabel=r'$\alpha_{\rm f} ^{\circ}$',
zlabel="",
**kwargs)
def plot_slices(noisy):
"""
Plot 1D slices along y-axis at certain x-axis values.
"""
plt.yscale('log')
# projection along Y, slice at fixed x-value
proj1 = noisy.yProjection(0)
plt.plot(proj1.axis(0).binCenters(),
proj1.flatVector(),
label=r'$\varphi=0.0^{\circ}$')
# projection along Y, slice at fixed x-value
proj2 = noisy.yProjection(0.5) # slice at fixed value
plt.plot(proj2.axis(0).binCenters(),
proj2.flatVector(),
label=r'$\varphi=0.5^{\circ}$')
# projection along Y for all X values between [xlow, xup], averaged
proj3 = noisy.yProjection(0.41, 0.59)
plt.plot(proj3.axis(0).binCenters(),
proj3.flatVector(),
label=r'$<\varphi>=0.5^{\circ}$')
plt.xlim(proj1.axis(0).min(), proj1.axis(0).max())
plt.ylim(proj1.maxVal()*3e-6, proj1.maxVal()*3)
plt.xlabel(r'$\alpha_{\rm f} ^{\circ}$', fontsize=16)
plt.legend(loc='upper right')
def plot(field):
"""
Demonstrates modified data plots.
"""
plt.subplots(2, 2, figsize=(12.80, 10.24))
plt.subplot(2, 2, 1)
bp.plot_histogram(field)
plt.title("Intensity as heatmap")
plt.subplot(2, 2, 2)
crop = field.crop(-1, 0.5, 1, 1)
bp.plot_histogram(crop)
plt.title("Cropping")
plt.subplot(2, 2, 3)
noisy = get_noisy_image(field)
reldiff = ba.relativeDifferenceField(noisy, field).npArray()
bp.plot_array(reldiff, intensity_min=1e-03, intensity_max=10)
plt.title("Relative difference")
plt.subplot(2, 2, 4)
plot_slices(noisy)
plt.title("Various slicing of 2D into 1D")
plt.tight_layout()
if __name__ == '__main__':
sample = get_sample()
simulation = get_simulation(sample)
result = simulation.simulate()
if bp.datfile:
ba.writeDatafield(result, bp.datfile + ".int")
# Other supported extensions are .tif and .txt.
# Besides compression .gz, we support .bz2, and uncompressed.
plot(result)
bp.show_or_export()
#!/usr/bin/env python3
"""
Extended example for simulation results treatment (cropping, slicing, exporting)
"""
import math
import random
import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, std_samples
from matplotlib import pyplot as plt
import datetime
def get_sample():
return std_samples.cylinders()
def get_simulation(sample):
"""
A GISAXS simulation with beam and detector defined.
"""
beam = ba.Beam(1e5, 1*angstrom, 0.2*deg)
n = 50
det = ba.SphericalDetector(n, -2*deg, 2*deg, n, 0, 2*deg)
simulation = ba.ScatteringSimulation(beam, sample, det)
return simulation
def get_noisy_image(field):
"""
Returns clone of input field filled with additional noise
"""
result = field.clone()
noise_factor = 2.0
for i in range(0, result.size()):
amplitude = field.valAt(i)
sigma = noise_factor*math.sqrt(amplitude)
noisy_amplitude = random.gauss(amplitude, sigma)
result.setAt(i, noisy_amplitude)
return result
def plot_histogram(field, **kwargs):
bp.plot_histogram(field,
xlabel=r'$\varphi_f ^{\circ}$',
ylabel=r'$\alpha_{\rm f} ^{\circ}$',
zlabel="",
**kwargs)
def plot_slices(noisy):
"""
Plot 1D slices along y-axis at certain x-axis values.
"""
plt.yscale('log')
# projection along Y, slice at fixed x-value
proj1 = noisy.yProjection(0)
plt.plot(proj1.axis(0).binCenters(),
proj1.flatVector(),
label=r'$\varphi=0.0^{\circ}$')
# projection along Y, slice at fixed x-value
proj2 = noisy.yProjection(0.5) # slice at fixed value
plt.plot(proj2.axis(0).binCenters(),
proj2.flatVector(),
label=r'$\varphi=0.5^{\circ}$')
# projection along Y for all X values between [xlow, xup], averaged
proj3 = noisy.yProjection(0.41, 0.59)
plt.plot(proj3.axis(0).binCenters(),
proj3.flatVector(),
label=r'$<\varphi>=0.5^{\circ}$')
plt.xlim(proj1.axis(0).min(), proj1.axis(0).max())
plt.ylim(proj1.maxVal()*3e-6, proj1.maxVal()*3)
plt.xlabel(r'$\alpha_{\rm f} ^{\circ}$', fontsize=16)
plt.legend(loc='upper right')
def plot(field):
"""
Demonstrates modified data plots.
"""
plt.subplots(2, 2, figsize=(12.80, 10.24))
plt.subplot(2, 2, 1)
bp.plot_histogram(field)
plt.title("Intensity as heatmap")
plt.subplot(2, 2, 2)
crop = field.crop(-1, 0.5, 1, 1)
bp.plot_histogram(crop)
plt.title("Cropping")
plt.subplot(2, 2, 3)
noisy = get_noisy_image(field)
reldiff = ba.relativeDifferenceField(noisy, field).npArray()
bp.plot_array(reldiff, intensity_min=1e-03, intensity_max=10)
plt.title("Relative difference")
plt.subplot(2, 2, 4)
plot_slices(noisy)
plt.title("Various slicing of 2D into 1D")
plt.tight_layout()
if __name__ == '__main__':
sample = get_sample()
simulation = get_simulation(sample)
result = simulation.simulate()
if bp.datfile:
ba.writeDatafield(result, bp.datfile + ".int")
# Other supported extensions are .tif and .txt.
# Besides compression .gz, we support .bz2, and uncompressed.
plot(result)
bp.show_or_export()
...@@ -81,7 +81,6 @@ hist.save("result.int.gz") ...@@ -81,7 +81,6 @@ hist.save("result.int.gz")
Additional information can be found in the following pages: Additional information can be found in the following pages:
* [Accessing simulation results example](/ex/result/export/more.md)
* [Plotting with axes in different units](/ex/result/export/axes-in-different-units) * [Plotting with axes in different units](/ex/result/export/axes-in-different-units)
* [SimulationResult C++ class reference](http://apps.jcns.fz-juelich.de/doxy/BornAgain/classSimulationResult.html) * [SimulationResult C++ class reference](http://apps.jcns.fz-juelich.de/doxy/BornAgain/classSimulationResult.html)
* [Histogram1D C++ class reference](http://apps.jcns.fz-juelich.de/doxy/BornAgain/classHistogram1D.html) * [Histogram1D C++ class reference](http://apps.jcns.fz-juelich.de/doxy/BornAgain/classHistogram1D.html)
......
+++
title = "Accessing simulation results"
weight = 10
+++
### Accessing simulation results
This is an extended example for the further treatment of simulation results: accessing the results, plotting, cropping, slicing and exporting. This serves as a supporting example to the [Accessing simulation results
](/py/export/_index.md) tutorial.
* The standard [Cylinders in DWBA](/ex/sim/gisas) sample
is used for running the simulation.
* The simulation results are retrieved as a `Histogram2D` object and then processed in various functions to achieve a resulting image.
{{< galleryscg >}}
{{< figscg src="/img/auto/varia/AccessingSimulationResults.png" width="670px" caption="Intensity images">}}
{{< /galleryscg >}}
{{< show-ex file="varia/AccessingSimulationResults.py" >}}
#!/usr/bin/env python3
"""
Extended example for simulation results treatment (cropping, slicing, exporting)
"""
import math
import random
import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, std_samples
from matplotlib import pyplot as plt
import datetime
def get_sample():
return std_samples.cylinders()
def get_simulation(sample):
"""
A GISAXS simulation with beam and detector defined.
"""
beam = ba.Beam(1e5, 1*angstrom, 0.2*deg)
n = <%= sm ? 50 : 200 %>
det = ba.SphericalDetector(n, -2*deg, 2*deg, n, 0, 2*deg)
simulation = ba.ScatteringSimulation(beam, sample, det)
return simulation
def get_noisy_image(field):
"""
Returns clone of input field filled with additional noise
"""
result = field.clone()
noise_factor = 2.0
for i in range(0, result.size()):
amplitude = field.valAt(i)
sigma = noise_factor*math.sqrt(amplitude)
noisy_amplitude = random.gauss(amplitude, sigma)
result.setAt(i, noisy_amplitude)
return result
def plot_histogram(field, **kwargs):
bp.plot_histogram(field,
xlabel=r'$\varphi_f ^{\circ}$',
ylabel=r'$\alpha_{\rm f} ^{\circ}$',
zlabel="",
**kwargs)
def plot_slices(noisy):
"""
Plot 1D slices along y-axis at certain x-axis values.
"""
plt.yscale('log')
# projection along Y, slice at fixed x-value
proj1 = noisy.yProjection(0)
plt.plot(proj1.axis(0).binCenters(),
proj1.flatVector(),
label=r'$\varphi=0.0^{\circ}$')
# projection along Y, slice at fixed x-value
proj2 = noisy.yProjection(0.5) # slice at fixed value
plt.plot(proj2.axis(0).binCenters(),
proj2.flatVector(),
label=r'$\varphi=0.5^{\circ}$')
# projection along Y for all X values between [xlow, xup], averaged
proj3 = noisy.yProjection(0.41, 0.59)
plt.plot(proj3.axis(0).binCenters(),
proj3.flatVector(),
label=r'$<\varphi>=0.5^{\circ}$')
plt.xlim(proj1.axis(0).min(), proj1.axis(0).max())
plt.ylim(proj1.maxVal()*3e-6, proj1.maxVal()*3)
plt.xlabel(r'$\alpha_{\rm f} ^{\circ}$', fontsize=16)
plt.legend(loc='upper right')
def plot(field):
"""
Demonstrates modified data plots.
"""
plt.subplots(2, 2, figsize=(12.80, 10.24))
plt.subplot(2, 2, 1)
bp.plot_histogram(field)
plt.title("Intensity as heatmap")
plt.subplot(2, 2, 2)
crop = field.crop(-1, 0.5, 1, 1)
bp.plot_histogram(crop)
plt.title("Cropping")
plt.subplot(2, 2, 3)
noisy = get_noisy_image(field)
reldiff = ba.relativeDifferenceField(noisy, field).npArray()
bp.plot_array(reldiff, intensity_min=1e-03, intensity_max=10)
plt.title("Relative difference")
plt.subplot(2, 2, 4)
plot_slices(noisy)
plt.title("Various slicing of 2D into 1D")
plt.tight_layout()
if __name__ == '__main__':
sample = get_sample()
simulation = get_simulation(sample)
result = simulation.simulate()
if bp.datfile:
ba.writeDatafield(result, bp.datfile + ".int")
# Other supported extensions are .tif and .txt.
# Besides compression .gz, we support .bz2, and uncompressed.
plot(result)
bp.show_or_export()
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