Giter Site home page Giter Site logo

fluorescence-tools / tttrlib Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 0.0 925.5 MB

File format agnostic low level, high performance API to read and process time-tagged-time resolved (TTTR) data for single-molecule and image spectroscopy

Home Page: http://tttrlib.rtfd.io/

License: BSD 3-Clause "New" or "Revised" License

CMake 2.65% C++ 50.29% C 11.32% Python 18.88% Batchfile 0.12% Shell 0.31% SWIG 16.43%
ptu flim becker picoquant python single-molecule fluorescence fluorescence-correlation fluorescence-microscopy-imaging imaging

tttrlib's Introduction

tttrlib

Anaconda-Server Badge PyPI version conda build

General description

tttrlib is a file format agnostic high performance library to read, process, and write time-tagged-time resolved (TTTR) data acquired by PicoQuant (PQ) and Becker & Hickl measurement devices/cards or TTTR files in the open Photon-HDF format.

The library facilitates the work with files containing time-tagged time resolved photon streams by providing a vendor independent C++ application programming interface (API) for TTTR files that is wrapped by SWIG (Simplified Wrapper and Interface Generator) for common scripting languages as Python as target languages and non-scripting languages such as C# and Java including Octave, Scilab and R. Currently, tttrlib is wrapped for the use in Python.

  • Multi-dimensional histograms
  • Correlation analysis
  • Time-window analysis
  • Photon distribution anaylsis
  • FLIM image generation and analysis

tttrlib FLIM

tttrlib is programmed in C++ and wrapped for python. Thus, it can be used to integrate time-resolved data into advanced data analysis pipelines.

Capabilities

  • Fast reading TTTR files (IO limited)
  • Generation / analysis of fluorescence decays
  • Time window analysis
  • Correlation of time event traces
  • Filtering of time event traces to generate instrument response functions for fluorescence decays analysis without the need of independent measurements..
  • Fast photon distribution analysis
  • Fast selection of photons from a photon stream

Generation of fluorescence decay histograms tttrlib outperforms pure numpy and Python based libraries by a factor of ~40.

Documentation

Installation

In an anaconda environment the library can be installed by the following command:

conda install -c tpeulen tttrlib

Alternatively, you can use pip to install tttrlib

pip install tttrlib

Usage

The API of tttrlib as well as some use cases are documented on its web page. Below you find a small selection of code snippets.

Access photon data as follows:

import tttrlib
fn = 'photon_stream.ptu'
data = tttrlib.TTTR(fn)

macro_times = data.macro_times
micro_times = data.micro_times
routing_channels = data.routing_channels

Print header-information:

import tttrlib
fn = 'photon_stream.ptu'
data = tttrlib.TTTR(fn)
print(data.json)

Correlate photon streams:

import tttrlib
fn = 'photon_stream.ptu'
data = tttrlib.TTTR(fn)
correlator = tttrlib.Correlator(
    channels=([1], [2]),
    tttr=data
)
taus = correlator.x_axis,
correlation_amplitude = correlator.correlation

Create intensity images from CLSM data:

import tttrlib
fn = 'image.ptu'
data = tttrlib.TTTR(fn)
clsm = tttrlib.CLSM(data)

channels = [0, 1]
prompt_range = [0, 16000]
clsm.fill(channels=channels, micro_time_ranges=[prompt_range])

intensity_image = clsm.intensity

tttrlib is in active development. In case you notice unusual behaviour do not hesitate to contact the authors.

Supported file formats

PicoQuant (PQ)

  • PicoHarp ptu, T2/T3
  • HydraHarp ptu, T2/T3
  • HydraHarp ht3, PTU

Becker & Hickl (BH)

  • spc132
  • spc630 (256 & 4096 mode)

Photon HDF5

Design goals

  • Low memory footprint (keep objective large datasets, e.g., FLIM in memory).
  • Platform independent C/C++ library with interfaces for scripting libraries

Building and Installation

C++ shared library

The C++ shared library can be installed from source with cmake:

git clone --recursive https://github.com/fluorescence-tools/tttrlib.git
mkdir tttrlib/build; cd tttrlib/build
cmake ..
sudo make install

On Linux you can build and install a package instead:

Python bindings

The Python bindings can be either be installed by downloading and compiling the source code or by using a precompiled distribution for Python anaconda environment.

The following commands can be used to download and compile the source code:

