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

  • Rename PqFileMagic to PqFileType (breaking).

  • Rename PqFile.magic to PqFile.type (breaking).

  • Add PQDAT and SPQR file types.

2025.2.12

  • Add options to specify file open modes to PqFile and PtuFile.read_records.

  • Add convenience properties to PqFile and PtuFile.

  • Cache records read from file.

2025.1.13

  • Fall back to file size if TTResult_NumberOfRecords is zero (#2).

2024.12.28

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.2.6.tar.gz (72.5 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.2.6-cp314-cp314t-win_arm64.whl (150.3 kB view details)

Uploaded CPython 3.14tWindows ARM64

ptufile-2026.2.6-cp314-cp314t-win_amd64.whl (195.4 kB view details)

Uploaded CPython 3.14tWindows x86-64

ptufile-2026.2.6-cp314-cp314t-win32.whl (159.9 kB view details)

Uploaded CPython 3.14tWindows x86

ptufile-2026.2.6-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

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

ptufile-2026.2.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.2.6-cp314-cp314t-macosx_11_0_arm64.whl (210.6 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

ptufile-2026.2.6-cp314-cp314t-macosx_10_15_x86_64.whl (217.5 kB view details)

Uploaded CPython 3.14tmacOS 10.15+ x86-64

ptufile-2026.2.6-cp311-abi3-win_arm64.whl (140.8 kB view details)

Uploaded CPython 3.11+Windows ARM64

ptufile-2026.2.6-cp311-abi3-win_amd64.whl (166.6 kB view details)

Uploaded CPython 3.11+Windows x86-64

ptufile-2026.2.6-cp311-abi3-win32.whl (133.1 kB view details)

Uploaded CPython 3.11+Windows x86

ptufile-2026.2.6-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

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

ptufile-2026.2.6-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

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

ptufile-2026.2.6-cp311-abi3-macosx_11_0_arm64.whl (187.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

ptufile-2026.2.6-cp311-abi3-macosx_10_9_x86_64.whl (190.3 kB view details)

Uploaded CPython 3.11+macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.2.6.tar.gz
Algorithm Hash digest
SHA256 9d0cc5c7a0eb5186638174f3c0a968223b76c63eba1d33503bbe9323d6e4afc4
MD5 9a48f4c06aacee15f14b3f09c4f43f1a
BLAKE2b-256 e215bf196c6aa2fdde49c7553ec74001b58252eca3132adb26544633aaedf231

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 1a1e01866f2e75b8105ec096191e4fbd840e8d16e31058e1cc8a58eba5687abf
MD5 7c288d0acc65fd3d41bacaada438403e
BLAKE2b-256 db0960dab1051fe1aef55134d3d5ae40fc3c5d79bc56535b11f120e5b3bd598e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ptufile-2026.2.6-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 1d812818f0a103d7c52d21b1bd6bf86b60a56ea278213349fd959050b48afbfd
MD5 a7c94bd6a47343e665c2317a94f5f66a
BLAKE2b-256 854961d9f09e7257ff962abbb3ea0d1af1246e6451811ebd5e14d755f59b07c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ptufile-2026.2.6-cp314-cp314t-win32.whl
  • Upload date:
  • Size: 159.9 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.2.6-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 dad986fef9a2e34d1b1af2b66c7cd4d306740434dfe859a4d1ac89eec2d203d0
MD5 8532be6cc4dd748520c82a4f96fdfbc3
BLAKE2b-256 539926f777c51a9c64328bb6bb928226437acfcad72df953c8a74634e1d38cf5

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.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.2.6-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d303432b79b16ac039fc96632c2d114155587d4b6e4e7c9eb926ddc43261507
MD5 bb3026394806103cc696daec33392976
BLAKE2b-256 f2b975831bb86ff359e55900f850d1d0987052c14e068d4d955e9e5e4cd97f18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9c339df57aa124152523c8aaf121062172b6493ba3925502da07e97e6e6302fa
MD5 b3bab0597c13814653451f21c7043fc1
BLAKE2b-256 c73e704dd77bbaf4a94e61318bfcce600445b00344df0b3805009aeffa1734f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6a8301b824713aa333abffd36c6826730b90ed7e1fde260e12f38b35759a2cb8
MD5 4f76ce4448367e9d6d157c042d46d45f
BLAKE2b-256 9ddfaae21bb6055e14d8b5ad25583855b49d84d7ae63655ff8cde73c912752e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp314-cp314t-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 21713259cee3958bb849f1471bd335276d7f14199d0497e7fca9e12781791360
MD5 26f0337b54bccde28bf6798eabbdcac1
BLAKE2b-256 5c35ea3a319ec3895a56ffa36ed4a1d2d7b3108ae583140496c692ee62137759

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-win_arm64.whl.

File metadata

  • Download URL: ptufile-2026.2.6-cp311-abi3-win_arm64.whl
  • Upload date:
  • Size: 140.8 kB
  • Tags: CPython 3.11+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cb1df0d8caff07623f608f602b3f46ba3ec049ae48d4e1460ae8e1247c5b3125
MD5 45a0675ca36b222917e97e9bbd94e6fc
BLAKE2b-256 281571b30ab68ba3f8ea1ec868de0ed681de282bb80c66f330e19a94c566de75

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 00f1b54f81cb2a59d36ccac5bbbd2c00dfa5b5b2c378af2a3ca9c142ebf3d787
MD5 5d48111dac8bfa2cfe98b4a87d22b918
BLAKE2b-256 81811edc4739a3a2a0be1ed552e5fe835004782d7f92eb67858a7ab2a5b158ae

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-win32.whl.

File metadata

  • Download URL: ptufile-2026.2.6-cp311-abi3-win32.whl
  • Upload date:
  • Size: 133.1 kB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 cbaf39e9c75500bcf04c6b8017368f1e63e8dd41eabdca6124cbca40cff06837
MD5 767eca0f59350a14295a13f11a6d796f
BLAKE2b-256 434cc0e03352de8ebe3545d700ed18357eb93e592d444027ccc2090f4eb8df71

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ff99d48e79c29082089d0535ca9294157bc3bfeac7864f89e0a5209542931869
MD5 405f04d77e583cecd238656dd9f4291f
BLAKE2b-256 5d36e212d47081e15e9fcbdef17e375c53f9c3c2245b73ca06c6ccfa9dc87681

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e9225ca5312284428bc3e1ecdcd25c65122f1d5d58bc65afeb871b90a8271364
MD5 27933761a690e1fee168963a5fcc65e5
BLAKE2b-256 a95eeea81d8af650c882740fb30a81e9ebd27c07ca3048b3d17c716c832eba2c

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40bdd5533fa76969cee7ce9a71984da7e351224e52ec567e48cbba25113c4500
MD5 bfbe45426f5c1bea8bfd80ab11314b0f
BLAKE2b-256 6ae4be6b430ab973012e41e7254f3ad8329bcc1321857eaf10629e8e2f9e09ec

See more details on using hashes here.

File details

Details for the file ptufile-2026.2.6-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ptufile-2026.2.6-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e849fbb329884d65ad710ae4547488c6b493adf9fa536e7c7269e27a8153891f
MD5 4d9d4bb3c7d8ecb9971b7548f4e08c0e
BLAKE2b-256 3a6a7d1b2bf99de99a7f2acaf78cb17d1cf7806485e229de65ec50c3c4cf6953

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