diff --git a/Tests/Examples/CMakeLists.txt b/Tests/Examples/CMakeLists.txt index cc446e152265b5ec6bf06e3fd1aa2fd7cc0aef20..d2dcec2fed3bac306b9afbc3a202dc7e34471475 100644 --- a/Tests/Examples/CMakeLists.txt +++ b/Tests/Examples/CMakeLists.txt @@ -196,7 +196,6 @@ test_example(varia/TransmissionVsAlpha 2e-10) test_example(varia/TransmissionVsDepth 2e-10) test_example(varia/TransmittedModulus 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/MaterialProfileWithParticles) diff --git a/auto/Examples/varia/AccessingSimulationResults.py b/auto/Examples/varia/AccessingSimulationResults.py deleted file mode 100755 index 48704d03db6acd2172d06f2183ec1ef4ca01ae95..0000000000000000000000000000000000000000 --- a/auto/Examples/varia/AccessingSimulationResults.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/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() diff --git a/auto/MiniExamples/varia/AccessingSimulationResults.py b/auto/MiniExamples/varia/AccessingSimulationResults.py deleted file mode 100755 index d48cf926701eab102817c10f48fa40e340d3fb75..0000000000000000000000000000000000000000 --- a/auto/MiniExamples/varia/AccessingSimulationResults.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/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() diff --git a/hugo/content/ex/result/export/_index.md b/hugo/content/ex/result/export/_index.md index a1dd126501831ff11ad9a53b5a71f128a217c1f9..fe8dfcaf0dc13ff4b9b7030f606c21e26b9c74ff 100644 --- a/hugo/content/ex/result/export/_index.md +++ b/hugo/content/ex/result/export/_index.md @@ -81,7 +81,6 @@ hist.save("result.int.gz") 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) * [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) diff --git a/hugo/content/ex/result/export/more.md b/hugo/content/ex/result/export/more.md deleted file mode 100644 index 7e816901676072603010ea2b3b5baad728a56743..0000000000000000000000000000000000000000 --- a/hugo/content/ex/result/export/more.md +++ /dev/null @@ -1,19 +0,0 @@ -+++ -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" >}} diff --git a/rawEx/varia/AccessingSimulationResults.py b/rawEx/varia/AccessingSimulationResults.py deleted file mode 100755 index 033b69071b9615755d63f2b795bb5909303b541c..0000000000000000000000000000000000000000 --- a/rawEx/varia/AccessingSimulationResults.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/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()