Metadata-Version: 2.1
Name: pyptu
Version: 2023.1
Summary: Load PicoQuant PTU files.
Project-URL: Source, https://gitlab.inria.fr/jrye/pyptu
Project-URL: Documentation, https://jrye.gitlabpages.inria.fr/pyptu/
Author-email: Jan-Michael Rye <jan-michael.rye@inria.fr>
License: MIT License
        
        Copyright (c) 2022, Inria
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License-File: LICENSE.txt
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Requires-Dist: numpy
Requires-Dist: pandas
Description-Content-Type: text/markdown

---
title: README
author: Jan-Michael Rye
---

# Synopsis

Read [PicoQuand PTU files](https://github.com/PicoQuant/PicoQuant-Time-Tagged-File-Format-Demos). The code follows the same parsing logic as the [Python demo provided by PicoQuant](https://github.com/PicoQuant/PicoQuant-Time-Tagged-File-Format-Demos/blob/master/PTU/Python/Read_PTU.py) but is up to 40 times faster due to the use of vectorized operations using [Numpy](https://numpy.org/) arrays.

## Links

* [Source code](https://gitlab.inria.fr/jrye/pyptu)
* [Online documentation](https://jrye.gitlabpages.inria.fr/pyptu/)
* [PyPI package](https://pypi.org/project/pyptu)

# Usage

## Python API

The data in the file is parsed into the following objects which are set as attributes of the parser:

* `headers` - A dict mapping header fields to their values.
* `markers` - A Pandas DataFrame where each row is a record index with an index, a time tag and a marker.
* `overflows` - A Pandas DataFrame where each row is a record with a record index and an overflow values.
* `photons.csv` - A Pandas DataFrame where each row is a record with a record index, a channel, a time tag, a resolved time tag (using the global resolution value), and a dtime value.


~~~python
from pyptu import PTUParser

# A path to a PTU file.
path = /tmp/example.ptu

# Instantiate the parser.
parser = PTUParser(path)

# Load the data.
parser.load()

# The PTU header data.
headers = parser.headers

# The Pandas DataFrame of photon data.
photons = parser.photons

# The Pandas DataFrame of marker data.
markers = parser.markers

# The Pandas DataFrame of overflow values.
overflows = parser.overflows
~~~

## Command-Line

The package installs the `pyptu` command-line tool that can be used to convert the data in a PTU file to JSON and CSV files. It accepts the path to a PTU file and an output directory.

~~~sh
# Extract the PTU data to files in an output directory.
pyptu example.ptu output_directory
~~~

The output directory will contain the following files:

* `header.json` - A JSON file with the headers described above.
* `markers.csv` - A CSV file containing the `markers` DataFrame.
* `overflows.csv` - A CSV file containing the `overflows` DataFrame.
* `photons.csv` - A CSV containing the `photons` DataFrame.

### Help Message

~~~
$ pyptu -h
usage: pyptu [-h] path dir

Extract PTU data to standard files.

positional arguments:
  path        A path to a PTU file.
  dir         A path to an output directory.

options:
  -h, --help  show this help message and exit
~~~