git clone --recursive https://github.com/fluorescence-tools/tttrlib.git
cd tttrlib
sudo python setup.py install

In an anaconda environment the library can be installed by the following command:

conda install -c tpeulen tttrlib

For most users, the latter approach is recommended. Currently, pre-compiled packages for the anaconda distribution system are available for Windows (x86), Linux (x86, ARM64, PPCle), and macOS (x86). Precompiled libary are linked against conda-forge HDF5 & Boost. Thus, the use of miniforge is recommended.

Legacy 32-bit platforms and versions of programming languages, e.g., Python 2.7 are not supported.

Citation

If you use this software please also check the pre-print:

tttrlib: modular software for integrating fluorescence spectroscopy, imaging, and molecular modeling; Thomas-Otavio Peulen, Katherina Hemmen, Annemarie Greife, Benjamin M. Webb, Suren Felekyan, Andrej Sali, Claus A. M. Seidel, Hugo Sanabria, Katrin G. Heinze; https://arxiv.org/abs/2402.17252

License

Copyright 2007-2024 tttrlib developers. Licensed under the BSD-3-Clause

tttrlib's People

Contributors

khemmen avatar tpeulen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tttrlib's Issues

Extraction of Histogram traces does not work

import pylab as p
import numpy as np

import tttrlib

data = tttrlib.TTTR("E:\Users\Hemmen\A488_1.ptu", '0')
mt = data.get_macro_time()

green_indeces = data.get_selection_by_channel(np.array([0, 2]))
red_indeces = data.get_selection_by_channel(np.array([1, 3]))

fig, ax = p.subplots(2, 1, sharex=True, sharey=False)

p.setp(ax[0].get_xticklabels(), visible=False)
ax[0].plot(tttrlib.histogram_trace(mt[green_indeces], 30000), 'g')

ax[1].plot(tttrlib.histogram_trace(mt[red_indeces], 30000), 'r')
ax[1].invert_yaxis()

p.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0)

p.show()

executing the script gives the following error:

AttributeError Traceback (most recent call last)
in
13
14 p.setp(ax[0].get_xticklabels(), visible=False)
---> 15 ax[0].plot(tttrlib.histogram_trace(mt[green_indeces], 30000), 'g')
16
17 ax[1].plot(tttrlib.histogram_trace(mt[red_indeces], 30000), 'r')

AttributeError: module 'tttrlib' has no attribute 'histogram_trace'

tttrlib for python 3.7 does not build on macOS

When tttrlib is build for python 3.7 on macOS it cannot be imported. Python 2.7 works for some reason. A debug with lldb gives the following errors. CMake seems to link against the correct libraries. No idea what is going on...

(tttrlib) tpeulen@MacBook-Pro-9:~/development/fluorescence-tools/tttrlib$ lldb python
(lldb) target create "python"
Current executable set to 'python' (x86_64).
(lldb) run
Process 51048 launched: '/Users/tpeulen/miniconda3/envs/tttrlib/bin/python' (x86_64)
Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 14:38:56) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tttrlib
Process 51048 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x000000010345f2d2 libpython3.7m.dylib`PyTuple_New + 322
libpython3.7m.dylib`PyTuple_New:
->  0x10345f2d2 <+322>: movq   0x8(%rax), %rdx
    0x10345f2d6 <+326>: movq   %rdx, -0x10(%r14)
    0x10345f2da <+330>: movq   %rcx, (%rdx)
    0x10345f2dd <+333>: movq   %rcx, 0x8(%rax)
Target 0: (python) stopped.

