{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Convert t3r files to Photon-HDF5\n", "\n", "# Prepare the data file\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", "\n", "Specify the input data file in the following cell:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "filename = 'data/Point_11_s23d9A15_70%25sucrose_55%25.t3r'" ] }, { "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_t3r(filename,\n", " donor = 1,\n", " acceptor = 0,\n", " alex_period_donor = (3000, 4000),\n", " alex_period_acceptor = (0, 2000),\n", " excitation_wavelengths = (470e-9, 635e-9),\n", " detection_wavelengths = (525e-9, 690e-9),\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "phc.plotter.alternation_hist(d)" ] }, { "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": [ "## Meta data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "author = 'Biswajit'\n", "author_affiliation = 'Leiden University'\n", "description = 'A demonstrative pt3 data readin.'\n", "sample_name = 'Fluorescence enhancement experiment with a gold nanorod'\n", "dye_names = 'Alexa 647'\n", "buffer_name = '70% sucrose solution'" ] }, { "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": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# del d" ] }, { "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 [default]", "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.5.2" }, "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": { "colors": { "hover_highlight": "#DAA520", "navigate_num": "#000000", "navigate_text": "#333333", "running_highlight": "#FF0000", "selected_highlight": "#FFD700", "sidebar_border": "#EEEEEE", "wrapper_background": "#FFFFFF" }, "moveMenuLeft": true, "nav_menu": { "height": "47px", "width": "252px" }, "navigate_menu": true, "number_sections": true, "sideBar": true, "threshold": 4, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false, "widenNotebook": false } }, "nbformat": 4, "nbformat_minor": 1 }