{"cells": [{"cell_type": "raw", "id": "3ef6e4ee", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["Accessing the Results of an Optimization\n", "########################################\n", "\n", ".. contents::\n", "\n", "\n", "\n", "We start with some basic, universal loading and setup.\n", "This is the same in all how-tos and tutorials, so that there is a unified set of data to work with.\n", "\n", ".. note::\n", "\n", " Download the example file here: `HP3_TE300_SPC630.hdf5 `_\n", "\n", "First let's import the necessary modules and process the data with FRETBursts.\n", "This code is essential the same as that found in the :doc:`tutorial ` ."]}, {"cell_type": "code", "execution_count": 1, "id": "bec4fd47", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": [" - Optimized (cython) burst search loaded.\n", " - Optimized (cython) photon counting loaded.\n", "--------------------------------------------------------------\n", " You are running FRETBursts (version 0.7.1).\n", "\n", " If you use this software please cite the following paper:\n", "\n", " FRETBursts: An Open Source Toolkit for Analysis of Freely-Diffusing Single-Molecule FRET\n", " Ingargiola et al. (2016). http://dx.doi.org/10.1371/journal.pone.0160716 \n", "\n", "--------------------------------------------------------------\n", "# Total photons (after ALEX selection): 11,414,157\n", "# D photons in D+A excitation periods: 5,208,392\n", "# A photons in D+A excitation periods: 6,205,765\n", "# D+A photons in D excitation period: 6,611,308\n", "# D+A photons in A excitation period: 4,802,849\n", "\n", " - Calculating BG rates ... get bg th arrays\n", "Channel 0\n", "[DONE]\n", " - Performing burst search (verbose=False) ...[DONE]\n", " - Calculating burst periods ...[DONE]\n", " - Counting D and A ph and calculating FRET ... \n", " - Applying background correction.\n", " [DONE Counting D/A]\n"]}], "source": ["import numpy as np\n", "from matplotlib import pyplot as plt\n", "\n", "import fretbursts as frb\n", "import burstH2MM as bhm\n", "\n", "filename = 'HP3_TE300_SPC630.hdf5'\n", "# load the data into the data object frbdata\n", "frbdata = frb.loader.photon_hdf5(filename)\n", "# plot the alternation histogram\n", "# frb.bpl.plot_alternation_hist(frbdata) # commented so plot will not be displayed\n", "# if the alternation period is correct, apply data\n", "frb.loader.alex_apply_period(frbdata)\n", "# calcualte the background rate\n", "frbdata.calc_bg(frb.bg.exp_fit, F_bg=1.7)\n", "# plot bg parameters, to verify quality\n", "# frb.dplot(frbdata, frb.hist_bg) # commented so plot will not be displayed\n", "# now perform burst search\n", "frbdata.burst_search(m=10, F=6)\n", "# make sure to set the appropriate thresholds of ALL size\n", "# parameters to the particulars of your experiment\n", "frbdata_sel = frbdata.select_bursts(frb.select_bursts.size, th1=50)\n", "# frb.alex_jointplot(frbdata_sel) # commented so plot will not be displayed"]}, {"cell_type": "raw", "id": "994f9ec9", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["Order of object creation\n", "************************\n", "\n", "\n", "\n", "\n", "Now that we're done with FRETBursts to select our data, we can segment the photons into bursts, which will be stored in a :class:`BurstData ` object:"]}, {"cell_type": "code", "execution_count": 2, "id": "924b5c57", "metadata": {}, "outputs": [], "source": ["bdata = bhm.BurstData(frbdata_sel)"]}, {"cell_type": "raw", "id": "710bb05b", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": [".. _acbeg:\n", "\n", "\n", "\n", ":meth:`H2MM_list.calc_models() ` is designed to streamline this process, which optimizes models until the ideal model is found (it actually calculates one more than necessary because it must see that there is at least one model with too many models).\n", "\n", "So before :meth:`H2MM_list.calc_models() ` is called on an :class:`H2MM_list ` object, it has no optimizations associated with it. \n", ""]}, {"cell_type": "code", "execution_count": 3, "id": "089936c2", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["No optimizations run, must run calc_models or optimize for H2MM_result objects to exist\n"]}], "source": ["try:\n", " bdata.models[0]\n", "except Exception as e:\n", " print(e)\n", "else:\n", " print('bdata has models')"]}, {"cell_type": "raw", "id": "c1662297", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["After :meth:`H2MM_list.calc_models() ` is called, then several different state models are stored in the :attr:`H2MM_list.opts ` attribute, but are also accessible by indexing :class:`H2MM_list ` ."]}, {"cell_type": "code", "execution_count": 4, "id": "830fecbb", "metadata": {}, "outputs": [{"data": {"text/plain": ["The model converged after 1 iterations"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/plain": ["The model converged after 36 iterations"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/plain": ["The model converged after 121 iterations"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/plain": ["The model converged after 404 iterations"]}, "metadata": {}, "output_type": "display_data"}, {"data": {"text/html": ["\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
 E_rawS_rawto_state_0
state_00.1613290.68717220000000.000000
\n"], "text/plain": [""]}, "execution_count": 4, "metadata": {}, "output_type": "execute_result"}], "source": ["# calculate models\n", "bdata.models.calc_models()\n", "\n", "bdata.models[0]"]}, {"cell_type": "raw", "id": "6009104d", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["The elements within :class:`H2MM_list ` are, as you see above, :class:`H2MM_result ` objects. \n", "These serve to organize both the optimized models, and various results we will discuss later in this section. \n", "But the first thing to examine are the statistical discriminators. \n", "These take the loglikelihood of the model given the data, and add penalties for the number of states. \n", "There are 2 primary discriminators:\n", "\n", "1. BIC: the Bayes Information Criterion\n", "\n", "Based on the likelihood of the model over all possible state paths through the data, usually found to always improve with more states, and therefore less useful\n", "\n", "2. ICL: the Integrated Complete Likelihood\n", "\n", "Based on the likelihood of the most likely state path through the data. \n", "Usually is minimized for the ideal state-model, and therefore the preferred statistical discriminator to use.\n", "\n", "In both cases, the smaller the better. \n", "Since these are computed for each optimized model, each :class:`H2MM_result ` object (index of :class:`H2MM_list ` ), has an attribute to get this value. \n", "However, since these values are generally only useful in relation to other models optimized against the same data, the :class:`H2MM_result ` object has its own attribute to return an array with the values of all the optimized models:\n", "\n", "**BIC**: :attr:`H2MM_list.BIC ` : an array for every model in the list"]}, {"cell_type": "code", "execution_count": 5, "id": "5eab6a27", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([323390.78889963, 274041.04580956, 266584.73431315, 265800.67189548])"]}, "execution_count": 5, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models.BIC"]}, {"cell_type": "raw", "id": "bb9760a2", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["and the value of for an individual model :attr:`H2MM_result.bic ` "]}, {"cell_type": "code", "execution_count": 6, "id": "a1ec93b0", "metadata": {}, "outputs": [{"data": {"text/plain": ["323390.7888996289"]}, "execution_count": 6, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[0].bic"]}, {"cell_type": "raw", "id": "aeb4dc56", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["**ICL**: :attr:`H2MM_list.ICL ` : an array for every model in the list"]}, {"cell_type": "code", "execution_count": 7, "id": "d8ef4670", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([323390.78889956, 275340.11281888, 269885.74586401, 271100.67269904])"]}, "execution_count": 7, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models.ICL"]}, {"cell_type": "raw", "id": "2df0f54c", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["and the value of for an individual model :attr:`H2MM_result.icl ` "]}, {"cell_type": "code", "execution_count": 8, "id": "306cbce5", "metadata": {}, "outputs": [{"data": {"text/plain": ["323390.78889956296"]}, "execution_count": 8, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[0].icl"]}, {"cell_type": "raw", "id": "bd534886", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["burstH2MM has an easy, graphical way to compare these: "]}, {"cell_type": "code", "execution_count": 9, "id": "6c8f97de", "metadata": {}, "outputs": [{"data": {"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAEGCAYAAABYV4NmAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAYS0lEQVR4nO3df6zf1X3f8eeLH+LHEgiQ247agJF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wN8EjgV5t112ZuxzIfrcjJwU5LDGfyyvb2q7knyWzDvrsnejGU+XJORel8TPypGktSFj8gkSV0YMJKkLgwYSVIXBowkqQsDRpLUhQEjzaEklyc59kCdJx1MXKYszaH2zurxqvrxgThPOph4ByPNkiR/L8mftw9F/H6SdcAvAV9L8rV2zvVJJoa/eyTJb484b3mSB5I8nORL7fPLSPJfkjzWvs/js3MzUmnAOxhpliT5NWBlVf1me3088F2G7kySnFhVk+2d418Ffruqvjd8B9M+5+pO4P1V9TdJfgc4CvjvwAPAP6qqSvKm9vlZ0pzwDkaaPY8C70tydZJfrqoXRpzzkSQPA98BzgbOGnHOslb+l+0jZdYApwEvAn8LfCHJhxh83Ic0Z/wsMmmWVNUPkpzL4POe/nOSvxg+nuR04D8A/7iqdiS5ETh6RFNh8L0kv/5zBwYftng+gw80/HfAew/sKKS95x2MNEuS/BLwclX9CfBZBl9Z/RKDr0cGOA74G+CFJL8IvH+o+vB53wLek+SM1u6xSf5Bm4c5vn1k/OXAOX1HJM3MOxhp9rwN+IMkPwP+DrgUeDdwb5LnquqfJ/kOsBn4K+Avh+qun3bevwG+mOSodvz3GITQXUmOZnCX8/FZGZW0G07yS5K68BGZJKkLA0aS1IUBI0nqwoCRJHVhwEiSujBgJEldGDCSpC7+PyScRao7FqNcAAAAAElFTkSuQmCC\n", "text/plain": ["
"]}, "metadata": {"needs_background": "light"}, "output_type": "display_data"}], "source": ["# give ICL_plot a H2MM_list object\n", "bhm.ICL_plot(bdata.models);"]}, {"cell_type": "raw", "id": "f7f2b6a3", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["Note that we do not index ``bdata.models`` because this is comparing the different state models, not looking at a single model.\n", "\n", "So now that we know how to select the model, what actually composes a model, which is stored in a :class:`H2MM_result ` object?\n", "\n", "There are three key components:\n", "\n", "1. Initial probability matrix (the .prior matrix)\n", " - The likelihood of a burst beginning in a given state\n", "\n", "2. Observation probability matrix (the .obs matrix)\n", " - Contains probability a given state will emit a photon in a given index, from this the E and S values can be calculated.\n", "\n", "3. Transition probability matrix (the .trans matrix)\n", " - The rate at which each state transitions to the others. This indicates the rate of transitions, characterizing the thermodynamic stability of each state (assuming you are using a model that has an appropriate number of states, over and underfit models will obviously have transition rates not reflective of the actual dynamics).\n", "\n", ".. note::\n", "\n", " The attribute names for the statistical discriminators from :class:`H2MM_list ` objects use capital letters, while :class:`H2MM_result ` objects are use lowercase letters.\n", "\n", "The initial probability matrix does not have a clear physical meaning, but the observation probability and transition probability matrices contain very valuable information. \n", "burstH2MM automatically converts the values in these from the abstract units of the core algorithm into more human-friendly units (E/S values and transition rates in seconds).\n", "\n", "E and S can be accessed with the attributes :attr:`H2MM_result.E ` :"]}, {"cell_type": "code", "execution_count": 10, "id": "32efd792", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([0.66031034, 0.15955158, 0.06730048])"]}, "execution_count": 10, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[2].E"]}, {"cell_type": "raw", "id": "1ac55fd9", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["and :attr:`H2MM_result.S ` "]}, {"cell_type": "code", "execution_count": 11, "id": "f7743584", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([0.43073408, 0.55348988, 0.9708039 ])"]}, "execution_count": 11, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[2].S"]}, {"cell_type": "raw", "id": "73894d92", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["The above values are the raw values, if you want to have them corrected for leakage, direct excitation, and the beta and gamma values, you can access them by adding \" ``_corr`` \" to the attribute name, to get :attr:`H2MM_result.E_corr ` and :attr:`H2MM_result.S_corr ` .\n", "\n", "The transition rates are accessed through the H2MM_result.trans attributes."]}, {"cell_type": "code", "execution_count": 12, "id": "016975cb", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([[1.99994147e+07, 5.31727338e+02, 5.35450105e+01],\n", " [2.05278771e+02, 1.99996914e+07, 1.03279278e+02],\n", " [7.90911127e+00, 1.16271189e+02, 1.99998758e+07]])"]}, "execution_count": 12, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[2].trans"]}, {"cell_type": "raw", "id": "538caabd", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["These are in s :sup:`-1`\\ and the organization is \\[from state, to state\\]. \n", "Notice that the diagonal is all very large values, this is because the diagonal represents the probability that the system remains in the same state from one time step to the next, as the time steps are in the clock rate of the acquisiation (typically 20 mHz, meaning 50 ns from one time step to the next) this is a very large number.\n", "\n", "Now H\\ :sup:`2`\\ MM also contains the *Viterbi* algorithm, which takes the data and optimized model, and finds the most likely state of each photon. \n", "burstH2MM continues to perform analysis on this state path to produce a number of usefull parameters to help understand the data.\n", "\n", "Table of Attributes\n", "*******************\n", "\n", "\n", "\n", "Below is a list and description of the different possible parameters and their descriptions.\n", "\n", "\n", "\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| Attribute | Description | Type |\n", "+===============================================================================================+=======================+==================+\n", "| \\ :attr:`H2MM_result.nanohist ` | Number of photons in | state stream |\n", "| | each state and TCSPC | nanotime array |\n", "| | bin | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.burst_state_counts ` | Counts per dwell of | state burst |\n", "| | states present within | array |\n", "| | bursts | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.burst_type ` | Bininary code | burst array |\n", "| | specifying the state | |\n", "| | present within each | |\n", "| | burst | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.trans_locs ` | The location of | burst list |\n", "| | transitions with | |\n", "| | bursts | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.burst_dwell_num ` | Duration of each | dwell array |\n", "| | dwell (in ms) | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_state ` | The state of each | dwell array |\n", "| | dwell | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_pos ` | Numerical indicator | dwell array |\n", "| | of location within | |\n", "| | the burst of each | |\n", "| | dwell array | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_ph_counts ` | Number of photons in | stream dwell |\n", "| | each stream and dwell | array |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_ph_counts_bg ` | Background corrected | stream dwell |\n", "| | number of photons in | array |\n", "| | each stream and dwell | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_E ` | Raw FRET efficiency | dwell array |\n", "| | (E\\ :sup:`raw`\\ ) of | |\n", "| | each dwell | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_E_corr ` | Fully corrected FRET | dwell array |\n", "| | efficiency of each | |\n", "| | dwell (E) | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_S ` | Raw stoichiometry | dwell array |\n", "| | (S\\ :sup:`raw`\\ ) of | |\n", "| | each dwell | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_S_corr ` | Fully corrected | dwell array |\n", "| | stoichiometry of each | |\n", "| | dwell (S) | |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "| \\ :attr:`H2MM_result.dwell_nano_mean ` | Mean nanotime of each | stream dwell |\n", "| | stream in each dwell | array |\n", "+-----------------------------------------------------------------------------------------------+-----------------------+------------------+\n", "\n", "\n", "Meaning of \u201ctype\u201d explained in next section.\n", "\n", "Understanding dwell array organization\n", "**************************************\n", "\n", "\n", "\n", "Data in dwell attributes (those that begin with \u201cdwell\u201d) are organized into numpy arrays. \n", "As diagrammed in the figure below, the dwells are placed in the same order that they in the data. \n", "This means the consecutive dwells indicate a transition from one state to another. \n", "However, when one bursts ends, it is generally unreasonable to consider the dwell in the next burst to be considered a transition. \n", "Hence, special consideration needs to be given for bursts at the start and end of bursts, as well as for bursts which contain only a single state, which is still counted as a dwell. \n", "Since these are still included in the dwell arrays, the position of a burst within a dwell is recorded in the :attr:`H2MM_result.dwell_pos ` paremeter.\n", "\n", ".. figure:: images/dwellorg.png\n", " :alt: dwell_org\n", "\n", "\n", "\n", "As seen, dwells in the middle of burst are marked with a ``0`` in :attr:`H2MM_result.dwell_pos ` , end with a ``1`` , beginning with a ``2`` and bursts that span the whole dwell are marked with a ``3`` . \n", "The size of :attr:`H2MM_result.dwell_pos ` and other dwell array parameters match, and therefore :attr:`H2MM_result.dwell_pos ` can be used to make masks to select only dwells in one of the possible positions.\n", "\n", "For instance if you want to get the E values of only dwells that are in the middle of bursts, excluding beginning, ending and whole burst dwells, you could execute the following:"]}, {"cell_type": "code", "execution_count": 13, "id": "39ca8202", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["Middle dwells:\n"]}, {"data": {"text/plain": ["array([0.8 , 0.21875 , 0.55555556, 0.28571429, 0.58823529,\n", " 0.27272727, 0.11111111, 0.85714286, 0.21428571, 0.08108108,\n", " 0.66666667, 0.08571429, 0.58333333, 0.14285714, 0. ,\n", " 0. , 0.2 , 0.70588235, 0. , 0.74193548,\n", " 0.08 , 0.06 , 0.57142857, 0.04651163, 0.63636364,\n", " 0.775 , 0.85714286, 0.07692308, 0.57142857, 0.17021277,\n", " 0.54166667, 1. , 0.64285714, 0.03846154, 0.7 ,\n", " 0.10526316, 0. , 0. , 0.23076923, 0.08108108,\n", " 0.18181818, 0.5 , 0.83333333, 0.70454545, 0.2 ,\n", " 0.07843137, 0.13333333, 0.71428571, 0.06666667, 0.77777778,\n", " 0.875 , 0.14285714, 0. , 0.76470588, 0. ,\n", " 0.9 , 0.56 , 0.72 , 0.08108108, 0.35714286,\n", " 0.6 , 0.65909091, 0.13333333, 0.8 , 0. ,\n", " 0.55555556, 0.16853933, 0.75 , 0.24637681, 0.8 ,\n", " 0.15 , 0.05660377, 0.6875 , 0.8125 , nan,\n", " 0.54166667, 0.07692308, 0. , 0.86666667, 0.14285714,\n", " 0.075 , 0.10447761, 0.10606061, 0.17647059, 0.85714286,\n", " 0.12 , 0.6 , 0.11111111, 0.71052632, 0.14634146,\n", " 0.62857143, 0.06451613, 0.12121212, 0.16666667, 0.61111111,\n", " 0.17647059, 0.71428571, 0.17647059, 0.24637681, 0.7 ,\n", " 0. , 0.5625 , 0.13636364, 0.22222222, 0.2 ,\n", " 0.75 , 0. , 0.07692308, 0.69230769, 0. ,\n", " 0.58333333, 0.5 , 0.16470588, 0.83333333, 0.128 ,\n", " 0.10714286, 0.73076923, 0.08474576, 1. , 0.76190476,\n", " 0.07142857, 0.88888889, 0.6 , 0. , 0.11111111,\n", " 0.73076923, 0.22727273, 0.69230769, 0. , 0.25490196,\n", " 0.67741935, 0.77777778, 0.18518519, 0. , 0.44444444,\n", " 0.5862069 , 0.30612245, 0.04761905, 0.8 , 0.26785714,\n", " 1. , 0.28125 , 0.66666667, 0.75 , 0.16666667,\n", " 0.78571429, 0.08 , 0.33333333, 0.1038961 , 0.11428571,\n", " 0.76666667, 0.78431373, 0.56666667, 0. , 0.6 ,\n", " 0.51111111, 0.15 , 0.03846154, 1. , 0.08108108,\n", " 0.53846154, 0.22352941, 0.18181818, 0.8 , 0.05555556,\n", " 0.22222222, 0. , 0.06666667, 0.12121212, 0.11764706,\n", " 0.125 , 0.57142857, 0. , 0.73333333, 0.02564103,\n", " 0.75 , 0.78947368, 0.20588235, 0.875 , 0.27272727,\n", " 0.73333333, 0.16 , 0.04347826, 0.19587629, 0.06 ,\n", " 0.81818182, 0.21052632, 0.85714286, 0.03921569, 0.33333333,\n", " 0.33333333, 0.05769231, 0. , 0.72727273, 0.11111111,\n", " 0.78947368, 0.75 , 0.06666667, 0.375 , nan,\n", " 0.02816901, 0.15909091, 0.57894737, 0. , 0.14035088,\n", " 0.51162791, 0.83333333, 0.11111111, 0.6 , 0.07142857,\n", " 0. , 0.51351351, 0.33333333, 0.08695652, 0.78571429,\n", " 0.66666667, 0.69230769, 0.13513514, 0.09090909, 0. ,\n", " 0.5 , 0.28 , 0.13636364, 0.16666667, 0.05263158,\n", " 0.02631579, 0.61764706, 0.6 , 0.57894737, 0. ,\n", " 1. , 0.8 , 0.82608696, 0.13636364, 0.71428571,\n", " 0.11111111, 0.44444444, 0. , 0.66666667, 0.13513514,\n", " 0.12727273, 0.25925926, 0.1 , 0.875 , 0.875 ,\n", " 0.16666667, 0.15555556, 0.66666667, 0.125 , 0. ,\n", " 0. , 0.8 , 0.05128205, 0. , 0.0625 ,\n", " 0.06896552, 0.77777778, 0.73076923, 0.05555556])"]}, "execution_count": 13, "metadata": {}, "output_type": "execute_result"}], "source": ["mid_dwell_mask = bdata.models[2].dwell_pos == 0\n", "mid_dwell_E = bdata.models[2].dwell_E[mid_dwell_mask]\n", "print(\"Middle dwells:\")\n", "mid_dwell_E"]}, {"cell_type": "raw", "id": "fa9e3688", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["Now some of the dwell parameters have extra dimensions, like :attr:`H2MM_result.dwell_nano_mean ` , where the mean nanotime is calculate per stream in addition to per dwell. \n", "Therefore, it is a 2D array, with the last dimension marking the dwell.\n", "\n", "Now, to get an accurate :attr:`H2MM_result.dwell_nano_mean ` , we first need to set the IRF thresholds:"]}, {"cell_type": "code", "execution_count": 14, "id": "f3c8dde7", "metadata": {}, "outputs": [], "source": ["bdata.irf_thresh = np.array([2355, 2305, 220])"]}, {"cell_type": "raw", "id": "fe9fcb49", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["So, with the :attr:`BurstData.irf_thresh ` set, to get the mean nanotimes of the mid-burst dwells, we would execute the following:"]}, {"cell_type": "code", "execution_count": 15, "id": "761586cf", "metadata": {"scrolled": false}, "outputs": [{"data": {"text/plain": ["array([[ 5.28919324, 3.02778298, 3.07976408, 4.42869837, 1.83839165,\n", " 2.11497928, 2.99796568, nan, 2.2720322 , 3.53096402,\n", " 3.91131565, 5.02676288, 0.80131888, 4.31401096, 2.71656024,\n", " 4.09526792, 3.82860111, 2.19385475, 2.07353476, 2.01958418,\n", " 4.18760187, 3.45690921, 3.24925035, 3.75190694, 3.62486858,\n", " 3.02259003, 4.32826206, 2.81541278, 2.1645382 , 3.94518814,\n", " 3.23703513, nan, 1.00572035, 3.84502028, 7.40649924,\n", " 4.2236496 , 3.95926042, 4.24145992, 3.148314 , 3.20631198,\n", " 3.42922136, 1.453612 , 1.36810541, 1.66432466, 3.38972546,\n", " 3.73029762, 3.80175446, 2.98606774, 4.77411784, 1.61851756,\n", " nan, 2.4286092 , 4.32317238, 4.07988578, 4.724239 ,\n", " 0.36645681, 0.95957393, 3.37954611, 3.56204741, 4.53795679,\n", " 1.80785358, 2.04944362, 2.21095607, 0.5008243 , 3.34856546,\n", " 4.11653146, 3.58945354, 2.53313268, 3.03955562, 2.3147855 ,\n", " 3.02449018, 3.74143462, 3.74702085, 2.02162005, nan,\n", " 1.69028202, 2.77063555, 8.87436233, 0.89171156, 3.71885796,\n", " 3.91430159, 4.06329151, 3.84734405, 2.78851705, 0.3175959 ,\n", " 3.85334885, 0.72767852, 2.98307204, 0.45196339, 3.07300208,\n", " 2.42472254, 3.71538341, 2.84207612, 3.01148969, 2.3605926 ,\n", " 2.592447 , 0.26873499, 4.07988578, 3.65185426, 5.38691506,\n", " 1.41696632, 2.29820769, 2.92961858, 3.71702169, 2.78470157,\n", " 2.4063997 , 3.87752019, 3.49860947, 1.88419875, 1.91168301,\n", " 5.57380803, 0.46417862, 4.65004946, 10.34629717, 3.52616955,\n", " 2.72677178, 4.95716117, 3.92036929, nan, 1.01691764,\n", " 2.8442686 , 1.42918155, 6.87717274, 3.85512561, 3.78512705,\n", " 0.93324333, 4.78022546, 1.16655417, 4.51596938, 2.91909022,\n", " 1.05923467, 7.51236454, 3.37780107, 3.53630818, 2.20790226,\n", " 2.41128579, 2.31710218, 3.39111843, nan, 4.08865569,\n", " nan, 4.30082206, 1.01793557, 0.92835724, 3.45012297,\n", " 4.29975986, 4.99195606, 3.27368081, 4.25879187, 4.35156928,\n", " 1.18313198, 2.84614787, 3.43247876, 1.91473681, 3.07212956,\n", " 2.20790226, 2.93491185, 3.54880103, nan, 4.01198349,\n", " 2.89908051, 3.77882742, 2.48672407, 0.54561347, 3.76725232,\n", " 4.7700461 , 4.03102487, 3.53070954, 3.42343044, 5.23563417,\n", " 4.52207699, 2.21872939, 3.84016195, 0.50693192, 3.90344361,\n", " 2.54687481, 2.59369984, 2.68522553, nan, 2.19686157,\n", " 0.43567643, 3.66224136, 4.23096885, 3.46778578, 4.00768022,\n", " 0.76345168, 4.1994205 , 2.12544948, 3.63443717, 5.86941652,\n", " 4.29823296, 3.0740788 , 2.87835165, 7.53068738, 3.71081143,\n", " 4.28449083, 1.0444019 , 6.46098251, 3.82641982, nan,\n", " 3.80881553, 1.76347159, 2.75377021, 3.12961298, 3.82038007,\n", " 3.03368752, 0.17101318, 3.36609165, 5.86330891, 3.11830312,\n", " 4.98483051, 2.89644586, 6.21755049, 4.04581173, 0.51711127,\n", " 6.28677011, 0.44585578, 2.14246354, 3.26553732, 4.32785489,\n", " 0.72069839, 5.00824302, 2.26307437, 5.75031806, 3.13795606,\n", " 4.31095716, 2.28813409, 1.39100896, 3.75170335, 5.06372051,\n", " nan, 0.94668008, 3.15763615, 4.14706953, 2.12370445,\n", " 3.33475694, 6.50460832, 4.28088179, 5.07746264, 2.0586729 ,\n", " 2.8485378 , 2.15502319, 3.28436913, nan, 0.12215227,\n", " 1.49297218, 3.7520555 , 3.21464054, 4.59964368, 3.4258159 ,\n", " 2.92351097, 0.57411566, 3.96366662, 3.27775255, 4.23526347,\n", " 3.36804942, 6.44353218, 1.31680146, 3.12709808],\n", " [ 6.8588499 , 5.54396798, 5.28104976, 0.92530344, 6.40444346,\n", " 5.41338138, 7.69559294, 3.33475694, 2.38196924, 4.57663834,\n", " 4.3877095 , 3.302183 , 6.44527722, 1.89336017, nan,\n", " nan, 2.37586163, 6.09234441, nan, 4.8446652 ,\n", " 2.34837737, 2.56926939, 5.2693435 , 8.21474008, 4.18371521,\n", " 4.08314317, 3.56828334, 1.93611346, 4.9532745 , 4.67690499,\n", " 2.54828426, 3.88240628, 5.88638211, 0.09772182, 4.28958051,\n", " 4.52574156, nan, nan, 4.29568812, 8.03761929,\n", " 5.7228338 , 4.52835911, 4.4952035 , 5.43892828, 14.64605704,\n", " 2.43693776, 4.19593044, 4.07729467, 4.73950803, 3.05206169,\n", " 2.57392281, 3.33475694, nan, 4.68759332, nan,\n", " 3.67067568, 5.11643503, 5.06117567, 0.72884187, 5.44554815,\n", " 3.61774303, 5.47494893, 4.73950803, 4.9059405 , nan,\n", " 5.80223277, 5.55548519, 5.00905737, 3.51870389, 6.0419566 ,\n", " 8.83160904, 0.44789165, 3.34253027, 3.86102963, nan,\n", " 3.57702561, 1.91779062, nan, 5.14167089, 5.34619763,\n", " 4.60921228, 2.2862833 , 4.15666721, 5.80494727, 3.97300255,\n", " 3.81115079, 5.06422948, 6.28880598, 6.34768963, 2.93369032,\n", " 5.91216981, 6.77334331, 5.76558709, 3.18003073, 6.07985157,\n", " 1.39864348, 2.62138769, 4.24937205, 3.90200154, 7.22443419,\n", " nan, 4.36490774, 7.8747496 , 2.95608491, 7.65759001,\n", " 5.41134551, nan, 6.3152723 , 4.74525637, nan,\n", " 4.32593535, 5.06321155, 4.47513562, 1.22885182, 6.0877637 ,\n", " 3.96180525, 4.89927034, 3.02204713, 4.7700461 , 4.30434057,\n", " 6.18090481, 5.79307135, 2.76878476, nan, 7.08890334,\n", " 5.8337352 , 5.75581491, 7.69711984, nan, 4.71883611,\n", " 3.81987595, 5.92438504, 4.06034142, nan, 5.29224705,\n", " 4.64681602, 5.53838387, 2.65884772, 5.33805415, 4.40073907,\n", " 5.31769544, 7.06175839, 4.23664786, 5.19757904, 4.84639127,\n", " 4.60291959, 2.43083015, 2.78507173, 7.48269899, 6.89244177,\n", " 3.85445932, 3.88256288, 5.24895485, nan, 6.75705634,\n", " 2.91222114, 5.28104976, 9.71110538, 2.99028754, 3.68899852,\n", " 2.92990942, 5.51163895, 6.94741029, 4.42343904, 7.06650876,\n", " 5.18841762, nan, 3.62181477, 2.77692825, 3.79893556,\n", " 4.64178622, 3.85919735, nan, 5.91949895, 2.73621082,\n", " 3.60145606, 5.25254756, 4.2264685 , 5.22113698, 4.72240672,\n", " 4.48434552, 4.07683197, 3.99437919, 3.61355153, 3.48541141,\n", " 3.11488286, 5.2250633 , 2.15232298, 4.75172326, 1.69791654,\n", " 5.98546118, 1.45768374, nan, 2.53924029, 4.57460247,\n", " 5.43821901, 5.90266908, 0.29316545, 2.93979794, nan,\n", " 4.58071008, 5.4052379 , 4.17594188, nan, 5.35026938,\n", " 5.09258626, 3.61448564, 11.89763099, 6.38449192, 1.85060687,\n", " nan, 6.32298718, 1.05050951, 4.97770496, 4.94161451,\n", " 5.24643995, 5.96510246, 5.93660027, 1.39253587, nan,\n", " 2.42472254, 4.95938212, 6.46999851, 1.453612 , 1.36810541,\n", " 2.89500877, 4.72322106, 3.62894032, 4.30208657, nan,\n", " 4.04866909, 4.58071008, 4.32351169, 6.9219619 , 4.61588994,\n", " 5.32583892, 6.63592201, nan, 4.69919778, 3.70854288,\n", " 4.58071008, 9.84896294, 4.9960278 , 1.85322442, 3.38768959,\n", " 4.84333746, 4.09454405, 2.35420736, 2.02772766, nan,\n", " nan, 5.57625107, 2.49190629, nan, 2.80034076,\n", " 2.63848901, 5.91216981, 4.79994126, 5.59457392],\n", " [ 4.11277293, 3.94991577, 3.37893968, 3.13524157, 5.32865782,\n", " 4.02578978, 2.64052488, 2.07658857, 4.68453951, nan,\n", " 5.04582834, 3.85797583, 3.6355569 , 4.76149544, 2.86447071,\n", " nan, 4.15026875, 4.47484478, 3.74763161, 4.71536165,\n", " 2.05826573, nan, 3.48541141, 4.70286235, 4.30098139,\n", " 3.68390884, 4.86104954, 2.9182177 , 4.44557914, 3.75507179,\n", " 3.68946834, 2.36839677, 4.54057434, 1.97886676, 4.21968227,\n", " 4.04647354, 3.33359359, nan, 4.75715225, 3.01716104,\n", " 4.69064713, 3.9115871 , 2.49434933, 3.73785943, 2.55053937,\n", " 6.67358562, 2.95404904, 5.42382064, 4.21049475, 3.00441472,\n", " 4.17854723, 4.33466051, nan, 6.65322691, 2.82375328,\n", " 4.6784319 , 4.12492943, 5.71184009, nan, 4.18100071,\n", " 3.55288599, 3.76086951, 3.80324682, 4.51023762, 4.65400144,\n", " 4.10724789, 4.12392489, 3.83319778, 4.82135005, 5.45148126,\n", " 2.79660833, 1.36403367, 3.79893556, 3.36325914, 3.04973498,\n", " 5.35075799, nan, 4.34862077, 3.48291582, 3.52964533,\n", " 8.43461417, 5.64343482, 4.58071008, 3.51416809, 5.6570595 ,\n", " nan, 4.60061638, 3.6713075 , 4.32627585, 4.09304064,\n", " 2.88007905, 15.59884474, 0.58225915, 3.44537261, 4.65970188,\n", " 2.97807232, 2.63604596, 4.07135817, 6.1035417 , 4.2421738 ,\n", " 2.38196924, 3.50228005, nan, 4.01392356, 4.4659742 ,\n", " 2.87179984, 9.25914198, 8.79496336, 4.15317714, 3.24619655,\n", " 3.65545512, 5.73640627, 3.82162098, 2.42777634, 4.21444717,\n", " 8.09258781, 3.82995836, 0.46417862, 1.28259882, 3.40397656,\n", " 2.28424743, 8.53030011, 3.6055278 , nan, 4.22937689,\n", " 4.28690173, 3.10615769, 3.51870389, nan, 4.94411308,\n", " 3.54627324, 3.12954113, 4.1776076 , 7.48386234, 4.57296384,\n", " 3.10140399, 5.02387851, 1.53911859, 6.19922765, 4.36981778,\n", " 2.07658857, 3.42716779, 3.82511105, 8.42697965, 5.25814621,\n", " 4.93058908, 11.18914783, 5.35026938, 6.03432208, 3.44425772,\n", " 3.82071053, 4.94988138, 4.36897948, 2.44711712, 4.70474162,\n", " 3.65693355, 2.37518301, 3.48948315, 2.41250731, 1.78342313,\n", " 3.23189187, 4.97788459, 4.05704862, 4.43005562, nan,\n", " 6.42520934, 2.75249779, nan, nan, 5.57537856,\n", " 2.69142166, 4.41754955, 5.32176718, 5.63636285, 4.62346338,\n", " 2.30867788, 2.79395553, 4.27088751, 3.79649252, 2.97644362,\n", " 4.85310964, 5.39607648, 1.71013176, 2.79030683, nan,\n", " 4.52166982, 4.02350781, 6.16461784, nan, 4.3552236 ,\n", " 6.34581037, 5.37714288, 3.46135111, 3.71037517, 4.27908794,\n", " 5.65658968, 4.55976969, 6.58400729, 3.91123684, 8.65448825,\n", " 0.48860908, 3.97370727, 4.26893096, 1.25206076, 6.47407025,\n", " 3.4710037 , 4.98457602, 2.84933445, 3.47455343, 4.98381257,\n", " 4.00863029, 3.94943638, 2.32496485, nan, 5.0268567 ,\n", " 4.87509705, 3.06689447, 3.85785607, 3.10642616, 4.34404006,\n", " 3.21472906, 3.77503621, 3.87397196, 3.52612883, nan,\n", " 6.22976571, 5.20900619, 5.23596975, 3.4900189 , 4.31916052,\n", " 5.53502468, 3.93493176, 4.90659489, 4.65535869, 4.12407616,\n", " 5.26679866, 4.62941637, nan, 3.48215401, 3.99597248,\n", " 5.23422472, 5.2265902 , 3.47645357, 2.04197876, 2.53465958,\n", " 5.20368665, 5.5964062 , 4.15046265, 4.24438417, nan,\n", " 5.9060622 , 3.0873986 , 4.71813139, 2.80339457, 4.01270203,\n", " 2.84207612, 4.09491991, 4.48214584, 3.64353073]])"]}, "execution_count": 15, "metadata": {}, "output_type": "execute_result"}], "source": ["mid_dwell_mask = bdata.models[2].dwell_pos == 0\n", "mid_dwell_nano_mean = bdata.models[2].dwell_nano_mean[:, mid_dwell_mask]\n", "\n", "mid_dwell_nano_mean"]}, {"cell_type": "raw", "id": "16ce4365", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["Of course, you probably want to look at just on photon stream\u2019s nanomean, more often than not this will be the D :sub:`ex`\\ D\\ :sub:`em`\\ stream, which for this data is the 0th stream. \n", "\n", "So to get this we would execute the following:"]}, {"cell_type": "code", "execution_count": 16, "id": "547cea7d", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([ 5.28919324, 3.02778298, 3.07976408, 4.42869837, 1.83839165,\n", " 2.11497928, 2.99796568, nan, 2.2720322 , 3.53096402,\n", " 3.91131565, 5.02676288, 0.80131888, 4.31401096, 2.71656024,\n", " 4.09526792, 3.82860111, 2.19385475, 2.07353476, 2.01958418,\n", " 4.18760187, 3.45690921, 3.24925035, 3.75190694, 3.62486858,\n", " 3.02259003, 4.32826206, 2.81541278, 2.1645382 , 3.94518814,\n", " 3.23703513, nan, 1.00572035, 3.84502028, 7.40649924,\n", " 4.2236496 , 3.95926042, 4.24145992, 3.148314 , 3.20631198,\n", " 3.42922136, 1.453612 , 1.36810541, 1.66432466, 3.38972546,\n", " 3.73029762, 3.80175446, 2.98606774, 4.77411784, 1.61851756,\n", " nan, 2.4286092 , 4.32317238, 4.07988578, 4.724239 ,\n", " 0.36645681, 0.95957393, 3.37954611, 3.56204741, 4.53795679,\n", " 1.80785358, 2.04944362, 2.21095607, 0.5008243 , 3.34856546,\n", " 4.11653146, 3.58945354, 2.53313268, 3.03955562, 2.3147855 ,\n", " 3.02449018, 3.74143462, 3.74702085, 2.02162005, nan,\n", " 1.69028202, 2.77063555, 8.87436233, 0.89171156, 3.71885796,\n", " 3.91430159, 4.06329151, 3.84734405, 2.78851705, 0.3175959 ,\n", " 3.85334885, 0.72767852, 2.98307204, 0.45196339, 3.07300208,\n", " 2.42472254, 3.71538341, 2.84207612, 3.01148969, 2.3605926 ,\n", " 2.592447 , 0.26873499, 4.07988578, 3.65185426, 5.38691506,\n", " 1.41696632, 2.29820769, 2.92961858, 3.71702169, 2.78470157,\n", " 2.4063997 , 3.87752019, 3.49860947, 1.88419875, 1.91168301,\n", " 5.57380803, 0.46417862, 4.65004946, 10.34629717, 3.52616955,\n", " 2.72677178, 4.95716117, 3.92036929, nan, 1.01691764,\n", " 2.8442686 , 1.42918155, 6.87717274, 3.85512561, 3.78512705,\n", " 0.93324333, 4.78022546, 1.16655417, 4.51596938, 2.91909022,\n", " 1.05923467, 7.51236454, 3.37780107, 3.53630818, 2.20790226,\n", " 2.41128579, 2.31710218, 3.39111843, nan, 4.08865569,\n", " nan, 4.30082206, 1.01793557, 0.92835724, 3.45012297,\n", " 4.29975986, 4.99195606, 3.27368081, 4.25879187, 4.35156928,\n", " 1.18313198, 2.84614787, 3.43247876, 1.91473681, 3.07212956,\n", " 2.20790226, 2.93491185, 3.54880103, nan, 4.01198349,\n", " 2.89908051, 3.77882742, 2.48672407, 0.54561347, 3.76725232,\n", " 4.7700461 , 4.03102487, 3.53070954, 3.42343044, 5.23563417,\n", " 4.52207699, 2.21872939, 3.84016195, 0.50693192, 3.90344361,\n", " 2.54687481, 2.59369984, 2.68522553, nan, 2.19686157,\n", " 0.43567643, 3.66224136, 4.23096885, 3.46778578, 4.00768022,\n", " 0.76345168, 4.1994205 , 2.12544948, 3.63443717, 5.86941652,\n", " 4.29823296, 3.0740788 , 2.87835165, 7.53068738, 3.71081143,\n", " 4.28449083, 1.0444019 , 6.46098251, 3.82641982, nan,\n", " 3.80881553, 1.76347159, 2.75377021, 3.12961298, 3.82038007,\n", " 3.03368752, 0.17101318, 3.36609165, 5.86330891, 3.11830312,\n", " 4.98483051, 2.89644586, 6.21755049, 4.04581173, 0.51711127,\n", " 6.28677011, 0.44585578, 2.14246354, 3.26553732, 4.32785489,\n", " 0.72069839, 5.00824302, 2.26307437, 5.75031806, 3.13795606,\n", " 4.31095716, 2.28813409, 1.39100896, 3.75170335, 5.06372051,\n", " nan, 0.94668008, 3.15763615, 4.14706953, 2.12370445,\n", " 3.33475694, 6.50460832, 4.28088179, 5.07746264, 2.0586729 ,\n", " 2.8485378 , 2.15502319, 3.28436913, nan, 0.12215227,\n", " 1.49297218, 3.7520555 , 3.21464054, 4.59964368, 3.4258159 ,\n", " 2.92351097, 0.57411566, 3.96366662, 3.27775255, 4.23526347,\n", " 3.36804942, 6.44353218, 1.31680146, 3.12709808])"]}, "execution_count": 16, "metadata": {}, "output_type": "execute_result"}], "source": ["mid_dwell_mask = bdata.models[2].dwell_pos == 0\n", "mid_dwell_nano_mean_DD = bdata.models[2].dwell_nano_mean[0, mid_dwell_mask]\n", "mid_dwell_nano_mean_DD"]}, {"cell_type": "raw", "id": "1f4b0739", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["You could also isolate a particular state using the :attr:`H2MM_result.dwell_state ` parameter to make another mask:"]}, {"cell_type": "code", "execution_count": 17, "id": "0604e2c7", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([3.02778298, 4.42869837, 2.11497928, 2.99796568, 2.2720322 ,\n", " 5.02676288, 4.31401096, 3.82860111, 2.07353476, 2.81541278,\n", " 3.94518814, 4.2236496 , 3.95926042, 3.148314 , 3.42922136,\n", " 3.38972546, 3.80175446, 4.77411784, 2.4286092 , 4.724239 ,\n", " 4.53795679, 2.21095607, 3.34856546, 3.58945354, 3.03955562,\n", " 3.02449018, nan, 8.87436233, 3.71885796, 3.84734405,\n", " 2.78851705, 2.98307204, 3.07300208, 3.01148969, 2.592447 ,\n", " 4.07988578, 1.41696632, 3.71702169, 2.78470157, 1.91168301,\n", " 4.65004946, 3.52616955, 2.72677178, 2.8442686 , 3.78512705,\n", " 4.78022546, 2.91909022, 3.37780107, 3.53630818, 2.31710218,\n", " 4.08865569, 4.30082206, 3.45012297, 3.27368081, 4.35156928,\n", " 1.91473681, 2.93491185, 3.77882742, 2.48672407, 4.7700461 ,\n", " 4.03102487, 5.23563417, 4.52207699, 3.84016195, 2.68522553,\n", " 2.19686157, 3.66224136, 4.1994205 , 4.29823296, 2.87835165,\n", " 3.71081143, 6.46098251, nan, 1.76347159, 3.36609165,\n", " 4.98483051, 6.21755049, 2.14246354, 3.26553732, 4.32785489,\n", " 5.00824302, 2.26307437, 5.75031806, 5.06372051, 4.14706953,\n", " 3.33475694, 2.0586729 , 2.15502319, 3.28436913, 1.49297218,\n", " 3.7520555 , 4.59964368, 2.92351097, 3.27775255, 3.12709808])"]}, "execution_count": 17, "metadata": {}, "output_type": "execute_result"}], "source": ["mid_dwell_mask = bdata.models[2].dwell_pos == 0\n", "state1_mask = bdata.models[2].dwell_state == 1\n", "comb_mask = mid_dwell_mask * state1_mask\n", "state1_mid_nano_mean_DD = bdata.models[2].dwell_nano_mean[0, comb_mask]\n", "state1_mid_nano_mean_DD"]}, {"cell_type": "raw", "id": "5fdd6330", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["Thus you can have a great deal of customization. \n", "\n", "Example: Calculate variance of state 1 dwell E values\n", "=====================================================\n", "\n", "\n", "Let\u2019s put this into practice. \n", "Let\u2019s say you want to know how tightly a given state\u2019s dwell cluster around a given value. The steps would be simple:\n", "\n", "1. Make mask of dwells in that state\n", "\n", "2. Get E values of those dwells using mask\n", "\n", "3. Calculate standard deviation (or whatever other value is of interest)\n", "\n", "So lets see this in code:"]}, {"cell_type": "code", "execution_count": 18, "id": "d09d9636", "metadata": {}, "outputs": [{"data": {"text/plain": ["0.12135964925716479"]}, "execution_count": 18, "metadata": {}, "output_type": "execute_result"}], "source": ["# make mask of dwells in state 1\n", "state1_mask = bdata.models[2].dwell_state == 1\n", "# get E values\n", "state1_E = bdata.models[2].dwell_E[state1_mask]\n", "# calculate standard deviation\n", "np.nanstd(state1_E)"]}, {"cell_type": "raw", "id": "3bcc8d35", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": [".. note::\n", "\n", " We used np.nanstd, as dwells with no D :sub:`ex`\\ D\\ :sub:`em`\\ or D\\ :sub:`ex`\\ A\\ :sub:`em`\\ photons will have nan values, so we must exclude them to get a result that is not nan\n", "\n", ".. _usemaskfunc:\n", "\n", "\n", "Using masking functions to make masks\n", "=====================================\n", "\n", "\n", "\n", "burstH2MM also provides a set of masking functions in the :mod:`Masking ` module. \n", "They are named descriptively, and simply take a :class:`H2MM_list ` object as input. \n", "So we can get the mid dwell mask like this:"]}, {"cell_type": "code", "execution_count": 19, "id": "bc03de06", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([False, False, True, ..., False, False, False])"]}, "execution_count": 19, "metadata": {}, "output_type": "execute_result"}], "source": ["mid_dwell_mask = bhm.mid_dwell(bdata.models[2])\n", "mid_dwell_mask"]}, {"cell_type": "raw", "id": "12ecef49", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["These functions can be used to filter which dwells are shown in various plotting functions, which is their primary use in burstH2MM. See Plotting only dwells of certain position and other masking for a demonstration of thier use in plotting. \n", "\n", ".. _burstbasedarrays:\n", "\n", "\n", "Burst Based Arrays\n", "******************\n", "\n", "\n", "\n", "In the list of attributes, you will notice two burst as opposed to dwell based attributes :attr:`H2MM_result.burst_state_counts ` and :attr:`H2MM_result.burst_type ` \n", "\n", "These arrays are based not on dwells, but on the bursts instead. \n", ":attr:`H2MM_result.burst_state_counts ` is the larger, but ironically easier to understand of these arrays. \n", "Going down the rows, you go through different states, each element indicating the number of dwells in that state, each column a different state."]}, {"cell_type": "code", "execution_count": 20, "id": "ba431ec8", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([[0, 2, 0, ..., 0, 0, 0],\n", " [0, 3, 0, ..., 0, 0, 1],\n", " [1, 0, 1, ..., 1, 1, 1]])"]}, "execution_count": 20, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[2].burst_state_counts"]}, {"cell_type": "raw", "id": "ebce198e", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["So for instance, the :attr:`H2MM_result.burst_state_counts ` \\[1,23\\] will tell you how many dwells there were in state 1 burst 23.\n", "\n", ":attr:`H2MM_result.burst_type ` is essentially a simplification of :attr:`H2MM_result.burst_state_counts ` where it no longer matters how many dwells in a given state are present, just whether there is at least one instance of a given state. \n", "It represents this in a binary form, so a burst with only State0 will take the value ``0b1`` , while only State1 will have ``0b10`` , and a dwell with transitions between State0 and State1 will be represented as ``0b11`` . \n", "Of course, python usually doesn\u2019t display things in binary, so these will become 1, 2 and 3 when acutally displayed."]}, {"cell_type": "code", "execution_count": 21, "id": "aadd2099", "metadata": {}, "outputs": [{"data": {"text/plain": ["array([4, 3, 4, ..., 4, 4, 6])"]}, "execution_count": 21, "metadata": {}, "output_type": "execute_result"}], "source": ["bdata.models[2].burst_type"]}, {"cell_type": "raw", "id": "9ae6da01", "metadata": {"raw_mimetype": "text/restructuredtext"}, "source": ["That's the end of this How-To, thank you for using burstH2MM. ", "\n", "\n", "Download this documentation as a jupyter notebook here: :download:`ResultsAccess.ipynb `"]}], "metadata": {"kernelspec": {"display_name": "Python 3 (ipykernel)", "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.9.12"}}, "nbformat": 4, "nbformat_minor": 5}