Other people had similar problems (see UCL/STIR#291)

License clarification

Currently there are 3 different places that describe at least 3 different licenses for this repository.

  1. BSD 3-Clause License - from the file COPYING (and also in github)
  2. MPL 2.0 License - described in README.md
  3. MIT License - described here: https://tttrlib.readthedocs.io/en/latest/

Which license is the code under?

Fail to load large PTU file

Hello, I test three PTU files (>2GB, export from SP8), but fail to load at the first step:
data = tttrlib.TTTR(filename, 'PTU')
In the console, it showed that 'Process finished with exit code -1073741819 (0xC0000005)'
I think is not a python environment problem. Because everything works well, if I use smaller PTU files (<500MB). Also works for calculating the intensity images after that.

My environment is Win 10, python 3.7(Anaconda & Pycharm), tttrlib 0.0.19, with 128GB RAM

It would be great if you could give me any suggestions for this situation!

Kernel errors when trying to run CLSMImage

I installed tttrlib using the Anaconda prebuilt binary method (Windows 10, Python 3.7.7). I am working with .ptu files both produced from an SP8 and from custom Picoquant hardware, so the reading_routine is either "default" or "SP8". I am able to create the tttrlib object, which successfully pulls all the data from the .ptu file (event_type, routing_channel, macro_time, micro_time). I then try to create the CLSMImage object as follows:

ptu_reading_parameter = {
    "marker_frame_start": [4],
    "marker_line_start": 1,
    "marker_line_stop": 2,
    "marker_event_type": 1,
    "n_pixel_per_line": 512,
    "reading_routine": 'SP8',
    "tttr_data": data,
    }
clsm_image = tttrlib.CLSMImage(**ptu_reading_parameter)

Whenever I attempt this, the kernel restarts with a warning ("[SpyderKernelApp] WARNING | No such comm: 585492d2d6ad11eaaa82878b32ad1518"). The same issue happens if I do this using Jupyter, so it doesn't seem to be specifically a Spyder issue.

I am able to get a CLSMImage object if I try to assign it as follows:

data = tttrlib.TTTR(filename, 'PTU')
clsm_image = tttrlib.CLSMImage(tttr_data = data, reading_routine = 'SP8')

However, doing so pops up a warning ("WARNING: No TTTR data or frame marker provided"). Also, calling methods from that CLSMImage object either returns nothing (clsm_image.get_frames() returns an empty tuple), or returns a "ValueError: array is too big; arr.size * arr.dtype.itemsize is larger than the maximum possible size." error for other methods (.get_fluorescence_decay_image(data, 256) or .get_intensity_image()).

At first I thought it was just that these files are too big and I run out of memory. However, the error persists even if I'm using small .ptu files (5MB). I'm working on a laptop, but it has a decent amount of memory (16GB) and I've been able to work with much larger arrays than what these could possibly be creating. So, I'm at a loss as to what could be the underlying problem. I've tried searching all these errors, but I couldn't find anything useful.

Is there anything that you can see that I'm missing or doing wrong here?

tttr.intensity_trace() crashes kernel

Dear Thomas,

ffile = r'path\to\some\file.ptu trace = tttrlib.TTTR(ffile) trace.intensity_trace()
causes a kernel crash (python 3.7).

Giving an argument to intensity_trace resolves this issue.
trace.intensity_trace(1)
According to the docs, the time_window_length argument is a keyword argument, so I was not expecting this issue.

It is mostly a problem because you can crash the kernel when you don't expect it. I can send you the .ptu file that goes with this.

get_phasor_image is not working?

Hi tpeulen,

I am trying to create a phasor image but, unfortunately, the example file '../examples/imaging/imaging_phasor.py' is not available in 'auto_examples_python.zip'. Could you please update it?

I have found a former package 'fit2x' which also has been developed by you:
https://fit2x.readthedocs.io/en/latest/auto_examples/imaging/plot_imaging_phasor.html#sphx-glr-auto-examples-imaging-plot-imaging-phasor-py

Guessing that you have implemented the get_phasor_image into tttrlib, I have tried the code above and had no success.

phasor = CLSMimage.get_phasor_image(data, frequency=(float(header.loc['TTResult_SyncRate'][0]) * micro_res * 0.000000001), stack_frames = True)

The 4D-array has only zeros, no error message. SyncRate is in Hz, micro_res in ns.
Sidenote: get_mean_lifetime_image and get_intensity_image are working without any issue.
Data has been aquired with a Leica SP8 - PicoQuant system, files are in PTU format.
Thanks in advance for your help.

Travis fails to build the daily build on macOS

Travis on macOS fails to build the daily builds. The daily builds create a distributable app that is embedded in a dmg file. Unmounting the dmg file fails in the build process with the message

Fixing permissions...

Done fixing permissions.

Blessing started

Blessing finished

Unmounting disk image...

hdiutil: detach: timeout for DiskArbitration expired

hdiutil: detach: drive not detached

fileicon: ERROR: Target not found or neither file nor folder: '/Users/travis/build/Fluorescence-Tools/chisurf/dist/osx/ChiSurf-Installer.dmg'

python: can't open file 'upload_sftp': [Errno 2] No such file or directory

Others have similar problems (see dmgbuild/dmgbuild#13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.