# Class Datafield on BornAgain

file:///usr/share/doc/bornagain/html/ref/data/datafield/index.html Recent content in Class Datafield on BornAgain Hugo en-us

# Export

file:///usr/share/doc/bornagain/html/ref/data/datafield/export.html Mon, 01 Jan 0001 00:00:00 +0000 file:///usr/share/doc/bornagain/html/ref/data/datafield/export.html <h2 id="export-a-datafield">Export a Datafield</h2> <h4 id="save-in-various-formats">Save in various formats</h4> <p>A <code>Datafield</code> can be saved in various data formats through the BornAgain Python method</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">bornagain</span> <span class="k">as</span> <span class="nn">ba</span> </span></span><span class="line"><span class="cl"><span class="n">simulation</span> <span class="o">=</span> <span class="o">...</span> </span></span><span class="line"><span class="cl"><span class="n">result</span> <span class="o">=</span> <span class="n">simulation</span><span class="o">.</span><span class="n">simulate</span><span class="p">()</span> </span></span><span class="line"><span class="cl"><span class="n">ba</span><span class="o">.</span><span class="n">IOFactory</span><span class="o">.</span><span class="n">writeDatafield</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">file_name</span><span class="p">)</span> </span></span></code></pre></div><p>where <code>file_name</code> must have one of the extensions</p> <ul> <li><code>.txt</code> &mdash; ASCII file with 2D array [nrow][ncol], layout as in NumPy,</li> <li><code>.int</code> &mdash; BornAgain internal ASCII format,</li> <li><code>.tif</code> &mdash; 32-bits TIFF file,</li> </ul> <p>to which one may append a second extension that specifies compression:</p> <ul> <li><code>.gz</code>,</li> <li><code>.bz2</code>.</li> </ul> <h4 id="export-to-numpy">Export to NumPy</h4> <p>To extract data from <code>Datafield</code> in form of NumPy arrays, use</p>

# Find intensity peaks

file:///usr/share/doc/bornagain/html/ref/data/datafield/find-peaks.html Mon, 01 Jan 0001 00:00:00 +0000 file:///usr/share/doc/bornagain/html/ref/data/datafield/find-peaks.html <h2 id="finding-intensity-peaks">Finding intensity peaks</h2> <p>To find the intensity peaks from a GISAXS simulation, use the method <code>FindPeaks</code>. It returns an array of (x,y) coordinates:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"> <span class="n">result</span> <span class="o">=</span> <span class="n">run_simulation</span><span class="p">()</span><span class="o">.</span><span class="n">histogram2d</span><span class="p">()</span> </span></span><span class="line"><span class="cl"> <span class="n">peaks</span> <span class="o">=</span> <span class="n">ba</span><span class="o">.</span><span class="n">FindPeaks</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="s2">&#34;nomarkov&#34;</span><span class="p">,</span> <span class="mf">0.001</span><span class="p">)</span> </span></span><span class="line"><span class="cl"> <span class="n">peaks_x</span> <span class="o">=</span> <span class="p">[</span><span class="n">peak</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">peak</span> <span class="ow">in</span> <span class="n">peaks</span><span class="p">]</span> </span></span><span class="line"><span class="cl"> <span class="n">ypeak_y</span> <span class="o">=</span> <span class="p">[</span><span class="n">peak</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">peak</span> <span class="ow">in</span> <span class="n">peaks</span><span class="p">]</span> </span></span></code></pre></div> <div class="galleryscg "> <div class="row justify-content-center align-items-center"> <figure > <a href="file:///usr/share/doc/bornagain/html/img/auto/scatter2d/FindPeaks.png"> <img src="file:///usr/share/doc/bornagain/html/img/auto/scatter2d/FindPeaks.png" width="670px"> </a> <figcaption> <p>Intensity images</p> </figcaption> </figure> </div> </div> <p>The following script offers a complete example in which the peaks are found after carrying on a GISAXS simulation. This particular example uses as a sample a grating of long boxes distributed along a 1D lattice.</p> <div class="highlight"><div class="chroma"> <table class="lntable"><tr><td class="lntd"> <pre tabindex="0" class="chroma"><code></code></pre></td> <td class="lntd"> <pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"></code></pre></td></tr></table> </div> </div> <a class="linktofile" href="https://jugit.fz-juelich.de/mlz/bornagain/-/tree/r23/auto/Examples/scatter2d/FindPeaks.py"/>auto/Examples/scatter2d/FindPeaks.py</a>