Skip to main content

Read and write PicoQuant PTU and related files

Project description

Ptufile is a Python library to

  1. read data and metadata from PicoQuant PTU and related files (PHU, PCK, PCO, PFS, PUS, PQRES, PQDAT, PQUNI, SPQR, and BIN), and

  2. write TCSPC histograms to T3 image mode PTU files.

PTU files contain time correlated single photon counting (TCSPC) measurement data and instrumentation parameters.

Author:

Christoph Gohlke

License:

BSD-3-Clause

Version:

2026.3.21

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

2026.3.21

  • Add bounds checking to encode_t3_image function.

  • Use format-dispatch in hot decode loops to allow compiler inlining.

  • Build wheels on Windows with LLVM (30% faster decoding than MSVC).

  • Drop support for Python 3.11.

2026.2.6

  • Fix code review issues.

2026.1.14

  • Improve code quality.

2025.12.12

  • Add PQUNI file type.

  • Add attrs properties and return with xarray DataSets.

  • Improve code quality.

2025.11.8

  • Fix reading files with negative TTResult_NumberOfRecords.

  • Remove cache argument from PtuFile.read_records (breaking).

  • Add cache_records property to PtuFile to control caching behavior.

  • Derive PqFileError from ValueError.

  • Factor out BinaryFile base class.

  • Build ABI3 wheels.

2025.9.9

  • Log error when decoding image with invalid line or frame masks.

2025.7.30

  • Add option to specify pixel time for decoding images.

  • Add functions to read and write PicoQuant BIN files.

  • Drop support for Python 3.10.

2025.5.10

  • Mark Cython extension free-threading compatible.

  • Support Python 3.14.

2025.2.20

Refer to the CHANGES file for older revisions.

Notes

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 due to the lack of test files or documentation: PT2 and PT3 files, decoding images from T2 and SPQR formats, bidirectional per frame, and deprecated image reconstruction.

Compatibility with PTU files written by non-PicoQuant software (for example, Leica LAS X or Abberior Imspector) is limited, as is decoding line, bidirectional, and sinusoidal scanning.

Other modules for reading or writing PicoQuant files are Read_PTU.py, readPTU, readPTU_FLIM, fastFLIM, PyPTU, PTU_Reader, PTU_Writer, FlimReader, tangy, tttrlib, picoquantio, ptuparser, phconvert, trattoria (wrapper of trattoria-core, tttr-toolbox), PAM, FLOPA, and napari-flim-phasor-plotter.

Examples

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

>>> pq = PqFile('tests/data/Settings.pfs')
>>> pq.type
<PqFileType.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/data/FLIM.ptu')
>>> ptu.type
<PqFileType.PTU: ...>
>>> ptu.record_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()
>>> decoded.dtype
dtype([('time', '<u8'), ('dtime', '<i2'), ('channel', 'i1'), ('marker', 'u1')])

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]], shape=(2, 3126), 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')
>>> ptu.active_channels
(0, 1)

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]]],
      shape=(1, 256, 256), dtype=uint16)

Alternatively, decode the first channel and integrate all histogram bins into 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]]]]], shape=(1, 256, 256, 1, 1), dtype=uint16)
Coordinates:
  * T        (T) float64... 0.05625
  * Y        (Y) float64... -0.0001304 ... 0.0001294
  * X        (X) float64... -0.0001304 ... 0.0001294
  * C        (C) uint8... 0
  * H        (H) float64... 0.0
Attributes...
    name:                     FLIM.ptu
...

Write the TCSPC histogram and metadata to a PicoHarpT3 image mode PTU file:

>>> imwrite(
...     '_test.ptu',
...     ptu[:],
...     ptu.global_resolution,
...     ptu.tcspc_resolution,
...     # optional metadata
...     pixel_time=ptu.pixel_time,
...     record_type=PtuRecordType.PicoHarpT3,
...     comment='Written by ptufile.py',
...     tags={'File_RawData_GUID': [ptu.guid]},
... )

