{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Convert pt3 files to Photon-HDF5\n", "\n", "\n", "# Prepare the data file\n", "\n", "\n", "Before starting, you need to get a data file to be converted to Photon-HDF5.\n", "You can use one of our example data files available\n", "[on figshare](https://figshare.com/articles/data_files_for_phconvert/5421565).\n", "\n", "Specify the input data file in the following cell:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "filename = 'data/DNA_FRET_0.5nM.pt3'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "try: \n", " with open(filename): pass\n", " print('Data file found, you can proceed.')\n", "except IOError:\n", " print('ATTENTION: Data file not found, please check the filename.\\n'\n", " ' (current value \"%s\")' % filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import numpy as np\n", "import phconvert as phc\n", "print('phconvert version: ' + phc.__version__)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d, meta = phc.loader.nsalex_pq(filename,\n", " donor = 2,\n", " acceptor = 1,\n", " alex_period_donor = (0, 2000),\n", " alex_period_acceptor = (2000, 3200),\n", " excitation_wavelengths = (470e-9, 635e-9),\n", " detection_wavelengths = (525e-9, 690e-9),\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "meta['hardware_name']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detectors = d['photon_data']['detectors']\n", "\n", "print(\"Detector Counts\")\n", "print(\"-------- --------\")\n", "for det, count in zip(*np.unique(detectors, return_counts=True)):\n", " print(\"%8d %8d\" % (det, count))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Remove the overflow counts" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nanotimes = d['photon_data']['nanotimes']\n", "detectors = d['photon_data']['detectors']\n", "timestamps = d['photon_data']['timestamps']\n", "\n", "not_overflow = d['photon_data']['nanotimes'] != 0\n", "\n", "detectors = detectors[not_overflow]\n", "timestamps = timestamps[not_overflow]\n", "nanotimes = nanotimes[not_overflow]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Detector Counts\")\n", "print(\"-------- --------\")\n", "for det, count in zip(*np.unique(detectors, return_counts=True)):\n", " print(\"%8d %8d\" % (det, count))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d['photon_data']['nanotimes'] = nanotimes\n", "d['photon_data']['detectors'] = detectors\n", "d['photon_data']['timestamps'] = timestamps" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "phc.plotter.alternation_hist(d)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Metadata" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "author = 'Biswajit'\n", "author_affiliation = 'Leiden University'\n", "description = 'A demonstrative pt3 data file.'\n", "sample_name = 'Copper Azurin in 1mM Ascorbate'\n", "dye_names = 'ATTO655'\n", "buffer_name = 'HEPES pH7 with 100 mM NaCl'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add meta data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d['description'] = description\n", "\n", "d['sample'] = dict(\n", " sample_name=sample_name,\n", " dye_names=dye_names,\n", " buffer_name=buffer_name,\n", " num_dyes = len(dye_names.split(',')))\n", "\n", "d['identity'] = dict(\n", " author=author,\n", " author_affiliation=author_affiliation)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Remove some empty groups that may cause errors on saving\n", "_ = meta.pop('dispcurve', None)\n", "_ = meta.pop('imghdr', None)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d['user'] = {'picoquant': meta}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Save to Photon-HDF5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "phc.hdf5.save_photon_hdf5(d, overwrite=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load Photon-HDF5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pprint import pprint" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "filename = d['_data_file'].filename" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "h5data = phc.hdf5.load_photon_hdf5(filename)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "phc.hdf5.dict_from_group(h5data.identity)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "phc.hdf5.dict_from_group(h5data.setup)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pprint(phc.hdf5.dict_from_group(h5data.photon_data))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "h5data._v_file.close()" ] } ], "metadata": { "anaconda-cloud": {}, "hide_input": false, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "nav_menu": { "height": "65px", "width": "252px" }, "number_sections": false, "sideBar": true, "skip_h1_title": false, "toc_cell": false, "toc_position": { "height": "591.867px", "left": "0px", "right": "1004px", "top": "111.133px", "width": "212px" }, "toc_section_display": "block", "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 1 }