Laboratory for Fluorescence Dynamics (LFD) file formats
=======================================================

Lfdfiles is a Python library and console script for reading, writing,
converting, and viewing many of the proprietary file formats used
to store experimental data and metadata at the
`Laboratory for Fluorescence Dynamics <https://www.lfd.uci.edu/>`_.
For example:

- SimFCS VPL, VPP, JRN, BIN, INT, CYL REF, BH, BHZ FBF, FBD, B64, I64, Z64, R64
- GLOBALS LIF, ASCII
- CCP4 MAP
- Vaa3D RAW
- Bio-Rad(r) PIC
- Vista IFLI, IFI
- FlimFast FLIF

:Author: `Christoph Gohlke <https://www.cgohlke.com>`_
:License: BSD 3-Clause
:Version: 2022.9.20

Installation
------------

Install the lfdfiles package and common dependencies from the
Python Package Index::

    python -m pip install -U lfdfiles tifffile matplotlib

Binary wheels are currently available for Windows only. On other platforms,
a Python distutils compatible C compiler is required to install the package
from source.

This release has been tested with the following requirements and dependencies
(other versions may work):

- `CPython 3.8.10, 3.9.13, 3.10.7, 3.11.0rc2 <https://www.python.org>`_
  (win-amd64 platforms, 32-bit platforms are deprecated)
- `Cython 0.29.32 <https://pypi.org/project/cython/>`_ (build)
- `NumPy 1.22.4 <https://pypi.org/project/numpy/>`_
- `Tifffile 2022.8.12  <https://pypi.org/project/tifffile/>`_  (optional)
- `Czifile 2019.7.2 <https://pypi.org/project/czifile/>`_ (optional)
- `Oiffile 2022.2.2 <https://pypi.org/project/oiffile />`_ (optional)
- `Netpbmfile 2022.9.12 <https://pypi.org/project/netpbmfile />`_ (optional)
- `Matplotlib 3.5.3 <https://pypi.org/project/matplotlib/>`_
  (optional, for plotting)
- `Click 8.1 <https://pypi.python.org/pypi/click>`_
  (optional, for command line usage)

Revisions
---------

2022.9.20

- Update metadata.

2022.6.10

- Fix LfdFileSequence with tifffile 2022.4.22.
- Add fbd2b64 conversion function and script.
- Add decoder for 32-bit, 8 windows, 4 channels FLIMbox data from Spartan-6.
- Convert docstrings to Google style with Sphinx directives.

2022.2.2

- Add type hints.
- SimfcsFit.asarray returns dc_ref only; use p_fit for fit params (breaking).
- Remove additional positional arguments to LfdFile init (breaking).
- Guess SimfcsBin shape and dtype if not provided (breaking).
- Use TiffWriter.write instead of deprecated save.
- Drop support for Python 3.7 and NumPy < 1.19 (NEP29).

2021.7.15

- Refactor SimfcsFbd initialization.
- Print tracebacks of failing plugins in LfdFile.

2021.7.11

- Calculate pixel_dwell_time and frame_size for FBD files with header.
- Disable simfcsfbd_decode and simfcsfbd_histogram Python code (breaking).

2021.6.25

- ...

Refer to the CHANGES file for older revisions.

Notes
-----

Lfdfiles is currently developed, built, and tested on Windows only.

The API is not stable yet and might change between revisions.

The latest `Microsoft Visual C++ Redistributable for Visual Studio 2015-2022
<https://support.microsoft.com/en-us/help/2977003/
the-latest-supported-visual-c-downloads>`_ is required on Windows.

Many of the LFD's file formats are not documented and might change arbitrarily.
This implementation is mostly based on reverse engineering existing files.
No guarantee can be made as to the correctness of code and documentation.

Experimental data are often stored in plain binary files with metadata
available in separate, human readable journal files (`.jrn`).

Unless specified otherwise, data are stored in little-endian, C contiguous
order.

For command line usage run ``python -m lfdfiles --help``.

References
----------

The following software is referenced in this module:

1.  `SimFCS <https://www.lfd.uci.edu/globals/>`_, a.k.a. Globals for
    Images, is software for fluorescence image acquisition, analysis, and
    simulation, developed by Enrico Gratton at UCI.
2.  `Globals <https://www.lfd.uci.edu/globals/>`_, a.k.a. Globals for
    Spectroscopy, is software for the analysis of multiple files from
    fluorescence spectroscopy, developed by Enrico Gratton at UIUC and UCI.
3.  ImObj is software for image analysis, developed by LFD at UIUC.
    Implemented on Win16.
4.  `FlimFast <https://www.lfd.uci.edu/~gohlke/flimfast/>`_ is software for
    frequency-domain, full-field, fluorescence lifetime imaging at video
    rate, developed by Christoph Gohlke at UIUC.
5.  FLImage is software for frequency-domain, full-field, fluorescence
    lifetime imaging, developed by Christoph Gohlke at UIUC.
    Implemented in LabVIEW.
6.  FLIez is software for frequency-domain, full-field, fluorescence
    lifetime imaging, developed by Glen Redford at UIUC.
7.  Flie is software for frequency-domain, full-field, fluorescence
    lifetime imaging, developed by Peter Schneider at MPIBPC.
    Implemented on a Sun UltraSPARC.
8.  FLOP is software for frequency-domain, cuvette, fluorescence lifetime
    measurements, developed by Christoph Gohlke at MPIBPC.
    Implemented in LabVIEW.
9.  `VistaVision <http://www.iss.com/microscopy/software/vistavision.html>`_
    is commercial software for instrument control, data acquisition and data
    processing by ISS Inc (Champaign, IL).
10. `Vaa3D <https://github.com/Vaa3D>`_ is software for multi-dimensional
    data visualization and analysis, developed by the Hanchuan Peng group at
    the Allen Institute.
11. `Voxx <https://voxx.sitehost.iu.edu/>`_ is a volume rendering program
    for 3D microscopy, developed by Jeff Clendenon et al. at the Indiana
    University.
12. `CCP4 <https://www.ccp4.ac.uk/>`_, the Collaborative Computational Project
    No. 4, is software for macromolecular X-Ray crystallography.

Examples
--------

Create a Bio-Rad PIC file from a NumPy array:

>>> data = numpy.arange(1000000).reshape(100, 100, 100).astype('u1')
>>> bioradpic_write('_biorad.pic', data)

Read the volume data from the PIC file as NumPy array, and access metadata:

>>> with BioradPic('_biorad.pic') as f:
...     f.shape
...     f.spacing
...     data = f.asarray()
(100, 100, 100)
(1.0, 1.0, 1.0)

Convert the PIC file to a compressed TIFF file:

>>> with BioradPic('_biorad.pic') as f:
...     f.totiff('_biorad.tif', compression='zlib')
