
Nexus -> CBF
============

In this tutorial we will see how to export a Nexus archive produced by
the Eiger detector from Dectris into a bunch of CBF files, similar to
the one generated by Pilatus detectors, using the FabIO library to write
images and h5py to read them.

**Nota:** HDF5 files produced by Nexus detector use a specific LZ4
plugin for reading/writing. They require recent version of hdf5 (1.8.12
at least).

.. code:: python

    import fabio, h5py
.. code:: python

    h5_file = h5py.File("series_23_master.h5")
    print(list(h5_file.keys()))

.. parsed-literal::

    [u'entry']


.. code:: python

    print(list(h5_file["entry"].keys()))

.. parsed-literal::

    [u'instrument', u'data_000002', u'data_000001']


.. code:: python

    print(h5_file["entry/data_000001"].shape)

.. parsed-literal::

    (50, 2167, 2070)


.. code:: python

    h5_file["entry/instrument/detector"].keys()



.. parsed-literal::

    [u'beam_center_x',
     u'beam_center_y',
     u'bit_depth_readout',
     u'count_time',
     u'countrate_correction_applied',
     u'description',
     u'detectorSpecific',
     u'detector_distance',
     u'detector_number',
     u'detector_readout_time',
     u'efficiency_correction_applied',
     u'flatfield_correction_applied',
     u'frame_time',
     u'geometry',
     u'pixel_mask_applied',
     u'sensor_material',
     u'sensor_thickness',
     u'threshold_energy',
     u'virtual_pixel_correction_applied',
     u'x_pixel_size',
     u'y_pixel_size']



.. code:: python

    dset = h5_file["entry/data_000001"]
    for idx, frame in enumerate(dset):
        cbf = fabio.cbfimage.cbfimage(data=frame)
        fname = "series_23_%04i.cbf"%idx
        cbf.write(fname)
        print(fname)
        
        

.. parsed-literal::

    series_23_0000.cbf
    series_23_0001.cbf
    series_23_0002.cbf
    series_23_0003.cbf
    series_23_0004.cbf
    series_23_0005.cbf
    series_23_0006.cbf
    series_23_0007.cbf
    series_23_0008.cbf
    series_23_0009.cbf
    series_23_0010.cbf
    series_23_0011.cbf
    series_23_0012.cbf
    series_23_0013.cbf
    series_23_0014.cbf
    series_23_0015.cbf
    series_23_0016.cbf
    series_23_0017.cbf
    series_23_0018.cbf
    series_23_0019.cbf
    series_23_0020.cbf
    series_23_0021.cbf
    series_23_0022.cbf
    series_23_0023.cbf
    series_23_0024.cbf
    series_23_0025.cbf
    series_23_0026.cbf
    series_23_0027.cbf
    series_23_0028.cbf
    series_23_0029.cbf
    series_23_0030.cbf
    series_23_0031.cbf
    series_23_0032.cbf
    series_23_0033.cbf
    series_23_0034.cbf
    series_23_0035.cbf
    series_23_0036.cbf
    series_23_0037.cbf
    series_23_0038.cbf
    series_23_0039.cbf
    series_23_0040.cbf
    series_23_0041.cbf
    series_23_0042.cbf
    series_23_0043.cbf
    series_23_0044.cbf
    series_23_0045.cbf
    series_23_0046.cbf
    series_23_0047.cbf
    series_23_0048.cbf
    series_23_0049.cbf


Conclusion
----------

FabIO offers a versatile way for manipulating image files and convert
them.

.. code:: python

    print(fabio.version)
    print(h5py.version.version)
    print(h5py.version.hdf5_version)

.. parsed-literal::

    0.3.0-dev1
    2.5.0
    1.8.13


.. code:: python

    import os
    os.environ["HDF5_PLUGIN_PATH"]="/usr/lib/x86_64-linux-gnu/hdf5/plugins"
