.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tttr/plot_tttr_header.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_tttr_plot_tttr_header.py: =========== TTTR-Header =========== Introduction ============ TTTR files can contain additional meta-data. In tttrlib the meta data can be accessed and edited via the TTTRHeader class. Some TTTR file formats suchh as the PTU format provide the option for arbitrary meta data. In other TTTR formats have defined / fixed headers. Some of the information that can be found in a TTTR file is listed in `Header tags sheet `_. Note, the list of Header tags is by any means not comprehensive. If you have information on the used header tags. Please contact the authors of tttrlib to contribute to the list. Accessing header data ===================== Most TTTR container contain meta-data that can be accessed through ``tttrlib``. For that, a ``TTTR`` object provides a header attribute. The header attribute is of the type :class:`.Header`. .. GENERATED FROM PYTHON SOURCE LINES 25-33 .. code-block:: Python import tttrlib data = tttrlib.TTTR('../../tttr-data/bh/pq/bh_spc132.spc', 'SPC-130') # the header can be accesses by the method get_header or as an property header = data.header .. GENERATED FROM PYTHON SOURCE LINES 34-42 The most important attributes of the header are the :py:attr:`micro_time_resolution` and :py:attr:`macro_time_resolution`. Becker&Hickl Spc132 files files contain only a limited amount of information in the first record (32 bit). PicoQuant PTU and HT3 files provide more extensive information in their header that can be accessed via the :py:attr:`json` attribute of a header object. The :py:attr:`json` attribute of a header object is a JSON string. Setting the :py:attr:`json` attribute modifies the header / meta data of a TTTR object. .. GENERATED FROM PYTHON SOURCE LINES 42-46 .. code-block:: Python import json data = tttrlib.TTTR('./test/data/PQ/PTU/pq_ptu_hh_t3.ptu', 'PTU') .. GENERATED FROM PYTHON SOURCE LINES 47-48 the header can be accesses by the method get_header or as a property .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: Python header = data.header header_json = header.json header_dict = json.loads(header_json) print(header_dict) .. rst-class:: sphx-glr-script-out .. code-block:: none {'MeasDesc_ContainerType': -1, 'MeasDesc_RecordType': -1, 'tags': []} .. GENERATED FROM PYTHON SOURCE LINES 55-64 Time calibration data ===================== Essential for the analysis of TTTR data is the time calibration (time resolution) of the macro and the micro times in addition to the number of possible micro time channels. In many functions the micro and macro time calibration are transparently handeled, meaning there is no need to worry. The ``macro_time`` and the ``micro_time`` TTTR attributes correspond the to raw uncalibrated data. The macro and micro time resolution is accessed as follows. .. GENERATED FROM PYTHON SOURCE LINES 64-68 .. code-block:: Python macro_time_resolution = data.header.macro_time_resolution micro_time_resolution = data.header.micro_time_resolution .. GENERATED FROM PYTHON SOURCE LINES 69-71 The number of micro time channels can be accessed as displayed below. The header can be accesses by the method get_header or as an property. .. GENERATED FROM PYTHON SOURCE LINES 71-83 .. code-block:: Python header = data.get_header() macro_time_resolution = data.header.macro_time_resolution # macro_time_resolution = 12.5 ns micro_time_resolution = data.header.micro_time_resolution # micro_time_resolution = 4 ps data.header.number_of_micro_time_channels # will return 8129 data.get_number_of_micro_time_channels() # will return 3125 .. rst-class:: sphx-glr-script-out .. code-block:: none 1 .. GENERATED FROM PYTHON SOURCE LINES 84-95 Note, the effective number of micro time channels, i.e., the number of micro time channels can be smaller than the actual number of micro time channels. For instance at a micro time channel resolution of 4 ps and macro time resolution of 12.5 ns effectively only 3125 micro time channels will be filled with photons. Creating and writing TTTRHeader =============================== Each TTTR object has an attribute that is an instance of the TTTRHeader class. This instances makes the meta-data contained in the TTTR file accessible. TTTRHeader objects can also be created independently of TTTR object. .. GENERATED FROM PYTHON SOURCE LINES 95-99 .. code-block:: Python header = tttrlib.TTTRHeader() .. GENERATED FROM PYTHON SOURCE LINES 100-104 Modifying meta-data =================== The data containted in a TTTRHeader instance can be accesses as JSON string. The `JSON `_ string. .. GENERATED FROM PYTHON SOURCE LINES 104-107 .. code-block:: Python header = tttrlib.TTTRHeader() .. GENERATED FROM PYTHON SOURCE LINES 108-110 The JSON string must contain a `tags` list. The `tags` list is a list of dictionarys in which each dictionary corresponds to a meta-data field in the header. For instance, .. GENERATED FROM PYTHON SOURCE LINES 110-113 .. code-block:: Python print(header.json) # '{\n "tags": []\n}' .. rst-class:: sphx-glr-script-out .. code-block:: none { "MeasDesc_ContainerType": 0, "MeasDesc_RecordType": -1, "tags": [] } .. GENERATED FROM PYTHON SOURCE LINES 114-116 Different meta data fields are listed in `Header tags sheet `_. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.015 seconds) .. _sphx_glr_download_auto_examples_tttr_plot_tttr_header.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tttr_header.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tttr_header.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_