Skip to main content

Read PicoQuant PTU and related files

Project description

Ptufile is a Python library to read image and metadata from PicoQuant PTU and related files: PHU, PCK, PCO, PFS, PUS, and PQRES. PTU files contain time correlated single photon counting (TCSPC) measurement data and instrumentation parameters.

Author:

Christoph Gohlke

License:

BSD 3-Clause

Version:

2024.4.24

DOI:

10.5281/zenodo.10120021

Quickstart

Install the ptufile package and all dependencies from the Python Package Index:

python -m pip install -U ptufile[all]

See Examples for using the programming interface.

Source code and support are available on GitHub.

Requirements

This revision was tested with the following requirements and dependencies (other versions may work):

Revisions

2024.4.24

  • Build wheels with numpy 2.

2024.2.20

  • Change definition of PtuFile.frequency (breaking).

  • Add option to specify number of bins returned by decode_histogram.

  • Add option to return histograms of one period.

2024.2.15

  • Add PtuFile.scanner property.

  • Add numcodecs compatible PTU codec.

2024.2.8

  • Support sinusoidal scanning correction.

2024.2.2

  • Change positive dtime parameter from index to size (breaking).

  • Fix segfault with ImgHdr_TimePerPixel = 0.

  • Rename MultiHarp to Generic conforming with changes in PicoQuant reference.

2023.11.16

  • Fix empty line when first record is start marker.

2023.11.13

  • Change image histogram dimension order to TYXCH (breaking).

  • Change frame start to start of first line in frame (breaking).

  • Improve trimming of incomplete frames (breaking).

  • Remove trim_dtime option (breaking).

  • Fix selection handling in PtuFile.decode_image.

  • Add option to trim T, C, and H axes of image histograms.

  • Add option to decode histograms to memory-mapped or user-provided arrays.

  • Add __getitem__ interface to image histogram.

2023.11.1

  • Initial alpha release.

Notes

The Chan Zuckerberg Initiative financially supported the development of this library.

PicoQuant GmbH is a manufacturer of photonic components and instruments.

The PicoQuant unified file formats are documented at the PicoQuant-Time-Tagged-File-Format-Demos.

The following features are currently not implemented: PT2 and PT3 files, decoding images from T2 formats, bidirectional scanning, and deprecated image reconstruction.

Other Python modules for reading PicoQuant files are:

Examples

Read properties and tags from any type of PicoQuant unified tagged file:

>>> pq = PqFile('tests/Settings.pfs')
>>> pq.magic
<PqFileMagic.PFS: ...>
>>> pq.guid
UUID('86d428e2-cb0b-4964-996c-04456ba6be7b')
>>> pq.tags
{...'CreatorSW_Name': 'SymPhoTime 64', 'CreatorSW_Version': '2.1'...}
>>> pq.close()

Read metadata from a PicoQuant PTU FLIM file:

>>> ptu = PtuFile('tests/FLIM.ptu')
>>> ptu.magic
<PqFileMagic.PTU: ...>
>>> ptu.type
<PtuRecordType.PicoHarpT3: 66307>
>>> ptu.measurement_mode
<PtuMeasurementMode.T3: 3>
>>> ptu.measurement_submode
<PtuMeasurementSubMode.IMAGE: 3>

Decode TTTR records from the PTU file to numpy.recarray.

>>> decoded = ptu.decode_records()

Get global times of frame changes from markers:

>>> decoded['time'][(decoded['marker'] & ptu.frame_change_mask) > 0]
array([1571185680], dtype=uint64)

Decode TTTR records to overall delay-time histograms per channel:

>>> ptu.decode_histogram(dtype='uint8')
array([[ 5,  7,  7, ..., 10,  9,  2]], dtype=uint8)

Get information about the FLIM image histogram in the PTU file:

>>> ptu.shape
(1, 256, 256, 2, 3126)
>>> ptu.dims
('T', 'Y', 'X', 'C', 'H')
>>> ptu.coords
{'T': ..., 'Y': ..., 'X': ..., 'H': ...}
>>> ptu.dtype
dtype('uint16')

Decode parts of the image histogram to numpy.ndarray using slice notation. Slice step sizes define binning, -1 being used to integrate along axis:

>>> ptu[:, ..., 0, ::-1]
array([[[103, ..., 38],
        ...
        [ 47, ..., 30]]], dtype=uint16)

Alternatively, decode the first channel and integrate all histogram bins to a xarray.DataArray, keeping reduced axes:

>>> ptu.decode_image(channel=0, dtime=-1, asxarray=True)
<xarray.DataArray (T: 1, Y: 256, X: 256, C: 1, H: 1)> ...
array([[[[[103]],
           ...
         [[ 30]]]]], dtype=uint16)
Coordinates:
  * T        (T) float64... 0.05625
  * Y        (Y) float64... -0.0001304 ... 0.0001294
  * X        (X) float64... -0.0001304 ... 0.0001294
  * H        (H) float64... 0.0
Dimensions without coordinates: C
Attributes...
    frequency:      19999200.0
...
>>> ptu.close()

Preview the image and metadata in a PTU file from the console:

python -m ptufile tests/FLIM.ptu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ptufile-2024.4.24.tar.gz (45.2 kB view hashes)

Uploaded Source

Built Distributions

ptufile-2024.4.24-cp312-cp312-win_arm64.whl (147.5 kB view hashes)

Uploaded CPython 3.12 Windows ARM64

ptufile-2024.4.24-cp312-cp312-win_amd64.whl (177.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

ptufile-2024.4.24-cp312-cp312-win32.whl (147.4 kB view hashes)

Uploaded CPython 3.12 Windows x86

ptufile-2024.4.24-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ptufile-2024.4.24-cp312-cp312-macosx_11_0_arm64.whl (195.1 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ptufile-2024.4.24-cp312-cp312-macosx_10_9_x86_64.whl (211.2 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

ptufile-2024.4.24-cp311-cp311-win_arm64.whl (146.3 kB view hashes)

Uploaded CPython 3.11 Windows ARM64

ptufile-2024.4.24-cp311-cp311-win_amd64.whl (174.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

ptufile-2024.4.24-cp311-cp311-win32.whl (143.9 kB view hashes)

Uploaded CPython 3.11 Windows x86

ptufile-2024.4.24-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ptufile-2024.4.24-cp311-cp311-macosx_11_0_arm64.whl (190.4 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ptufile-2024.4.24-cp311-cp311-macosx_10_9_x86_64.whl (208.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ptufile-2024.4.24-cp310-cp310-win_amd64.whl (174.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

ptufile-2024.4.24-cp310-cp310-win32.whl (144.8 kB view hashes)

Uploaded CPython 3.10 Windows x86

ptufile-2024.4.24-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ptufile-2024.4.24-cp310-cp310-macosx_11_0_arm64.whl (192.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ptufile-2024.4.24-cp310-cp310-macosx_10_9_x86_64.whl (207.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ptufile-2024.4.24-cp39-cp39-win_amd64.whl (174.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

ptufile-2024.4.24-cp39-cp39-win32.whl (145.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

ptufile-2024.4.24-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ptufile-2024.4.24-cp39-cp39-macosx_11_0_arm64.whl (193.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ptufile-2024.4.24-cp39-cp39-macosx_10_9_x86_64.whl (207.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page