Skip to content
Snippets Groups Projects
cfelpyutils.html 36.9 KiB
Newer Older
Valerio Mariani's avatar
Valerio Mariani committed


<!doctype html>


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>cfelpyutils package &#8212; cfelpyutils 0.5 documentation</title>
Valerio Mariani's avatar
Valerio Mariani committed
    
    <link rel="stylesheet" href="_static/bizstyle.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.5',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
Valerio Mariani's avatar
Valerio Mariani committed
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/bizstyle.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
Valerio Mariani's avatar
Valerio Mariani committed
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!--[if lt IE 9]>
    <script type="text/javascript" src="_static/css3-mediaqueries.js"></script>
    <![endif]-->
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">cfelpyutils 0.5 documentation</a> &#187;</li> 
Valerio Mariani's avatar
Valerio Mariani committed
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">cfelpyutils package</a><ul>
<li><a class="reference internal" href="#submodules">Submodules</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_crystfel">cfelpyutils.cfel_crystfel module</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_cxi">cfelpyutils.cfel_cxi module</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_fabio">cfelpyutils.cfel_fabio module</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_geom">cfelpyutils.cfel_geom module</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_hdf5">cfelpyutils.cfel_hdf5 module</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_optarg">cfelpyutils.cfel_optarg module</a></li>
<li><a class="reference internal" href="#module-cfelpyutils.cfel_psana">cfelpyutils.cfel_psana module</a></li>
Valerio Mariani's avatar
Valerio Mariani committed
<li><a class="reference internal" href="#module-cfelpyutils">Module contents</a></li>
Valerio Mariani's avatar
Valerio Mariani committed
</ul>
</li>
</ul>

  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/cfelpyutils.rst.txt"
Valerio Mariani's avatar
Valerio Mariani committed
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
Valerio Mariani's avatar
Valerio Mariani committed
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
Valerio Mariani's avatar
Valerio Mariani committed
  <div class="section" id="cfelpyutils-package">
