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.6.6

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.6.6

  • Remove memmap parameter from PtuFile.read_records (breaking).

  • Return copy of records from PtuFile.read_records by default (breaking).

  • Add options for memory-mapping and locked reading to BinaryFile.

  • Add option to memory-map PTU files.

  • Drop support for numpy 2.0 (SPEC0).

  • Support Python 3.15.

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.

All PicoQuant unified tagged formats use the same basic layout: a file header followed by typed tags and an optional data block. PTU is the main container for TTTR event streams, whereas related formats store histograms, instrument settings, analysis results, or other auxiliary data.

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.6.6.tar.gz (71.7 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.6.6-cp315-cp315t-win_arm64.whl (178.6 kB view details)

Uploaded CPython 3.15tWindows ARM64

ptufile-2026.6.6-cp315-cp315t-win_amd64.whl (196.7 kB view details)

Uploaded CPython 3.15tWindows x86-64

ptufile-2026.6.6-cp315-cp315t-win32.whl (186.5 kB view details)

Uploaded CPython 3.15tWindows x86

ptufile-2026.6.6-cp314-cp314t-win_arm64.whl (178.6 kB view details)

Uploaded CPython 3.14tWindows ARM64

ptufile-2026.6.6-cp314-cp314t-win_amd64.whl (196.8 kB view details)

Uploaded CPython 3.14tWindows x86-64

ptufile-2026.6.6-cp314-cp314t-win32.whl (186.6 kB view details)

Uploaded CPython 3.14tWindows x86

ptufile-2026.6.6-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.6.6-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.6.6-cp314-cp314t-macosx_11_0_arm64.whl (215.8 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

ptufile-2026.6.6-cp314-cp314t-macosx_10_15_x86_64.whl (223.8 kB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

ptufile-2026.6.6-cp312-abi3-win_arm64.whl (154.0 kB view details)

Uploaded CPython 3.12+Windows ARM64

ptufile-2026.6.6-cp312-abi3-win_amd64.whl (175.0 kB view details)

Uploaded CPython 3.12+Windows x86-64

ptufile-2026.6.6-cp312-abi3-win32.whl (160.6 kB view details)

Uploaded CPython 3.12+Windows x86

ptufile-2026.6.6-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.6.6-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.6.6-cp312-abi3-macosx_11_0_arm64.whl (188.5 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

ptufile-2026.6.6-cp312-abi3-macosx_10_13_x86_64.whl (199.3 kB view details)

Uploaded CPython 3.12+macOS 10.13+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.6.6.tar.gz
Algorithm Hash digest
SHA256 2dd440ed9f259cf8f6b4edcbfb7d0f97fe8a231882b9eb49579b264b11389cdd
MD5 90b39a05841b7a2b8bf63a4213738266
BLAKE2b-256 2d85ce8793ca67c45b23f70f8cd3813f9429f0c540bbb90208df43ccb7f4678e

See more details on using hashes here.

File details

Details for the file ptufile-2026.6.6-cp315-cp315t-win_arm64.whl.

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp315-cp315t-win_arm64.whl
Algorithm Hash digest
SHA256 e066165892578c84470ccc4edfca06fb64c2cdeb63d551ba46389d936a79f145
MD5 d2ded8688e34c7107cba9dbc9c44f1d4
BLAKE2b-256 4b39848ad4235ae9d7847651b88b2e00fb9ef56d4e4c640a1f2b8339c728fb15

See more details on using hashes here.

File details

Details for the file ptufile-2026.6.6-cp315-cp315t-win_amd64.whl.

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp315-cp315t-win_amd64.whl
Algorithm Hash digest
SHA256 c12cf59302d2c8267cb0f3c086890c74a21ca3cd566e67981de6dba37c2a1462
MD5 8c119f76da7c741053bf59928bd433f7
BLAKE2b-256 038934fc126087c2acad3fc7bb97a8a26afaecb614052d9b6fbf9113226ea499

See more details on using hashes here.

File details

Details for the file ptufile-2026.6.6-cp315-cp315t-win32.whl.

File metadata

  • Download URL: ptufile-2026.6.6-cp315-cp315t-win32.whl
  • Upload date:
  • Size: 186.5 kB
  • Tags: CPython 3.15t, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for ptufile-2026.6.6-cp315-cp315t-win32.whl
Algorithm Hash digest
SHA256 ea412f1da869ac6cfa9e334f467d8dab0c6025ee8575a2827254ac1d88fe849e
MD5 6537ddcc38b083f4abc2c9af8166c3db
BLAKE2b-256 74a36cf1feb2aefe25ae892009ce135bf9eeda352efdc6609462aec1efcbe7a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 24a6863c2c6837b18d3bcd9d941bdf8160c4b527ef86bc03f1855fa42928011b
MD5 96571c17ffa2c3e20d37183454720a34
BLAKE2b-256 0eeb1ae6b3a28c0853623be732f4decdd80ea20bd3243d3c66ed44146feb6b88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 baa70fc1233895fa63e7726a30b5654e96cb33186c9f0778b6af9f986f9a3508
MD5 6427f08c1c152d4fd11e98389daa6385
BLAKE2b-256 03c5d970545bb1e7ca69d6dcd12f6f704206861c05b80b500b18ebe5170f9205

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 372da6c35c09e2866f5e0f842f6b05d1f6df671bf6b0d0a55ddf14946dc48108
MD5 4fedb9ecfd27e6fac3a963c1b9fcb172
BLAKE2b-256 664156415b8c631876858f2bf89e99a3d6305ea7454b62c29891ab7a5549beb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cce9fb4d5d1a0e22f85b7d35f841a3c007e7a2ac76affb61176b2fcf37be88a6
MD5 1f8c8a7ec76e9bc7a738664f89c7cfac
BLAKE2b-256 6b9368f8439fe7d118460fbf051adbe79c31bbb75089e7a88ac116a40866da52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4411176e72fc0ab2a36fe032450e747a2cab57bff426ae6c9e7346ef49b67982
MD5 7e49c4965fa8bfa78b018f552fb8f30d
BLAKE2b-256 0fd349524e5f737e8a8a8339817e35c81bdd6d758439c4337210f1c0a73d9a76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bd99d1f846b504affb2731546474ea3bf7b9eef651565529939bc52db76a00a
MD5 51746d609078d25e20bb292714caf327
BLAKE2b-256 0cb3ac20a12a2be83e8ce412dbcf83b56d4fdbc92e95bb019582459af5ad8b44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d731447a20fb869b7bc45629c50dcf51477ac7abac90a2ff4f2106225ae973dd
MD5 c0e0826da1076d6a5a934684a66373cd
BLAKE2b-256 8ba0e6a5b3cf85b2e6c5e96ea3f9bfd677272905f4a3bed125aa3f74d93e2fef

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 3f25e7314ef1d7b069c4417950463b7389d589ed300187fdb0cabe0ef691a008
MD5 7032729f912eb32231dd61a33b17f084
BLAKE2b-256 2998ed4b0cdf0b24cc322de5635fd6c6b3db4b573a61ab214c0b9aeeff116ffa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f9bea9e938dca3945e23cbc541213e38d04a310be96108e69851dc3cb62e8489
MD5 aae61e2ee0957fe70895a954ade0a3a9
BLAKE2b-256 2bdde1bcf0e1311b77138166d6c77140cf090cc6fa70e60e2b465974ac3b2345

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 e18f12cf72f24e3dbacf38dc3a015e4721053c21d2ce9751336147f5020a9d9e
MD5 151ed889af71ccdeaedbc482e62ab539
BLAKE2b-256 ea9ac3481dcb947a8d749240b266905bc4f5ec62bc0a9b9135c7757aaa0d5f05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a46d93359626dc69f4d92d15f50dc724ca5aca97d8e3c6d4e3480a9ac77736ba
MD5 0e0d2f7f11f8e50202c1ac84be112902
BLAKE2b-256 53543ba47580c97135c7939b46984d9d7e65eed46499605fea52e9ae6c888ab3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e8c43dcd1d33ac2b101e21078716255e0ed788f945a574571a603050c1363761
MD5 44180be06bcbca39155d7ead1e147fe8
BLAKE2b-256 85936f85fb49a1b35aa9a7dca09e11215ab384e759be16423e19b98a94669499

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 54b15f86304ff7c7d3c2a8a02363809a2316b094772b5f082208946ad8787816
MD5 8db908acfb53d8e7a895304307e04c4c
BLAKE2b-256 b670a7d28a01756edd0214a31618086ef6b4cf4eb4b731955b747afcf49259c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.6.6-cp312-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 cc3f95c9ed648eae4620146595c3420d265a66e066f4ae5d54d0a1aaf113e384
MD5 1b594351b7627807e1372da4cf8a1d2b
BLAKE2b-256 590b44ebf8427bb38a44a68688d984175658003da242b00ea0ac3949f44e183d

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