From 630a9ef19200fc9b107d7120f0cf39a1da5b00f4 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Mon, 23 Nov 2020 11:12:34 +0100 Subject: [PATCH] Restore example FindPeaks; additional output from update-website --- Examples/Python/sim03_Structures/FindPeaks.py | 90 +++++++++++++++++++ devtools/code-tools/update-website.py | 11 ++- 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 Examples/Python/sim03_Structures/FindPeaks.py diff --git a/Examples/Python/sim03_Structures/FindPeaks.py b/Examples/Python/sim03_Structures/FindPeaks.py new file mode 100644 index 00000000000..67e819af38a --- /dev/null +++ b/Examples/Python/sim03_Structures/FindPeaks.py @@ -0,0 +1,90 @@ +""" +Simulation of grating using very long boxes and 1D lattice. +Monte-carlo integration is used to get rid of +large-particle form factor oscillations. +""" +import bornagain as ba +from bornagain import deg, angstrom, nm, micrometer +from matplotlib import pyplot as plt + + +def get_sample(lattice_rotation_angle=0.0*deg): + """ + Returns a sample with a grating on a substrate. + lattice_rotation_angle = 0 - beam parallel to grating lines + lattice_rotation_angle = 90*deg - beam perpendicular to grating lines + """ + # defining materials + m_vacuum = ba.HomogeneousMaterial("Vacuum", 0.0, 0.0) + m_si = ba.HomogeneousMaterial("Si", 5.78164736e-6, 1.02294578e-7) + + box_length, box_width, box_height = 50*micrometer, 70*nm, 50*nm + lattice_length = 150*nm + + # collection of particles + interference = ba.InterferenceFunction1DLattice( + lattice_length, 90.0*deg - lattice_rotation_angle) + + pdf = ba.ba.FTDecayFunction1DGauss(450.0) + interference.setDecayFunction(pdf) + + box_ff = ba.FormFactorLongBoxLorentz(box_length, box_width, box_height) + box = ba.Particle(m_si, box_ff) + + particle_layout = ba.ParticleLayout() + particle_layout.addParticle( + box, 1.0, ba.kvector_t(0.0, 0.0, 0.0), ba.RotationZ(lattice_rotation_angle)) + particle_layout.setInterferenceFunction(interference) + + # assembling the sample + vacuum_layer = ba.Layer(m_vacuum) + vacuum_layer.addLayout(particle_layout) + substrate_layer = ba.Layer(m_si) + + roughness = ba.LayerRoughness() + roughness.setSigma(5.0 * nm) + roughness.setHurstParameter(0.5) + roughness.setLatteralCorrLength(10.0 * nm) + + multi_layer = ba.MultiLayer() + multi_layer.addLayer(vacuum_layer) + multi_layer.addLayerWithTopRoughness(substrate_layer, roughness) + return multi_layer + + +def get_simulation(): + """ + Create and return GISAXS simulation with beam and detector defined + """ + simulation = ba.GISASSimulation() + simulation.setDetectorParameters(200, -0.5*deg, 0.5*deg, + 200, 0.0*deg, 0.6*deg) + simulation.setBeamParameters(1.34*angstrom, 0.4*deg, 0.0*deg) + simulation.setBeamIntensity(1e+08) + simulation.getOptions().setMonteCarloIntegration(True, 100) + return simulation + + +def run_simulation(): + """ + Runs simulation and returns intensity map. + """ + simulation = get_simulation() + simulation.setSample(get_sample()) + simulation.setTerminalProgressMonitor() + simulation.runSimulation() + return simulation.result() + + +if __name__ == '__main__': + result = run_simulation().histogram2d() + ba.plot_histogram(result, cmap='jet', aspect='auto') + + peaks = ba.FindPeaks(result, 2, "nomarkov", 0.001) + xpeaks = [peak[0] for peak in peaks] + ypeaks = [peak[1] for peak in peaks] + print(peaks) + plt.plot(xpeaks, ypeaks, linestyle='None', marker='x', color='white', + markersize=10) + plt.show() + diff --git a/devtools/code-tools/update-website.py b/devtools/code-tools/update-website.py index cac48d9f04b..0a5d0efafbe 100755 --- a/devtools/code-tools/update-website.py +++ b/devtools/code-tools/update-website.py @@ -24,7 +24,7 @@ def log2(msg): def find_files(dir_name): """ - Return recursive list of files in given dir_name + Return recursive list of files in given dir_name. """ for subdir, dirs, files in os.walk(dir_name): for filename in files: @@ -55,7 +55,8 @@ def find_files_with_same_name(filename_list, name_to_find): def update_one_file(source_list, dest): """ Update destination file 'dest', using a suitable source file from 'source_dir'. - Returns 2=error, 1=modified, 0=unchanged + Returns 2=error, 1=modified, 0=unchanged. + On succes (0 or 1), the source file is removed from source_list. """ likely_sources = find_files_with_same_name(source_list, os.path.basename(dest)) if len(likely_sources) == 0: @@ -67,6 +68,7 @@ def update_one_file(source_list, dest): log2(f' - {f}') return 2 src = likely_sources[0] + source_list.remove(src) if filecmp.cmp(src, dest): log(f'. {dest}\n is same as {src}') return 0 @@ -103,6 +105,11 @@ def update_all_files_of_one_type(source_dir, dest_dir, extension): log2(f'=> {nUnchanged} files unchanged, {nModified} files updated, {nError} errors') + if len(source_list)>0: + log2(f'!! WARNING: {len(source_list)} source files are unused') + for src in source_list: + log(f' unused: {src}') + def update_website(website_source_dir, ba_source_dir, ba_build_dir): """ -- GitLab