<h1>cfelpyutils package<a class="headerlink" href="#cfelpyutils-package" title="Permalink to this headline"></a></h1>
Valerio Mariani's avatar
Valerio Mariani committed
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="module-cfelpyutils.cfel_crystfel">
<span id="cfelpyutils-cfel-crystfel-module"></span><h2>cfelpyutils.cfel_crystfel module<a class="headerlink" href="#module-cfelpyutils.cfel_crystfel" title="Permalink to this headline"></a></h2>
<p>Utilities for interoperability with the CrystFEL software package.</p>
<p>This module contains reimplementation of Crystfel functions and utilities.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<dl class="function">
<dt id="cfelpyutils.cfel_crystfel.load_crystfel_geometry">
<code class="descclassname">cfelpyutils.cfel_crystfel.</code><code class="descname">load_crystfel_geometry</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_crystfel.load_crystfel_geometry" title="Permalink to this definition"></a></dt>
<dd><p>Loads a CrystFEL geometry file into a dictionary.</p>
<p>Reimplements the get_detector_geometry_2 function from CrystFEL amost verbatim. Returns a dictionary with the
geometry information. Entries in the geometry file appears as keys in the returned dictionary. For a full
documentation on the CrystFEL geometry format, see:</p>
<p>tfel/manual-crystfel_geometry.html</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>filename</strong> (<em>str</em>) &#8211; filename of the geometry file</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">dictionary with the geometry loaded from the file</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">detector (dict)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cfelpyutils.cfel_cxi">
<span id="cfelpyutils-cfel-cxi-module"></span><h2>cfelpyutils.cfel_cxi module<a class="headerlink" href="#module-cfelpyutils.cfel_cxi" title="Permalink to this headline"></a></h2>
<p>Utilities for writing multi-event files in the CXIDB format.</p>
<p>This module contains utilities to write files that adhere to the CXIDB file format:</p>
<p><a class="reference external" href="http://www.cxidb.org/cxi.html">http://www.cxidb.org/cxi.html</a> .</p>
<dl class="class">
<dt id="cfelpyutils.cfel_cxi.CXIWriter">
<em class="property">class </em><code class="descclassname">cfelpyutils.cfel_cxi.</code><code class="descname">CXIWriter</code><span class="sig-paren">(</span><em>filename</em>, <em>max_num_slices=5000</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal"><span class="pre">object</span></code></p>
<p>Writing of multi-event CXIDB files.</p>
<p>Implements a simple low-level CXIDB file format writer for multi event files. it allows the user to write data
&#8220;stacks&#8221; in the CXIDB files, making sure that the entries in all stacks are synchronized.</p>
<p>A CXI Writer instance manages one file. A user can add a stack to a CXI Writer instance with the
add_stack_to_writer function, which also writes the first entry in the stack. The user can then add to the writer
all the stacks that he wants in the file. Once all stacks are added, the user initializes them  with the
initialize_stacks function. After initialization, no more stacks can be added. Instead, entries can be appended to
the existing stacks, using the append_data_to_stack function.</p>
<p>A &#8220;slice&#8221; (a set of synced entries in all the stacks in the file) can be written to the a file only after an entry
has been appended to all stacks in the file. Conversely, after an entry has been appended to a stack, the user
cannot append another entry before a slice is written. This ensures synchronization of the data in all the stacks.</p>
<p>A file can be closed at any time. In any case, the writer will not allow a file to contain more than the
number_of_entries specified during instantiation.</p>
<p>Simple non-stack entries can be written to the file at any time, before or after stack initialization (provided of
course that the file is open). Entries and stacks will general never be overwritten unless the overwrite parameter
is set to True.</p>
<p>Example of usage of the stack API:</p>
<p>f1 = CXIWriter(&#8216;test1.h5&#8217;, )
f2 = CXIWriter(&#8216;test2.h5&#8217;, )</p>
<dl class="docutils">
<dt>f1.add_stack_to_writer(&#8216;detector1&#8217;, &#8216;/entry_1/detector_1/data&#8217;, numpy.random.rand(2, 2),</dt>
<dd>&#8216;frame:y:x&#8217;)</dd>
<dt>f2.add_stack_to_writer(&#8216;detector2&#8217;, &#8216;/entry_1/detector_1/data&#8217;, numpy.random.rand(3, 2),</dt>
<dd>&#8216;frame:y:x&#8217;, compression=False, chunk_size=(1,3,2))</dd>
</dl>
<p>f1.add_stack_to_writer(&#8216;counter1&#8217;, &#8216;/entry_1/detector_1/count&#8217;, c1)
f2.add_stack_to_writer(&#8216;counter2&#8217;, &#8216;/entry_1/detector_1/count&#8217;, c2)</p>
<p>f1.write_simple_entry(&#8216;/entry_1/detector_1/name&#8217;, &#8216;FrontCSPAD&#8217;)
f2.write_simple_entry(&#8216;/entry_1/detector_1/name&#8217;, &#8216;BackCSPAD&#8217;)</p>
<p>f1.initialize_stacks()
f2.initialize_stacks()</p>
<p>a = numpy.random.rand(2, 2)
b = numpy.random.rand(3, 2)</p>
<p>c1 += 1
c2 += 2</p>
<p>f1.append_data_to_stack(&#8216;detector1&#8217;, a)
f2.append_data_to_stack(&#8216;detector2&#8217;, b)</p>
<p>f1.append_data_to_stack(&#8216;counter1&#8217;, c1)
f2.append_data_to_stack(&#8216;counter2&#8217;, c2)</p>
<p>f1.write_stack_slice_and_increment()
f2.write_stack_slice_and_increment()</p>
<p>f1.close_file()
f2.close_file()</p>
<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.add_stack_to_writer">
<code class="descname">add_stack_to_writer</code><span class="sig-paren">(</span><em>name</em>, <em>path</em>, <em>initial_data</em>, <em>axes=None</em>, <em>compression=True</em>, <em>chunk_size=None</em>, <em>overwrite=True</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.add_stack_to_writer" title="Permalink to this definition"></a></dt>
<dd><p>Adds a new stack to the file.</p>
<p>Adds a new stack to the CXI Writer instance. The user must provide a name for the stack, that will identify
the stack in all subsequents operations. The user must also provide the data that will be written as the
initial entry in the stack (initial_data). This initial entry is used to set the size and type of data that the
stack will hold and these parameters are in turn be used to validate all data that is subsequently appended to
the stack.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) &#8211; stack name.</li>
<li><strong>path</strong> (<em>str</em>) &#8211; path in the hdf5 file where the stack will be written.</li>
<li><strong></strong><strong>(</strong><strong>Union</strong><strong>[</strong><strong>numpy.ndarray</strong><strong>, </strong><strong>str</strong><strong>, </strong><strong>int</strong><strong>, </strong><strong>float</strong><strong>]</strong><strong></strong> (<em>initial_data</em>) &#8211; initial entry in the stack. It gets written to the</li>
<li><strong>as slice 0. Its characteristics are used to validate all data subsequently appended to the stack.</strong> (<em>stack</em>) &#8211; </li>
<li><strong>axes</strong> (<em>str</em>) &#8211; the &#8216;axes&#8217; attribute for the stack, as defined by the CXIDB file format.</li>
<li><strong>compression</strong> (<em>Union</em><em>[</em><em>None</em><em>, </em><em>bool</em><em>,</em><em>str</em><em>]</em><em></em>) &#8211; compression parameter for the stack. This parameters works in the same</li>
<li><strong>as the normal compression parameter from h5py. The default value of this parameter is True.</strong> (<em>way</em>) &#8211; </li>
<li><strong>chunk_size</strong> (<em>Union</em><em>[</em><em>None</em><em>, </em><em>tuple</em><em>]</em><em></em>) &#8211; HDF5 chuck size for the stack. If this parameter is set to None, the</li>
<li><strong>writer will compute a chuck size automatically</strong> (<em>CXI</em>) &#8211; </li>
<li><strong>use the provided tuple to set the chunk size.</strong> (<em>will</em>) &#8211; </li>
<li><strong>overwrite</strong> (<em>bool</em>) &#8211; if set to True, a stack already existing at the same location will be overwritten. If set</li>
<li><strong>False</strong><strong>, </strong><strong>an attempt to overwrite a stack will raise an error.</strong> (<em>to</em>) &#8211; </li>
Valerio Mariani's avatar
Valerio Mariani committed
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.append_data_to_stack">
<code class="descname">append_data_to_stack</code><span class="sig-paren">(</span><em>name</em>, <em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.append_data_to_stack" title="Permalink to this definition"></a></dt>
<dd><p>Appends data to a stack.</p>
<p>Appends data to a stack, validating the data to make sure that the data type and size match the previous entries
in the stack. Only one entry can be appended to each stack before writing a slice across all stacks with
the write_slice_and_increment.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>name</strong> (<em>str</em>) &#8211; stack name, defining the stack to which the data will be appended.</li>
<li><strong></strong><strong>(</strong><strong>Union</strong> (<em>data</em>) &#8211; numpy.ndarray, str, int, float): data to write. The data will be validated against the type</li>
<li><strong>size of previous entries in the stack.</strong> (<em>and</em>) &#8211; </li>
</ul>
Valerio Mariani's avatar
Valerio Mariani committed
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.close_file">
<code class="descname">close_file</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.close_file" title="Permalink to this definition"></a></dt>
<dd><p>Closes the file.</p>
<p>Closes the file for writing, ending all writing operations.</p>
</dd></dl>

<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.get_file_handle">
<code class="descname">get_file_handle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.get_file_handle" title="Permalink to this definition"></a></dt>
<dd><p>Access to the naked h5py file handle.</p>
<p>This function allows access to the a naked h5py handle for the file managed by the CXI Writer. This allowa
operations on the file that are not covered by  CXI Writer API. Use it at your own risk.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">an h5py file handle to the file managed by the writer.</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">fh (h5py.File)</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.initialize_stacks">
<code class="descname">initialize_stacks</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.initialize_stacks" title="Permalink to this definition"></a></dt>
<dd><p>Initializes the stacks.</p>
<p>Initializes the stacks in the CXI Writer instance. This fixes the number and type of stacks in the file. No
stacks can be added to the CXI Writer after initialization.</p>
</dd></dl>

<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.write_simple_entry">
<code class="descname">write_simple_entry</code><span class="sig-paren">(</span><em>path</em>, <em>data</em>, <em>overwrite=False</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.write_simple_entry" title="Permalink to this definition"></a></dt>
<dd><p>Writes a simple, non-stack entry in the file.</p>
<p>Writes a simple, non-stack entry in the file, at the specified path. A simple entry can be written at all times,
before or after the stack initialization.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>path</strong> (<em>str</em>) &#8211; path in the hdf5 file where the entry will be written.</li>
<li><strong></strong><strong>(</strong><strong>Union</strong> (<em>data</em>) &#8211; numpy.ndarray, str, int, float): data to write</li>
<li><strong>overwrite</strong> (<em>bool</em>) &#8211; if set to True, an entry already existing at the same location will be overwritten. If set</li>
<li><strong>False</strong><strong>, </strong><strong>an attempt to overwrite an entry will raise an error.</strong> (<em>to</em>) &#8211; </li>
</ul>
Valerio Mariani's avatar
Valerio Mariani committed
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cfelpyutils.cfel_cxi.CXIWriter.write_stack_slice_and_increment">
<code class="descname">write_stack_slice_and_increment</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_cxi.CXIWriter.write_stack_slice_and_increment" title="Permalink to this definition"></a></dt>
<dd><p>Writes a slice across all stacks and resets the writer for the next slice.</p>
<p>Writes a slice across all stacks in the file. It checks that an entry has been appended to each stack, and
writes all the entries on top of the relevant stacks in one go. If an entry is missing in a stack, the function
will raise an error. After writing the slice, the function resets the writer to allow again appending data to
the stacks.</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cfelpyutils.cfel_fabio">
<span id="cfelpyutils-cfel-fabio-module"></span><h2>cfelpyutils.cfel_fabio module<a class="headerlink" href="#module-cfelpyutils.cfel_fabio" title="Permalink to this headline"></a></h2>
<p>Utilities based on the fabio python module.</p>
<p>This module contains utilities based on the fabio python module.
files.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<dl class="function">
<dt id="cfelpyutils.cfel_fabio.read_cbf_from_stream">
<code class="descclassname">cfelpyutils.cfel_fabio.</code><code class="descname">read_cbf_from_stream</code><span class="sig-paren">(</span><em>stream</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_fabio.read_cbf_from_stream" title="Permalink to this definition"></a></dt>
<dd><p>Reads a cbfimage object out of a data string buffer.</p>
<p>Read a data string buffer received as a payload from the PETRAIII P11 sender, and creates a cbfimage object from
it (See the documentation of the fabio python module).</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>stream</strong> (<em>str</em>) &#8211; a data string buffer received from the PETRAIII P11 sender.</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="docutils">
<dt>a cbfimage object containing the data extracted</dt>
<dd>from the string buffer.</dd>
</dl>
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">cbf_obj (fabio.cbfimage)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cfelpyutils.cfel_geom">
<span id="cfelpyutils-cfel-geom-module"></span><h2>cfelpyutils.cfel_geom module<a class="headerlink" href="#module-cfelpyutils.cfel_geom" title="Permalink to this headline"></a></h2>
<p>Utilities for CrystFEL-style geometry files.</p>
<p>This module contains utilities for the processing of CrystFEL-style geometry
files.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<dl class="function">
<dt id="cfelpyutils.cfel_geom.apply_geometry_from_file">
<code class="descclassname">cfelpyutils.cfel_geom.</code><code class="descname">apply_geometry_from_file</code><span class="sig-paren">(</span><em>data_as_slab</em>, <em>geometry_filename</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_geom.apply_geometry_from_file" title="Permalink to this definition"></a></dt>
<dd><p>Parses a geometry file and applies the geometry to data.</p>
<p>Parses a geometry file and applies the geometry to detector data in &#8216;slab&#8217; format. Turns a 2d array of pixel
values into an array containing a representation of the physical layout of the detector, keeping the origin of
the reference system at the beam interaction point.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data_as_slab</strong> (<em>numpy.ndarray</em>) &#8211; the pixel values to which geometry is to be applied.</li>
<li><strong>geometry_filename</strong> (<em>str</em>) &#8211; geometry filename.</li>
</ul>
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Array containing a representation of the physical layout of the
detector, with the origin of the  reference system at the beam interaction point.</p>
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">im_out (numpy.ndarray data_as_slab.dtype)</p>
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cfelpyutils.cfel_geom.apply_geometry_from_pixel_maps">
<code class="descclassname">cfelpyutils.cfel_geom.</code><code class="descname">apply_geometry_from_pixel_maps</code><span class="sig-paren">(</span><em>data_as_slab</em>, <em>yx</em>, <em>im_out=None</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_geom.apply_geometry_from_pixel_maps" title="Permalink to this definition"></a></dt>
<dd><p>Applies geometry in pixel map format to data.</p>
<p>Applies geometry, in the form of pixel maps, to detector data in &#8216;slab&#8217; format. Turns a 2d array of pixel values
into an array containing a representation of the physical layout of the detector, keeping the origin of the
reference system at the beam interaction point.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data_as_slab</strong> (<em>numpy.ndarray</em>) &#8211; the pixel values to which geometry is to be applied.</li>
<li><strong>yx</strong> (<em>tuple</em>) &#8211; the yx pixel maps describing the geometry of the detector; each map is a numpy.ndarray.</li>
<li><strong>im_out</strong> (<em>Optional</em><em>[</em><em>numpy.ndarray</em><em>]</em><em></em>) &#8211; array to hold the output; if not provided, one will be generated</li>
<li><strong>automatically.</strong> &#8211; </li>
</ul>
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Array containing a representation of the physical layout of the
detector, with the origin of the  reference system at the beam interaction point.</p>
Valerio Mariani's avatar
Valerio Mariani committed
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">im_out (numpy.ndarray data_as_slab.dtype)</p>
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

Valerio Mariani's avatar
Valerio Mariani committed
<dl class="function">
<dt id="cfelpyutils.cfel_geom.pixel_maps_for_image_view">
<code class="descclassname">cfelpyutils.cfel_geom.</code><code class="descname">pixel_maps_for_image_view</code><span class="sig-paren">(</span><em>geometry_filename</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_geom.pixel_maps_for_image_view" title="Permalink to this definition"></a></dt>
<dd><p>Parses a geometry file and creates pixel maps for pyqtgraph visualization.</p>
<p>Parse the geometry file and creates pixel maps for an  array in &#8216;slab&#8217; format containing pixel values. The pixel
maps can be used to create a representation of the physical layout of the detector in a pyqtgraph ImageView
widget (i.e. they apply the detector geometry setting the origin of the reference system is in the top left corner
of the output array).</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>geometry_filename</strong> (<em>str</em>) &#8211; geometry filename.</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">pixel maps<p>slab_shape tuple (int, int): shape of the original geometry uncorrected array (the pixel values in &#8220;slab&#8221;
format).</p>
<p>img_shape tuple (int, int): shape of the array needed to contain the representation of the physical layout
of the detector.</p>
Valerio Mariani's avatar
Valerio Mariani committed
</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">(y, x) (numpy.ndarray int, numpy.ndarray int)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cfelpyutils.cfel_geom.pixel_maps_from_geometry_file">
<code class="descclassname">cfelpyutils.cfel_geom.</code><code class="descname">pixel_maps_from_geometry_file</code><span class="sig-paren">(</span><em>fnam</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_geom.pixel_maps_from_geometry_file" title="Permalink to this definition"></a></dt>
<dd><p>Parses a geometry file and creates pixel maps.</p>
<p>Extracts pixel maps from a CrystFEL-style geometry file. The pixel maps can be used to create a representation of
the physical layout of the detector, keeping the origin of the  reference system at the beam interaction
point.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fnam</strong> (<em>str</em>) &#8211; geometry filename.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">slab-like pixel maps with
respectively x, y coordinates of the pixel and distance of the pixel from the center of the reference system.</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">x,y,r (numpy.ndarray float, numpy.ndarray float, numpy.ndarray float)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cfelpyutils.cfel_hdf5">
<span id="cfelpyutils-cfel-hdf5-module"></span><h2>cfelpyutils.cfel_hdf5 module<a class="headerlink" href="#module-cfelpyutils.cfel_hdf5" title="Permalink to this headline"></a></h2>
Valerio Mariani's avatar
Valerio Mariani committed
<p>Utilities for HDF5 files.</p>
<p>This module contains utilities for the processing of HDF5. This module builds
on what the h5py module already provides.</p>
<dl class="function">
<dt id="cfelpyutils.cfel_hdf5.load_nparray_from_hdf5_file">
<code class="descclassname">cfelpyutils.cfel_hdf5.</code><code class="descname">load_nparray_from_hdf5_file</code><span class="sig-paren">(</span><em>data_filename</em>, <em>data_group</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_hdf5.load_nparray_from_hdf5_file" title="Permalink to this definition"></a></dt>
Valerio Mariani's avatar
Valerio Mariani committed
<dd><p>Loads a numpy.ndarray from an HDF5 file.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data_filename</strong> (<em>str</em>) &#8211; filename of the file to read.</li>
<li><strong>data_group</strong> (<em>str</em>) &#8211; internal HDF5 path of the data block to read.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">numpy array with the data read from the file.</p>
Valerio Mariani's avatar
Valerio Mariani committed
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">nparray (numpy.ndarray)</p>
Valerio Mariani's avatar
Valerio Mariani committed
</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cfelpyutils.cfel_optarg">
<span id="cfelpyutils-cfel-optarg-module"></span><h2>cfelpyutils.cfel_optarg module<a class="headerlink" href="#module-cfelpyutils.cfel_optarg" title="Permalink to this headline"></a></h2>
Valerio Mariani's avatar
Valerio Mariani committed
<p>Utilities for parsing command line options and configuration files.</p>
<p>This module contains utilities for parsing of command line options and
configuration files.</p>
<dl class="function">
<dt id="cfelpyutils.cfel_optarg.parse_parameters">
<code class="descclassname">cfelpyutils.cfel_optarg.</code><code class="descname">parse_parameters</code><span class="sig-paren">(</span><em>config</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_optarg.parse_parameters" title="Permalink to this definition"></a></dt>
Valerio Mariani's avatar
Valerio Mariani committed
<dd><p>Sets correct types for parameter dictionaries.</p>
<p>Reads a parameter dictionary returned by the ConfigParser python module, and assigns correct types to parameters,
without changing the structure of the dictionary.</p>
<p>The parser tries to interpret each entry in the dictionary according to the following rules:</p>
Valerio Mariani's avatar
Valerio Mariani committed
<ul>
<li><p class="first">If the entry starts and ends with a single quote or double quote, it is
interpreted as a string.</p>
</li>
<li><p class="first">If the entry starts and ends with a square bracket, it is interpreted as a list.</p>
</li>
<li><p class="first">If the entry starts and ends with a brace, it is interpreted as a dictionary.</p>
Valerio Mariani's avatar
Valerio Mariani committed
</li>
<li><p class="first">If the entry is the word None, without quotes, then the entry is
interpreted as NoneType.</p>
</li>
<li><p class="first">If the entry is the word False, without quotes, then the entry is
interpreted as a boolean False.</p>
</li>
<li><p class="first">If the entry is the word True, without quotes, then the entry is
interpreted as a boolean True.</p>
</li>
<li><p class="first">If none of the previous options match the content of the entry,
Valerio Mariani's avatar
Valerio Mariani committed
the parser tries to interpret the entry in order as:</p>
<blockquote>
<div><ul class="simple">
<li>An integer number.</li>
<li>A float number.</li>
<li>A string.</li>
</ul>
</div></blockquote>
<p>The first choice that succeeds determines the entry type.</p>
</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
Valerio Mariani's avatar
Valerio Mariani committed
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>config</strong> (<em>class RawConfigParser</em>) &#8211; ConfigParser instance.</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">dictionary with the same structure as the input dictionary, but with correct types
assigned to each entry.</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">monitor_params (dict)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cfelpyutils.cfel_psana">
<span id="cfelpyutils-cfel-psana-module"></span><h2>cfelpyutils.cfel_psana module<a class="headerlink" href="#module-cfelpyutils.cfel_psana" title="Permalink to this headline"></a></h2>
Valerio Mariani's avatar
Valerio Mariani committed
<p>Utilities based on the psana python module.</p>
<p>This module provides utilities that build on the functionality provided by the psana python module.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<dl class="function">
<dt id="cfelpyutils.cfel_psana.dirname_from_source_runs">
<code class="descclassname">cfelpyutils.cfel_psana.</code><code class="descname">dirname_from_source_runs</code><span class="sig-paren">(</span><em>source</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_psana.dirname_from_source_runs" title="Permalink to this definition"></a></dt>
Valerio Mariani's avatar
Valerio Mariani committed
<dd><p>Returns a directory name based on a psana source string.</p>
<p>Takes a psana source string (e.g exp=CXI/cxix....) and returns a string that can be used as a subdirectory name or
a prefix for files and directories.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>source</strong> (<em>str</em>) &#8211; a psana source string (e.g. exp=CXI/cxi....).</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">a string that can be used as a filename or a prefix .</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">dirname (str)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cfelpyutils.cfel_psana.psana_event_inspection">
<code class="descclassname">cfelpyutils.cfel_psana.</code><code class="descname">psana_event_inspection</code><span class="sig-paren">(</span><em>source</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_psana.psana_event_inspection" title="Permalink to this definition"></a></dt>
Valerio Mariani's avatar
Valerio Mariani committed
<dd><p>Prints the structure of psana events.</p>
<p>Takes a psana source string (e.g. exp=CXI/cxix....) and inspects the structure of the first event in the data,
printing information about the the content of the event.</p>
Valerio Mariani's avatar
Valerio Mariani committed
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>source</strong> (<em>str</em>) &#8211; a psana source string (e.g. exp=CXI/cxix....).</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cfelpyutils.cfel_psana.psana_obj_from_string">
<code class="descclassname">cfelpyutils.cfel_psana.</code><code class="descname">psana_obj_from_string</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#cfelpyutils.cfel_psana.psana_obj_from_string" title="Permalink to this definition"></a></dt>
Valerio Mariani's avatar
Valerio Mariani committed
<dd><p>Converts a string into a psana object type.</p>
<p>Takes a string and returns the python object type described by the string.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>name</strong> (<em>str</em>) &#8211; a string describing a python type.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">the python type described by the string.</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">mod (type)</td>
Valerio Mariani's avatar
Valerio Mariani committed
</tr>
</tbody>
</table>
</dd></dl>

Valerio Mariani's avatar
Valerio Mariani committed
</div>
<div class="section" id="module-cfelpyutils">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-cfelpyutils" title="Permalink to this headline"></a></h2>
<p>Utilities for CFEL software projects.</p>
<p>This module provides utilities (functions, classes, etc.) used by many CFEL projects.</p>
<p>It contains the following submodules (non of which are automatically imported):</p>
<p>cfelfabio: utilities based on the fabio python module (a module that allows
python to work with several file format used in x-ray imaging).</p>
<p>cfelgeom: utilities for processing CrystFEL-style geometry files.</p>
<p>cfelhdf5: utilities for processing HDF5 files (based on the h5py python module).</p>
<p>cfeloptarg: utilities to parse command line arguments and parameter files.</p>
<p>cfelpsana: utilities that expand the functionality of the psana python module.</p>
Valerio Mariani's avatar
Valerio Mariani committed
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">cfelpyutils 0.5 documentation</a> &#187;</li> 
Valerio Mariani's avatar
Valerio Mariani committed
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, CFEL Team.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.1.
Valerio Mariani's avatar
Valerio Mariani committed
    </div>
  </body>
</html>