Read back the TCSPC histogram from the file:

>>> tcspc_histogram = imread('_test.ptu')
>>> import numpy
>>> numpy.array_equal(tcspc_histogram, ptu[:])
True

Close the file handle:

>>> ptu.close()

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

python -m ptufile tests/data/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-2026.3.21.tar.gz (74.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ptufile-2026.3.21-cp314-cp314t-win_arm64.whl (176.1 kB view details)

Uploaded CPython 3.14tWindows ARM64

ptufile-2026.3.21-cp314-cp314t-win_amd64.whl (194.3 kB view details)

Uploaded CPython 3.14tWindows x86-64

ptufile-2026.3.21-cp314-cp314t-win32.whl (184.1 kB view details)

Uploaded CPython 3.14tWindows x86

ptufile-2026.3.21-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ptufile-2026.3.21-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

ptufile-2026.3.21-cp314-cp314t-macosx_11_0_arm64.whl (213.1 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

ptufile-2026.3.21-cp314-cp314t-macosx_10_15_x86_64.whl (221.1 kB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

ptufile-2026.3.21-cp312-abi3-win_arm64.whl (151.4 kB view details)

Uploaded CPython 3.12+Windows ARM64

ptufile-2026.3.21-cp312-abi3-win_amd64.whl (172.5 kB view details)

Uploaded CPython 3.12+Windows x86-64

ptufile-2026.3.21-cp312-abi3-win32.whl (158.4 kB view details)

Uploaded CPython 3.12+Windows x86

ptufile-2026.3.21-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ptufile-2026.3.21-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

ptufile-2026.3.21-cp312-abi3-macosx_11_0_arm64.whl (186.0 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

ptufile-2026.3.21-cp312-abi3-macosx_10_13_x86_64.whl (197.8 kB view details)

Uploaded CPython 3.12+macOS 10.13+ x86-64

File details

Details for the file ptufile-2026.3.21.tar.gz.

File metadata

  • Download URL: ptufile-2026.3.21.tar.gz
  • Upload date:
  • Size: 74.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.3.21.tar.gz
Algorithm Hash digest
SHA256 c9f3c935b0c1d90a0f29443486e66392222a8c3a70d923884b412deb05d86e50
MD5 f95a2ec88e7ac453eed7599753d8d923
BLAKE2b-256 4be4c575fd849bb9c5fcbe4c0036b9dd5dc83b3c47b3ea48a92fe0395183ce24

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-win_arm64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 8dd461620c4485cfa8381c6a8220cd0fe9dcf7a6d94c7e03a68f9e46da627dc8
MD5 5f06379258a79f561641a5103e8b9ff8
BLAKE2b-256 12a7bbda087a88bd5901fe64a93ba3d3d67b64755192c675de786c6c0120d22e

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 24e40bbd21adc316afe113cea1d68af9b61e645481a88f617f6252019b6048ca
MD5 55f6949c0c16fa76612519c360de95f0
BLAKE2b-256 ead62f08c198132ccd957577d75ff5f4cd56e2b217a0e403c272edd5608f8bfb

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-win32.whl.

File metadata

  • Download URL: ptufile-2026.3.21-cp314-cp314t-win32.whl
  • Upload date:
  • Size: 184.1 kB
  • Tags: CPython 3.14t, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 8e3b98102d95d42819559c94975ea2c54b852de223c38b03ecb88617129fca02
MD5 4aa420f868e42f04069f0f95a55fdd15
BLAKE2b-256 a20c902cea8aeab676cfb191cd3b28179a1717cb24364761e0fa8d15cff4e03a

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 147d87060fb6a20e1e6374996523bb8f71326d370a277f0c7425747bea8b30e6
MD5 d382b35e19dc07f275132086cbfdf6f2
BLAKE2b-256 7dcafda6eeec43b4c0cb72480458087c9e0649440d9027a80ed0814e33bec332

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d48ef7315f9f92a7abf3dcbf100e2e537affd9653cb42788fc5a1c7558feb17f
MD5 9706abf4d490a464a4dd0f6a404958b1
BLAKE2b-256 f0638d1564090ff710d6f3d607dcedf000d5f0fd8dbf3097c69e3b45f0391a22

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0526897055749214ef038ea2c72b5ff0a096fde8e348543d10033dad6047986d
MD5 72626937fd275f352b85e8866b70962d
BLAKE2b-256 951f9b75e4d3873e4d2f8a8e88232a36510edce5e6937f6f6ae202b63410fdf4

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp314-cp314t-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 bdc4c01736a1c058d2ad4a7b6addee45e7f8e24400ae1d1687e1cfbc78f3ee23
MD5 23ba10a0e2dda39a4a522a53253abf55
BLAKE2b-256 7aacdae55f4c15359661f90c97819a6b79301da9ef4459f002f00203f5c8d36c

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-win_arm64.whl.

File metadata

  • Download URL: ptufile-2026.3.21-cp312-abi3-win_arm64.whl
  • Upload date:
  • Size: 151.4 kB
  • Tags: CPython 3.12+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 8c19b43cc633301ca4bd88825ca161b0a9a636f0935209cee2160579655c1082
MD5 c2ea013b8a472064bf656cc256f86ef3
BLAKE2b-256 813625564d3cffa5329dee82936c3d2425c46be7c980313879eabb8d601c321a

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: ptufile-2026.3.21-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 172.5 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1aa1b8719d3dfcc8b6be595097e8366790c9f069be4b6c8eecce6dc861dd1dcd
MD5 bca809fba984566784817e4887e59506
BLAKE2b-256 7c4dd46885b267065f5d26042ad2225eb9868da39fde505f850755d758ba61ec

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-win32.whl.

File metadata

  • Download URL: ptufile-2026.3.21-cp312-abi3-win32.whl
  • Upload date:
  • Size: 158.4 kB
  • Tags: CPython 3.12+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 a55499c864ff06e35b420f9f65a0a62c01efc1f61081d8a8d1d877c63e339e5a
MD5 8bba7bb687a4f7dfe28cc1c351c0b782
BLAKE2b-256 cf7f352559fa5ab8f18acdbd157920408cbd527178cbcc37fab31a1cf30d7786

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf1ff0b1ca9915ad0d0ffdb15a7550bbcd8889a788002d7c55a4346a840a0f19
MD5 9ceb61de68ff3b8704a977cb39a78c30
BLAKE2b-256 8af8c69ae9a1e90d08d6635d855f7d2d3e04ba929a44c34fa2c05acd0c0dccef

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4014d82a9278e24b8a6ddd2e273504fbaac5b4f7859e527faadb3b091731ab24
MD5 e00845559b1c5b3201664159d70e81a5
BLAKE2b-256 ee2584cadb3e61fab8f52db9b52035603cc11ba8f63dcadfa831d9a5a00fdbec

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5b26f85cef8fc4c2a20ae8b7443c635f0be70b705af385826d1f0a628b2586c6
MD5 01e6349bfc2ff1fe2d3318b5564b55c7
BLAKE2b-256 ea146338b1a3697f31e14d45bc7b4d3ad51e0d635f26e1b41f99a1a61ac86f64

See more details on using hashes here.

File details

Details for the file ptufile-2026.3.21-cp312-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ptufile-2026.3.21-cp312-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 c404e573cb64a2be7c814e3611ce3a0b935cfc91bbcae9252587536b6475a0b4
MD5 311474ac1133fe0236031468888f5808
BLAKE2b-256 3a7090b53dd33bb144b7848c86cd2facccbec21f5882c3d291444c3e852dc32a

See more details on using hashes here.

Supported by

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